001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.jk.config;
019:
020: import java.io.File;
021: import java.io.FileWriter;
022: import java.io.IOException;
023: import java.io.PrintWriter;
024: import java.util.Vector;
025:
026: /* Naming conventions:
027:
028: JK_CONF_DIR == serverRoot/work ( XXX /jkConfig ? )
029:
030: - Each vhost has a sub-dir named after the canonycal name
031:
032: - For each webapp in a vhost, there is a separate WEBAPP_NAME.jkmap
033:
034: - In httpd.conf ( or equivalent servers ), in each virtual host you
035: should "Include JK_CONF_DIR/VHOST/jk_apache.conf". The config
036: file will contain the Alias declarations and other rules required
037: for apache operation. Same for other servers.
038:
039: - WebXml2Jk will be invoked by a config tool or automatically for each
040: webapp - it'll generate the WEBAPP.jkmap files and config fragments.
041:
042: WebXml2Jk will _not_ generate anything else but mappings.
043: It should _not_ try to guess locations or anything else - that's
044: another components' job.
045:
046: */
047:
048: /**
049: *
050: * @author Costin Manolache
051: */
052: public class GeneratorJk2 implements WebXml2Jk.MappingGenerator {
053: WebXml2Jk wxml;
054: String vhost;
055: String cpath;
056: String worker;
057: PrintWriter out;
058:
059: public void setWebXmlReader(WebXml2Jk wxml) {
060: this .wxml = wxml;
061: vhost = wxml.vhost;
062: cpath = wxml.cpath;
063: worker = wxml.worker;
064: }
065:
066: public void generateStart() throws IOException {
067: File base = wxml.getJkDir();
068: File outF = new File(base, "jk2map.properties");
069: out = new PrintWriter(new FileWriter(outF));
070:
071: out.println("# Autogenerated from web.xml");
072: }
073:
074: public void generateEnd() {
075: out.close();
076: }
077:
078: public void generateServletMapping(String servlet, String url) {
079: out.println("[uri:" + vhost + cpath + url + "]");
080: out.println("group=" + worker);
081: out.println("servlet=" + servlet);
082: out.println("host=" + vhost);
083: out.println("context=" + cpath);
084: out.println();
085: }
086:
087: public void generateFilterMapping(String servlet, String url) {
088: out.println("[url:" + vhost + cpath + url + "]");
089: out.println("group=" + worker);
090: out.println("filter=" + servlet);
091: out.println("host=" + vhost);
092: out.println("context=" + cpath);
093: out.println();
094: }
095:
096: public void generateLoginConfig(String loginPage, String errPage,
097: String authM) {
098: out.println("[url:" + vhost + cpath + loginPage + "]");
099: 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 location) {
111:
112: }
113:
114: public void generateMimeMapping(String ext, String type) {
115:
116: }
117:
118: public void generateWelcomeFiles(Vector wf) {
119:
120: }
121:
122: public void generateConstraints(Vector urls, Vector methods,
123: Vector roles, boolean isSSL) {
124: for (int i = 0; i < urls.size(); i++) {
125: String url = (String) 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 role = (String) roles.elementAt(j);
133: out.println("role=" + role);
134: }
135: for (int j = 0; j < methods.size(); j++) {
136: String m = (String) methods.elementAt(j);
137: out.println("method=" + m);
138: }
139: if (isSSL)
140: out.println("ssl=true");
141: }
142: }
143: }
|