santiagopg 02/04/24 10:03:17
Modified: java/src/org/apache/xalan/xsltc DOM.java
java/src/org/apache/xalan/xsltc/compiler ApplyTemplates.java
AttributeValue.java AttributeValueTemplate.java
CastExpr.java Constants.java DocumentCall.java
ElementAvailableCall.java Expression.java
FormatNumberCall.java FunctionAvailableCall.java
FunctionCall.java Include.java LiteralElement.java
LiteralExpr.java Number.java
ParentLocationPath.java Parser.java
ProcessingInstruction.java Step.java
StepPattern.java Stylesheet.java SymbolTable.java
SyntaxTreeNode.java XSLTC.java XslAttribute.java
XslElement.java xpath.cup
java/src/org/apache/xalan/xsltc/compiler/util
ErrorMessages.java MethodGenerator.java
ReferenceType.java Util.java
java/src/org/apache/xalan/xsltc/dom
CurrentNodeListIterator.java DOMAdapter.java
DOMBuilder.java DOMImpl.java ExtendedSAX.java
MultiDOM.java SortingIterator.java
UnionIterator.java
java/src/org/apache/xalan/xsltc/runtime
AbstractTranslet.java BasisLibrary.java
Constants.java DefaultSAXOutputHandler.java
SAXAdapter.java StringValueHandler.java
TextOutput.java TransletLoader.java
java/src/org/apache/xalan/xsltc/trax DOM2SAX.java
SAX2DOM.java TemplatesHandlerImpl.java
TemplatesImpl.java TransformerFactoryImpl.java
TransformerImpl.java
Log:
Commit after syncing trunk with branch jaxp-ri-1_2_0-fcs-04.
Revision Changes Path
1.10 +3 -1 xml-xalan/java/src/org/apache/xalan/xsltc/DOM.java
Index: DOM.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/DOM.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DOM.java 26 Nov 2001 14:03:09 -0000 1.9
+++ DOM.java 24 Apr 2002 17:03:14 -0000 1.10
@@ -132,4 +132,6 @@
public void setupMapping(String[] names, String[] namespaces);
public boolean isElement(final int node);
public boolean isAttribute(final int node);
+ public String lookupNamespace(int node, String prefix)
+ throws TransletException;
}
1.13 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ApplyTemplates.java
Index: ApplyTemplates.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ApplyTemplates.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
1.2 +4 -4
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/AttributeValue.java
Index: AttributeValue.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/AttributeValue.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AttributeValue.java 17 Apr 2001 18:51:20 -0000 1.1
+++ AttributeValue.java 24 Apr 2002 17:03:15 -0000 1.2
@@ -71,16 +71,16 @@
AttributeValue result;
if (text.indexOf('{') != -1) {
- result = new AttributeValueTemplate(text, parser);
+ result = new AttributeValueTemplate(text, parser, parent);
}
else if (text.indexOf('}') != -1) {
- result = new AttributeValueTemplate(text, parser);
+ result = new AttributeValueTemplate(text, parser, parent);
}
else {
result = new SimpleAttributeValue(text);
result.setParser(parser);
+ result.setParent(parent);
}
- result.setParent(parent);
return result;
}
}
1.6 +7 -3
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/AttributeValueTemplate.java
Index: AttributeValueTemplate.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/AttributeValueTemplate.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AttributeValueTemplate.java 1 Feb 2002 20:07:08 -0000 1.5
+++ AttributeValueTemplate.java 24 Apr 2002 17:03:15 -0000 1.6
@@ -72,10 +72,14 @@
final class AttributeValueTemplate extends AttributeValue {
- public AttributeValueTemplate(String value, Parser parser) {
+ public AttributeValueTemplate(String value, Parser parser,
+ SyntaxTreeNode parent)
+ {
+ setParent(parent);
setParser(parser);
- if (check(value, parser))
+ if (check(value, parser)) {
parseAVTemplate(0, value, parser);
+ }
}
private void parseAVTemplate(final int start, String text, Parser
parser) {
1.11 +2 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CastExpr.java
Index: CastExpr.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CastExpr.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- CastExpr.java 1 Feb 2002 20:07:08 -0000 1.10
+++ CastExpr.java 24 Apr 2002 17:03:15 -0000 1.11
@@ -140,6 +140,7 @@
InternalTypeMap.put(Type.Reference, Type.String);
InternalTypeMap.put(Type.Reference, Type.Node);
InternalTypeMap.put(Type.Reference, Type.NodeSet);
+ InternalTypeMap.put(Type.Reference, Type.ResultTree);
InternalTypeMap.put(Type.Void, Type.String);
}
1.20 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Constants.java
Index: Constants.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Constants.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
1.13 +10 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/DocumentCall.java
Index: DocumentCall.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/DocumentCall.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DocumentCall.java 1 Feb 2002 20:07:08 -0000 1.12
+++ DocumentCall.java 24 Apr 2002 17:03:15 -0000 1.13
@@ -120,7 +120,15 @@
// Parse the second argument - the document URI base
if (ac == 2) {
_base = argument(1);
- if (!_base.typeCheck(stable).identicalTo(Type.NodeSet)) {
+ final Type baseType = _base.typeCheck(stable);
+
+ if (baseType.identicalTo(Type.Node)) {
+ _base = new CastExpr(_base, Type.NodeSet);
+ }
+ else if (baseType.identicalTo(Type.NodeSet)) {
+ // falls through
+ }
+ else {
ErrorMsg msg = new ErrorMsg(ErrorMsg.DOCUMENT_ARG_ERR, this);
throw new TypeCheckError(msg);
}
1.5 +6 -5
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ElementAvailableCall.java
Index: ElementAvailableCall.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ElementAvailableCall.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ElementAvailableCall.java 1 Feb 2002 20:07:08 -0000 1.4
+++ ElementAvailableCall.java 24 Apr 2002 17:03:15 -0000 1.5
@@ -91,10 +91,11 @@
* Returns the result that this function will return
*/
public boolean getResult() {
- final Parser parser = getParser();
- final LiteralExpr arg = (LiteralExpr)argument();
- final QName qname = parser.getQName(arg.getValue());
- return(parser.elementSupported(qname));
+ final LiteralExpr arg = (LiteralExpr) argument();
+ final String qname = arg.getValue();
+ final int index = qname.indexOf(':');
+ final String localName = (index > 0) ? qname.substring(index + 1) :
qname;
+ return getParser().elementSupported(arg.getNamespace(), localName);
}
/**
1.12 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Expression.java
Index: Expression.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Expression.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
1.7 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FormatNumberCall.java
Index: FormatNumberCall.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FormatNumberCall.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
1.6 +163 -13
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionAvailableCall.java
Index: FunctionAvailableCall.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionAvailableCall.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FunctionAvailableCall.java 1 Feb 2002 20:07:08 -0000 1.5
+++ FunctionAvailableCall.java 24 Apr 2002 17:03:15 -0000 1.6
@@ -56,7 +56,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * @author Jacek Ambroziak
+ * @author G. Todd Miller
* @author Santiago Pericas-Geertsen
*
*/
@@ -64,38 +64,188 @@
package org.apache.xalan.xsltc.compiler;
import java.util.Vector;
-import java.util.HashSet;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Method;
import org.apache.xalan.xsltc.compiler.util.Type;
import org.apache.bcel.generic.*;
import org.apache.xalan.xsltc.compiler.util.*;
+import org.apache.xalan.xsltc.runtime.TransletLoader;
final class FunctionAvailableCall extends FunctionCall {
+ private boolean _isFunctionAvailable = false;
+ private Expression _arg;
+ private String _namespaceOfFunct =null;
+ private String _nameOfFunct =null;
+
+
+ /**
+ * Constructs a FunctionAvailableCall FunctionCall. Takes the
+ * function name qname, for example, 'function-available', and a list
+ * of arguments where the arguments must be instances of
+ * LiteralExpression. The test for availability considers
+ * internal xsl functions such as 'floor' as well as external
+ * Java functions, such as 'java.lang.Math.sin'. The case of
+ * external functions is handled here, the case of internal
+ * functions is handled in getResult.
+ */
public FunctionAvailableCall(QName fname, Vector arguments) {
super(fname, arguments);
+ _arg = (Expression)arguments.elementAt(0);
+ _type = null;
+ if (_arg instanceof LiteralExpr) {
+ LiteralExpr arg = (LiteralExpr)_arg;
+ _namespaceOfFunct = arg.getNamespace();
+ _nameOfFunct = arg.getValue();
+ if ((_namespaceOfFunct != null) &&
+ (!_namespaceOfFunct.equals(Constants.EMPTYSTRING)))
+ {
+ // the function is external, such as a java function
+ _isFunctionAvailable = hasMethods();
+ }
+ // the case of internal function is handled in getResult.
+ }
+ // case where _arg is not instanceof LiteralExpr can not be handled.
}
/**
- * Force the argument to this function to be a literal string.
+ * Argument of function-available call must be literal, typecheck
+ * returns the type of function-available to be boolean.
*/
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
- if (argument() instanceof LiteralExpr) {
- return _type = Type.Boolean;
+ // may be already set
+ if ( _type != null ) {
+ return _type;
+ }
+ if (_arg instanceof LiteralExpr) {
+ _type = Type.Boolean;
+ return Type.Boolean;
}
ErrorMsg err = new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR,
- "function-available", this);
+ "function-available", this);
throw new TypeCheckError(err);
}
/**
- * Returns the result that this function will return
+ * (For ext. java functions only)
+ * Parses the argument to function-available to extract the package
+ * qualified class name, for example, given the argument
+ * 'java:java.lang.Math.sin', getClassName would return
+ * 'java.lang.Math'. See also 'getMethodName'.
+ */
+ private String getClassName(String argValue){
+ int colonSep = argValue.indexOf(":");
+ if (colonSep != -1) {
+ argValue = argValue.substring(colonSep+1);
+ }
+ int lastDot = argValue.lastIndexOf(".");
+ if (lastDot != -1) {
+ argValue = argValue.substring(0, lastDot);
+ }
+ return argValue;
+ }
+
+ /**
+ * (For ext. java functions only)
+ * Parses the argument to function-available
+ * to extract the method name, for example, given the argument
+ * 'java.lang.Math.sin', getMethodName would return 'sin'.
+ */
+ private String getMethodName(String argValue){
+ int lastDot = argValue.lastIndexOf(".");
+ if (lastDot != -1) {
+ argValue = argValue.substring(lastDot+1);
+ }
+ return argValue;
+ }
+
+ /**
+ * (For java external functions only)
+ * Creates a full package qualified
+ * function name taking into account the namespace and the
+ * function name derived from the argument passed to function-available.
+ * For example, given a name of 'java:java.lang.Math.sin' and a
+ * namespace of 'http://xml.apache.org/xalan/xsltc/java' this routine
+ * constructs a uri and then derives the class name
+ * 'java.lang.Math.sin' from the uri. The uri in this example would
+ * be 'http://xml.apache.org/xalan/xsltc/java.java.lang.Math.sin'
+ */
+ private String getExternalFunctionName() {
+ int colonIndex = _nameOfFunct.indexOf(":");
+ String uri = _namespaceOfFunct +
+ "." + _nameOfFunct.substring(colonIndex+1);
+ try{
+ return getClassNameFromUri(uri);
+ } catch (TypeCheckError e) {
+ return null;
+ }
+ }
+
+ /**
+ * for external java functions only: reports on whether or not
+ * the specified method is found in the specifed class.
+ */
+ private boolean hasMethods() {
+
+ LiteralExpr arg = (LiteralExpr)_arg;
+ final String externalFunctName = getExternalFunctionName();
+ if (externalFunctName == null) {
+ return false;
+ }
+ final String className = getClassName(externalFunctName);
+
+ if (_namespaceOfFunct.startsWith(JAVA_EXT_XSLTC) ||
+ _namespaceOfFunct.startsWith(JAVA_EXT_XALAN)) {
+ try {
+ TransletLoader loader = new TransletLoader();
+ final Class clazz = loader.loadClass(className);
+
+ if (clazz == null) {
+ final ErrorMsg msg =
+ new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR,
className);
+ getParser().reportError(Constants.ERROR, msg);
+ }
+ else {
+ final String methodName =
getMethodName(externalFunctName);
+ final Method[] methods = clazz.getDeclaredMethods();
+
+ for (int i = 0; i < methods.length; i++) {
+ final int mods = methods[i].getModifiers();
+
+ if (Modifier.isPublic(mods)
+ && Modifier.isStatic(mods)
+ && methods[i].getName().equals(methodName))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ catch (ClassNotFoundException e) {
+ final ErrorMsg msg =
+ new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, className);
+ getParser().reportError(Constants.ERROR, msg);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * reports on whether the function specified in the argument to
+ * xslt function 'function-available' was found.
*/
public boolean getResult() {
- final Parser parser = getParser();
- final LiteralExpr arg = (LiteralExpr)argument();
- return(parser.functionSupported(arg.getValue()));
+ if ((_namespaceOfFunct == null) ||
+ (_namespaceOfFunct.equals(Constants.EMPTYSTRING)))
+ {
+ // no namespace, so the function is an internal xslt function.
+ final Parser parser = getParser();
+ _isFunctionAvailable = parser.functionSupported(_nameOfFunct);
+ }
+ return _isFunctionAvailable;
}
+
/**
* Calls to 'function-available' are resolved at compile time since
* the namespaces declared in the stylsheet are not available at run
@@ -103,7 +253,7 @@
*/
public void translate(ClassGenerator classGen, MethodGenerator
methodGen) {
final ConstantPoolGen cpg = classGen.getConstantPool();
- final boolean result = getResult();
- methodGen.getInstructionList().append(new PUSH(cpg, result));
+ methodGen.getInstructionList().append(new PUSH(cpg, getResult()));
}
+
}
1.15 +30 -16
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionCall.java
Index: FunctionCall.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionCall.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- FunctionCall.java 4 Apr 2002 21:10:30 -0000 1.14
+++ FunctionCall.java 24 Apr 2002 17:03:15 -0000 1.15
@@ -86,10 +86,19 @@
private final static Vector EMPTY_ARG_LIST = new Vector(0);
// Valid namespaces for Java function-call extension
- private final static String JAVA_EXT_PREFIX = TRANSLET_URI + "/java";
- private final static String JAVA_EXT_XALAN =
+ protected final static String EXT_XSLTC =
+ TRANSLET_URI;
+
+ protected final static String JAVA_EXT_XSLTC =
+ EXT_XSLTC + "/java";
+
+ protected final static String EXT_XALAN =
+ "http://xml.apache.org/xalan";
+
+ protected final static String JAVA_EXT_XALAN =
"http://xml.apache.org/xslt/java";
+
// External Java function's class/method/signature
private String _className;
private Method _chosenMethod;
@@ -197,7 +206,7 @@
throws TypeCheckError
{
final int length =
- uri.startsWith(JAVA_EXT_PREFIX) ? JAVA_EXT_PREFIX.length() + 1 :
+ uri.startsWith(JAVA_EXT_XSLTC) ? JAVA_EXT_XSLTC.length() + 1 :
uri.startsWith(JAVA_EXT_XALAN) ? JAVA_EXT_XALAN.length() + 1 : 0;
if (length == 0) {
@@ -218,8 +227,11 @@
final String namespace = _fname.getNamespace();
final String local = _fname.getLocalPart();
- // XPath functions have no namespace
- if (isStandard()) {
+ if (isExtension()) {
+ _fname = new QName(null, null, local);
+ return typeCheckStandard(stable);
+ }
+ else if (isStandard()) {
return typeCheckStandard(stable);
}
// Handle extension functions (they all have a namespace)
@@ -264,8 +276,7 @@
* thrown, then catch it and re-throw it with a new "this".
*/
public Type typeCheckStandard(SymbolTable stable) throws TypeCheckError {
-
- _fname.clearNamespace(); // HACK!!!
+ _fname.clearNamespace(); // HACK!!!
final int n = _arguments.size();
final Vector argsType = typeCheckArgs(stable);
@@ -388,8 +399,8 @@
* Update true/false-lists.
*/
public void translateDesynthesized(ClassGenerator classGen,
- MethodGenerator methodGen) {
-
+ MethodGenerator methodGen)
+ {
Type type = Type.Boolean;
if (_chosenMethodType != null)
type = _chosenMethodType.resultType();
@@ -414,7 +425,7 @@
int index;
// Translate calls to methods in the BasisLibrary
- if (isStandard()) {
+ if (isStandard() || isExtension()) {
for (int i = 0; i < n; i++) {
final Expression exp = argument(i);
exp.translate(classGen, methodGen);
@@ -491,10 +502,13 @@
public boolean isStandard() {
final String namespace = _fname.getNamespace();
- if ((namespace == null) || (namespace.equals(Constants.EMPTYSTRING)))
- return true;
- else
- return false;
+ return (namespace == null) || (namespace.equals(Constants.EMPTYSTRING));
+ }
+
+ public boolean isExtension() {
+ final String namespace = _fname.getNamespace();
+ return (namespace != null) && (namespace.equals(EXT_XSLTC)
+ || namespace.equals(EXT_XALAN));
}
/**
@@ -506,7 +520,7 @@
Vector result = null;
final String namespace = _fname.getNamespace();
- if (namespace.startsWith(JAVA_EXT_PREFIX) ||
+ if (namespace.startsWith(JAVA_EXT_XSLTC) ||
namespace.startsWith(JAVA_EXT_XALAN)) {
final int nArgs = _arguments.size();
try {
1.15 +23 -23
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Include.java
Index: Include.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Include.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Include.java 16 Apr 2002 18:35:30 -0000 1.14
+++ Include.java 24 Apr 2002 17:03:15 -0000 1.15
@@ -107,28 +107,28 @@
input = loader.loadSource(docToLoad, currLoadedDoc, xsltc);
}
else {
- // bug 7835, patch by Stefan Kost ([EMAIL PROTECTED])
- if ((currLoadedDoc != null) && (currLoadedDoc.length() > 0))
{
- File file = new File(currLoadedDoc);
- if (file.exists()) {
- currLoadedDoc = "file:" + file.getCanonicalPath();
- }
- final URL url = new URL(new URL(currLoadedDoc),
docToLoad);
- docToLoad = url.toString();
- input = new InputSource(docToLoad);
- }
- else {
- File file = new File(System.getProperty("user.dir"),
- docToLoad);
- if (file.exists()) {
- docToLoad = "file:" + file.getCanonicalPath();
- }
- else {
- throw new FileNotFoundException(
- "Could not load file " + docToLoad);
- }
- input = new InputSource(docToLoad);
- }
+ // bug 7835, patch by Stefan Kost ([EMAIL PROTECTED])
+ if ((currLoadedDoc != null) && (currLoadedDoc.length() > 0)) {
+ File file = new File(currLoadedDoc);
+ if (file.exists()) {
+ currLoadedDoc = "file:" + file.getCanonicalPath();
+ }
+ final URL url = new URL(new URL(currLoadedDoc), docToLoad);
+ docToLoad = url.toString();
+ input = new InputSource(docToLoad);
+ }
+ else {
+ File file = new File(System.getProperty("user.dir"),
+ docToLoad);
+ if (file.exists()) {
+ docToLoad = "file:" + file.getCanonicalPath();
+ }
+ else {
+ throw new FileNotFoundException(
+ "Could not load file " + docToLoad);
+ }
+ input = new InputSource(docToLoad);
+ }
}
final SyntaxTreeNode root = parser.parse(input);
1.17 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralElement.java
Index: LiteralElement.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralElement.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
1.5 +2 -5
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralExpr.java
Index: LiteralExpr.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralExpr.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LiteralExpr.java 1 Feb 2002 20:07:08 -0000 1.4
+++ LiteralExpr.java 24 Apr 2002 17:03:15 -0000 1.5
@@ -88,10 +88,7 @@
*/
public LiteralExpr(String value, String namespace) {
_value = value;
- if (namespace.equals(Constants.EMPTYSTRING))
- _namespace = null;
- else
- _namespace = namespace;
+ _namespace = namespace.equals(Constants.EMPTYSTRING) ? null : namespace;
}
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
1.9 +6 -6
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Number.java
Index: Number.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Number.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Number.java 1 Feb 2002 20:07:08 -0000 1.8
+++ Number.java 24 Apr 2002 17:03:15 -0000 1.9
@@ -129,23 +129,23 @@
}
}
else if (name.equals("format")) {
- _format = new AttributeValueTemplate(value, parser);
+ _format = new AttributeValueTemplate(value, parser, this);
_formatNeeded = true;
}
else if (name.equals("lang")) {
- _lang = new AttributeValueTemplate(value, parser);
+ _lang = new AttributeValueTemplate(value, parser, this);
_formatNeeded = true;
}
else if (name.equals("letter-value")) {
- _letterValue = new AttributeValueTemplate(value, parser);
+ _letterValue = new AttributeValueTemplate(value, parser, this);
_formatNeeded = true;
}
else if (name.equals("grouping-separator")) {
- _groupingSeparator = new AttributeValueTemplate(value, parser);
+ _groupingSeparator = new AttributeValueTemplate(value, parser,
this);
_formatNeeded = true;
}
else if (name.equals("grouping-size")) {
- _groupingSize = new AttributeValueTemplate(value, parser);
+ _groupingSize = new AttributeValueTemplate(value, parser, this);
_formatNeeded = true;
}
}
1.17 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ParentLocationPath.java
Index: ParentLocationPath.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ParentLocationPath.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
1.40 +8 -8
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java
Index: Parser.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- Parser.java 2 Apr 2002 19:01:37 -0000 1.39
+++ Parser.java 24 Apr 2002 17:03:15 -0000 1.40
@@ -618,8 +618,8 @@
COMPILER_PACKAGE + '.' + className);
}
- public boolean elementSupported(QName qname) {
- return(_instructionClasses.get(qname) != null);
+ public boolean elementSupported(String namespace, String localName) {
+ return(_instructionClasses.get(getQName(namespace, XSL, localName)) !=
null);
}
public boolean functionSupported(String fname) {
@@ -664,6 +664,7 @@
MethodType B_V = new MethodType(Type.Boolean, Type.Void);
MethodType B_B = new MethodType(Type.Boolean, Type.Boolean);
MethodType B_S = new MethodType(Type.Boolean, Type.String);
+ MethodType D_T = new MethodType(Type.NodeSet, Type.ResultTree);
MethodType R_RR = new MethodType(Type.Real, Type.Real, Type.Real);
MethodType I_II = new MethodType(Type.Int, Type.Int, Type.Int);
MethodType B_RR = new MethodType(Type.Boolean, Type.Real, Type.Real);
@@ -748,6 +749,9 @@
_symbolTable.addPrimop("normalize-space", S_S);
_symbolTable.addPrimop("system-property", S_S);
+ // Extensions
+ _symbolTable.addPrimop("nodeset", D_T);
+
// Operators +, -, *, /, % defined on real types.
_symbolTable.addPrimop("+", R_RR);
_symbolTable.addPrimop("-", R_RR);
@@ -1097,11 +1101,7 @@
String qname, Attributes attributes)
throws SAXException {
final int col = qname.lastIndexOf(':');
- final String prefix;
- if (col == -1)
- prefix = null;
- else
- prefix = qname.substring(0, col);
+ final String prefix = (col == -1) ? null : qname.substring(0, col);
SyntaxTreeNode element = makeInstance(uri, prefix, localname);
if (element == null) {
1.7 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ProcessingInstruction.java
Index: ProcessingInstruction.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ProcessingInstruction.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
1.31 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Step.java
Index: Step.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Step.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
1.15 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/StepPattern.java
Index: StepPattern.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/StepPattern.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
1.38 +35 -4
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Stylesheet.java
Index: Stylesheet.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Stylesheet.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- Stylesheet.java 2 Apr 2002 19:01:37 -0000 1.37
+++ Stylesheet.java 24 Apr 2002 17:03:15 -0000 1.38
@@ -117,6 +117,7 @@
private int _importPrecedence = 1;
private Mode _defaultMode;
private boolean _multiDocument = false;
+ private boolean _callsNodeset = false;
// All named key elements (needed by Key/IdPattern)
private Hashtable _keys = new Hashtable();
@@ -155,6 +156,15 @@
return _multiDocument;
}
+ public void setCallsNodeset(boolean flag) {
+ if (flag) setMultiDocument(flag);
+ _callsNodeset = flag;
+ }
+
+ public boolean callsNodeset() {
+ return _callsNodeset;
+ }
+
public void numberFormattingUsed() {
_numberFormattingUsed = true;
}
@@ -693,12 +703,31 @@
return("("+DOM_INTF_SIG+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+")V");
}
-
+ /**
+ * This method returns a vector with variables in the order in which
+ * they are to be compiled. The order is determined by the dependencies
+ * between them. The first step is to close the input vector under
+ * the dependence relation (this is usually needed when variables are
+ * defined inside other variables in a RTF).
+ */
private Vector resolveReferences(Vector input) {
- Vector result = new Vector();
- int zeroDep = 0;
+ // Make sure that the vector 'input' is closed
+ for (int i = 0; i < input.size(); i++) {
+ final VariableBase var = (VariableBase) input.elementAt(i);
+ final Vector dep = var.getDependencies();
+ final int depSize = (dep != null) ? dep.size() : 0;
+
+ for (int j = 0; j < depSize; j++) {
+ final VariableBase depVar = (VariableBase) dep.elementAt(j);
+ if (!input.contains(depVar)) {
+ input.addElement(depVar);
+ }
+ }
+ }
+ Vector result = new Vector();
+ int zeroDep = 0;
while (input.size() > 0) {
boolean changed = false;
for (int i = 0; i < input.size(); ) {
@@ -718,6 +747,8 @@
i++;
}
}
+
+
// If nothing was changed in this pass then we have a circular ref
if (!changed) {
ErrorMsg err = new ErrorMsg(ErrorMsg.CIRCULAR_VARIABLE_ERR,
1.7 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SymbolTable.java
Index: SymbolTable.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SymbolTable.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
1.20 +40 -10
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java
Index: SyntaxTreeNode.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- SyntaxTreeNode.java 2 Apr 2002 19:01:37 -0000 1.19
+++ SyntaxTreeNode.java 24 Apr 2002 17:03:15 -0000 1.20
@@ -552,10 +552,11 @@
* @param methodGen BCEL Java method generator
*/
protected void compileResultTree(ClassGenerator classGen,
- MethodGenerator methodGen) {
-
+ MethodGenerator methodGen)
+ {
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
+ final Stylesheet stylesheet = classGen.getStylesheet();
// Save the current handler base on the stack
il.append(methodGen.loadHandler());
@@ -600,13 +601,42 @@
il.append(new NEW(cpg.addClass(DOM_ADAPTER_CLASS)));
il.append(new DUP_X1());
il.append(SWAP);
- // Give the DOM adapter an empty type mapping to start with.
- // Type mapping is expensive and will only be done when casting
- // a result tree fragment to a node-set.
- il.append(new ICONST(0));
- il.append(new ANEWARRAY(cpg.addClass(STRING)));
- il.append(DUP);
- il.append(new INVOKESPECIAL(index)); // leave DOMAdapter on stack
+
+ /*
+ * Give the DOM adapter an empty type mapping if the nodeset
+ * extension function is never called.
+ */
+ if (!stylesheet.callsNodeset()) {
+ il.append(new ICONST(0));
+ il.append(new ANEWARRAY(cpg.addClass(STRING)));
+ il.append(DUP);
+ il.append(new INVOKESPECIAL(index));
+ }
+ else {
+ // Push name arrays on the stack
+ il.append(ALOAD_0);
+ il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS,
+ NAMES_INDEX,
+ NAMES_INDEX_SIG)));
+ il.append(ALOAD_0);
+ il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS,
+ NAMESPACE_INDEX,
+ NAMESPACE_INDEX_SIG)));
+
+ // Initialized DOM adapter
+ il.append(new INVOKESPECIAL(index));
+
+ // Add DOM adapter to MultiDOM class by calling addDOMAdapter()
+ il.append(DUP);
+ il.append(methodGen.loadDOM());
+ il.append(new CHECKCAST(cpg.addClass(classGen.getDOMClass())));
+ il.append(SWAP);
+ index = cpg.addMethodref(MULTI_DOM_CLASS,
+ "addDOMAdapter",
+ "(" + DOM_ADAPTER_SIG + ")I");
+ il.append(new INVOKEVIRTUAL(index));
+ il.append(POP); // ignore mask returned by addDOMAdapter
+ }
}
// Restore old handler base from stack
1.36 +16 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XSLTC.java
Index: XSLTC.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XSLTC.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- XSLTC.java 1 Feb 2002 20:07:09 -0000 1.35
+++ XSLTC.java 24 Apr 2002 17:03:15 -0000 1.36
@@ -139,6 +139,7 @@
private int _outputType = FILE_OUTPUT; // by default
private Vector _classes;
+ private boolean _callsNodeset = false;
private boolean _multiDocument = false;
/**
@@ -317,6 +318,7 @@
}
// Generate the bytecodes and output the translet class(es)
if ((!_parser.errorsFound()) && (_stylesheet != null)) {
+ _stylesheet.setCallsNodeset(_callsNodeset);
_stylesheet.setMultiDocument(_multiDocument);
_stylesheet.translate();
}
@@ -435,7 +437,6 @@
_parser.printWarnings();
}
-
/**
* This method is called by the XPathParser when it encounters a call
* to the document() function. Affects the DOM used by the translet.
@@ -446,6 +447,19 @@
public boolean isMultiDocument() {
return _multiDocument;
+ }
+
+ /**
+ * This method is called by the XPathParser when it encounters a call
+ * to the nodeset() extension function. Implies multi document.
+ */
+ protected void setCallsNodeset(boolean flag) {
+ if (flag) setMultiDocument(flag);
+ _callsNodeset = flag;
+ }
+
+ public boolean callsNodeset() {
+ return _callsNodeset;
}
/**
1.18 +3 -3
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XslAttribute.java
Index: XslAttribute.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XslAttribute.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- XslAttribute.java 2 Apr 2002 19:01:37 -0000 1.17
+++ XslAttribute.java 24 Apr 2002 17:03:15 -0000 1.18
@@ -137,14 +137,14 @@
// Get namespace from namespace attribute?
if (namespace != null && namespace != Constants.EMPTYSTRING) {
_prefix = lookupPrefix(namespace);
- _namespace = new AttributeValueTemplate(namespace, parser);
+ _namespace = new AttributeValueTemplate(namespace, parser, this);
}
// Get namespace from prefix in name attribute?
else if (prefix != null && prefix != Constants.EMPTYSTRING) {
_prefix = prefix;
namespace = lookupNamespace(prefix);
if (namespace != null) {
- _namespace = new AttributeValueTemplate(namespace, parser);
+ _namespace = new AttributeValueTemplate(namespace, parser,
this);
}
}
1.17 +193 -81
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XslElement.java
Index: XslElement.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XslElement.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- XslElement.java 2 Apr 2002 19:01:37 -0000 1.16
+++ XslElement.java 24 Apr 2002 17:03:15 -0000 1.17
@@ -74,10 +74,11 @@
final class XslElement extends Instruction {
- private AttributeValue _name; // name treated as AVT (7.1.3)
- private AttributeValueTemplate _namespace = null;
private String _prefix;
private boolean _ignore = false;
+ private boolean _isLiteralName = true;
+ private AttributeValueTemplate _name;
+ private AttributeValueTemplate _namespace;
/**
* Displays the contents of the element
@@ -88,92 +89,125 @@
displayContents(indent + IndentIncrement);
}
+ /**
+ * This method is now deprecated. The new implemation of this class
+ * never declares the default NS.
+ */
public boolean declaresDefaultNS() {
- return (_namespace != null && _prefix == EMPTYSTRING);
+ return false;
}
/**
- * Parses the element's contents. Special care taken for namespaces.
- * TODO: The namespace attribute that specifies the namespace to use
- * for the element is an attribute value template and not a string
- * constant. This means that we do not know what namespace is used
- * before runtime. This causes a problem with the way output namespaces
- * are handled at compile-time. We use a shortcut in this method to get
- * around the problem by treating the namaspace attribute as a constant.
- * (Yes, I know this is a hack, bad, bad, bad.)
+ * Checks if <param>str</param> is a literal (i.e. not an AVT) or not.
*/
- public void parseContents(Parser parser) {
+ private boolean isLiteral(String str) {
+ final int length = str.length();
+ for (int i = 0; i < length; i++) {
+ if (str.charAt(i) == '{' && str.charAt(i + 1) != '{') {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Simple check to determine if qname is legal. If it returns false
+ * then <param>str</param> is illegal; if it returns true then
+ * <param>str</param> may or may not be legal.
+ */
+ private boolean isLegalName(String str) {
+ if (str.indexOf(' ') > -1) {
+ return false;
+ }
+ final int colon = str.indexOf(':');
+ if (colon == 0 || colon == str.length() - 1) {
+ return false;
+ }
+ final char first = str.charAt(0);
+ if (!Character.isLetter(first) && first != '_') {
+ return false;
+ }
+ return true;
+ }
+ public void parseContents(Parser parser) {
final SymbolTable stable = parser.getSymbolTable();
- // Get the "name" attribute of the <xsl:element> element
+ // Handle the 'name' attribute
String name = getAttribute("name");
- if ((name == null) || (name.equals(EMPTYSTRING))) {
+ if (name == EMPTYSTRING) {
ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_ELEM_NAME_ERR,
name, this);
parser.reportError(WARNING, msg);
- _ignore = true; // Ignore the element if the QName is invalid
+ parseChildren(parser);
+ _ignore = true; // Ignore the element if the QName is invalid
return;
}
- // Try to construct a QName and then get the prefix and local part
- QName qname = parser.getQNameSafe(name);
- String prefix = qname.getPrefix();
- String local = qname.getLocalPart();
-
- // First try to get the namespace URI from the "namespace" attribute
+ // Get namespace attribute
String namespace = getAttribute("namespace");
- // Then try to get it from the "name" attribute QName prefix
- if (!hasAttribute("namespace")) {
- // We are supposed to use the default namespace URI if the QName
- // from the "name" attribute is not prefixed, so check that first
- if (prefix == null) prefix = EMPTYSTRING;
- // Then look up the URI that is in scope for the prefix
- namespace = lookupNamespace(prefix);
-
- // Signal error if the prefix does not map to any namespace URI
- if (namespace == null) {
- ErrorMsg err = new ErrorMsg(ErrorMsg.NAMESPACE_UNDEF_ERR,
- prefix, this);
- parser.reportError(WARNING, err);
+
+ // Optimize compilation when name is known at compile time
+ _isLiteralName = isLiteral(name);
+ if (_isLiteralName) {
+ if (!isLegalName(name)) {
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_ELEM_NAME_ERR,
+ name, this);
+ parser.reportError(WARNING, msg);
parseChildren(parser);
- _ignore = true; // Ignore the element if prefix is undeclared
+ _ignore = true; // Ignore the element if the QName is
invalid
return;
}
- _namespace = new AttributeValueTemplate(namespace, parser);
- _prefix = prefix;
+
+ final QName qname = parser.getQNameSafe(name);
+ String prefix = qname.getPrefix();
+ String local = qname.getLocalPart();
+
+ if (prefix == null) {
+ prefix = EMPTYSTRING;
+ }
+
+ if (!hasAttribute("namespace")) {
+ namespace = lookupNamespace(prefix);
+ if (namespace == null) {
+ ErrorMsg err = new ErrorMsg(ErrorMsg.NAMESPACE_UNDEF_ERR,
+ prefix, this);
+ parser.reportError(WARNING, err);
+ parseChildren(parser);
+ _ignore = true; // Ignore the element if prefix is
undeclared
+ return;
+ }
+ _prefix = prefix;
+ _namespace = (namespace == EMPTYSTRING) ? null :
+ new AttributeValueTemplate(namespace, parser,
this);
+ }
+ else {
+ if (prefix == EMPTYSTRING) {
+ if (isLiteral(namespace)) {
+ prefix = lookupPrefix(namespace);
+ if (prefix == null) {
+ prefix = stable.generateNamespacePrefix();
+ }
+ }
+
+ // Prepend prefix to local name
+ final StringBuffer newName = new StringBuffer(prefix);
+ if (prefix != EMPTYSTRING) {
+ newName.append(':');
+ }
+ name = newName.append(local).toString();
+ }
+ _prefix = prefix;
+ _namespace = new AttributeValueTemplate(namespace, parser,
this);
+ }
}
- // Check if this element belongs in a specific namespace
else {
- // Get the namespace requested by the xsl:element
- _namespace = new AttributeValueTemplate(namespace, parser);
- // Get the current prefix for that namespace (if any)
- _prefix = lookupPrefix(namespace);
- // Is it the default namespace?
- if ((_prefix = prefix) == null) _prefix = EMPTYSTRING;
-
- // Construct final element QName
- if (_prefix == EMPTYSTRING)
- name = qname.getLocalPart();
- else
- name = _prefix+":"+qname.getLocalPart();
- }
-
- _name = AttributeValue.create(this, name, parser);
-
- // Next check that the local part of the QName is legal (no whitespace)
- if (_name instanceof SimpleAttributeValue) {
- if (local.equals(EMPTYSTRING) || (local.indexOf(' ') > -1)) {
- ErrorMsg err = new ErrorMsg(ErrorMsg.ILLEGAL_ELEM_NAME_ERR,
- local, this);
- parser.reportError(WARNING, err);
- parseChildren(parser);
- _ignore = true; // Ignore the element if local part is invalid
- return;
- }
+ _namespace = (namespace == EMPTYSTRING) ? null :
+ new AttributeValueTemplate(namespace, parser, this);
}
- // Handle the 'use-attribute-sets' attribute
+ _name = new AttributeValueTemplate(name, parser, this);
+
final String useSets = getAttribute("use-attribute-sets");
if (useSets.length() > 0) {
setFirstElement(new UseAttributeSets(useSets, parser));
@@ -188,34 +222,30 @@
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
if (!_ignore) {
_name.typeCheck(stable);
- if (_namespace != null)
+ if (_namespace != null) {
_namespace.typeCheck(stable);
+ }
}
typeCheckContents(stable);
return Type.Void;
}
/**
- * Compiles code that emits the element with the necessary namespace
- * definitions. The element itself is ignored if the element definition
- * was in any way erronous, but the child nodes are still processed.
- * See the overriden translateContents() method as well.
+ * This method is called when the name of the element is known at
compile time.
+ * In this case, there is no need to inspect the element name at runtime
to
+ * determine if a prefix exists, needs to be generated, etc.
*/
- public void translate(ClassGenerator classGen, MethodGenerator
methodGen) {
+ public void translateLiteral(ClassGenerator classGen, MethodGenerator
methodGen) {
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
- // Ignore this element if not correctly declared
if (!_ignore) {
- // Compile code that emits the element start tag
il.append(methodGen.loadHandler());
_name.translate(classGen, methodGen);
- il.append(DUP2); // duplicate these 2 args for endElement
+ il.append(DUP2);
il.append(methodGen.startElement());
- // Compile code that emits any needed namespace declaration
if (_namespace != null) {
- // public void attribute(final String name, final String value)
il.append(methodGen.loadHandler());
il.append(new PUSH(cpg, _prefix));
_namespace.translate(classGen,methodGen);
@@ -223,12 +253,94 @@
}
}
- // Compile code that emits the element attributes and contents
translateContents(classGen, methodGen);
- // Ignore this element if not correctly declared
if (!_ignore) {
- // Compile code that emits the element end tag
+ il.append(methodGen.endElement());
+ }
+ }
+
+ /**
+ * At runtime the compilation of xsl:element results in code that: (i)
+ * evaluates the avt for the name, (ii) checks for a prefix in the name
+ * (iii) generates a new prefix and create a new qname when necessary
+ * (iv) calls startElement() on the handler (v) looks up a uri in the XML
+ * when the prefix is not known at compile time (vi) calls namespace()
+ * on the handler (vii) evaluates the contents (viii) calls endElement().
+ */
+ public void translate(ClassGenerator classGen, MethodGenerator
methodGen) {
+ LocalVariableGen local = null;
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+
+ // Optimize translation if element name is a literal
+ if (_isLiteralName) {
+ translateLiteral(classGen, methodGen);
+ return;
+ }
+
+ if (!_ignore) {
+ il.append(methodGen.loadHandler());
+ _name.translate(classGen, methodGen);
+
+ // Call BasisLibrary.getPrefix() and store result in local variable
+ il.append(DUP);
+ final int getPrefix = cpg.addMethodref(BASIS_LIBRARY_CLASS,
"getPrefix",
+ "(" + STRING_SIG + ")" +
STRING_SIG);
+ il.append(new INVOKESTATIC(getPrefix));
+ il.append(DUP);
+ local = methodGen.addLocalVariable("prefix",
+
org.apache.bcel.generic.Type.STRING,
+ il.getEnd(), null);
+ il.append(new ASTORE(local.getIndex()));
+
+ // If prefix is null then generate a prefix at runtime
+ final BranchHandle ifNotNull = il.append(new IFNONNULL(null));
+ if (_namespace != null) {
+ final int generatePrefix =
cpg.addMethodref(BASIS_LIBRARY_CLASS,
+ "generatePrefix",
+ "()" + STRING_SIG);
+ il.append(new INVOKESTATIC(generatePrefix));
+ il.append(DUP);
+ il.append(new ASTORE(local.getIndex()));
+
+ // Prepend newly generated prefix to the name
+ final int makeQName = cpg.addMethodref(BASIS_LIBRARY_CLASS,
"makeQName",
+ "(" + STRING_SIG + STRING_SIG + ")" +
STRING_SIG);
+ il.append(new INVOKESTATIC(makeQName));
+ }
+ ifNotNull.setTarget(il.append(DUP2));
+ il.append(methodGen.startElement());
+
+ if (_namespace != null) {
+ il.append(methodGen.loadHandler());
+ il.append(new ALOAD(local.getIndex()));
+ _namespace.translate(classGen, methodGen);
+ il.append(methodGen.namespace());
+ }
+ else {
+ // If prefix not known at compile time, call
DOM.lookupNamespace()
+ il.append(new ALOAD(local.getIndex()));
+ final BranchHandle ifNull = il.append(new IFNULL(null));
+ il.append(methodGen.loadHandler());
+ il.append(new ALOAD(local.getIndex()));
+
+ il.append(methodGen.loadDOM());
+ il.append(methodGen.loadCurrentNode());
+ il.append(new ALOAD(local.getIndex()));
+
+ final int lookupNamespace = cpg.addInterfaceMethodref(DOM_INTF,
+ "lookupNamespace",
+ "(I" + STRING_SIG + ")" + STRING_SIG);
+ il.append(new INVOKEINTERFACE(lookupNamespace, 3));
+ il.append(methodGen.namespace());
+ ifNull.setTarget(il.append(NOP));
+ }
+ }
+
+ translateContents(classGen, methodGen);
+
+ if (!_ignore) {
il.append(methodGen.endElement());
}
}
@@ -243,7 +355,7 @@
for (int i = 0; i < n; i++) {
final SyntaxTreeNode item =
(SyntaxTreeNode)getContents().elementAt(i);
- if ((_ignore) && (item instanceof XslAttribute)) continue;
+ if (_ignore && item instanceof XslAttribute) continue;
item.translate(classGen, methodGen);
}
}
1.34 +10 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/xpath.cup
Index: xpath.cup
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/xpath.cup,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- xpath.cup 10 Dec 2001 12:53:07 -0000 1.33
+++ xpath.cup 24 Apr 2002 17:03:15 -0000 1.34
@@ -119,6 +119,10 @@
_xsltc.setMultiDocument(flag);
}
+ public void setCallsNodeset(boolean flag) {
+ _xsltc.setCallsNodeset(flag);
+ }
+
public int findNodeType(int axis, Object test) {
if (test == null) { // *
@@ -894,6 +898,11 @@
}
else if (fname == parser.getQName("namespace-uri")) {
RESULT = new NamespaceUriCall(fname, argl);
+ }
+ // Special case for extension function nodeset()
+ else if (fname.getLocalPart().equals("nodeset")) {
+ parser.setCallsNodeset(true); // implies MultiDOM
+ RESULT = new FunctionCall(fname, argl);
}
else {
RESULT = new FunctionCall(fname, argl);
1.6 +5 -5
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ErrorMessages.java
Index: ErrorMessages.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ErrorMessages.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ErrorMessages.java 5 Dec 2001 11:27:50 -0000 1.5
+++ ErrorMessages.java 24 Apr 2002 17:03:16 -0000 1.6
@@ -220,8 +220,8 @@
"The -i option must be used with the -o option.",
// COMPILE_USAGE_STR
"Usage:\n" +
- " xsltc [-o <output>] [-d <directory>] [-j <jarfile>]\n"+
- " [-p <package name>] [-x] [-s] [-u] <stylesheet>|-i\n\n"+
+ " java org.apache.xalan.xsltc.cmdline.Compile [-o <output>] [-d
<directory>] [-j <jarfile>]\n"+
+ " [-p <package name>] [-x] [-s] [-u] { <stylesheet> | -i }\n\n"+
" Where <output> is the name to give the the generated translet.\n"+
" <stylesheet> is one or more stylesheet file names, or if\n"+
" the -u options is specified, one or more stylesheet URLs.\n"+
@@ -235,8 +235,8 @@
" The -s option disables calling System.exit.",
// TRANSFORM_USAGE_STR
"Usage: \n" +
- " xslt [-j <jarfile>] {-u <document_url> | <document>} <class>\n"+
- " [<name1>=<value1> ...]\n\n" +
+ " java org.apache.xalan.xsltc.cmdline.Transform [-j <jarfile>] [-x]
[-s]\n" +
+ " {-u <document_url> | <document>} <class> [<param1>=<value1>
...]\n" +
" Where <document> is the xml document to be transformed, or\n" +
" <document_url> is a url for the xml document,\n" +
" <class> is the translet class which is either in\n" +
1.9 +15 -5
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/MethodGenerator.java
Index: MethodGenerator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/MethodGenerator.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- MethodGenerator.java 1 Feb 2002 20:27:46 -0000 1.8
+++ MethodGenerator.java 24 Apr 2002 17:03:16 -0000 1.9
@@ -103,6 +103,7 @@
private final Instruction _nextNode;
private SlotAllocator _slotAllocator;
+ private boolean _allocatorInit = false;
public MethodGenerator(int access_flags, Type return_type,
Type[] arg_types, String[] arg_names,
@@ -173,17 +174,26 @@
_slotAllocator = new SlotAllocator();
_slotAllocator.initialize(getLocalVariables());
+ _allocatorInit = true;
}
+ /**
+ * Allocates a local variable. If the slot allocator has already been
+ * initialized, then call addLocalVariable2() so that the new variable
+ * is known to the allocator. Failing to do this may cause the allocator
+ * to return a slot that is already in use.
+ */
public LocalVariableGen addLocalVariable(String name, Type type,
InstructionHandle start,
- InstructionHandle end) {
-
- return super.addLocalVariable(name, type, start, end);
+ InstructionHandle end)
+ {
+ return (_allocatorInit) ? addLocalVariable2(name, type, start)
+ : super.addLocalVariable(name, type, start, end);
}
public LocalVariableGen addLocalVariable2(String name, Type type,
- InstructionHandle start) {
+ InstructionHandle start)
+ {
return super.addLocalVariable(name, type,
_slotAllocator.allocateSlot(type),
start, null);
1.8 +18 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ReferenceType.java
Index: ReferenceType.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ReferenceType.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ReferenceType.java 1 Feb 2002 20:08:11 -0000 1.7
+++ ReferenceType.java 24 Apr 2002 17:03:16 -0000 1.8
@@ -113,6 +113,9 @@
else if (type == Type.Node) {
translateTo(classGen, methodGen, (NodeType) type);
}
+ else if (type == Type.ResultTree) {
+ translateTo(classGen, methodGen, (ResultTreeType) type);
+ }
else {
ErrorMsg err = new ErrorMsg(ErrorMsg.INTERNAL_ERR, type.toString());
classGen.getParser().reportError(Constants.FATAL, err);
@@ -208,6 +211,20 @@
NodeType type) {
translateTo(classGen, methodGen, Type.NodeSet);
Type.NodeSet.translateTo(classGen, methodGen, type);
+ }
+
+ /**
+ * Casts a reference into a ResultTree.
+ *
+ * @see org.apache.xalan.xsltc.compiler.util.Type#translateTo
+ */
+ public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
+ ResultTreeType type) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ int index = cpg.addMethodref(BASIS_LIBRARY_CLASS,
"referenceToResultTree",
+ "(" + OBJECT_SIG + ")" + DOM_INTF_SIG);
+ il.append(new INVOKESTATIC(index));
}
/**
1.6 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/Util.java
Index: Util.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/Util.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
1.7 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/dom/CurrentNodeListIterator.java
Index: CurrentNodeListIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/CurrentNodeListIterator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
1.12 +18 -2
xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMAdapter.java
Index: DOMAdapter.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMAdapter.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DOMAdapter.java 26 Nov 2001 14:03:09 -0000 1.11
+++ DOMAdapter.java 24 Apr 2002 17:03:16 -0000 1.12
@@ -80,6 +80,8 @@
private short[] _NSreverse;
private StripFilter _filter = null;
+
+ private int _multiDOMMask;
public DOMAdapter(DOMImpl dom,
String[] namesArray,
@@ -111,6 +113,14 @@
return _domImpl.getTreeString();
}
+ public int getMultiDOMMask() {
+ return _multiDOMMask;
+ }
+
+ public void setMultiDOMMask(int mask) {
+ _multiDOMMask = mask;
+ }
+
public NodeIterator getChildren(final int node) {
NodeIterator iterator = _domImpl.getChildren(node);
if (_filter == null) {
@@ -139,8 +149,9 @@
public NodeIterator getAxisIterator(final int axis) {
NodeIterator iterator = _domImpl.getAxisIterator(axis);
- if (_filter != null)
+ if (_filter != null) {
iterator = _domImpl.strippingIterator(iterator,_mapping,_filter);
+ }
return(iterator);
}
@@ -278,4 +289,9 @@
return(_domImpl.isAttribute(node));
}
+ public String lookupNamespace(int node, String prefix)
+ throws TransletException
+ {
+ return _domImpl.lookupNamespace(node, prefix);
+ }
}
1.3 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMBuilder.java
Index: DOMBuilder.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
1.69 +51 -7
xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java
Index: DOMImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -r1.68 -r1.69
--- DOMImpl.java 2 Apr 2002 19:01:38 -0000 1.68
+++ DOMImpl.java 24 Apr 2002 17:03:16 -0000 1.69
@@ -141,7 +141,8 @@
private BitArray _dontEscape = null;
// The URI to this document
- private String _documentURI;
+ private String _documentURI = null;
+ static private int _documentURIIndex = 0;
// Support for access/navigation through org.w3c.dom API
private Node[] _nodes;
@@ -163,11 +164,11 @@
* Returns the origin of the document from which the tree was built
*/
public String getDocumentURI() {
- return(_documentURI);
+ return (_documentURI != null) ? _documentURI : "rtf" +
_documentURIIndex++;
}
public String getDocumentURI(int node) {
- return(_documentURI);
+ return getDocumentURI();
}
public void setupMapping(String[] names, String[] namespaces) {
@@ -175,6 +176,37 @@
}
/**
+ * Lookup a namespace URI from a prefix starting at node. This method
+ * is used in the execution of xsl:element when the prefix is not known
+ * at compile time.
+ */
+ public String lookupNamespace(int node, String prefix)
+ throws TransletException
+ {
+ int anode, nsnode;
+ final AncestorIterator ancestors = new AncestorIterator();
+
+ if (isElement(node)) {
+ ancestors.includeSelf();
+ }
+
+ ancestors.setStartNode(node);
+ while ((anode = ancestors.next()) != NULL) {
+ final NodeIterator namespaces =
+ new NamespaceIterator().setStartNode(anode);
+
+ while ((nsnode = namespaces.next()) != NULL) {
+ if (_prefixArray[_prefix[nsnode]].equals(prefix)) {
+ return getNodeValue(nsnode);
+ }
+ }
+ }
+
+ // TODO: Internationalization?
+ throw new TransletException("Namespace prefix '" + prefix + "' is
undeclared.");
+ }
+
+ /**
* Returns 'true' if a specific node is an element (of any type)
*/
public boolean isElement(final int node) {
@@ -1487,7 +1519,9 @@
public int next() {
while (++_node < _limit) {
- if (_type[_node] > TEXT) return(returnNode(_node));
+ if (_type[_node] > TEXT) {
+ return(returnNode(_node));
+ }
}
return(NULL);
}
@@ -3268,7 +3302,7 @@
{
final int node = nextAttributeNode();
final String qname = attList.getQName(i);
- String localname = attList.getLocalName(i);
+ String localName = attList.getLocalName(i);
final String value = attList.getValue(i);
StringBuffer namebuf = new StringBuffer(EMPTYSTRING);
@@ -3276,6 +3310,11 @@
xmlSpaceDefine(attList.getValue(i), parent);
}
+ // If local name is null set it to the empty string
+ if (localName == null) {
+ localName = EMPTYSTRING;
+ }
+
// Create the internal attribute node name ([EMAIL PROTECTED])
final String uri = attList.getURI(i);
if (uri != null && !uri.equals(EMPTYSTRING)) {
@@ -3283,7 +3322,7 @@
namebuf.append(':');
}
namebuf.append('@');
- namebuf.append(localname.length() > 0 ? localname : qname);
+ namebuf.append(localName.length() > 0 ? localName : qname);
String name = namebuf.toString();
@@ -3435,6 +3474,11 @@
_nextSibling2[last] = _currentAttributeNode;
}
}
+ }
+
+ // If local name is null set it to the empty string
+ if (localName == null) {
+ localName = EMPTYSTRING;
}
// Append any attribute nodes
1.2 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/dom/ExtendedSAX.java
Index: ExtendedSAX.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/ExtendedSAX.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
1.17 +12 -5
xml-xalan/java/src/org/apache/xalan/xsltc/dom/MultiDOM.java
Index: MultiDOM.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/MultiDOM.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- MultiDOM.java 4 Dec 2001 10:30:07 -0000 1.16
+++ MultiDOM.java 24 Apr 2002 17:03:16 -0000 1.17
@@ -114,6 +114,7 @@
public NodeIterator setStartNode(final int node) {
_mask = node & SET;
int dom = node >>> 24;
+
// consider caching these
if ((_type == NO_TYPE) || (_type == DOM.ELEMENT)) {
_source = _adapters[dom].getAxisIterator(_axis);
@@ -262,8 +263,7 @@
// This method only has a function in DOM adapters
}
- public int addDOMAdapter(DOM dom) {
-
+ public int addDOMAdapter(DOMAdapter dom) {
// Add the DOM adapter to the array of DOMs
final int domNo = _free++;
if (domNo == _size) {
@@ -275,9 +275,11 @@
// Store reference to document (URI) in hashtable
String uri = dom.getDocumentURI(0);
- _documents.put(uri,new Integer(domNo));
+ _documents.put(uri, new Integer(domNo));
- return domNo << 24;
+ // Store mask in DOMAdapter
+ dom.setMultiDOMMask(domNo << 24);
+ return (domNo << 24);
}
public int getDocumentMask(String uri) {
@@ -453,4 +455,9 @@
return(_adapters[node>>>24].isAttribute(node & CLR));
}
+ public String lookupNamespace(int node, String prefix)
+ throws TransletException
+ {
+ return _adapters[node>>>24].lookupNamespace(node, prefix);
+ }
}
1.3 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/dom/SortingIterator.java
Index: SortingIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/SortingIterator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
1.12 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/dom/UnionIterator.java
Index: UnionIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/UnionIterator.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
1.34 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/AbstractTranslet.java
Index: AbstractTranslet.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/AbstractTranslet.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
1.36 +60 -21
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java
Index: BasisLibrary.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- BasisLibrary.java 2 Apr 2002 19:18:46 -0000 1.35
+++ BasisLibrary.java 24 Apr 2002 17:03:16 -0000 1.36
@@ -79,6 +79,10 @@
import org.apache.xalan.xsltc.*;
import org.apache.xalan.xsltc.DOM;
import org.apache.xalan.xsltc.NodeIterator;
+import org.apache.xalan.xsltc.dom.Axis;
+import org.apache.xalan.xsltc.dom.DOMAdapter;
+import org.apache.xalan.xsltc.dom.MultiDOM;
+import org.apache.xalan.xsltc.dom.AbsoluteIterator;
import org.apache.xalan.xsltc.dom.SingletonIterator;
/**
@@ -447,6 +451,15 @@
return EMPTYSTRING;
}
+ /**
+ * Implements the nodeset() extension function.
+ */
+ public static NodeIterator nodesetF(DOM rtf) {
+ final DOMAdapter adapter = (DOMAdapter) rtf;
+ return new SingletonIterator(
+ DOM.ROOTNODE | adapter.getMultiDOMMask(), true);
+ }
+
//-- Begin utility functions
private static boolean isWhiteSpace(char ch) {
@@ -891,28 +904,31 @@
* obj is an instanceof Node then create a singleton iterator.
*/
public static NodeIterator referenceToNodeSet(Object obj) {
+ // Convert var/param -> node
+ if (obj instanceof Node) {
+ return(new SingletonIterator(((Node)obj).node));
+ }
+ // Convert var/param -> node-set
+ else if (obj instanceof NodeIterator) {
+ return(((NodeIterator)obj).cloneIterator());
+ }
+ else {
+ final String className = obj.getClass().getName();
+ runTimeError(DATA_CONVERSION_ERR, "reference", className);
+ return null;
+ }
+ }
+
+ /**
+ * Utility function used to convert references to DOMs.
+ */
+ public static DOM referenceToResultTree(Object obj) {
try {
- // Convert var/param -> node
- if (obj instanceof Node) {
- return(new SingletonIterator(((Node)obj).node));
- }
- // Convert var/param -> node-set
- else if (obj instanceof NodeIterator) {
- return(((NodeIterator)obj).cloneIterator());
- }
- // Convert var/param -> result-tree fragment
- else if (obj instanceof DOM) {
- DOM dom = (DOM)obj;
- return(dom.getIterator());
- }
- else {
- final String className = obj.getClass().getName();
- runTimeError(DATA_CONVERSION_ERR, "reference", className);
- return null;
- }
+ return ((DOM) obj);
}
- catch (ClassCastException e) {
- runTimeError(DATA_CONVERSION_ERR, "reference", "node-set");
+ catch (IllegalArgumentException e) {
+ final String className = obj.getClass().getName();
+ runTimeError(DATA_CONVERSION_ERR, "reference", className);
return null;
}
}
@@ -960,6 +976,29 @@
}
}
+ /**
+ * This function is used in the execution of xsl:element
+ */
+ public static String getPrefix(String qname) {
+ final int index = qname.indexOf(':');
+ return (index > 0) ? qname.substring(0, index) : null;
+ }
+
+ /**
+ * This function is used in the execution of xsl:element
+ */
+ private static int prefixIndex = 0;
+ public static String generatePrefix() {
+ return ("ns" + prefixIndex++);
+ }
+
+ /**
+ * This function is used in the execution of xsl:element
+ */
+ public static String makeQName(String localName, String prefix) {
+ return (new
StringBuffer(prefix).append(':').append(localName).toString());
+ }
+
public static final int RUN_TIME_INTERNAL_ERR = 0;
public static final int RUN_TIME_COPY_ERR = 1;
public static final int DATA_CONVERSION_ERR = 2;
1.4 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/Constants.java
Index: Constants.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/Constants.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
1.24 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/DefaultSAXOutputHandler.java
Index: DefaultSAXOutputHandler.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/DefaultSAXOutputHandler.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
1.11 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/SAXAdapter.java
Index: SAXAdapter.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/SAXAdapter.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
1.4 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/StringValueHandler.java
Index: StringValueHandler.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/StringValueHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
1.55 +19 -12
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TextOutput.java
Index: TextOutput.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TextOutput.java,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- TextOutput.java 2 Apr 2002 21:52:29 -0000 1.54
+++ TextOutput.java 24 Apr 2002 17:03:16 -0000 1.55
@@ -97,6 +97,7 @@
private boolean _startTagOpen = false;
private boolean _headTagOpen = false;
private boolean _cdataTagOpen = false;
+ private boolean _is8859Encoded = false;
// Contains all elements that should be output as CDATA sections
private Hashtable _cdata = null;
@@ -178,6 +179,7 @@
_saxHandler = handler;
init();
_encoding = encoding;
+ _is8859Encoded = _encoding.equalsIgnoreCase("iso-8859-1");
}
/**
@@ -193,6 +195,7 @@
_lexHandler = lex;
init();
_encoding = encoding;
+ _is8859Encoded = _encoding.equalsIgnoreCase("iso-8859-1");
}
/**
@@ -399,17 +402,19 @@
// the first CDATA and '>' at the beginning of the next. Other
// special characters/sequences are _NOT_ escaped within CDATA.
Integer I = (Integer)_cdataStack.peek();
- if ((I.intValue() == _depth) && (!_cdataTagOpen))
+ if ((I.intValue() == _depth) && (!_cdataTagOpen)) {
startCDATA(ch, off, len);
- // Output characters escaped if required.
- else if (_escapeChars)
- if (_cdataTagOpen)
+ }
+ else if (_escapeChars) {
+ if (_cdataTagOpen) {
escapeCDATA(ch, off, len);
- else
+ } else {
escapeCharacters(ch, off, len);
- // Output the chracters as the are if not.
- else
+ }
+ }
+ else {
_saxHandler.characters(ch, off, len);
+ }
return;
case HTML:
@@ -532,9 +537,11 @@
if (limit > ch.length) limit = ch.length;;
+
// Step through characters and escape all special characters
for (int i = off; i < limit; i++) {
- switch (ch[i]) {
+ char current = ch[i];
+ switch (current) {
case '&':
_saxHandler.characters(ch, offset, i - offset);
_saxHandler.characters(AMP, 0, AMP_length);
@@ -556,9 +563,9 @@
offset = i + 1;
break;
default:
- // Escape all characters not in the basic ASCII character set
- // to simple (hexadecimal) character references
- if (ch[i] > '\u007F') {
+ if ( (current >= '\u007F' && current < '\u00A0') ||
+ (_is8859Encoded && (current > '\u00FF')) )
+ {
StringBuffer buf = new StringBuffer(CHAR_ESC_START);
buf.append(Integer.toString((int)ch[i]));
buf.append(';');
1.3 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TransletLoader.java
Index: TransletLoader.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TransletLoader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
1.12 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/trax/DOM2SAX.java
Index: DOM2SAX.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/DOM2SAX.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
1.11 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/trax/SAX2DOM.java
Index: SAX2DOM.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/SAX2DOM.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
1.6 +2 -3
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java
Index: TemplatesHandlerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TemplatesHandlerImpl.java 16 Apr 2002 11:29:53 -0000 1.5
+++ TemplatesHandlerImpl.java 24 Apr 2002 17:03:17 -0000 1.6
@@ -136,8 +136,7 @@
if (_systemId != null) transletName = Util.baseName(_systemId);
xsltc.setClassName(transletName);
// get java-legal class name from XSLTC module
- transletName = xsltc.getClassName();
-
+ transletName = xsltc.getClassName();
Stylesheet stylesheet = null;
SyntaxTreeNode root = getDocumentRoot();
1.11 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesImpl.java
Index: TemplatesImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesImpl.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
1.35 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java
Index: TransformerFactoryImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
1.38 +1 -1
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerImpl.java
Index: TransformerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerImpl.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]