|
What this is
Other links
The source code
/*
* $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/CommandLineCompiler.java,v 1.10 2004/02/23 06:22:36 billbarker Exp $
* $Revision: 1.10 $
* $Date: 2004/02/23 06:22:36 $
*
*
* Copyright 1999-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jasper.compiler;
import java.io.File;
import org.apache.jasper.CommandLineContext;
import org.apache.jasper.Constants;
/**
* Overrides some methods so that we get the desired effects.
*@author Danno Ferrin
*/
public class CommandLineCompiler extends Compiler implements Mangler {
String javaFileName;
String classFileName;
String pkgName;
String className;
File jsp;
String outputDir;
public CommandLineCompiler(CommandLineContext ctxt) {
super(ctxt);
jsp = new File(ctxt.getJspFile());
outputDir = ctxt.getOptions().getScratchDir().getAbsolutePath();
setMangler(this);
computePackageName();
ctxt.setServletPackageName(pkgName);
className = getBaseClassName();
// yes this is kind of messed up ... but it works
if (ctxt.isOutputInDirs()) {
String pkgName = ctxt.getServletPackageName();
if (pkgName == null) {
pkgName = "";
}
String tmpDir = outputDir
+ File.separatorChar
+ pkgName.replace('.', File.separatorChar);
File f = new File(tmpDir);
if (!f.exists()) {
if (f.mkdirs()) {
outputDir = tmpDir;
}
} else {
outputDir = tmpDir;
}
}
computeClassFileName();
computeJavaFileName();
}
/**
* Always outDated. (Of course we are, this is an explicit invocation
*@returns true
*/
public boolean isOutDated() {
return true;
}
public final void computeJavaFileName() {
javaFileName = ctxt.getServletClassName() + ".java";
if ("null.java".equals(javaFileName)) {
javaFileName = getBaseClassName() + ".java";
};
if (outputDir != null && !outputDir.equals(""))
javaFileName = outputDir + File.separatorChar + javaFileName;
}
void computeClassFileName() {
String prefix = getPrefix(jsp.getPath());
classFileName = prefix + getBaseClassName() + ".class";
if (outputDir != null && !outputDir.equals(""))
classFileName = outputDir + File.separatorChar + classFileName;
}
public static String [] keywords = {
"abstract", "boolean", "break", "byte",
"case", "catch", "char", "class",
"const", "continue", "default", "do",
"double", "else", "extends", "final",
"finally", "float", "for", "goto",
"if", "implements", "import",
"instanceof", "int", "interface",
"long", "native", "new", "package",
"private", "protected", "public",
"return", "short", "static", "super",
"switch", "synchronized", "this",
"throw", "throws", "transient",
"try", "void", "volatile", "while"
};
void computePackageName() {
String pathName = jsp.getPath();
StringBuffer modifiedpkgName = new StringBuffer ();
int indexOfSepChar = pathName.lastIndexOf(File.separatorChar);
if (("".equals(ctxt.getServletPackageName())) ||
(indexOfSepChar == -1) || (indexOfSepChar == 0)) {
pkgName = null;
} else {
for (int i = 0; i < keywords.length; i++) {
char fs = File.separatorChar;
int index;
if (pathName.startsWith(keywords[i] + fs)) {
index = 0;
} else {
index = pathName.indexOf(fs + keywords[i] + fs);
}
while (index != -1) {
String tmpathName = pathName.substring (0,index+1) + '%';
pathName = tmpathName + pathName.substring (index+2);
index = pathName.indexOf(fs + keywords[i] + fs);
}
}
// XXX fix for paths containing '.'.
// Need to be more elegant here.
pathName = pathName.replace('.','_');
pkgName = pathName.substring(0, pathName.lastIndexOf(
File.separatorChar)).replace(File.separatorChar, '.');
if (ctxt.getServletPackageName() != null) {
pkgName = ctxt.getServletPackageName();
}
for (int i=0; i |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.