1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jelly.tags.jetty;
18
19 import org.apache.commons.jelly.JellyTagException;
20 import org.apache.commons.jelly.TagSupport;
21 import org.apache.commons.jelly.XMLOutput;
22
23 import org.mortbay.http.HashUserRealm;
24
25 import java.io.IOException;
26 import java.net.URL;
27
28 /***
29 * Declare a user realm for a Jetty http server
30 *
31 * @author rtl
32 * @version $Id: RealmTag.java,v 1.3 2002/07/14 12:38:22 dion Exp $
33 */
34 public class RealmTag extends TagSupport {
35
36 /*** parameter name with default*/
37 private String _name;
38
39 /*** parameter config, with default */
40 private String _config;
41
42 /*** Creates a new instance of RealmTag */
43 public RealmTag() {
44 }
45
46 /***
47 * Perform the tag functionality. In this case, add a realm with the
48 * specified name using the specified config (preperties) file to the
49 * parent server,
50 *
51 * @param xmlOutput where to send output
52 * @throws Exception when an error occurs
53 */
54 public void doTag(XMLOutput xmlOutput) throws JellyTagException {
55 JettyHttpServerTag httpserver = (JettyHttpServerTag) findAncestorWithClass(
56 JettyHttpServerTag.class);
57 if ( httpserver == null ) {
58 throw new JellyTagException( "<realm> tag must be enclosed inside a <server> tag" );
59 }
60 if (null == getName() || null == getConfig()) {
61 throw new JellyTagException( "<realm> tag must have a name and a config" );
62 }
63
64
65
66 try {
67 URL configURL = getContext().getResource(getConfig());
68 httpserver.addRealm( new HashUserRealm(getName(), configURL.toString() ) );
69 } catch (IOException e) {
70 throw new JellyTagException(e);
71 }
72
73 invokeBody(xmlOutput);
74 }
75
76
77
78
79
80 /***
81 * Getter for property name.
82 *
83 * @return value of property name.
84 */
85 public String getName() {
86 return _name;
87 }
88
89 /***
90 * Setter for property name.
91 *
92 * @param name New value of property name.
93 */
94 public void setName(String name) {
95 _name = name;
96 }
97
98 /***
99 * Getter for property config.
100 *
101 * @return value of property config.
102 */
103 public String getConfig() {
104 return _config;
105 }
106
107 /***
108 * Setter for property config.
109 *
110 * @param config New value of property config.
111 */
112 public void setConfig(String config) {
113 _config = config;
114 }
115
116 }