KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jk > config > GeneratorJk2


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.jk.config;
18
19 import java.io.File JavaDoc;
20 import java.io.FileWriter JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.PrintWriter JavaDoc;
23 import java.util.Vector JavaDoc;
24
25
26 /* Naming conventions:
27
28 JK_CONF_DIR == serverRoot/work ( XXX /jkConfig ? )
29
30 - Each vhost has a sub-dir named after the canonycal name
31
32 - For each webapp in a vhost, there is a separate WEBAPP_NAME.jkmap
33
34 - In httpd.conf ( or equivalent servers ), in each virtual host you
35 should "Include JK_CONF_DIR/VHOST/jk_apache.conf". The config
36 file will contain the Alias declarations and other rules required
37 for apache operation. Same for other servers.
38
39 - WebXml2Jk will be invoked by a config tool or automatically for each
40 webapp - it'll generate the WEBAPP.jkmap files and config fragments.
41
42 WebXml2Jk will _not_ generate anything else but mappings.
43 It should _not_ try to guess locations or anything else - that's
44 another components' job.
45
46 */

47
48 /**
49  *
50  * @author Costin Manolache
51  */

52 public class GeneratorJk2 implements WebXml2Jk.MappingGenerator {
53     WebXml2Jk wxml;
54     String JavaDoc vhost;
55     String JavaDoc cpath;
56     String JavaDoc worker;
57     PrintWriter JavaDoc out;
58     
59     public void setWebXmlReader(WebXml2Jk wxml ) {
60         this.wxml=wxml;
61         vhost=wxml.vhost;
62         cpath=wxml.cpath;
63         worker=wxml.worker;
64     }
65
66     public void generateStart( ) throws IOException JavaDoc {
67         File JavaDoc base=wxml.getJkDir();
68         File JavaDoc outF=new File JavaDoc(base, "jk2map.properties");
69         out=new PrintWriter JavaDoc( new FileWriter JavaDoc( outF ));
70
71         out.println("# Autogenerated from web.xml" );
72     }
73
74     public void generateEnd() {
75         out.close();
76     }
77     
78     public void generateServletMapping( String JavaDoc servlet, String JavaDoc url ) {
79         out.println( "[uri:" + vhost + cpath + url + "]");
80         out.println( "group=" + worker );
81         out.println( "servlet=" + servlet);
82         out.println( "host=" + vhost);
83         out.println( "context=" + cpath);
84         out.println();
85     }
86
87     public void generateFilterMapping( String JavaDoc servlet, String JavaDoc url ) {
88         out.println( "[url:" + vhost + cpath + url + "]");
89         out.println( "group=" + worker );
90         out.println( "filter=" + servlet);
91         out.println( "host=" + vhost);
92         out.println( "context=" + cpath);
93         out.println();
94     }
95
96     public void generateLoginConfig( String JavaDoc loginPage,
97                                         String JavaDoc errPage, String JavaDoc authM ) {
98         out.println("[url:" + vhost + cpath + loginPage + "]" );
99         out.println( "group=" + worker );
100         out.println( "host=" + vhost);
101         out.println( "context=" + cpath);
102         out.println();
103         out.println("[url:" + vhost + cpath + errPage + "]" );
104         out.println( "group=" + worker );
105         out.println( "host=" + vhost);
106         out.println( "context=" + cpath);
107         out.println();
108     }
109
110     public void generateErrorPage( int err, String JavaDoc location ) {
111
112     }
113
114     public void generateMimeMapping( String JavaDoc ext, String JavaDoc type ) {
115
116     }
117     
118     public void generateWelcomeFiles( Vector JavaDoc wf ) {
119
120     }
121                                             
122     
123     public void generateConstraints( Vector JavaDoc urls, Vector JavaDoc methods, Vector JavaDoc roles, boolean isSSL ) {
124         for( int i=0; i<urls.size(); i++ ) {
125             String JavaDoc url=(String JavaDoc)urls.elementAt(i);
126
127             out.println("[url:" + vhost + cpath + url + "]");
128             out.println( "group=" + worker );
129             out.println( "host=" + vhost);
130             out.println( "context=" + cpath);
131             for( int j=0; j<roles.size(); j++ ) {
132                 String JavaDoc role=(String JavaDoc)roles.elementAt(j);
133                 out.println( "role=" + role);
134             }
135             for( int j=0; j<methods.size(); j++ ) {
136                 String JavaDoc m=(String JavaDoc)methods.elementAt(j);
137                 out.println( "method=" + m);
138             }
139             if( isSSL )
140                 out.println("ssl=true");
141         }
142     }
143 }
144
Popular Tags