1 16 17 package org.apache.jk.config; 18 19 import java.io.File ; 20 import java.io.FileWriter ; 21 import java.io.IOException ; 22 import java.io.PrintWriter ; 23 import java.util.Vector ; 24 25 import org.w3c.dom.Node ; 26 27 28 49 50 54 public class GeneratorApache2 implements WebXml2Jk.MappingGenerator { 55 WebXml2Jk wxml; 56 String vhost; 57 String cpath; 58 String worker; 59 PrintWriter out; 60 61 public void setWebXmlReader(WebXml2Jk wxml ) { 62 this.wxml=wxml; 63 vhost=wxml.vhost; 64 cpath=wxml.cpath; 65 worker=wxml.worker; 66 } 67 68 public void generateStart() throws IOException { 69 File base=wxml.getJkDir(); 70 File outF=new File (base, "jk2.conf"); 71 out=new PrintWriter ( new FileWriter ( outF )); 72 73 out.println("# Must be included in a virtual host context for " + vhost ); 74 75 out.println("Alias " + cpath + " \"" + wxml.docBase + "\""); 76 out.println("<Directory \"" + wxml.docBase + "\" >"); 77 out.println(" Options Indexes FollowSymLinks"); 78 generateMimeMapping( out ); 79 generateWelcomeFiles( out); 80 81 out.println(" AddHandler jakarta-servlet2 .jsp"); 84 out.println("</Directory>"); 85 out.println(); 86 87 out.println("<Location \"" + cpath + "/WEB-INF\" >"); 88 out.println(" AllowOverride None"); 89 out.println(" Deny from all"); 90 out.println("</Location>"); 91 out.println(); 92 out.println("<Location \"" + cpath + "/META-INF\" >"); 93 out.println(" AllowOverride None"); 94 out.println(" Deny from all"); 95 out.println("</Location>"); 96 out.println(); 97 } 98 99 private void generateWelcomeFiles( PrintWriter out ) { 100 Vector wf= wxml.getWellcomeFiles(); 101 out.print(" DirectoryIndex "); 102 for( int i=0; i<wf.size(); i++ ) { 103 out.print( " " + (String )wf.elementAt(i)); 104 } 105 out.println(); 106 } 107 108 private void generateMimeMapping( PrintWriter out ) { 109 Node webN=wxml.getWebXmlNode(); 110 for( Node mapN=WebXml2Jk.getChild( webN, "mime-mapping" ); 111 mapN != null; mapN = WebXml2Jk.getNext( mapN ) ) { 112 String ext=WebXml2Jk.getChildContent( mapN, "extension" ); 113 String type=WebXml2Jk.getChildContent( mapN, "mime-type" ); 114 115 out.println(" AddType " + type + " " + ext ); 116 } 117 118 119 } 120 121 public void generateEnd() { 122 out.close(); 123 } 124 125 public void generateServletMapping( String servlet, String url ) { 126 out.println( "<Location \"" + cpath + url + "\" >"); 127 out.println( " SetHandler jakarta-servlet2" ); 128 out.println( " JkUriSet group " + worker ); 129 out.println( " JkUriSet servlet " + servlet); 130 out.println( " JkUriSet host " + vhost ); 131 out.println( " JkUriSet context " + cpath ); 132 out.println( "</Location>"); 133 out.println(); 134 } 135 136 public void generateFilterMapping( String servlet, String url ) { 137 out.println( "<Location \"" + cpath + url + "\" >"); 138 out.println( " SetHandler jakarta-servlet2" ); 139 out.println( " JkUriSet group " + worker ); 140 out.println( " JkUriSet servlet " + servlet); 141 out.println( " JkUriSet host " + vhost ); 142 out.println( " JkUriSet context " + cpath ); 143 out.println( "</Location>"); 144 out.println(); 145 } 146 147 public void generateLoginConfig( String loginPage, 148 String errPage, String authM ) { 149 out.println( "<Location \"" + cpath + loginPage + "\" >"); 150 out.println( " SetHandler jakarta-servlet2" ); 151 out.println( " JkUriSet group " + worker ); 152 out.println( " JkUriSet host " + vhost ); 153 out.println( " JkUriSet context " + cpath ); 154 out.println( "</Location>"); 155 out.println(); 156 } 157 158 public void generateErrorPage( int err, String location ) { 159 160 } 161 162 public void generateConstraints( Vector urls, Vector methods, Vector roles, boolean isSSL ) { 164 for( int i=0; i<urls.size(); i++ ) { 165 String url=(String )urls.elementAt(i); 166 167 out.println( "<Location \"" + cpath + url + "\" >"); 168 169 if( methods.size() > 0 ) { 170 out.print(" <Limit "); 171 for( int j=0; j<methods.size(); j++ ) { 172 String m=(String )methods.elementAt(j); 173 out.print( " " + m); 174 } 175 out.println( " >" ); 176 } 177 178 out.println( " AuthType basic" ); 179 out.print( " Require group " ); 180 for( int j=0; j<roles.size(); j++ ) { 181 String role=(String )roles.elementAt(j); 182 out.print( " " + role); 183 } 184 out.println(); 185 186 if( methods.size() > 0 ) { 187 out.println(" </Limit>"); 188 } 189 190 out.println( "</Location>"); 191 } 192 } 193 } 194 | Popular Tags |