feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
155
jdkSrc/jdk8/com/sun/org/apache/xalan/internal/Version.java
Normal file
155
jdkSrc/jdk8/com/sun/org/apache/xalan/internal/Version.java
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 2003-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.
|
||||
*/
|
||||
/*
|
||||
* $Id: Version.java,v 1.1.2.1 2005/08/01 02:11:19 jeffsuttor Exp $
|
||||
*/
|
||||
package com.sun.org.apache.xalan.internal;
|
||||
|
||||
/**
|
||||
* Administrative class to keep track of the version number of
|
||||
* the Xalan release.
|
||||
* <P>This class implements the upcoming standard of having
|
||||
* org.apache.project-name.Version.getVersion() be a standard way
|
||||
* to get version information. This class will replace the older
|
||||
* com.sun.org.apache.xalan.internal.processor.Version class.</P>
|
||||
* <P>See also: com/sun/org/apache/xalan/internal/res/XSLTInfo.properties for
|
||||
* information about the version of the XSLT spec we support.</P>
|
||||
* @xsl.usage general
|
||||
*/
|
||||
public class Version
|
||||
{
|
||||
|
||||
/**
|
||||
* Get the basic version string for the current Xalan release.
|
||||
* Version String formatted like
|
||||
* <CODE>"<B>Xalan</B> <B>Java</B> v.r[.dd| <B>D</B>nn]"</CODE>.
|
||||
*
|
||||
* Futurework: have this read version info from jar manifest.
|
||||
*
|
||||
* @return String denoting our current version
|
||||
*/
|
||||
public static String getVersion()
|
||||
{
|
||||
return getProduct()+" "+getImplementationLanguage()+" "
|
||||
+getMajorVersionNum()+"."+getReleaseVersionNum()+"."
|
||||
+( (getDevelopmentVersionNum() > 0) ?
|
||||
("D"+getDevelopmentVersionNum()) : (""+getMaintenanceVersionNum()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the processor version to the command line.
|
||||
*
|
||||
* @param argv command line arguments, unused.
|
||||
*/
|
||||
public static void _main(String argv[])
|
||||
{
|
||||
System.out.println(getVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of product: Xalan.
|
||||
*/
|
||||
public static String getProduct()
|
||||
{
|
||||
return "Xalan";
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation Language: Java.
|
||||
*/
|
||||
public static String getImplementationLanguage()
|
||||
{
|
||||
return "Java";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Major version number.
|
||||
* Version number. This changes only when there is a
|
||||
* significant, externally apparent enhancement from
|
||||
* the previous release. 'n' represents the n'th
|
||||
* version.
|
||||
*
|
||||
* Clients should carefully consider the implications
|
||||
* of new versions as external interfaces and behaviour
|
||||
* may have changed.
|
||||
*/
|
||||
public static int getMajorVersionNum()
|
||||
{
|
||||
return 2;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Release Number.
|
||||
* Release number. This changes when:
|
||||
* - a new set of functionality is to be added, eg,
|
||||
* implementation of a new W3C specification.
|
||||
* - API or behaviour change.
|
||||
* - its designated as a reference release.
|
||||
*/
|
||||
public static int getReleaseVersionNum()
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maintenance Drop Number.
|
||||
* Optional identifier used to designate maintenance
|
||||
* drop applied to a specific release and contains
|
||||
* fixes for defects reported. It maintains compatibility
|
||||
* with the release and contains no API changes.
|
||||
* When missing, it designates the final and complete
|
||||
* development drop for a release.
|
||||
*/
|
||||
public static int getMaintenanceVersionNum()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Development Drop Number.
|
||||
* Optional identifier designates development drop of
|
||||
* a specific release. D01 is the first development drop
|
||||
* of a new release.
|
||||
*
|
||||
* Development drops are works in progress towards a
|
||||
* compeleted, final release. A specific development drop
|
||||
* may not completely implement all aspects of a new
|
||||
* feature, which may take several development drops to
|
||||
* complete. At the point of the final drop for the
|
||||
* release, the D suffix will be omitted.
|
||||
*
|
||||
* Each 'D' drops can contain functional enhancements as
|
||||
* well as defect fixes. 'D' drops may not be as stable as
|
||||
* the final releases.
|
||||
*/
|
||||
public static int getDevelopmentVersionNum()
|
||||
{
|
||||
try {
|
||||
if ((new String("")).length() == 0)
|
||||
return 0;
|
||||
else
|
||||
return Integer.parseInt("");
|
||||
} catch (NumberFormatException nfe) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
|
||||
|
||||
/**
|
||||
* Commonly used constants.
|
||||
*
|
||||
* @author Huizhe Wang, Oracle
|
||||
*
|
||||
*/
|
||||
public final class XalanConstants {
|
||||
|
||||
//
|
||||
// Constants
|
||||
//
|
||||
//Xerces security manager
|
||||
public static final String SECURITY_MANAGER =
|
||||
"http://apache.org/xml/properties/security-manager";
|
||||
|
||||
//
|
||||
// Implementation limits: API properties
|
||||
//
|
||||
/** Oracle JAXP property prefix ("http://www.oracle.com/xml/jaxp/properties/"). */
|
||||
public static final String ORACLE_JAXP_PROPERTY_PREFIX =
|
||||
"http://www.oracle.com/xml/jaxp/properties/";
|
||||
/**
|
||||
* JDK entity expansion limit; Note that the existing system property
|
||||
* "entityExpansionLimit" with no prefix is still observed
|
||||
*/
|
||||
public static final String JDK_ENTITY_EXPANSION_LIMIT =
|
||||
ORACLE_JAXP_PROPERTY_PREFIX + "entityExpansionLimit";
|
||||
|
||||
/**
|
||||
* JDK element attribute limit; Note that the existing system property
|
||||
* "elementAttributeLimit" with no prefix is still observed
|
||||
*/
|
||||
public static final String JDK_ELEMENT_ATTRIBUTE_LIMIT =
|
||||
ORACLE_JAXP_PROPERTY_PREFIX + "elementAttributeLimit";
|
||||
|
||||
/**
|
||||
* JDK maxOccur limit; Note that the existing system property
|
||||
* "maxOccurLimit" with no prefix is still observed
|
||||
*/
|
||||
public static final String JDK_MAX_OCCUR_LIMIT =
|
||||
ORACLE_JAXP_PROPERTY_PREFIX + "maxOccurLimit";
|
||||
|
||||
/**
|
||||
* JDK total entity size limit
|
||||
*/
|
||||
public static final String JDK_TOTAL_ENTITY_SIZE_LIMIT =
|
||||
ORACLE_JAXP_PROPERTY_PREFIX + "totalEntitySizeLimit";
|
||||
|
||||
/**
|
||||
* JDK maximum general entity size limit
|
||||
*/
|
||||
public static final String JDK_GENERAL_ENTITY_SIZE_LIMIT =
|
||||
ORACLE_JAXP_PROPERTY_PREFIX + "maxGeneralEntitySizeLimit";
|
||||
|
||||
/**
|
||||
* JDK node count limit in entities that limits the total number of nodes
|
||||
* in all of entity references.
|
||||
*/
|
||||
public static final String JDK_ENTITY_REPLACEMENT_LIMIT =
|
||||
ORACLE_JAXP_PROPERTY_PREFIX + "entityReplacementLimit";
|
||||
|
||||
/**
|
||||
* JDK maximum parameter entity size limit
|
||||
*/
|
||||
public static final String JDK_PARAMETER_ENTITY_SIZE_LIMIT =
|
||||
ORACLE_JAXP_PROPERTY_PREFIX + "maxParameterEntitySizeLimit";
|
||||
/**
|
||||
* JDK maximum XML name limit
|
||||
*/
|
||||
public static final String JDK_XML_NAME_LIMIT =
|
||||
ORACLE_JAXP_PROPERTY_PREFIX + "maxXMLNameLimit";
|
||||
|
||||
/**
|
||||
* JDK maxElementDepth limit
|
||||
*/
|
||||
public static final String JDK_MAX_ELEMENT_DEPTH =
|
||||
ORACLE_JAXP_PROPERTY_PREFIX + "maxElementDepth";
|
||||
|
||||
/**
|
||||
* JDK property indicating whether the parser shall print out entity
|
||||
* count information
|
||||
* Value: a string "yes" means print, "no" or any other string means not.
|
||||
*/
|
||||
public static final String JDK_ENTITY_COUNT_INFO =
|
||||
ORACLE_JAXP_PROPERTY_PREFIX + "getEntityCountInfo";
|
||||
|
||||
//
|
||||
// Implementation limits: corresponding System Properties of the above
|
||||
// API properties
|
||||
//
|
||||
/**
|
||||
* JDK entity expansion limit; Note that the existing system property
|
||||
* "entityExpansionLimit" with no prefix is still observed
|
||||
*/
|
||||
public static final String SP_ENTITY_EXPANSION_LIMIT = "jdk.xml.entityExpansionLimit";
|
||||
|
||||
/**
|
||||
* JDK element attribute limit; Note that the existing system property
|
||||
* "elementAttributeLimit" with no prefix is still observed
|
||||
*/
|
||||
public static final String SP_ELEMENT_ATTRIBUTE_LIMIT = "jdk.xml.elementAttributeLimit";
|
||||
|
||||
/**
|
||||
* JDK maxOccur limit; Note that the existing system property
|
||||
* "maxOccurLimit" with no prefix is still observed
|
||||
*/
|
||||
public static final String SP_MAX_OCCUR_LIMIT = "jdk.xml.maxOccurLimit";
|
||||
|
||||
/**
|
||||
* JDK total entity size limit
|
||||
*/
|
||||
public static final String SP_TOTAL_ENTITY_SIZE_LIMIT = "jdk.xml.totalEntitySizeLimit";
|
||||
|
||||
/**
|
||||
* JDK maximum general entity size limit
|
||||
*/
|
||||
public static final String SP_GENERAL_ENTITY_SIZE_LIMIT = "jdk.xml.maxGeneralEntitySizeLimit";
|
||||
|
||||
/**
|
||||
* JDK node count limit in entities that limits the total number of nodes
|
||||
* in all of entity references.
|
||||
*/
|
||||
public static final String SP_ENTITY_REPLACEMENT_LIMIT = "jdk.xml.entityReplacementLimit";
|
||||
|
||||
/**
|
||||
* JDK maximum parameter entity size limit
|
||||
*/
|
||||
public static final String SP_PARAMETER_ENTITY_SIZE_LIMIT = "jdk.xml.maxParameterEntitySizeLimit";
|
||||
/**
|
||||
* JDK maximum XML name limit
|
||||
*/
|
||||
public static final String SP_XML_NAME_LIMIT = "jdk.xml.maxXMLNameLimit";
|
||||
|
||||
/**
|
||||
* JDK maxElementDepth limit
|
||||
*/
|
||||
public static final String SP_MAX_ELEMENT_DEPTH = "jdk.xml.maxElementDepth";
|
||||
|
||||
/**
|
||||
* JDK TransformerFactory and Transformer attribute that specifies a class
|
||||
* loader that will be used for extension functions class loading
|
||||
* Value: a "null", the default value, means that the default EF class loading
|
||||
* path will be used.
|
||||
* Instance of ClassLoader: the specified instance of ClassLoader will be used
|
||||
* for extension functions loading during translation process
|
||||
*/
|
||||
public static final String JDK_EXTENSION_CLASSLOADER = "jdk.xml.transform.extensionClassLoader";
|
||||
|
||||
/**
|
||||
* JDK XPath Expression group limit
|
||||
*/
|
||||
public static final String XPATH_GROUP_LIMIT = "jdk.xml.xpathExprGrpLimit";
|
||||
|
||||
/**
|
||||
* JDK XPath Expression operators limit
|
||||
*/
|
||||
public static final String XPATH_OP_LIMIT = "jdk.xml.xpathExprOpLimit";
|
||||
|
||||
/**
|
||||
* JDK XSL XPath limit or Total Number of Operators Permitted in an XSL Stylesheet
|
||||
*/
|
||||
public static final String XPATH_TOTALOP_LIMIT = "jdk.xml.xpathTotalOpLimit";
|
||||
|
||||
//legacy System Properties
|
||||
public final static String ENTITY_EXPANSION_LIMIT = "entityExpansionLimit";
|
||||
public static final String ELEMENT_ATTRIBUTE_LIMIT = "elementAttributeLimit" ;
|
||||
public final static String MAX_OCCUR_LIMIT = "maxOccurLimit";
|
||||
|
||||
/**
|
||||
* A string "yes" that can be used for properties such as getEntityCountInfo
|
||||
*/
|
||||
public static final String JDK_YES = "yes";
|
||||
|
||||
// Oracle Feature:
|
||||
/**
|
||||
* <p>Use Service Mechanism</p>
|
||||
*
|
||||
* <ul>
|
||||
* <li>
|
||||
* {@code true} instruct an object to use service mechanism to
|
||||
* find a service implementation. This is the default behavior.
|
||||
* </li>
|
||||
* <li>
|
||||
* {@code false} instruct an object to skip service mechanism and
|
||||
* use the default implementation for that service.
|
||||
* </li>
|
||||
* </ul>
|
||||
*/
|
||||
public static final String ORACLE_FEATURE_SERVICE_MECHANISM = "http://www.oracle.com/feature/use-service-mechanism";
|
||||
|
||||
|
||||
//System Properties corresponding to ACCESS_EXTERNAL_* properties
|
||||
public static final String SP_ACCESS_EXTERNAL_STYLESHEET = "javax.xml.accessExternalStylesheet";
|
||||
public static final String SP_ACCESS_EXTERNAL_DTD = "javax.xml.accessExternalDTD";
|
||||
|
||||
//all access keyword
|
||||
public static final String ACCESS_EXTERNAL_ALL = "all";
|
||||
|
||||
/**
|
||||
* Default value when FEATURE_SECURE_PROCESSING (FSP) is set to true
|
||||
*/
|
||||
public static final String EXTERNAL_ACCESS_DEFAULT_FSP = "";
|
||||
|
||||
/**
|
||||
* FEATURE_SECURE_PROCESSING (FSP) is false by default
|
||||
*/
|
||||
public static final String EXTERNAL_ACCESS_DEFAULT = ACCESS_EXTERNAL_ALL;
|
||||
|
||||
public static final String XML_SECURITY_PROPERTY_MANAGER =
|
||||
ORACLE_JAXP_PROPERTY_PREFIX + "xmlSecurityPropertyManager";
|
||||
|
||||
/**
|
||||
* Feature enableExtensionFunctions
|
||||
*/
|
||||
public static final String ORACLE_ENABLE_EXTENSION_FUNCTION =
|
||||
ORACLE_JAXP_PROPERTY_PREFIX + "enableExtensionFunctions";
|
||||
public static final String SP_ORACLE_ENABLE_EXTENSION_FUNCTION = "javax.xml.enableExtensionFunctions";
|
||||
|
||||
/**
|
||||
* Values for a feature
|
||||
*/
|
||||
public static final String FEATURE_TRUE = "true";
|
||||
public static final String FEATURE_FALSE = "false";
|
||||
|
||||
/**
|
||||
* Check if we're in jdk8 or above
|
||||
*/
|
||||
public static final boolean IS_JDK8_OR_ABOVE = isJavaVersionAtLeast(8);
|
||||
|
||||
/*
|
||||
* Check the version of the current JDK against that specified in the
|
||||
* parameter
|
||||
*
|
||||
* There is a proposal to change the java version string to:
|
||||
* MAJOR.MINOR.FU.CPU.PSU-BUILDNUMBER_BUGIDNUMBER_OPTIONAL
|
||||
* This method would work with both the current format and that proposed
|
||||
*
|
||||
* @param compareTo a JDK version to be compared to
|
||||
* @return true if the current version is the same or above that represented
|
||||
* by the parameter
|
||||
*/
|
||||
public static boolean isJavaVersionAtLeast(int compareTo) {
|
||||
String javaVersion = SecuritySupport.getSystemProperty("java.version");
|
||||
String versions[] = javaVersion.split("\\.", 3);
|
||||
if (Integer.parseInt(versions[0]) >= compareTo ||
|
||||
Integer.parseInt(versions[1]) >= compareTo) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // class Constants
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.extensions;
|
||||
|
||||
import javax.xml.transform.ErrorListener;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.objects.XObject;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.traversal.NodeIterator;
|
||||
|
||||
/**
|
||||
* An object that implements this interface can supply
|
||||
* information about the current XPath expression context.
|
||||
*/
|
||||
public interface ExpressionContext
|
||||
{
|
||||
|
||||
/**
|
||||
* Get the current context node.
|
||||
* @return The current context node.
|
||||
*/
|
||||
public Node getContextNode();
|
||||
|
||||
/**
|
||||
* Get the current context node list.
|
||||
* @return An iterator for the current context list, as
|
||||
* defined in XSLT.
|
||||
*/
|
||||
public NodeIterator getContextNodes();
|
||||
|
||||
/**
|
||||
* Get the error listener.
|
||||
* @return The registered error listener.
|
||||
*/
|
||||
public ErrorListener getErrorListener();
|
||||
|
||||
/**
|
||||
* Get the value of a node as a number.
|
||||
* @param n Node to be converted to a number. May be null.
|
||||
* @return value of n as a number.
|
||||
*/
|
||||
public double toNumber(Node n);
|
||||
|
||||
/**
|
||||
* Get the value of a node as a string.
|
||||
* @param n Node to be converted to a string. May be null.
|
||||
* @return value of n as a string, or an empty string if n is null.
|
||||
*/
|
||||
public String toString(Node n);
|
||||
|
||||
/**
|
||||
* Get a variable based on it's qualified name.
|
||||
*
|
||||
* @param qname The qualified name of the variable.
|
||||
*
|
||||
* @return The evaluated value of the variable.
|
||||
*
|
||||
* @throws javax.xml.transform.TransformerException
|
||||
*/
|
||||
public XObject getVariableOrParam(com.sun.org.apache.xml.internal.utils.QName qname)
|
||||
throws javax.xml.transform.TransformerException;
|
||||
|
||||
/**
|
||||
* Get the XPathContext that owns this ExpressionContext.
|
||||
*
|
||||
* Note: exslt:function requires the XPathContext to access
|
||||
* the variable stack and TransformerImpl.
|
||||
*
|
||||
* @return The current XPathContext.
|
||||
* @throws javax.xml.transform.TransformerException
|
||||
*/
|
||||
public com.sun.org.apache.xpath.internal.XPathContext getXPathContext()
|
||||
throws javax.xml.transform.TransformerException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.lib;
|
||||
|
||||
import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* The base class for some EXSLT extension classes.
|
||||
* It contains common utility methods to be used by the sub-classes.
|
||||
*/
|
||||
public abstract class ExsltBase
|
||||
{
|
||||
/**
|
||||
* Return the string value of a Node
|
||||
*
|
||||
* @param n The Node.
|
||||
* @return The string value of the Node
|
||||
*/
|
||||
protected static String toString(Node n)
|
||||
{
|
||||
if (n instanceof DTMNodeProxy)
|
||||
return ((DTMNodeProxy)n).getStringValue();
|
||||
else
|
||||
{
|
||||
String value = n.getNodeValue();
|
||||
if (value == null)
|
||||
{
|
||||
NodeList nodelist = n.getChildNodes();
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = 0; i < nodelist.getLength(); i++)
|
||||
{
|
||||
Node childNode = nodelist.item(i);
|
||||
buf.append(toString(childNode));
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
else
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the string value of a Node to a number.
|
||||
* Return NaN if the string is not a valid number.
|
||||
*
|
||||
* @param n The Node.
|
||||
* @return The number value of the Node
|
||||
*/
|
||||
protected static double toNumber(Node n)
|
||||
{
|
||||
double d = 0.0;
|
||||
String str = toString(n);
|
||||
try
|
||||
{
|
||||
d = Double.valueOf(str).doubleValue();
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
d= Double.NaN;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.lib;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.extensions.ExpressionContext;
|
||||
import com.sun.org.apache.xml.internal.dtm.DTMIterator;
|
||||
import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeIterator;
|
||||
import com.sun.org.apache.xpath.internal.NodeSet;
|
||||
|
||||
/**
|
||||
* This class contains EXSLT common extension functions.
|
||||
* It is accessed by specifying a namespace URI as follows:
|
||||
* <pre>
|
||||
* xmlns:exslt="http://exslt.org/common"
|
||||
* </pre>
|
||||
*
|
||||
* The documentation for each function has been copied from the relevant
|
||||
* EXSLT Implementer page.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
* @xsl.usage general
|
||||
*/
|
||||
public class ExsltCommon
|
||||
{
|
||||
/**
|
||||
* The exsl:object-type function returns a string giving the type of the object passed
|
||||
* as the argument. The possible object types are: 'string', 'number', 'boolean',
|
||||
* 'node-set', 'RTF', or 'external'.
|
||||
*
|
||||
* Most XSLT object types can be coerced to each other without error. However, there are
|
||||
* certain coercions that raise errors, most importantly treating anything other than a
|
||||
* node set as a node set. Authors of utilities such as named templates or user-defined
|
||||
* extension functions may wish to give some flexibility in the parameter and argument values
|
||||
* that are accepted by the utility; the exsl:object-type function enables them to do so.
|
||||
*
|
||||
* The Xalan extensions MethodResolver converts 'object-type' to 'objectType'.
|
||||
*
|
||||
* @param obj The object to be typed.
|
||||
* @return objectType 'string', 'number', 'boolean', 'node-set', 'RTF', or 'external'.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
*/
|
||||
public static String objectType (Object obj)
|
||||
{
|
||||
if (obj instanceof String)
|
||||
return "string";
|
||||
else if (obj instanceof Boolean)
|
||||
return "boolean";
|
||||
else if (obj instanceof Number)
|
||||
return "number";
|
||||
else if (obj instanceof DTMNodeIterator)
|
||||
{
|
||||
DTMIterator dtmI = ((DTMNodeIterator)obj).getDTMIterator();
|
||||
if (dtmI instanceof com.sun.org.apache.xpath.internal.axes.RTFIterator)
|
||||
return "RTF";
|
||||
else
|
||||
return "node-set";
|
||||
}
|
||||
else
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
/**
|
||||
* The exsl:node-set function converts a result tree fragment (which is what you get
|
||||
* when you use the content of xsl:variable rather than its select attribute to give
|
||||
* a variable value) into a node set. This enables you to process the XML that you create
|
||||
* within a variable, and therefore do multi-step processing.
|
||||
*
|
||||
* You can also use this function to turn a string into a text node, which is helpful
|
||||
* if you want to pass a string to a function that only accepts a node set.
|
||||
*
|
||||
* The Xalan extensions MethodResolver converts 'node-set' to 'nodeSet'.
|
||||
*
|
||||
* @param myProcessor is passed in by the Xalan extension processor
|
||||
* @param rtf The result tree fragment to be converted to a node-set.
|
||||
*
|
||||
* @return node-set with the contents of the result tree fragment.
|
||||
*
|
||||
* Note: Already implemented in the xalan namespace as nodeset.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
*/
|
||||
public static NodeSet nodeSet(ExpressionContext myProcessor, Object rtf)
|
||||
{
|
||||
return Extensions.nodeset(myProcessor, rtf);
|
||||
}
|
||||
|
||||
}
|
||||
1120
jdkSrc/jdk8/com/sun/org/apache/xalan/internal/lib/ExsltDatetime.java
Normal file
1120
jdkSrc/jdk8/com/sun/org/apache/xalan/internal/lib/ExsltDatetime.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,612 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.lib;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.extensions.ExpressionContext;
|
||||
import com.sun.org.apache.xalan.internal.res.XSLMessages;
|
||||
import com.sun.org.apache.xalan.internal.res.XSLTErrorResources;
|
||||
import com.sun.org.apache.xpath.internal.NodeSet;
|
||||
import com.sun.org.apache.xpath.internal.NodeSetDTM;
|
||||
import com.sun.org.apache.xpath.internal.XPath;
|
||||
import com.sun.org.apache.xpath.internal.XPathContext;
|
||||
import com.sun.org.apache.xpath.internal.objects.XBoolean;
|
||||
import com.sun.org.apache.xpath.internal.objects.XNodeSet;
|
||||
import com.sun.org.apache.xpath.internal.objects.XNumber;
|
||||
import com.sun.org.apache.xpath.internal.objects.XObject;
|
||||
import jdk.xml.internal.JdkXmlUtils;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
|
||||
/**
|
||||
* This class contains EXSLT dynamic extension functions.
|
||||
*
|
||||
* It is accessed by specifying a namespace URI as follows:
|
||||
* <pre>
|
||||
* xmlns:dyn="http://exslt.org/dynamic"
|
||||
* </pre>
|
||||
* The documentation for each function has been copied from the relevant
|
||||
* EXSLT Implementer page.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
|
||||
* @xsl.usage general
|
||||
*/
|
||||
public class ExsltDynamic extends ExsltBase
|
||||
{
|
||||
|
||||
public static final String EXSL_URI = "http://exslt.org/common";
|
||||
|
||||
/**
|
||||
* The dyn:max function calculates the maximum value for the nodes passed as
|
||||
* the first argument, where the value of each node is calculated dynamically
|
||||
* using an XPath expression passed as a string as the second argument.
|
||||
* <p>
|
||||
* The expressions are evaluated relative to the nodes passed as the first argument.
|
||||
* In other words, the value for each node is calculated by evaluating the XPath
|
||||
* expression with all context information being the same as that for the call to
|
||||
* the dyn:max function itself, except for the following:
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>the context node is the node whose value is being calculated.</li>
|
||||
* <li>the context position is the position of the node within the node set passed as
|
||||
* the first argument to the dyn:max function, arranged in document order.</li>
|
||||
* <li>the context size is the number of nodes passed as the first argument to the
|
||||
* dyn:max function.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* The dyn:max function returns the maximum of these values, calculated in exactly
|
||||
* the same way as for math:max.
|
||||
* <p>
|
||||
* If the expression string passed as the second argument is an invalid XPath
|
||||
* expression (including an empty string), this function returns NaN.
|
||||
* <p>
|
||||
* This function must take a second argument. To calculate the maximum of a set of
|
||||
* nodes based on their string values, you should use the math:max function.
|
||||
*
|
||||
* @param myContext The ExpressionContext passed by the extension processor
|
||||
* @param nl The node set
|
||||
* @param expr The expression string
|
||||
*
|
||||
* @return The maximum evaluation value
|
||||
*/
|
||||
public static double max(ExpressionContext myContext, NodeList nl, String expr)
|
||||
throws SAXNotSupportedException
|
||||
{
|
||||
|
||||
XPathContext xctxt = null;
|
||||
if (myContext instanceof XPathContext.XPathExpressionContext)
|
||||
xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
|
||||
else
|
||||
throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext }));
|
||||
|
||||
if (expr == null || expr.length() == 0)
|
||||
return Double.NaN;
|
||||
|
||||
NodeSetDTM contextNodes = new NodeSetDTM(nl, xctxt);
|
||||
xctxt.pushContextNodeList(contextNodes);
|
||||
|
||||
double maxValue = - Double.MAX_VALUE;
|
||||
for (int i = 0; i < contextNodes.getLength(); i++)
|
||||
{
|
||||
int contextNode = contextNodes.item(i);
|
||||
xctxt.pushCurrentNode(contextNode);
|
||||
|
||||
double result = 0;
|
||||
try
|
||||
{
|
||||
XPath dynamicXPath = new XPath(expr, xctxt.getSAXLocator(),
|
||||
xctxt.getNamespaceContext(),
|
||||
XPath.SELECT);
|
||||
result = dynamicXPath.execute(xctxt, contextNode, xctxt.getNamespaceContext()).num();
|
||||
}
|
||||
catch (TransformerException e)
|
||||
{
|
||||
xctxt.popCurrentNode();
|
||||
xctxt.popContextNodeList();
|
||||
return Double.NaN;
|
||||
}
|
||||
|
||||
xctxt.popCurrentNode();
|
||||
|
||||
if (result > maxValue)
|
||||
maxValue = result;
|
||||
}
|
||||
|
||||
xctxt.popContextNodeList();
|
||||
return maxValue;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The dyn:min function calculates the minimum value for the nodes passed as the
|
||||
* first argument, where the value of each node is calculated dynamically using
|
||||
* an XPath expression passed as a string as the second argument.
|
||||
* <p>
|
||||
* The expressions are evaluated relative to the nodes passed as the first argument.
|
||||
* In other words, the value for each node is calculated by evaluating the XPath
|
||||
* expression with all context information being the same as that for the call to
|
||||
* the dyn:min function itself, except for the following:
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>the context node is the node whose value is being calculated.</li>
|
||||
* <li>the context position is the position of the node within the node set passed
|
||||
* as the first argument to the dyn:min function, arranged in document order.</li>
|
||||
* <li>the context size is the number of nodes passed as the first argument to the
|
||||
* dyn:min function.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* The dyn:min function returns the minimum of these values, calculated in exactly
|
||||
* the same way as for math:min.
|
||||
* <p>
|
||||
* If the expression string passed as the second argument is an invalid XPath expression
|
||||
* (including an empty string), this function returns NaN.
|
||||
* <p>
|
||||
* This function must take a second argument. To calculate the minimum of a set of
|
||||
* nodes based on their string values, you should use the math:min function.
|
||||
*
|
||||
* @param myContext The ExpressionContext passed by the extension processor
|
||||
* @param nl The node set
|
||||
* @param expr The expression string
|
||||
*
|
||||
* @return The minimum evaluation value
|
||||
*/
|
||||
public static double min(ExpressionContext myContext, NodeList nl, String expr)
|
||||
throws SAXNotSupportedException
|
||||
{
|
||||
|
||||
XPathContext xctxt = null;
|
||||
if (myContext instanceof XPathContext.XPathExpressionContext)
|
||||
xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
|
||||
else
|
||||
throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext }));
|
||||
|
||||
if (expr == null || expr.length() == 0)
|
||||
return Double.NaN;
|
||||
|
||||
NodeSetDTM contextNodes = new NodeSetDTM(nl, xctxt);
|
||||
xctxt.pushContextNodeList(contextNodes);
|
||||
|
||||
double minValue = Double.MAX_VALUE;
|
||||
for (int i = 0; i < nl.getLength(); i++)
|
||||
{
|
||||
int contextNode = contextNodes.item(i);
|
||||
xctxt.pushCurrentNode(contextNode);
|
||||
|
||||
double result = 0;
|
||||
try
|
||||
{
|
||||
XPath dynamicXPath = new XPath(expr, xctxt.getSAXLocator(),
|
||||
xctxt.getNamespaceContext(),
|
||||
XPath.SELECT);
|
||||
result = dynamicXPath.execute(xctxt, contextNode, xctxt.getNamespaceContext()).num();
|
||||
}
|
||||
catch (TransformerException e)
|
||||
{
|
||||
xctxt.popCurrentNode();
|
||||
xctxt.popContextNodeList();
|
||||
return Double.NaN;
|
||||
}
|
||||
|
||||
xctxt.popCurrentNode();
|
||||
|
||||
if (result < minValue)
|
||||
minValue = result;
|
||||
}
|
||||
|
||||
xctxt.popContextNodeList();
|
||||
return minValue;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The dyn:sum function calculates the sum for the nodes passed as the first argument,
|
||||
* where the value of each node is calculated dynamically using an XPath expression
|
||||
* passed as a string as the second argument.
|
||||
* <p>
|
||||
* The expressions are evaluated relative to the nodes passed as the first argument.
|
||||
* In other words, the value for each node is calculated by evaluating the XPath
|
||||
* expression with all context information being the same as that for the call to
|
||||
* the dyn:sum function itself, except for the following:
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>the context node is the node whose value is being calculated.</li>
|
||||
* <li>the context position is the position of the node within the node set passed as
|
||||
* the first argument to the dyn:sum function, arranged in document order.</li>
|
||||
* <li>the context size is the number of nodes passed as the first argument to the
|
||||
* dyn:sum function.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* The dyn:sum function returns the sumimum of these values, calculated in exactly
|
||||
* the same way as for sum.
|
||||
* <p>
|
||||
* If the expression string passed as the second argument is an invalid XPath
|
||||
* expression (including an empty string), this function returns NaN.
|
||||
* <p>
|
||||
* This function must take a second argument. To calculate the sumimum of a set of
|
||||
* nodes based on their string values, you should use the sum function.
|
||||
*
|
||||
* @param myContext The ExpressionContext passed by the extension processor
|
||||
* @param nl The node set
|
||||
* @param expr The expression string
|
||||
*
|
||||
* @return The sum of the evaluation value on each node
|
||||
*/
|
||||
public static double sum(ExpressionContext myContext, NodeList nl, String expr)
|
||||
throws SAXNotSupportedException
|
||||
{
|
||||
XPathContext xctxt = null;
|
||||
if (myContext instanceof XPathContext.XPathExpressionContext)
|
||||
xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
|
||||
else
|
||||
throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext }));
|
||||
|
||||
if (expr == null || expr.length() == 0)
|
||||
return Double.NaN;
|
||||
|
||||
NodeSetDTM contextNodes = new NodeSetDTM(nl, xctxt);
|
||||
xctxt.pushContextNodeList(contextNodes);
|
||||
|
||||
double sum = 0;
|
||||
for (int i = 0; i < nl.getLength(); i++)
|
||||
{
|
||||
int contextNode = contextNodes.item(i);
|
||||
xctxt.pushCurrentNode(contextNode);
|
||||
|
||||
double result = 0;
|
||||
try
|
||||
{
|
||||
XPath dynamicXPath = new XPath(expr, xctxt.getSAXLocator(),
|
||||
xctxt.getNamespaceContext(),
|
||||
XPath.SELECT);
|
||||
result = dynamicXPath.execute(xctxt, contextNode, xctxt.getNamespaceContext()).num();
|
||||
}
|
||||
catch (TransformerException e)
|
||||
{
|
||||
xctxt.popCurrentNode();
|
||||
xctxt.popContextNodeList();
|
||||
return Double.NaN;
|
||||
}
|
||||
|
||||
xctxt.popCurrentNode();
|
||||
|
||||
sum = sum + result;
|
||||
|
||||
}
|
||||
|
||||
xctxt.popContextNodeList();
|
||||
return sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dyn:map function evaluates the expression passed as the second argument for
|
||||
* each of the nodes passed as the first argument, and returns a node set of those values.
|
||||
* <p>
|
||||
* The expressions are evaluated relative to the nodes passed as the first argument.
|
||||
* In other words, the value for each node is calculated by evaluating the XPath
|
||||
* expression with all context information being the same as that for the call to
|
||||
* the dyn:map function itself, except for the following:
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>The context node is the node whose value is being calculated.</li>
|
||||
* <li>the context position is the position of the node within the node set passed
|
||||
* as the first argument to the dyn:map function, arranged in document order.</li>
|
||||
* <li>the context size is the number of nodes passed as the first argument to the
|
||||
* dyn:map function.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* If the expression string passed as the second argument is an invalid XPath
|
||||
* expression (including an empty string), this function returns an empty node set.
|
||||
* <p>
|
||||
* If the XPath expression evaluates as a node set, the dyn:map function returns
|
||||
* the union of the node sets returned by evaluating the expression for each of the
|
||||
* nodes in the first argument. Note that this may mean that the node set resulting
|
||||
* from the call to the dyn:map function contains a different number of nodes from
|
||||
* the number in the node set passed as the first argument to the function.
|
||||
* <p>
|
||||
* If the XPath expression evaluates as a number, the dyn:map function returns a
|
||||
* node set containing one exsl:number element (namespace http://exslt.org/common)
|
||||
* for each node in the node set passed as the first argument to the dyn:map function,
|
||||
* in document order. The string value of each exsl:number element is the same as
|
||||
* the result of converting the number resulting from evaluating the expression to
|
||||
* a string as with the number function, with the exception that Infinity results
|
||||
* in an exsl:number holding the highest number the implementation can store, and
|
||||
* -Infinity results in an exsl:number holding the lowest number the implementation
|
||||
* can store.
|
||||
* <p>
|
||||
* If the XPath expression evaluates as a boolean, the dyn:map function returns a
|
||||
* node set containing one exsl:boolean element (namespace http://exslt.org/common)
|
||||
* for each node in the node set passed as the first argument to the dyn:map function,
|
||||
* in document order. The string value of each exsl:boolean element is 'true' if the
|
||||
* expression evaluates as true for the node, and '' if the expression evaluates as
|
||||
* false.
|
||||
* <p>
|
||||
* Otherwise, the dyn:map function returns a node set containing one exsl:string
|
||||
* element (namespace http://exslt.org/common) for each node in the node set passed
|
||||
* as the first argument to the dyn:map function, in document order. The string
|
||||
* value of each exsl:string element is the same as the result of converting the
|
||||
* result of evaluating the expression for the relevant node to a string as with
|
||||
* the string function.
|
||||
*
|
||||
* @param myContext The ExpressionContext passed by the extension processor
|
||||
* @param nl The node set
|
||||
* @param expr The expression string
|
||||
*
|
||||
* @return The node set after evaluation
|
||||
*/
|
||||
public static NodeList map(ExpressionContext myContext, NodeList nl, String expr)
|
||||
throws SAXNotSupportedException
|
||||
{
|
||||
XPathContext xctxt = null;
|
||||
Document lDoc = null;
|
||||
|
||||
if (myContext instanceof XPathContext.XPathExpressionContext)
|
||||
xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
|
||||
else
|
||||
throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext }));
|
||||
|
||||
if (expr == null || expr.length() == 0)
|
||||
return new NodeSet();
|
||||
|
||||
NodeSetDTM contextNodes = new NodeSetDTM(nl, xctxt);
|
||||
xctxt.pushContextNodeList(contextNodes);
|
||||
|
||||
NodeSet resultSet = new NodeSet();
|
||||
resultSet.setShouldCacheNodes(true);
|
||||
|
||||
for (int i = 0; i < nl.getLength(); i++)
|
||||
{
|
||||
int contextNode = contextNodes.item(i);
|
||||
xctxt.pushCurrentNode(contextNode);
|
||||
|
||||
XObject object = null;
|
||||
try
|
||||
{
|
||||
XPath dynamicXPath = new XPath(expr, xctxt.getSAXLocator(),
|
||||
xctxt.getNamespaceContext(),
|
||||
XPath.SELECT);
|
||||
object = dynamicXPath.execute(xctxt, contextNode, xctxt.getNamespaceContext());
|
||||
|
||||
if (object instanceof XNodeSet)
|
||||
{
|
||||
NodeList nodelist = null;
|
||||
nodelist = ((XNodeSet)object).nodelist();
|
||||
|
||||
for (int k = 0; k < nodelist.getLength(); k++)
|
||||
{
|
||||
Node n = nodelist.item(k);
|
||||
if (!resultSet.contains(n))
|
||||
resultSet.addNode(n);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lDoc == null)
|
||||
{
|
||||
lDoc = JdkXmlUtils.getDOMDocument();
|
||||
}
|
||||
|
||||
Element element = null;
|
||||
if (object instanceof XNumber)
|
||||
element = lDoc.createElementNS(EXSL_URI, "exsl:number");
|
||||
else if (object instanceof XBoolean)
|
||||
element = lDoc.createElementNS(EXSL_URI, "exsl:boolean");
|
||||
else
|
||||
element = lDoc.createElementNS(EXSL_URI, "exsl:string");
|
||||
|
||||
Text textNode = lDoc.createTextNode(object.str());
|
||||
element.appendChild(textNode);
|
||||
resultSet.addNode(element);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
xctxt.popCurrentNode();
|
||||
xctxt.popContextNodeList();
|
||||
return new NodeSet();
|
||||
}
|
||||
|
||||
xctxt.popCurrentNode();
|
||||
|
||||
}
|
||||
|
||||
xctxt.popContextNodeList();
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dyn:evaluate function evaluates a string as an XPath expression and returns
|
||||
* the resulting value, which might be a boolean, number, string, node set, result
|
||||
* tree fragment or external object. The sole argument is the string to be evaluated.
|
||||
* <p>
|
||||
* If the expression string passed as the second argument is an invalid XPath
|
||||
* expression (including an empty string), this function returns an empty node set.
|
||||
* <p>
|
||||
* You should only use this function if the expression must be constructed dynamically,
|
||||
* otherwise it is much more efficient to use the expression literally.
|
||||
*
|
||||
* @param myContext The ExpressionContext passed by the extension processor
|
||||
* @param xpathExpr The XPath expression string
|
||||
*
|
||||
* @return The evaluation result
|
||||
*/
|
||||
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
|
||||
throws SAXNotSupportedException
|
||||
{
|
||||
if (myContext instanceof XPathContext.XPathExpressionContext)
|
||||
{
|
||||
XPathContext xctxt = null;
|
||||
try
|
||||
{
|
||||
xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
|
||||
XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
|
||||
xctxt.getNamespaceContext(),
|
||||
XPath.SELECT);
|
||||
|
||||
return dynamicXPath.execute(xctxt, myContext.getContextNode(),
|
||||
xctxt.getNamespaceContext());
|
||||
}
|
||||
catch (TransformerException e)
|
||||
{
|
||||
return new XNodeSet(xctxt.getDTMManager());
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
|
||||
}
|
||||
|
||||
/**
|
||||
* The dyn:closure function creates a node set resulting from transitive closure of
|
||||
* evaluating the expression passed as the second argument on each of the nodes passed
|
||||
* as the first argument, then on the node set resulting from that and so on until no
|
||||
* more nodes are found. For example:
|
||||
* <pre>
|
||||
* dyn:closure(., '*')
|
||||
* </pre>
|
||||
* returns all the descendant elements of the node (its element children, their
|
||||
* children, their children's children and so on).
|
||||
* <p>
|
||||
* The expression is thus evaluated several times, each with a different node set
|
||||
* acting as the context of the expression. The first time the expression is
|
||||
* evaluated, the context node set is the first argument passed to the dyn:closure
|
||||
* function. In other words, the node set for each node is calculated by evaluating
|
||||
* the XPath expression with all context information being the same as that for
|
||||
* the call to the dyn:closure function itself, except for the following:
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>the context node is the node whose value is being calculated.</li>
|
||||
* <li>the context position is the position of the node within the node set passed
|
||||
* as the first argument to the dyn:closure function, arranged in document order.</li>
|
||||
* <li>the context size is the number of nodes passed as the first argument to the
|
||||
* dyn:closure function.</li>
|
||||
* <li>the current node is the node whose value is being calculated.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* The result for a particular iteration is the union of the node sets resulting
|
||||
* from evaluting the expression for each of the nodes in the source node set for
|
||||
* that iteration. This result is then used as the source node set for the next
|
||||
* iteration, and so on. The result of the function as a whole is the union of
|
||||
* the node sets generated by each iteration.
|
||||
* <p>
|
||||
* If the expression string passed as the second argument is an invalid XPath
|
||||
* expression (including an empty string) or an expression that does not return a
|
||||
* node set, this function returns an empty node set.
|
||||
*
|
||||
* @param myContext The ExpressionContext passed by the extension processor
|
||||
* @param nl The node set
|
||||
* @param expr The expression string
|
||||
*
|
||||
* @return The node set after evaluation
|
||||
*/
|
||||
public static NodeList closure(ExpressionContext myContext, NodeList nl, String expr)
|
||||
throws SAXNotSupportedException
|
||||
{
|
||||
XPathContext xctxt = null;
|
||||
if (myContext instanceof XPathContext.XPathExpressionContext)
|
||||
xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
|
||||
else
|
||||
throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext }));
|
||||
|
||||
if (expr == null || expr.length() == 0)
|
||||
return new NodeSet();
|
||||
|
||||
NodeSet closureSet = new NodeSet();
|
||||
closureSet.setShouldCacheNodes(true);
|
||||
|
||||
NodeList iterationList = nl;
|
||||
do
|
||||
{
|
||||
|
||||
NodeSet iterationSet = new NodeSet();
|
||||
|
||||
NodeSetDTM contextNodes = new NodeSetDTM(iterationList, xctxt);
|
||||
xctxt.pushContextNodeList(contextNodes);
|
||||
|
||||
for (int i = 0; i < iterationList.getLength(); i++)
|
||||
{
|
||||
int contextNode = contextNodes.item(i);
|
||||
xctxt.pushCurrentNode(contextNode);
|
||||
|
||||
XObject object = null;
|
||||
try
|
||||
{
|
||||
XPath dynamicXPath = new XPath(expr, xctxt.getSAXLocator(),
|
||||
xctxt.getNamespaceContext(),
|
||||
XPath.SELECT);
|
||||
object = dynamicXPath.execute(xctxt, contextNode, xctxt.getNamespaceContext());
|
||||
|
||||
if (object instanceof XNodeSet)
|
||||
{
|
||||
NodeList nodelist = null;
|
||||
nodelist = ((XNodeSet)object).nodelist();
|
||||
|
||||
for (int k = 0; k < nodelist.getLength(); k++)
|
||||
{
|
||||
Node n = nodelist.item(k);
|
||||
if (!iterationSet.contains(n))
|
||||
iterationSet.addNode(n);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xctxt.popCurrentNode();
|
||||
xctxt.popContextNodeList();
|
||||
return new NodeSet();
|
||||
}
|
||||
}
|
||||
catch (TransformerException e)
|
||||
{
|
||||
xctxt.popCurrentNode();
|
||||
xctxt.popContextNodeList();
|
||||
return new NodeSet();
|
||||
}
|
||||
|
||||
xctxt.popCurrentNode();
|
||||
|
||||
}
|
||||
|
||||
xctxt.popContextNodeList();
|
||||
|
||||
iterationList = iterationSet;
|
||||
|
||||
for (int i = 0; i < iterationList.getLength(); i++)
|
||||
{
|
||||
Node n = iterationList.item(i);
|
||||
if (!closureSet.contains(n))
|
||||
closureSet.addNode(n);
|
||||
}
|
||||
|
||||
} while(iterationList.getLength() > 0);
|
||||
|
||||
return closureSet;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
390
jdkSrc/jdk8/com/sun/org/apache/xalan/internal/lib/ExsltMath.java
Normal file
390
jdkSrc/jdk8/com/sun/org/apache/xalan/internal/lib/ExsltMath.java
Normal file
@@ -0,0 +1,390 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.lib;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.NodeSet;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* This class contains EXSLT math extension functions.
|
||||
* It is accessed by specifying a namespace URI as follows:
|
||||
* <pre>
|
||||
* xmlns:math="http://exslt.org/math"
|
||||
* </pre>
|
||||
*
|
||||
* The documentation for each function has been copied from the relevant
|
||||
* EXSLT Implementer page.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
|
||||
* @xsl.usage general
|
||||
*/
|
||||
public class ExsltMath extends ExsltBase
|
||||
{
|
||||
// Constants
|
||||
private static String PI = "3.1415926535897932384626433832795028841971693993751";
|
||||
private static String E = "2.71828182845904523536028747135266249775724709369996";
|
||||
private static String SQRRT2 = "1.41421356237309504880168872420969807856967187537694";
|
||||
private static String LN2 = "0.69314718055994530941723212145817656807550013436025";
|
||||
private static String LN10 = "2.302585092994046";
|
||||
private static String LOG2E = "1.4426950408889633";
|
||||
private static String SQRT1_2 = "0.7071067811865476";
|
||||
|
||||
/**
|
||||
* The math:max function returns the maximum value of the nodes passed as the argument.
|
||||
* The maximum value is defined as follows. The node set passed as an argument is sorted
|
||||
* in descending order as it would be by xsl:sort with a data type of number. The maximum
|
||||
* is the result of converting the string value of the first node in this sorted list to
|
||||
* a number using the number function.
|
||||
* <p>
|
||||
* If the node set is empty, or if the result of converting the string values of any of the
|
||||
* nodes to a number is NaN, then NaN is returned.
|
||||
*
|
||||
* @param nl The NodeList for the node-set to be evaluated.
|
||||
*
|
||||
* @return the maximum value found, NaN if any node cannot be converted to a number.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
*/
|
||||
public static double max (NodeList nl)
|
||||
{
|
||||
if (nl == null || nl.getLength() == 0)
|
||||
return Double.NaN;
|
||||
|
||||
double m = - Double.MAX_VALUE;
|
||||
for (int i = 0; i < nl.getLength(); i++)
|
||||
{
|
||||
Node n = nl.item(i);
|
||||
double d = toNumber(n);
|
||||
if (Double.isNaN(d))
|
||||
return Double.NaN;
|
||||
else if (d > m)
|
||||
m = d;
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:min function returns the minimum value of the nodes passed as the argument.
|
||||
* The minimum value is defined as follows. The node set passed as an argument is sorted
|
||||
* in ascending order as it would be by xsl:sort with a data type of number. The minimum
|
||||
* is the result of converting the string value of the first node in this sorted list to
|
||||
* a number using the number function.
|
||||
* <p>
|
||||
* If the node set is empty, or if the result of converting the string values of any of
|
||||
* the nodes to a number is NaN, then NaN is returned.
|
||||
*
|
||||
* @param nl The NodeList for the node-set to be evaluated.
|
||||
*
|
||||
* @return the minimum value found, NaN if any node cannot be converted to a number.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
*/
|
||||
public static double min (NodeList nl)
|
||||
{
|
||||
if (nl == null || nl.getLength() == 0)
|
||||
return Double.NaN;
|
||||
|
||||
double m = Double.MAX_VALUE;
|
||||
for (int i = 0; i < nl.getLength(); i++)
|
||||
{
|
||||
Node n = nl.item(i);
|
||||
double d = toNumber(n);
|
||||
if (Double.isNaN(d))
|
||||
return Double.NaN;
|
||||
else if (d < m)
|
||||
m = d;
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:highest function returns the nodes in the node set whose value is the maximum
|
||||
* value for the node set. The maximum value for the node set is the same as the value as
|
||||
* calculated by math:max. A node has this maximum value if the result of converting its
|
||||
* string value to a number as if by the number function is equal to the maximum value,
|
||||
* where the equality comparison is defined as a numerical comparison using the = operator.
|
||||
* <p>
|
||||
* If any of the nodes in the node set has a non-numeric value, the math:max function will
|
||||
* return NaN. The definition numeric comparisons entails that NaN != NaN. Therefore if any
|
||||
* of the nodes in the node set has a non-numeric value, math:highest will return an empty
|
||||
* node set.
|
||||
*
|
||||
* @param nl The NodeList for the node-set to be evaluated.
|
||||
*
|
||||
* @return node-set with nodes containing the maximum value found, an empty node-set
|
||||
* if any node cannot be converted to a number.
|
||||
*/
|
||||
public static NodeList highest (NodeList nl)
|
||||
{
|
||||
double maxValue = max(nl);
|
||||
|
||||
NodeSet highNodes = new NodeSet();
|
||||
highNodes.setShouldCacheNodes(true);
|
||||
|
||||
if (Double.isNaN(maxValue))
|
||||
return highNodes; // empty Nodeset
|
||||
|
||||
for (int i = 0; i < nl.getLength(); i++)
|
||||
{
|
||||
Node n = nl.item(i);
|
||||
double d = toNumber(n);
|
||||
if (d == maxValue)
|
||||
highNodes.addElement(n);
|
||||
}
|
||||
return highNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:lowest function returns the nodes in the node set whose value is the minimum value
|
||||
* for the node set. The minimum value for the node set is the same as the value as calculated
|
||||
* by math:min. A node has this minimum value if the result of converting its string value to
|
||||
* a number as if by the number function is equal to the minimum value, where the equality
|
||||
* comparison is defined as a numerical comparison using the = operator.
|
||||
* <p>
|
||||
* If any of the nodes in the node set has a non-numeric value, the math:min function will return
|
||||
* NaN. The definition numeric comparisons entails that NaN != NaN. Therefore if any of the nodes
|
||||
* in the node set has a non-numeric value, math:lowest will return an empty node set.
|
||||
*
|
||||
* @param nl The NodeList for the node-set to be evaluated.
|
||||
*
|
||||
* @return node-set with nodes containing the minimum value found, an empty node-set
|
||||
* if any node cannot be converted to a number.
|
||||
*
|
||||
*/
|
||||
public static NodeList lowest (NodeList nl)
|
||||
{
|
||||
double minValue = min(nl);
|
||||
|
||||
NodeSet lowNodes = new NodeSet();
|
||||
lowNodes.setShouldCacheNodes(true);
|
||||
|
||||
if (Double.isNaN(minValue))
|
||||
return lowNodes; // empty Nodeset
|
||||
|
||||
for (int i = 0; i < nl.getLength(); i++)
|
||||
{
|
||||
Node n = nl.item(i);
|
||||
double d = toNumber(n);
|
||||
if (d == minValue)
|
||||
lowNodes.addElement(n);
|
||||
}
|
||||
return lowNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:abs function returns the absolute value of a number.
|
||||
*
|
||||
* @param num A number
|
||||
* @return The absolute value of the number
|
||||
*/
|
||||
public static double abs(double num)
|
||||
{
|
||||
return Math.abs(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:acos function returns the arccosine value of a number.
|
||||
*
|
||||
* @param num A number
|
||||
* @return The arccosine value of the number
|
||||
*/
|
||||
public static double acos(double num)
|
||||
{
|
||||
return Math.acos(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:asin function returns the arcsine value of a number.
|
||||
*
|
||||
* @param num A number
|
||||
* @return The arcsine value of the number
|
||||
*/
|
||||
public static double asin(double num)
|
||||
{
|
||||
return Math.asin(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:atan function returns the arctangent value of a number.
|
||||
*
|
||||
* @param num A number
|
||||
* @return The arctangent value of the number
|
||||
*/
|
||||
public static double atan(double num)
|
||||
{
|
||||
return Math.atan(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:atan2 function returns the angle ( in radians ) from the X axis to a point (y,x).
|
||||
*
|
||||
* @param num1 The X axis value
|
||||
* @param num2 The Y axis value
|
||||
* @return The angle (in radians) from the X axis to a point (y,x)
|
||||
*/
|
||||
public static double atan2(double num1, double num2)
|
||||
{
|
||||
return Math.atan2(num1, num2);
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:cos function returns cosine of the passed argument.
|
||||
*
|
||||
* @param num A number
|
||||
* @return The cosine value of the number
|
||||
*/
|
||||
public static double cos(double num)
|
||||
{
|
||||
return Math.cos(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:exp function returns e (the base of natural logarithms) raised to a power.
|
||||
*
|
||||
* @param num A number
|
||||
* @return The value of e raised to the given power
|
||||
*/
|
||||
public static double exp(double num)
|
||||
{
|
||||
return Math.exp(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:log function returns the natural logarithm of a number.
|
||||
*
|
||||
* @param num A number
|
||||
* @return The natural logarithm of the number
|
||||
*/
|
||||
public static double log(double num)
|
||||
{
|
||||
return Math.log(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:power function returns the value of a base expression taken to a specified power.
|
||||
*
|
||||
* @param num1 The base
|
||||
* @param num2 The power
|
||||
* @return The value of the base expression taken to the specified power
|
||||
*/
|
||||
public static double power(double num1, double num2)
|
||||
{
|
||||
return Math.pow(num1, num2);
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:random function returns a random number from 0 to 1.
|
||||
*
|
||||
* @return A random double from 0 to 1
|
||||
*/
|
||||
public static double random()
|
||||
{
|
||||
return Math.random();
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:sin function returns the sine of the number.
|
||||
*
|
||||
* @param num A number
|
||||
* @return The sine value of the number
|
||||
*/
|
||||
public static double sin(double num)
|
||||
{
|
||||
return Math.sin(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:sqrt function returns the square root of a number.
|
||||
*
|
||||
* @param num A number
|
||||
* @return The square root of the number
|
||||
*/
|
||||
public static double sqrt(double num)
|
||||
{
|
||||
return Math.sqrt(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:tan function returns the tangent of the number passed as an argument.
|
||||
*
|
||||
* @param num A number
|
||||
* @return The tangent value of the number
|
||||
*/
|
||||
public static double tan(double num)
|
||||
{
|
||||
return Math.tan(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* The math:constant function returns the specified constant to a set precision.
|
||||
* The possible constants are:
|
||||
* <pre>
|
||||
* PI
|
||||
* E
|
||||
* SQRRT2
|
||||
* LN2
|
||||
* LN10
|
||||
* LOG2E
|
||||
* SQRT1_2
|
||||
* </pre>
|
||||
* @param name The name of the constant
|
||||
* @param precision The precision
|
||||
* @return The value of the specified constant to the given precision
|
||||
*/
|
||||
public static double constant(String name, double precision)
|
||||
{
|
||||
String value = null;
|
||||
if (name.equals("PI"))
|
||||
value = PI;
|
||||
else if (name.equals("E"))
|
||||
value = E;
|
||||
else if (name.equals("SQRRT2"))
|
||||
value = SQRRT2;
|
||||
else if (name.equals("LN2"))
|
||||
value = LN2;
|
||||
else if (name.equals("LN10"))
|
||||
value = LN10;
|
||||
else if (name.equals("LOG2E"))
|
||||
value = LOG2E;
|
||||
else if (name.equals("SQRT1_2"))
|
||||
value = SQRT1_2;
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
int bits = new Double(precision).intValue();
|
||||
|
||||
if (bits <= value.length())
|
||||
value = value.substring(0, bits);
|
||||
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
else
|
||||
return Double.NaN;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
241
jdkSrc/jdk8/com/sun/org/apache/xalan/internal/lib/ExsltSets.java
Normal file
241
jdkSrc/jdk8/com/sun/org/apache/xalan/internal/lib/ExsltSets.java
Normal file
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
/*
|
||||
* $Id: ExsltSets.java,v 1.1.2.1 2005/08/01 02:08:50 jeffsuttor Exp $
|
||||
*/
|
||||
package com.sun.org.apache.xalan.internal.lib;
|
||||
|
||||
import com.sun.org.apache.xml.internal.utils.DOM2Helper;
|
||||
import com.sun.org.apache.xpath.internal.NodeSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* This class contains EXSLT set extension functions.
|
||||
* It is accessed by specifying a namespace URI as follows:
|
||||
* <pre>
|
||||
* xmlns:set="http://exslt.org/sets"
|
||||
* </pre>
|
||||
*
|
||||
* The documentation for each function has been copied from the relevant
|
||||
* EXSLT Implementer page.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
* @xsl.usage general
|
||||
*/
|
||||
public class ExsltSets extends ExsltBase
|
||||
{
|
||||
/**
|
||||
* The set:leading function returns the nodes in the node set passed as the first argument that
|
||||
* precede, in document order, the first node in the node set passed as the second argument. If
|
||||
* the first node in the second node set is not contained in the first node set, then an empty
|
||||
* node set is returned. If the second node set is empty, then the first node set is returned.
|
||||
*
|
||||
* @param nl1 NodeList for first node-set.
|
||||
* @param nl2 NodeList for second node-set.
|
||||
* @return a NodeList containing the nodes in nl1 that precede in document order the first
|
||||
* node in nl2; an empty node-set if the first node in nl2 is not in nl1; all of nl1 if nl2
|
||||
* is empty.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
*/
|
||||
public static NodeList leading (NodeList nl1, NodeList nl2)
|
||||
{
|
||||
if (nl2.getLength() == 0)
|
||||
return nl1;
|
||||
|
||||
NodeSet ns1 = new NodeSet(nl1);
|
||||
NodeSet leadNodes = new NodeSet();
|
||||
Node endNode = nl2.item(0);
|
||||
if (!ns1.contains(endNode))
|
||||
return leadNodes; // empty NodeSet
|
||||
|
||||
for (int i = 0; i < nl1.getLength(); i++)
|
||||
{
|
||||
Node testNode = nl1.item(i);
|
||||
if (DOM2Helper.isNodeAfter(testNode, endNode)
|
||||
&& !DOM2Helper.isNodeTheSame(testNode, endNode))
|
||||
leadNodes.addElement(testNode);
|
||||
}
|
||||
return leadNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* The set:trailing function returns the nodes in the node set passed as the first argument that
|
||||
* follow, in document order, the first node in the node set passed as the second argument. If
|
||||
* the first node in the second node set is not contained in the first node set, then an empty
|
||||
* node set is returned. If the second node set is empty, then the first node set is returned.
|
||||
*
|
||||
* @param nl1 NodeList for first node-set.
|
||||
* @param nl2 NodeList for second node-set.
|
||||
* @return a NodeList containing the nodes in nl1 that follow in document order the first
|
||||
* node in nl2; an empty node-set if the first node in nl2 is not in nl1; all of nl1 if nl2
|
||||
* is empty.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
*/
|
||||
public static NodeList trailing (NodeList nl1, NodeList nl2)
|
||||
{
|
||||
if (nl2.getLength() == 0)
|
||||
return nl1;
|
||||
|
||||
NodeSet ns1 = new NodeSet(nl1);
|
||||
NodeSet trailNodes = new NodeSet();
|
||||
Node startNode = nl2.item(0);
|
||||
if (!ns1.contains(startNode))
|
||||
return trailNodes; // empty NodeSet
|
||||
|
||||
for (int i = 0; i < nl1.getLength(); i++)
|
||||
{
|
||||
Node testNode = nl1.item(i);
|
||||
if (DOM2Helper.isNodeAfter(startNode, testNode)
|
||||
&& !DOM2Helper.isNodeTheSame(startNode, testNode))
|
||||
trailNodes.addElement(testNode);
|
||||
}
|
||||
return trailNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* The set:intersection function returns a node set comprising the nodes that are within
|
||||
* both the node sets passed as arguments to it.
|
||||
*
|
||||
* @param nl1 NodeList for first node-set.
|
||||
* @param nl2 NodeList for second node-set.
|
||||
* @return a NodeList containing the nodes in nl1 that are also
|
||||
* in nl2.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
*/
|
||||
public static NodeList intersection(NodeList nl1, NodeList nl2)
|
||||
{
|
||||
NodeSet ns1 = new NodeSet(nl1);
|
||||
NodeSet ns2 = new NodeSet(nl2);
|
||||
NodeSet inter = new NodeSet();
|
||||
|
||||
inter.setShouldCacheNodes(true);
|
||||
|
||||
for (int i = 0; i < ns1.getLength(); i++)
|
||||
{
|
||||
Node n = ns1.elementAt(i);
|
||||
|
||||
if (ns2.contains(n))
|
||||
inter.addElement(n);
|
||||
}
|
||||
|
||||
return inter;
|
||||
}
|
||||
|
||||
/**
|
||||
* The set:difference function returns the difference between two node sets - those nodes that
|
||||
* are in the node set passed as the first argument that are not in the node set passed as the
|
||||
* second argument.
|
||||
*
|
||||
* @param nl1 NodeList for first node-set.
|
||||
* @param nl2 NodeList for second node-set.
|
||||
* @return a NodeList containing the nodes in nl1 that are not in nl2.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
*/
|
||||
public static NodeList difference(NodeList nl1, NodeList nl2)
|
||||
{
|
||||
NodeSet ns1 = new NodeSet(nl1);
|
||||
NodeSet ns2 = new NodeSet(nl2);
|
||||
|
||||
NodeSet diff = new NodeSet();
|
||||
|
||||
diff.setShouldCacheNodes(true);
|
||||
|
||||
for (int i = 0; i < ns1.getLength(); i++)
|
||||
{
|
||||
Node n = ns1.elementAt(i);
|
||||
|
||||
if (!ns2.contains(n))
|
||||
diff.addElement(n);
|
||||
}
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* The set:distinct function returns a subset of the nodes contained in the node-set NS passed
|
||||
* as the first argument. Specifically, it selects a node N if there is no node in NS that has
|
||||
* the same string value as N, and that precedes N in document order.
|
||||
*
|
||||
* @param nl NodeList for the node-set.
|
||||
* @return a NodeList with nodes from nl containing distinct string values.
|
||||
* In other words, if more than one node in nl contains the same string value,
|
||||
* only include the first such node found.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
*/
|
||||
public static NodeList distinct(NodeList nl)
|
||||
{
|
||||
NodeSet dist = new NodeSet();
|
||||
dist.setShouldCacheNodes(true);
|
||||
|
||||
Map<String, Node> stringTable = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < nl.getLength(); i++)
|
||||
{
|
||||
Node currNode = nl.item(i);
|
||||
String key = toString(currNode);
|
||||
|
||||
if (key == null)
|
||||
dist.addElement(currNode);
|
||||
else if (!stringTable.containsKey(key))
|
||||
{
|
||||
stringTable.put(key, currNode);
|
||||
dist.addElement(currNode);
|
||||
}
|
||||
}
|
||||
|
||||
return dist;
|
||||
}
|
||||
|
||||
/**
|
||||
* The set:has-same-node function returns true if the node set passed as the first argument shares
|
||||
* any nodes with the node set passed as the second argument. If there are no nodes that are in both
|
||||
* node sets, then it returns false.
|
||||
*
|
||||
* The Xalan extensions MethodResolver converts 'has-same-node' to 'hasSameNode'.
|
||||
*
|
||||
* Note: Not to be confused with hasSameNodes in the Xalan namespace, which returns true if
|
||||
* the two node sets contain the exactly the same nodes (perhaps in a different order),
|
||||
* otherwise false.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
*/
|
||||
public static boolean hasSameNode(NodeList nl1, NodeList nl2)
|
||||
{
|
||||
|
||||
NodeSet ns1 = new NodeSet(nl1);
|
||||
NodeSet ns2 = new NodeSet(nl2);
|
||||
|
||||
for (int i = 0; i < ns1.getLength(); i++)
|
||||
{
|
||||
if (ns2.contains(ns1.elementAt(i)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.lib;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
import com.sun.org.apache.xpath.internal.NodeSet;
|
||||
import jdk.xml.internal.JdkXmlUtils;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
/**
|
||||
* This class contains EXSLT strings extension functions.
|
||||
*
|
||||
* It is accessed by specifying a namespace URI as follows:
|
||||
* <pre>
|
||||
* xmlns:str="http://exslt.org/strings"
|
||||
* </pre>
|
||||
* The documentation for each function has been copied from the relevant
|
||||
* EXSLT Implementer page.
|
||||
*
|
||||
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
||||
|
||||
* @xsl.usage general
|
||||
*/
|
||||
public class ExsltStrings extends ExsltBase
|
||||
{
|
||||
|
||||
/**
|
||||
* The str:align function aligns a string within another string.
|
||||
* <p>
|
||||
* The first argument gives the target string to be aligned. The second argument gives
|
||||
* the padding string within which it is to be aligned.
|
||||
* <p>
|
||||
* If the target string is shorter than the padding string then a range of characters
|
||||
* in the padding string are repaced with those in the target string. Which characters
|
||||
* are replaced depends on the value of the third argument, which gives the type of
|
||||
* alignment. It can be one of 'left', 'right' or 'center'. If no third argument is
|
||||
* given or if it is not one of these values, then it defaults to left alignment.
|
||||
* <p>
|
||||
* With left alignment, the range of characters replaced by the target string begins
|
||||
* with the first character in the padding string. With right alignment, the range of
|
||||
* characters replaced by the target string ends with the last character in the padding
|
||||
* string. With center alignment, the range of characters replaced by the target string
|
||||
* is in the middle of the padding string, such that either the number of unreplaced
|
||||
* characters on either side of the range is the same or there is one less on the left
|
||||
* than there is on the right.
|
||||
* <p>
|
||||
* If the target string is longer than the padding string, then it is truncated to be
|
||||
* the same length as the padding string and returned.
|
||||
*
|
||||
* @param targetStr The target string
|
||||
* @param paddingStr The padding string
|
||||
* @param type The type of alignment
|
||||
*
|
||||
* @return The string after alignment
|
||||
*/
|
||||
public static String align(String targetStr, String paddingStr, String type)
|
||||
{
|
||||
if (targetStr.length() >= paddingStr.length())
|
||||
return targetStr.substring(0, paddingStr.length());
|
||||
|
||||
if (type.equals("right"))
|
||||
{
|
||||
return paddingStr.substring(0, paddingStr.length() - targetStr.length()) + targetStr;
|
||||
}
|
||||
else if (type.equals("center"))
|
||||
{
|
||||
int startIndex = (paddingStr.length() - targetStr.length()) / 2;
|
||||
return paddingStr.substring(0, startIndex) + targetStr + paddingStr.substring(startIndex + targetStr.length());
|
||||
}
|
||||
// Default is left
|
||||
else
|
||||
{
|
||||
return targetStr + paddingStr.substring(targetStr.length());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See above
|
||||
*/
|
||||
public static String align(String targetStr, String paddingStr)
|
||||
{
|
||||
return align(targetStr, paddingStr, "left");
|
||||
}
|
||||
|
||||
/**
|
||||
* The str:concat function takes a node set and returns the concatenation of the
|
||||
* string values of the nodes in that node set. If the node set is empty, it returns
|
||||
* an empty string.
|
||||
*
|
||||
* @param nl A node set
|
||||
* @return The concatenation of the string values of the nodes in that node set
|
||||
*/
|
||||
public static String concat(NodeList nl)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < nl.getLength(); i++)
|
||||
{
|
||||
Node node = nl.item(i);
|
||||
String value = toString(node);
|
||||
|
||||
if (value != null && value.length() > 0)
|
||||
sb.append(value);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* The str:padding function creates a padding string of a certain length.
|
||||
* The first argument gives the length of the padding string to be created.
|
||||
* The second argument gives a string to be used to create the padding. This
|
||||
* string is repeated as many times as is necessary to create a string of the
|
||||
* length specified by the first argument; if the string is more than a character
|
||||
* long, it may have to be truncated to produce the required length. If no second
|
||||
* argument is specified, it defaults to a space (' '). If the second argument is
|
||||
* an empty string, str:padding returns an empty string.
|
||||
*
|
||||
* @param length The length of the padding string to be created
|
||||
* @param pattern The string to be used as pattern
|
||||
*
|
||||
* @return A padding string of the given length
|
||||
*/
|
||||
public static String padding(double length, String pattern)
|
||||
{
|
||||
if (pattern == null || pattern.length() == 0)
|
||||
return "";
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
int len = (int)length;
|
||||
int numAdded = 0;
|
||||
int index = 0;
|
||||
while (numAdded < len)
|
||||
{
|
||||
if (index == pattern.length())
|
||||
index = 0;
|
||||
|
||||
sb.append(pattern.charAt(index));
|
||||
index++;
|
||||
numAdded++;
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* See above
|
||||
*/
|
||||
public static String padding(double length)
|
||||
{
|
||||
return padding(length, " ");
|
||||
}
|
||||
|
||||
/**
|
||||
* The str:split function splits up a string and returns a node set of token
|
||||
* elements, each containing one token from the string.
|
||||
* <p>
|
||||
* The first argument is the string to be split. The second argument is a pattern
|
||||
* string. The string given by the first argument is split at any occurrence of
|
||||
* this pattern. For example:
|
||||
* <pre>
|
||||
* str:split('a, simple, list', ', ') gives the node set consisting of:
|
||||
*
|
||||
* <token>a</token>
|
||||
* <token>simple</token>
|
||||
* <token>list</token>
|
||||
* </pre>
|
||||
* If the second argument is omitted, the default is the string ' ' (i.e. a space).
|
||||
*
|
||||
* @param str The string to be split
|
||||
* @param pattern The pattern
|
||||
*
|
||||
* @return A node set of split tokens
|
||||
*/
|
||||
public static NodeList split(String str, String pattern)
|
||||
{
|
||||
|
||||
|
||||
NodeSet resultSet = new NodeSet();
|
||||
resultSet.setShouldCacheNodes(true);
|
||||
|
||||
boolean done = false;
|
||||
int fromIndex = 0;
|
||||
int matchIndex = 0;
|
||||
String token = null;
|
||||
|
||||
while (!done && fromIndex < str.length())
|
||||
{
|
||||
matchIndex = str.indexOf(pattern, fromIndex);
|
||||
if (matchIndex >= 0)
|
||||
{
|
||||
token = str.substring(fromIndex, matchIndex);
|
||||
fromIndex = matchIndex + pattern.length();
|
||||
}
|
||||
else
|
||||
{
|
||||
done = true;
|
||||
token = str.substring(fromIndex);
|
||||
}
|
||||
|
||||
Document doc = JdkXmlUtils.getDOMDocument();
|
||||
synchronized (doc)
|
||||
{
|
||||
Element element = doc.createElement("token");
|
||||
Text text = doc.createTextNode(token);
|
||||
element.appendChild(text);
|
||||
resultSet.addNode(element);
|
||||
}
|
||||
}
|
||||
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* See above
|
||||
*/
|
||||
public static NodeList split(String str)
|
||||
{
|
||||
return split(str, " ");
|
||||
}
|
||||
|
||||
/**
|
||||
* The str:tokenize function splits up a string and returns a node set of token
|
||||
* elements, each containing one token from the string.
|
||||
* <p>
|
||||
* The first argument is the string to be tokenized. The second argument is a
|
||||
* string consisting of a number of characters. Each character in this string is
|
||||
* taken as a delimiting character. The string given by the first argument is split
|
||||
* at any occurrence of any of these characters. For example:
|
||||
* <pre>
|
||||
* str:tokenize('2001-06-03T11:40:23', '-T:') gives the node set consisting of:
|
||||
*
|
||||
* <token>2001</token>
|
||||
* <token>06</token>
|
||||
* <token>03</token>
|
||||
* <token>11</token>
|
||||
* <token>40</token>
|
||||
* <token>23</token>
|
||||
* </pre>
|
||||
* If the second argument is omitted, the default is the string '	

 '
|
||||
* (i.e. whitespace characters).
|
||||
* <p>
|
||||
* If the second argument is an empty string, the function returns a set of token
|
||||
* elements, each of which holds a single character.
|
||||
* <p>
|
||||
* Note: This one is different from the tokenize extension function in the Xalan
|
||||
* namespace. The one in Xalan returns a set of Text nodes, while this one wraps
|
||||
* the Text nodes inside the token Element nodes.
|
||||
*
|
||||
* @param toTokenize The string to be tokenized
|
||||
* @param delims The delimiter string
|
||||
*
|
||||
* @return A node set of split token elements
|
||||
*/
|
||||
public static NodeList tokenize(String toTokenize, String delims)
|
||||
{
|
||||
|
||||
|
||||
NodeSet resultSet = new NodeSet();
|
||||
|
||||
if (delims != null && delims.length() > 0)
|
||||
{
|
||||
StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims);
|
||||
|
||||
Document doc = JdkXmlUtils.getDOMDocument();
|
||||
synchronized (doc)
|
||||
{
|
||||
while (lTokenizer.hasMoreTokens())
|
||||
{
|
||||
Element element = doc.createElement("token");
|
||||
element.appendChild(doc.createTextNode(lTokenizer.nextToken()));
|
||||
resultSet.addNode(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
// If the delimiter is an empty string, create one token Element for
|
||||
// every single character.
|
||||
else
|
||||
{
|
||||
|
||||
Document doc = JdkXmlUtils.getDOMDocument();
|
||||
synchronized (doc)
|
||||
{
|
||||
for (int i = 0; i < toTokenize.length(); i++)
|
||||
{
|
||||
Element element = doc.createElement("token");
|
||||
element.appendChild(doc.createTextNode(toTokenize.substring(i, i+1)));
|
||||
resultSet.addNode(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* See above
|
||||
*/
|
||||
public static NodeList tokenize(String toTokenize)
|
||||
{
|
||||
return tokenize(toTokenize, " \t\n\r");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.lib;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.extensions.ExpressionContext;
|
||||
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
|
||||
import com.sun.org.apache.xalan.internal.xslt.EnvironmentCheck;
|
||||
import com.sun.org.apache.xpath.internal.NodeSet;
|
||||
import com.sun.org.apache.xpath.internal.objects.XBoolean;
|
||||
import com.sun.org.apache.xpath.internal.objects.XNumber;
|
||||
import com.sun.org.apache.xpath.internal.objects.XObject;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
import jdk.xml.internal.JdkXmlUtils;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.DocumentFragment;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Text;
|
||||
import org.w3c.dom.traversal.NodeIterator;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
|
||||
/**
|
||||
* This class contains many of the Xalan-supplied extensions.
|
||||
* It is accessed by specifying a namespace URI as follows:
|
||||
* <pre>
|
||||
* xmlns:xalan="http://xml.apache.org/xalan"
|
||||
* </pre>
|
||||
* @xsl.usage general
|
||||
*/
|
||||
public class Extensions
|
||||
{
|
||||
/**
|
||||
* Constructor Extensions
|
||||
*
|
||||
*/
|
||||
private Extensions(){} // Make sure class cannot be instantiated
|
||||
|
||||
/**
|
||||
* This method is an extension that implements as a Xalan extension
|
||||
* the node-set function also found in xt and saxon.
|
||||
* If the argument is a Result Tree Fragment, then <code>nodeset</code>
|
||||
* returns a node-set consisting of a single root node as described in
|
||||
* section 11.1 of the XSLT 1.0 Recommendation. If the argument is a
|
||||
* node-set, <code>nodeset</code> returns a node-set. If the argument
|
||||
* is a string, number, or boolean, then <code>nodeset</code> returns
|
||||
* a node-set consisting of a single root node with a single text node
|
||||
* child that is the result of calling the XPath string() function on the
|
||||
* passed parameter. If the argument is anything else, then a node-set
|
||||
* is returned consisting of a single root node with a single text node
|
||||
* child that is the result of calling the java <code>toString()</code>
|
||||
* method on the passed argument.
|
||||
* Most of the
|
||||
* actual work here is done in <code>MethodResolver</code> and
|
||||
* <code>XRTreeFrag</code>.
|
||||
* @param myProcessor Context passed by the extension processor
|
||||
* @param rtf Argument in the stylesheet to the nodeset extension function
|
||||
*
|
||||
* NEEDSDOC ($objectName$) @return
|
||||
*/
|
||||
public static NodeSet nodeset(ExpressionContext myProcessor, Object rtf)
|
||||
{
|
||||
|
||||
String textNodeValue;
|
||||
|
||||
if (rtf instanceof NodeIterator)
|
||||
{
|
||||
return new NodeSet((NodeIterator) rtf);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rtf instanceof String)
|
||||
{
|
||||
textNodeValue = (String) rtf;
|
||||
}
|
||||
else if (rtf instanceof Boolean)
|
||||
{
|
||||
textNodeValue = new XBoolean(((Boolean) rtf).booleanValue()).str();
|
||||
}
|
||||
else if (rtf instanceof Double)
|
||||
{
|
||||
textNodeValue = new XNumber(((Double) rtf).doubleValue()).str();
|
||||
}
|
||||
else
|
||||
{
|
||||
textNodeValue = rtf.toString();
|
||||
}
|
||||
|
||||
// This no longer will work right since the DTM.
|
||||
// Document myDoc = myProcessor.getContextNode().getOwnerDocument();
|
||||
Document myDoc = JdkXmlUtils.getDOMDocument();
|
||||
|
||||
Text textNode = myDoc.createTextNode(textNodeValue);
|
||||
DocumentFragment docFrag = myDoc.createDocumentFragment();
|
||||
|
||||
docFrag.appendChild(textNode);
|
||||
|
||||
return new NodeSet(docFrag);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the intersection of two node-sets.
|
||||
*
|
||||
* @param nl1 NodeList for first node-set
|
||||
* @param nl2 NodeList for second node-set
|
||||
* @return a NodeList containing the nodes in nl1 that are also in nl2
|
||||
*
|
||||
* Note: The usage of this extension function in the xalan namespace
|
||||
* is deprecated. Please use the same function in the EXSLT sets extension
|
||||
* (http://exslt.org/sets).
|
||||
*/
|
||||
public static NodeList intersection(NodeList nl1, NodeList nl2)
|
||||
{
|
||||
return ExsltSets.intersection(nl1, nl2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the difference between two node-sets.
|
||||
*
|
||||
* @param nl1 NodeList for first node-set
|
||||
* @param nl2 NodeList for second node-set
|
||||
* @return a NodeList containing the nodes in nl1 that are not in nl2
|
||||
*
|
||||
* Note: The usage of this extension function in the xalan namespace
|
||||
* is deprecated. Please use the same function in the EXSLT sets extension
|
||||
* (http://exslt.org/sets).
|
||||
*/
|
||||
public static NodeList difference(NodeList nl1, NodeList nl2)
|
||||
{
|
||||
return ExsltSets.difference(nl1, nl2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns node-set containing distinct string values.
|
||||
*
|
||||
* @param nl NodeList for node-set
|
||||
* @return a NodeList with nodes from nl containing distinct string values.
|
||||
* In other words, if more than one node in nl contains the same string value,
|
||||
* only include the first such node found.
|
||||
*
|
||||
* Note: The usage of this extension function in the xalan namespace
|
||||
* is deprecated. Please use the same function in the EXSLT sets extension
|
||||
* (http://exslt.org/sets).
|
||||
*/
|
||||
public static NodeList distinct(NodeList nl)
|
||||
{
|
||||
return ExsltSets.distinct(nl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if both node-sets contain the same set of nodes.
|
||||
*
|
||||
* @param nl1 NodeList for first node-set
|
||||
* @param nl2 NodeList for second node-set
|
||||
* @return true if nl1 and nl2 contain exactly the same set of nodes.
|
||||
*/
|
||||
public static boolean hasSameNodes(NodeList nl1, NodeList nl2)
|
||||
{
|
||||
|
||||
NodeSet ns1 = new NodeSet(nl1);
|
||||
NodeSet ns2 = new NodeSet(nl2);
|
||||
|
||||
if (ns1.getLength() != ns2.getLength())
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < ns1.getLength(); i++)
|
||||
{
|
||||
Node n = ns1.elementAt(i);
|
||||
|
||||
if (!ns2.contains(n))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of evaluating the argument as a string containing
|
||||
* an XPath expression. Used where the XPath expression is not known until
|
||||
* run-time. The expression is evaluated as if the run-time value of the
|
||||
* argument appeared in place of the evaluate function call at compile time.
|
||||
*
|
||||
* @param myContext an <code>ExpressionContext</code> passed in by the
|
||||
* extension mechanism. This must be an XPathContext.
|
||||
* @param xpathExpr The XPath expression to be evaluated.
|
||||
* @return the XObject resulting from evaluating the XPath
|
||||
*
|
||||
* @throws SAXNotSupportedException
|
||||
*
|
||||
* Note: The usage of this extension function in the xalan namespace
|
||||
* is deprecated. Please use the same function in the EXSLT dynamic extension
|
||||
* (http://exslt.org/dynamic).
|
||||
*/
|
||||
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
|
||||
throws SAXNotSupportedException
|
||||
{
|
||||
return ExsltDynamic.evaluate(myContext, xpathExpr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a NodeSet containing one text node for each token in the first argument.
|
||||
* Delimiters are specified in the second argument.
|
||||
* Tokens are determined by a call to <code>StringTokenizer</code>.
|
||||
* If the first argument is an empty string or contains only delimiters, the result
|
||||
* will be an empty NodeSet.
|
||||
*
|
||||
* Contributed to XalanJ1 by <a href="mailto:benoit.cerrina@writeme.com">Benoit Cerrina</a>.
|
||||
*
|
||||
* @param toTokenize The string to be split into text tokens.
|
||||
* @param delims The delimiters to use.
|
||||
* @return a NodeSet as described above.
|
||||
*/
|
||||
public static NodeList tokenize(String toTokenize, String delims)
|
||||
{
|
||||
|
||||
Document doc = JdkXmlUtils.getDOMDocument();
|
||||
|
||||
StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims);
|
||||
NodeSet resultSet = new NodeSet();
|
||||
|
||||
synchronized (doc)
|
||||
{
|
||||
while (lTokenizer.hasMoreTokens())
|
||||
{
|
||||
resultSet.addNode(doc.createTextNode(lTokenizer.nextToken()));
|
||||
}
|
||||
}
|
||||
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a NodeSet containing one text node for each token in the first argument.
|
||||
* Delimiters are whitespace. That is, the delimiters that are used are tab (	),
|
||||
* linefeed (
), return (
), and space ( ).
|
||||
* Tokens are determined by a call to <code>StringTokenizer</code>.
|
||||
* If the first argument is an empty string or contains only delimiters, the result
|
||||
* will be an empty NodeSet.
|
||||
*
|
||||
* Contributed to XalanJ1 by <a href="mailto:benoit.cerrina@writeme.com">Benoit Cerrina</a>.
|
||||
*
|
||||
* @param toTokenize The string to be split into text tokens.
|
||||
* @return a NodeSet as described above.
|
||||
*/
|
||||
public static NodeList tokenize(String toTokenize)
|
||||
{
|
||||
return tokenize(toTokenize, " \t\n\r");
|
||||
}
|
||||
|
||||
}
|
||||
248
jdkSrc/jdk8/com/sun/org/apache/xalan/internal/lib/NodeInfo.java
Normal file
248
jdkSrc/jdk8/com/sun/org/apache/xalan/internal/lib/NodeInfo.java
Normal file
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.lib;
|
||||
|
||||
import javax.xml.transform.SourceLocator;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.extensions.ExpressionContext;
|
||||
import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* <code>NodeInfo</code> defines a set of XSLT extension functions to be
|
||||
* used from stylesheets.
|
||||
*
|
||||
* @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
|
||||
* @since May 24, 2001
|
||||
*/
|
||||
public class NodeInfo
|
||||
{
|
||||
/**
|
||||
* <code>systemId</code> returns the system id of the current
|
||||
* context node.
|
||||
*
|
||||
* @param context an <code>ExpressionContext</code> value
|
||||
* @return a <code>String</code> value
|
||||
*/
|
||||
public static String systemId(ExpressionContext context)
|
||||
{
|
||||
Node contextNode = context.getContextNode();
|
||||
int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
|
||||
SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
|
||||
.getSourceLocatorFor(nodeHandler);
|
||||
|
||||
if (locator != null)
|
||||
return locator.getSystemId();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>systemId</code> returns the system id of the node passed as
|
||||
* argument. If a node set is passed as argument, the system id of
|
||||
* the first node in the set is returned.
|
||||
*
|
||||
* @param nodeList a <code>NodeList</code> value
|
||||
* @return a <code>String</code> value
|
||||
*/
|
||||
public static String systemId(NodeList nodeList)
|
||||
{
|
||||
if (nodeList == null || nodeList.getLength() == 0)
|
||||
return null;
|
||||
|
||||
Node node = nodeList.item(0);
|
||||
int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
|
||||
SourceLocator locator = ((DTMNodeProxy)node).getDTM()
|
||||
.getSourceLocatorFor(nodeHandler);
|
||||
|
||||
if (locator != null)
|
||||
return locator.getSystemId();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>publicId</code> returns the public identifier of the current
|
||||
* context node.
|
||||
*
|
||||
* Xalan does not currently record this value, and will return null.
|
||||
*
|
||||
* @param context an <code>ExpressionContext</code> value
|
||||
* @return a <code>String</code> value
|
||||
*/
|
||||
public static String publicId(ExpressionContext context)
|
||||
{
|
||||
Node contextNode = context.getContextNode();
|
||||
int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
|
||||
SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
|
||||
.getSourceLocatorFor(nodeHandler);
|
||||
|
||||
if (locator != null)
|
||||
return locator.getPublicId();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>publicId</code> returns the public identifier of the node passed as
|
||||
* argument. If a node set is passed as argument, the public identifier of
|
||||
* the first node in the set is returned.
|
||||
*
|
||||
* Xalan does not currently record this value, and will return null.
|
||||
*
|
||||
* @param nodeList a <code>NodeList</code> value
|
||||
* @return a <code>String</code> value
|
||||
*/
|
||||
public static String publicId(NodeList nodeList)
|
||||
{
|
||||
if (nodeList == null || nodeList.getLength() == 0)
|
||||
return null;
|
||||
|
||||
Node node = nodeList.item(0);
|
||||
int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
|
||||
SourceLocator locator = ((DTMNodeProxy)node).getDTM()
|
||||
.getSourceLocatorFor(nodeHandler);
|
||||
|
||||
if (locator != null)
|
||||
return locator.getPublicId();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>lineNumber</code> returns the line number of the current
|
||||
* context node.
|
||||
*
|
||||
* NOTE: Xalan does not normally record location information for each node.
|
||||
* To obtain it, you must set the custom TrAX attribute
|
||||
* "http://xml.apache.org/xalan/features/source_location"
|
||||
* true in the TransformerFactory before generating the Transformer and executing
|
||||
* the stylesheet. Storage cost per node will be noticably increased in this mode.
|
||||
*
|
||||
* @param context an <code>ExpressionContext</code> value
|
||||
* @return an <code>int</code> value. This may be -1 to indicate that the
|
||||
* line number is not known.
|
||||
*/
|
||||
public static int lineNumber(ExpressionContext context)
|
||||
{
|
||||
Node contextNode = context.getContextNode();
|
||||
int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
|
||||
SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
|
||||
.getSourceLocatorFor(nodeHandler);
|
||||
|
||||
if (locator != null)
|
||||
return locator.getLineNumber();
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>lineNumber</code> returns the line number of the node
|
||||
* passed as argument. If a node set is passed as argument, the line
|
||||
* number of the first node in the set is returned.
|
||||
*
|
||||
* NOTE: Xalan does not normally record location information for each node.
|
||||
* To obtain it, you must set the custom TrAX attribute
|
||||
* "http://xml.apache.org/xalan/features/source_location"
|
||||
* true in the TransformerFactory before generating the Transformer and executing
|
||||
* the stylesheet. Storage cost per node will be noticably increased in this mode.
|
||||
*
|
||||
* @param nodeList a <code>NodeList</code> value
|
||||
* @return an <code>int</code> value. This may be -1 to indicate that the
|
||||
* line number is not known.
|
||||
*/
|
||||
public static int lineNumber(NodeList nodeList)
|
||||
{
|
||||
if (nodeList == null || nodeList.getLength() == 0)
|
||||
return -1;
|
||||
|
||||
Node node = nodeList.item(0);
|
||||
int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
|
||||
SourceLocator locator = ((DTMNodeProxy)node).getDTM()
|
||||
.getSourceLocatorFor(nodeHandler);
|
||||
|
||||
if (locator != null)
|
||||
return locator.getLineNumber();
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>columnNumber</code> returns the column number of the
|
||||
* current context node.
|
||||
*
|
||||
* NOTE: Xalan does not normally record location information for each node.
|
||||
* To obtain it, you must set the custom TrAX attribute
|
||||
* "http://xml.apache.org/xalan/features/source_location"
|
||||
* true in the TransformerFactory before generating the Transformer and executing
|
||||
* the stylesheet. Storage cost per node will be noticably increased in this mode.
|
||||
*
|
||||
* @param context an <code>ExpressionContext</code> value
|
||||
* @return an <code>int</code> value. This may be -1 to indicate that the
|
||||
* column number is not known.
|
||||
*/
|
||||
public static int columnNumber(ExpressionContext context)
|
||||
{
|
||||
Node contextNode = context.getContextNode();
|
||||
int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
|
||||
SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
|
||||
.getSourceLocatorFor(nodeHandler);
|
||||
|
||||
if (locator != null)
|
||||
return locator.getColumnNumber();
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>columnNumber</code> returns the column number of the node
|
||||
* passed as argument. If a node set is passed as argument, the line
|
||||
* number of the first node in the set is returned.
|
||||
*
|
||||
* NOTE: Xalan does not normally record location information for each node.
|
||||
* To obtain it, you must set the custom TrAX attribute
|
||||
* "http://xml.apache.org/xalan/features/source_location"
|
||||
* true in the TransformerFactory before generating the Transformer and executing
|
||||
* the stylesheet. Storage cost per node will be noticably increased in this mode.
|
||||
*
|
||||
* @param nodeList a <code>NodeList</code> value
|
||||
* @return an <code>int</code> value. This may be -1 to indicate that the
|
||||
* column number is not known.
|
||||
*/
|
||||
public static int columnNumber(NodeList nodeList)
|
||||
{
|
||||
if (nodeList == null || nodeList.getLength() == 0)
|
||||
return -1;
|
||||
|
||||
Node node = nodeList.item(0);
|
||||
int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
|
||||
SourceLocator locator = ((DTMNodeProxy)node).getDTM()
|
||||
.getSourceLocatorFor(nodeHandler);
|
||||
|
||||
if (locator != null)
|
||||
return locator.getColumnNumber();
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.res;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.res.XPATHMessages;
|
||||
|
||||
/**
|
||||
* Sets things up for issuing error messages. This class is misnamed, and should
|
||||
* be called XalanMessages, or some such.
|
||||
*
|
||||
* @xsl.usage internal
|
||||
*/
|
||||
public class XSLMessages extends XPATHMessages {
|
||||
|
||||
/**
|
||||
* The language specific resource object for Xalan messages.
|
||||
*/
|
||||
private static ListResourceBundle XSLTBundle = null;
|
||||
/**
|
||||
* The class name of the Xalan error message string table.
|
||||
*/
|
||||
private static final String XSLT_ERROR_RESOURCES =
|
||||
"com.sun.org.apache.xalan.internal.res.XSLTErrorResources";
|
||||
|
||||
/**
|
||||
* Creates a message from the specified key and replacement arguments,
|
||||
* localized to the given locale.
|
||||
*
|
||||
* @param msgKey The key for the message text.
|
||||
* @param args The arguments to be used as replacement text in the message
|
||||
* created.
|
||||
*
|
||||
* @return The formatted message string.
|
||||
*/
|
||||
public static String createMessage(String msgKey, Object args[]) //throws Exception
|
||||
{
|
||||
if (XSLTBundle == null) {
|
||||
XSLTBundle = SecuritySupport.getResourceBundle(XSLT_ERROR_RESOURCES);
|
||||
}
|
||||
|
||||
if (XSLTBundle != null) {
|
||||
return createMsg(XSLTBundle, msgKey, args);
|
||||
} else {
|
||||
return "Could not load any resource bundles.";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a message from the specified key and replacement arguments,
|
||||
* localized to the given locale.
|
||||
*
|
||||
* @param msgKey The key for the message text.
|
||||
* @param args The arguments to be used as replacement text in the message
|
||||
* created.
|
||||
*
|
||||
* @return The formatted warning string.
|
||||
*/
|
||||
public static String createWarning(String msgKey, Object args[]) //throws Exception
|
||||
{
|
||||
if (XSLTBundle == null) {
|
||||
XSLTBundle = SecuritySupport.getResourceBundle(XSLT_ERROR_RESOURCES);
|
||||
}
|
||||
|
||||
if (XSLTBundle != null) {
|
||||
return createMsg(XSLTBundle, msgKey, args);
|
||||
} else {
|
||||
return "Could not load any resource bundles.";
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.res;
|
||||
|
||||
|
||||
/**
|
||||
* Default implementation of XSLTErrorResources. This is just
|
||||
* an empty class.
|
||||
* @xsl.usage advanced
|
||||
*/
|
||||
public class XSLTErrorResources_en extends XSLTErrorResources
|
||||
{
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,400 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.templates;
|
||||
|
||||
|
||||
/**
|
||||
* Primary constants used in the TransformerImpl classes.
|
||||
* @xsl.usage advanced
|
||||
*/
|
||||
public class Constants extends com.sun.org.apache.xml.internal.utils.Constants
|
||||
{
|
||||
|
||||
/**
|
||||
* IDs for XSL element types. These are associated
|
||||
* with the string literals in the TransformerImpl class.
|
||||
* Don't change the numbers. NOTE THAT THESE ARE NOT IN
|
||||
* ALPHABETICAL ORDER!
|
||||
* (It's a pity Java doesn't have a real Enumerated Mnemonic
|
||||
* datatype... or a C-like preprocessor in lieu thereof which
|
||||
* could be used to generate and maintain synch between these lists.)
|
||||
*/
|
||||
public static final int ELEMNAME_UNDEFINED = -1, ELEMNAME_WITHPARAM = 2,
|
||||
ELEMNAME_ADDATTRIBUTE = 4, ELEMNAME_ANCHOR = 22,
|
||||
|
||||
// ELEMNAME_ANCHOR_PATTERN = 23,
|
||||
ELEMNAME_APPLY_TEMPLATES = 50, ELEMNAME_USE = 34, ELEMNAME_CHILDREN = 6,
|
||||
ELEMNAME_CHOOSE = 37, ELEMNAME_COMMENT = 59, // my own
|
||||
ELEMNAME_CONSTRUCT = 7, // my own
|
||||
ELEMNAME_CONTENTS = 8, ELEMNAME_COPY = 9,
|
||||
ELEMNAME_COPY_OF = 74,
|
||||
ELEMNAME_DECIMALFORMAT = 83,
|
||||
ELEMNAME_DEFINEATTRIBUTESET = 40,
|
||||
|
||||
// ELEMNAME_DEFINECONSTANT = 29,
|
||||
// ELEMNAME_DEFINEMACRO = 10,
|
||||
ELEMNAME_DEFINESCRIPT = 11, ELEMNAME_DISPLAYIF = 12, // my own
|
||||
ELEMNAME_EMPTY = 14, ELEMNAME_EVAL = 15,
|
||||
ELEMNAME_EXPECTEDCHILDREN = 16,
|
||||
ELEMNAME_EXTENSION = 54,
|
||||
ELEMNAME_EXTENSIONHANDLER = 63,
|
||||
ELEMNAME_FOREACH = 28, ELEMNAME_KEY = 31,
|
||||
ELEMNAME_IF = 36, ELEMNAME_IMPORT = 26,
|
||||
ELEMNAME_INCLUDE = 27,
|
||||
ELEMNAME_CALLTEMPLATE = 17,
|
||||
ELEMNAME_PARAMVARIABLE = 41,
|
||||
ELEMNAME_NUMBER = 35, ELEMNAME_NSALIAS = 84,
|
||||
ELEMNAME_OTHERWISE = 39, ELEMNAME_PI = 58,
|
||||
ELEMNAME_PRESERVESPACE = 33,
|
||||
ELEMNAME_REMOVEATTRIBUTE = 5,
|
||||
ELEMNAME_TEMPLATE = 19, ELEMNAME_SORT = 64,
|
||||
ELEMNAME_STRIPSPACE = 32,
|
||||
ELEMNAME_STYLESHEET = 25, ELEMNAME_TEXT = 42,
|
||||
ELEMNAME_VALUEOF = 30, ELEMNAME_WHEN = 38,
|
||||
|
||||
// Pattern by example support
|
||||
ELEMNAME_ROOT = 44, ELEMNAME_ANY = 45, ELEMNAME_ELEMENT = 46,
|
||||
ELEMNAME_TARGETELEMENT = 47, ELEMNAME_ATTRIBUTE = 48,
|
||||
ELEMNAME_TARGETATTRIBUTE = 49, ELEMNAME_URL = 52, // my own
|
||||
ELEMNAME_CALL = 55, // my own
|
||||
|
||||
// ELEMNAME_WITHPARAM = 56,
|
||||
ELEMNAME_FALLBACK = 57, // my own
|
||||
ELEMNAME_TARGETPI = 60, // my own
|
||||
ELEMNAME_TARGETCOMMENT = 61, // my own
|
||||
ELEMNAME_TARGETTEXT = 62, // my own
|
||||
ELEMNAME_CSSSTYLECONVERSION = 65, // my own
|
||||
ELEMNAME_COUNTER = 66, ELEMNAME_COUNTERS = 67,
|
||||
ELEMNAME_COUNTERINCREMENT = 68, ELEMNAME_COUNTERRESET = 69,
|
||||
ELEMNAME_COUNTERSCOPE = 71, ELEMNAME_APPLY_IMPORTS = 72,
|
||||
ELEMNAME_VARIABLE = 73, ELEMNAME_MESSAGE = 75, ELEMNAME_LOCALE = 76,
|
||||
ELEMNAME_LITERALRESULT = 77, ELEMNAME_TEXTLITERALRESULT = 78,
|
||||
ELEMNAME_EXTENSIONCALL = 79, ELEMNAME_EXTENSIONDECL = 85,
|
||||
ELEMNAME_EXTENSIONSCRIPT = 86, ELEMNAME_OUTPUT = 80,
|
||||
ELEMNAME_COMPONENT = 81, ELEMNAME_SCRIPT = 82;
|
||||
|
||||
// Next free number: 90 (88 and 89 used for EXSLT elements);
|
||||
|
||||
/**
|
||||
* Literals for XSL element names. Note that there are more
|
||||
* names than IDs, because some names map to the same ID.
|
||||
*/
|
||||
public static final String
|
||||
ELEMNAME_ANCHOR_STRING = "anchor",
|
||||
ELEMNAME_ANY_STRING = "any", // pattern-by-example support
|
||||
ELEMNAME_APPLY_IMPORTS_STRING = "apply-imports",
|
||||
ELEMNAME_APPLY_TEMPLATES_STRING = "apply-templates",
|
||||
ELEMNAME_ARG_STRING = "arg",
|
||||
ELEMNAME_ATTRIBUTESET_STRING = "attribute-set",
|
||||
ELEMNAME_ATTRIBUTE_STRING = "attribute", // pattern-by-example support
|
||||
ELEMNAME_CALLTEMPLATEARG_STRING = "invoke-arg",
|
||||
ELEMNAME_CALLTEMPLATE_STRING = "call-template",
|
||||
ELEMNAME_CALL_STRING = "call",
|
||||
ELEMNAME_CHILDREN_STRING = "children",
|
||||
ELEMNAME_CHOOSE_STRING = "choose",
|
||||
ELEMNAME_COMMENT_STRING = "comment",
|
||||
ELEMNAME_COMPONENT_STRING = "component",
|
||||
ELEMNAME_CONSTRUCT_STRING = "construct", // my own
|
||||
ELEMNAME_CONTENTS_STRING = "contents",
|
||||
ELEMNAME_COPY_OF_STRING ="copy-of",
|
||||
ELEMNAME_COPY_STRING = "copy",
|
||||
ELEMNAME_COUNTERINCREMENT_STRING = "counter-increment",
|
||||
ELEMNAME_COUNTERRESET_STRING = "counter-reset",
|
||||
ELEMNAME_COUNTERSCOPE_STRING = "counter-scope",
|
||||
ELEMNAME_COUNTERS_STRING = "counters",
|
||||
ELEMNAME_COUNTER_STRING = "counter",
|
||||
ELEMNAME_CSSSTYLECONVERSION_STRING = "css-style-conversion",
|
||||
ELEMNAME_DECIMALFORMAT_STRING = "decimal-format",
|
||||
ELEMNAME_DISPLAYIF_STRING = "display-if", // my own
|
||||
ELEMNAME_ELEMENT_STRING = "element", // pattern-by-example support
|
||||
ELEMNAME_EMPTY_STRING = "empty",
|
||||
ELEMNAME_EVAL_STRING = "eval",
|
||||
ELEMNAME_EXPECTEDCHILDREN_STRING = "expectedchildren",
|
||||
ELEMNAME_EXTENSIONHANDLER_STRING = "code-dispatcher",
|
||||
ELEMNAME_EXTENSION_STRING = "functions",
|
||||
ELEMNAME_FALLBACK_STRING = "fallback",
|
||||
ELEMNAME_FOREACH_STRING = "for-each",
|
||||
ELEMNAME_IF_STRING = "if",
|
||||
ELEMNAME_IMPORT_STRING = "import",
|
||||
ELEMNAME_INCLUDE_STRING = "include",
|
||||
ELEMNAME_KEY_STRING = "key",
|
||||
ELEMNAME_LOCALE_STRING = "locale",
|
||||
ELEMNAME_MESSAGE_STRING = "message",
|
||||
ELEMNAME_NSALIAS_STRING = "namespace-alias",
|
||||
ELEMNAME_NUMBER_STRING = "number",
|
||||
ELEMNAME_OTHERWISE_STRING = "otherwise",
|
||||
ELEMNAME_OUTPUT_STRING = "output",
|
||||
ELEMNAME_PARAMVARIABLE_STRING = "param",
|
||||
ELEMNAME_PI_OLD_STRING = "pi",
|
||||
ELEMNAME_PI_STRING = "processing-instruction",
|
||||
ELEMNAME_PRESERVESPACE_STRING = "preserve-space",
|
||||
ELEMNAME_ROOT_STRING = "root", // pattern-by-example support
|
||||
ELEMNAME_SCRIPT_STRING = "script",
|
||||
ELEMNAME_SORT_STRING = "sort",
|
||||
ELEMNAME_STRIPSPACE_STRING = "strip-space",
|
||||
ELEMNAME_STYLESHEET_STRING = "stylesheet",
|
||||
ELEMNAME_TARGETATTRIBUTE_STRING = "target-attribute", // pattern-by-example support
|
||||
ELEMNAME_TARGETCOMMENT_STRING = "target-comment",
|
||||
ELEMNAME_TARGETELEMENT_STRING = "target-element", // pattern-by-example support
|
||||
ELEMNAME_TARGETPI_STRING = "target-pi",
|
||||
ELEMNAME_TARGETTEXT_STRING = "target-text",
|
||||
ELEMNAME_TEMPLATE_STRING = "template",
|
||||
ELEMNAME_TEXT_STRING = "text",
|
||||
ELEMNAME_TRANSFORM_STRING = "transform",
|
||||
ELEMNAME_URL_STRING = "uri", // pattern-by-example support
|
||||
ELEMNAME_USE_STRING = "use",
|
||||
ELEMNAME_VALUEOF_STRING = "value-of",
|
||||
ELEMNAME_VARIABLE_STRING = "variable",
|
||||
ELEMNAME_WHEN_STRING = "when",
|
||||
ELEMNAME_WITHPARAM_STRING = "with-param";
|
||||
|
||||
/**
|
||||
* Literals for EXSLT function elements.
|
||||
*/
|
||||
public static final String
|
||||
EXSLT_ELEMNAME_FUNCTION_STRING = "function",
|
||||
EXSLT_ELEMNAME_FUNCRESULT_STRING = "result";
|
||||
public static final int
|
||||
EXSLT_ELEMNAME_FUNCTION = 88,
|
||||
EXSLT_ELEMNAME_FUNCRESULT = 89;
|
||||
|
||||
|
||||
/**
|
||||
* Literals for XSL attribute names. Note that there may be more
|
||||
* names than IDs, because some names may map to the same ID.
|
||||
*/
|
||||
public static final String
|
||||
ATTRNAME_AMOUNT = "amount",
|
||||
ATTRNAME_ANCESTOR = "ancestor",
|
||||
ATTRNAME_ARCHIVE = "archive",
|
||||
ATTRNAME_ATTRIBUTE = "attribute",
|
||||
ATTRNAME_ATTRIBUTE_SET = "attribute-set",
|
||||
ATTRNAME_CASEORDER = "case-order",
|
||||
ATTRNAME_CLASS = "class",
|
||||
ATTRNAME_CLASSID = "classid",
|
||||
ATTRNAME_CODEBASE = "codebase",
|
||||
ATTRNAME_CODETYPE = "type",
|
||||
ATTRNAME_CONDITION = "condition",
|
||||
ATTRNAME_COPYTYPE = "copy-type",
|
||||
ATTRNAME_COUNT = "count",
|
||||
ATTRNAME_DATATYPE = "data-type",
|
||||
ATTRNAME_DECIMALSEPARATOR = "decimal-separator",
|
||||
ATTRNAME_DEFAULT = "default",
|
||||
ATTRNAME_DEFAULTSPACE = "default-space",
|
||||
ATTRNAME_DEPTH = "with-children",
|
||||
ATTRNAME_DIGIT = "digit",
|
||||
ATTRNAME_DIGITGROUPSEP = "digit-group-sep",
|
||||
ATTRNAME_DISABLE_OUTPUT_ESCAPING = "disable-output-escaping",
|
||||
ATTRNAME_ELEMENT = "element",
|
||||
ATTRNAME_ELEMENTS = "elements",
|
||||
ATTRNAME_EXCLUDE_RESULT_PREFIXES ="exclude-result-prefixes",
|
||||
ATTRNAME_EXPR = "expr",
|
||||
ATTRNAME_EXTENSIONELEMENTPREFIXES = "extension-element-prefixes",
|
||||
ATTRNAME_FORMAT = "format",
|
||||
ATTRNAME_FROM = "from",
|
||||
ATTRNAME_GROUPINGSEPARATOR = "grouping-separator",
|
||||
ATTRNAME_GROUPINGSIZE = "grouping-size",
|
||||
ATTRNAME_HREF = "href",
|
||||
ATTRNAME_ID = "id",
|
||||
ATTRNAME_IMPORTANCE = "importance",
|
||||
ATTRNAME_INDENTRESULT = "indent-result",
|
||||
ATTRNAME_INFINITY = "infinity",
|
||||
ATTRNAME_LANG = "lang",
|
||||
ATTRNAME_LETTERVALUE = "letter-value",
|
||||
ATTRNAME_LEVEL = "level",
|
||||
ATTRNAME_MATCH = "match",
|
||||
ATTRNAME_METHOD = "calls",
|
||||
ATTRNAME_MINUSSIGN = "minus-sign",
|
||||
ATTRNAME_MODE = "mode",
|
||||
ATTRNAME_NAME = "name",
|
||||
ATTRNAME_NAMESPACE = "namespace",
|
||||
ATTRNAME_NAN = "NaN",
|
||||
ATTRNAME_NDIGITSPERGROUP = "n-digits-per-group",
|
||||
ATTRNAME_NS = "ns",
|
||||
ATTRNAME_ONLY = "only",
|
||||
ATTRNAME_ORDER = "order",
|
||||
ATTRNAME_OUTPUT_CDATA_SECTION_ELEMENTS = "cdata-section-elements",
|
||||
ATTRNAME_OUTPUT_DOCTYPE_PUBLIC = "doctype-public",
|
||||
ATTRNAME_OUTPUT_DOCTYPE_SYSTEM = "doctype-system",
|
||||
ATTRNAME_OUTPUT_ENCODING = "encoding",
|
||||
ATTRNAME_OUTPUT_INDENT = "indent",
|
||||
ATTRNAME_OUTPUT_MEDIATYPE = "media-type",
|
||||
ATTRNAME_OUTPUT_METHOD = "method", // qname,
|
||||
ATTRNAME_OUTPUT_OMITXMLDECL = "omit-xml-declaration",
|
||||
ATTRNAME_OUTPUT_STANDALONE = "standalone",
|
||||
ATTRNAME_OUTPUT_VERSION = "version",
|
||||
ATTRNAME_PATTERNSEPARATOR = "pattern-separator",
|
||||
ATTRNAME_PERCENT = "percent",
|
||||
ATTRNAME_PERMILLE = "per-mille",
|
||||
ATTRNAME_PRIORITY = "priority",
|
||||
ATTRNAME_REFID = "refID",
|
||||
ATTRNAME_RESULTNS = "result-ns",
|
||||
ATTRNAME_RESULT_PREFIX = "result-prefix",
|
||||
ATTRNAME_SELECT = "select",
|
||||
ATTRNAME_SEQUENCESRC = "sequence-src",
|
||||
ATTRNAME_STYLE = "style",
|
||||
ATTRNAME_STYLESHEET_PREFIX = "stylesheet-prefix",
|
||||
ATTRNAME_TERMINATE = "terminate",
|
||||
ATTRNAME_TEST = "test",
|
||||
ATTRNAME_TOSTRING = "to-string",
|
||||
ATTRNAME_TYPE = "type",
|
||||
ATTRNAME_USE = "use",
|
||||
ATTRNAME_USEATTRIBUTESETS = "use-attribute-sets",
|
||||
ATTRNAME_VALUE = "value",
|
||||
ATTRNAME_VERSION = "version",
|
||||
ATTRNAME_XMLNS = "xmlns:", // namespace declaration prefix -- NOT an attribute by itself
|
||||
ATTRNAME_XMLNSDEF = "xmlns", // default namespace
|
||||
ATTRNAME_XMLSPACE = "xml:space",
|
||||
ATTRNAME_ZERODIGIT = "zero-digit";
|
||||
|
||||
/** IDs for XSL attribute types. These are associated
|
||||
* with the string literals in the TransformerImpl class.
|
||||
* Don't change the numbers. NOTE THAT THESE ARE NOT IN
|
||||
* ALPHABETICAL ORDER!
|
||||
*/
|
||||
public static final int TATTRNAME_OUTPUT_METHOD = 1, TATTRNAME_AMOUNT = 2,
|
||||
TATTRNAME_ANCESTOR = 3, TATTRNAME_ARCHIVE = 4,
|
||||
TATTRNAME_ATTRIBUTE = 5,
|
||||
TATTRNAME_ATTRIBUTE_SET = 6,
|
||||
TATTRNAME_CASEORDER = 7, TATTRNAME_CLASS = 8,
|
||||
TATTRNAME_CLASSID = 9, TATTRNAME_CODEBASE = 10,
|
||||
TATTRNAME_CODETYPE = 11, TATTRNAME_CONDITION = 12,
|
||||
TATTRNAME_COPYTYPE = 13, TATTRNAME_COUNT = 14,
|
||||
TATTRNAME_DATATYPE = 15, TATTRNAME_DEFAULT = 16,
|
||||
TATTRNAME_DEFAULTSPACE = 17, TATTRNAME_DEPTH = 18,
|
||||
TATTRNAME_DIGITGROUPSEP = 19,
|
||||
TATTRNAME_DISABLE_OUTPUT_ESCAPING = 20,
|
||||
TATTRNAME_ELEMENT = 21, TATTRNAME_ELEMENTS = 22,
|
||||
TATTRNAME_EXPR = 23,
|
||||
TATTRNAME_EXTENSIONELEMENTPREFIXES = 24,
|
||||
TATTRNAME_FORMAT = 25, TATTRNAME_FROM = 26,
|
||||
TATTRNAME_GROUPINGSEPARATOR = 27,
|
||||
TATTRNAME_GROUPINGSIZE = 28, TATTRNAME_HREF = 29,
|
||||
TATTRNAME_ID = 30, TATTRNAME_IMPORTANCE = 31,
|
||||
TATTRNAME_INDENTRESULT = 32, TATTRNAME_LANG = 33,
|
||||
TATTRNAME_LETTERVALUE = 34, TATTRNAME_LEVEL = 35,
|
||||
TATTRNAME_MATCH = 36, TATTRNAME_METHOD = 37,
|
||||
TATTRNAME_MODE = 38, TATTRNAME_NAME = 39,
|
||||
TATTRNAME_NAMESPACE = 40,
|
||||
TATTRNAME_NDIGITSPERGROUP = 41, TATTRNAME_NS = 42,
|
||||
TATTRNAME_ONLY = 43, TATTRNAME_ORDER = 44,
|
||||
TATTRNAME_OUTPUT_CDATA_SECTION_ELEMENTS = 45,
|
||||
TATTRNAME_OUTPUT_DOCTYPE_PUBLIC = 46,
|
||||
TATTRNAME_OUTPUT_DOCTYPE_SYSTEM = 47,
|
||||
TATTRNAME_OUTPUT_ENCODING = 48,
|
||||
TATTRNAME_OUTPUT_INDENT = 49,
|
||||
TATTRNAME_OUTPUT_MEDIATYPE = 50,
|
||||
TATTRNAME_OUTPUT_STANDALONE = 51,
|
||||
TATTRNAME_OUTPUT_VERSION = 52,
|
||||
TATTRNAME_OUTPUT_OMITXMLDECL = 53,
|
||||
TATTRNAME_PRIORITY = 54, TATTRNAME_REFID = 55,
|
||||
TATTRNAME_RESULTNS = 56, TATTRNAME_SELECT = 57,
|
||||
TATTRNAME_SEQUENCESRC = 58, TATTRNAME_STYLE = 59,
|
||||
TATTRNAME_TEST = 60, TATTRNAME_TOSTRING = 61,
|
||||
TATTRNAME_TYPE = 62, TATTRNAME_USE = 63,
|
||||
TATTRNAME_USEATTRIBUTESETS = 64,
|
||||
TATTRNAME_VALUE = 65, TATTRNAME_XMLNSDEF = 66,
|
||||
TATTRNAME_XMLNS = 67, TATTRNAME_XMLSPACE = 68,
|
||||
TATTRNAME_EXCLUDE_RESULT_PREFIXES = 69;
|
||||
|
||||
/** Mnemonics for the possible values of the xsl:output element's
|
||||
* method= attribute:
|
||||
* <ul>
|
||||
* <li>ATTRVAL_OUTPUT_METHOD_XML = Use an XML formatter to
|
||||
* produce the output document (basic XSLT operation).</li>
|
||||
* <li>ATTRVAL_OUTPUT_METHOD_HTML: Use an HTML formatter to
|
||||
* produce the output document. When generating HTML documents,
|
||||
* this may yield better results; it does things like escaping
|
||||
* characters in href attributes.</li>
|
||||
* </li>ATTRVAL_OUTPUT_METHOD_TEXT: Use a Text formatter to
|
||||
* produce the output document. Generally the right choice if your
|
||||
* stylesheet wants to take over _all_ the details of formatting,
|
||||
* most often when producing something that isn't an XML or HTML
|
||||
* document.</li>
|
||||
* </ul>
|
||||
* */
|
||||
public static final String ATTRVAL_OUTPUT_METHOD_HTML = "html",
|
||||
ATTRVAL_OUTPUT_METHOD_XML = "xml",
|
||||
ATTRVAL_OUTPUT_METHOD_TEXT = "text";
|
||||
|
||||
|
||||
/* For space-att*/
|
||||
public static final int ATTRVAL_PRESERVE = 1, ATTRVAL_STRIP = 2;
|
||||
|
||||
|
||||
/** For indent-result */
|
||||
public static final boolean ATTRVAL_YES = true, ATTRVAL_NO = false;
|
||||
|
||||
|
||||
/** For letter-value attribute (part of conversion attributes). */
|
||||
public static final String ATTRVAL_ALPHABETIC = "alphabetic",
|
||||
ATTRVAL_OTHER = "other",
|
||||
ATTRVAL_TRADITIONAL = "traditional";
|
||||
|
||||
|
||||
/** For level attribute in xsl:number. */
|
||||
public static final String ATTRVAL_SINGLE = "single",
|
||||
ATTRVAL_MULTI = "multiple", ATTRVAL_ANY = "any";
|
||||
|
||||
|
||||
/** For Stylesheet-prefix and result-prefix in xsl:namespace-alias */
|
||||
public static final String ATTRVAL_DEFAULT_PREFIX = "#default";
|
||||
|
||||
/** Integer equivalents for above */
|
||||
public static final int NUMBERLETTER_ALPHABETIC = 1, NUMBERLETTER_TRADITIONAL = 2;
|
||||
|
||||
/** Integer equivelents for above */
|
||||
public static final int NUMBERLEVEL_SINGLE = 1, NUMBERLEVEL_MULTI = 2,
|
||||
NUMBERLEVEL_ANY = 3, MAX_MULTI_COUNTING_DEPTH = 32;
|
||||
|
||||
|
||||
/** some stuff for my patterns-by-example */
|
||||
public static final String ATTRVAL_THIS = ".", ATTRVAL_PARENT = "..",
|
||||
ATTRVAL_ANCESTOR = "ancestor", ATTRVAL_ID = "id";
|
||||
|
||||
|
||||
/** Stuff for sorting */
|
||||
public static final String ATTRVAL_DATATYPE_TEXT = "text",
|
||||
ATTRVAL_DATATYPE_NUMBER = "number",
|
||||
ATTRVAL_ORDER_ASCENDING = "ascending",
|
||||
ATTRVAL_ORDER_DESCENDING = "descending",
|
||||
ATTRVAL_CASEORDER_UPPER = "upper-first",
|
||||
ATTRVAL_CASEORDER_LOWER = "lower-first";
|
||||
|
||||
/** Integer equivelents for DATATYPE attribute */
|
||||
public static final int SORTDATATYPE_TEXT = 1, SORTDATATYPE_NUMBER = 2;
|
||||
|
||||
/** Integer equivelents for ORDER attribute */
|
||||
public static final int SORTORDER_ASCENDING = 1, SORTORDER_DESCENDING = 2;
|
||||
|
||||
/** Integer equivelents for CASE-ORDER attribute */
|
||||
public static final int SORTCASEORDER_UPPERFIRST = 1, SORTCASEORDER_LOWERFIRST = 2;
|
||||
|
||||
/** some stuff for Decimal-format */
|
||||
public static final String ATTRVAL_INFINITY = "Infinity",
|
||||
ATTRVAL_NAN = "NaN",
|
||||
DEFAULT_DECIMAL_FORMAT = "#default";
|
||||
|
||||
|
||||
/** temp dummy */
|
||||
public static final String ATTRNAME_XXXX = "XXXX";
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.utils;
|
||||
|
||||
/**
|
||||
* A configuration error. This was an internal class in ObjectFactory previously
|
||||
*/
|
||||
public final class ConfigurationError
|
||||
extends Error {
|
||||
|
||||
//
|
||||
// Data
|
||||
//
|
||||
|
||||
/** Exception. */
|
||||
private Exception exception;
|
||||
|
||||
//
|
||||
// Constructors
|
||||
//
|
||||
|
||||
/**
|
||||
* Construct a new instance with the specified detail string and
|
||||
* exception.
|
||||
*/
|
||||
ConfigurationError(String msg, Exception x) {
|
||||
super(msg);
|
||||
this.exception = x;
|
||||
} // <init>(String,Exception)
|
||||
|
||||
//
|
||||
// methods
|
||||
//
|
||||
|
||||
/** Returns the exception associated to this error. */
|
||||
public Exception getException() {
|
||||
return exception;
|
||||
} // getException():Exception
|
||||
|
||||
} // class ConfigurationError
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.utils;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.XalanConstants;
|
||||
|
||||
/**
|
||||
* This is the base class for features and properties
|
||||
*
|
||||
*/
|
||||
public abstract class FeaturePropertyBase {
|
||||
|
||||
/**
|
||||
* States of the settings of a property, in the order: default value, value
|
||||
* set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system
|
||||
* properties, and jaxp api properties
|
||||
*/
|
||||
public static enum State {
|
||||
//this order reflects the overriding order
|
||||
DEFAULT, FSP, JAXPDOTPROPERTIES, SYSTEMPROPERTY, APIPROPERTY
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Values of the properties as defined in enum Properties
|
||||
*/
|
||||
String[] values = null;
|
||||
/**
|
||||
* States of the settings for each property in Properties above
|
||||
*/
|
||||
State[] states = {State.DEFAULT, State.DEFAULT};
|
||||
|
||||
|
||||
/**
|
||||
* Set the value for a specific property.
|
||||
*
|
||||
* @param property the property
|
||||
* @param state the state of the property
|
||||
* @param value the value of the property
|
||||
*/
|
||||
public void setValue(Enum property, State state, String value) {
|
||||
//only update if it shall override
|
||||
if (state.compareTo(states[property.ordinal()]) >= 0) {
|
||||
values[property.ordinal()] = value;
|
||||
states[property.ordinal()] = state;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of a property by its index
|
||||
* @param index the index of the property
|
||||
* @param state the state of the property
|
||||
* @param value the value of the property
|
||||
*/
|
||||
public void setValue(int index, State state, String value) {
|
||||
//only update if it shall override
|
||||
if (state.compareTo(states[index]) >= 0) {
|
||||
values[index] = value;
|
||||
states[index] = state;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value by property name and state
|
||||
* @param propertyName property name
|
||||
* @param state the state of the property
|
||||
* @param value the value of the property
|
||||
* @return true if the property is managed by the security property manager;
|
||||
* false if otherwise.
|
||||
*/
|
||||
public boolean setValue(String propertyName, State state, Object value) {
|
||||
int index = getIndex(propertyName);
|
||||
if (index > -1) {
|
||||
setValue(index, state, (String)value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value by property name and state
|
||||
* @param propertyName property name
|
||||
* @param state the state of the property
|
||||
* @param value the value of the property
|
||||
* @return true if the property is managed by the security property manager;
|
||||
* false if otherwise.
|
||||
*/
|
||||
public boolean setValue(String propertyName, State state, boolean value) {
|
||||
int index = getIndex(propertyName);
|
||||
if (index > -1) {
|
||||
if (value) {
|
||||
setValue(index, state, XalanConstants.FEATURE_TRUE);
|
||||
} else {
|
||||
setValue(index, state, XalanConstants.FEATURE_FALSE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of the specified property
|
||||
*
|
||||
* @param property the property
|
||||
* @return the value of the property
|
||||
*/
|
||||
public String getValue(Enum property) {
|
||||
return values[property.ordinal()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of the specified property
|
||||
*
|
||||
* @param property the property
|
||||
* @return the value of the property
|
||||
*/
|
||||
public String getValue(String property) {
|
||||
int index = getIndex(property);
|
||||
if (index > -1) {
|
||||
return getValueByIndex(index);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of the specified property.
|
||||
*
|
||||
* @param propertyName the property name
|
||||
* @return the value of the property as a string. If a property is managed
|
||||
* by this manager, its value shall not be null.
|
||||
*/
|
||||
public String getValueAsString(String propertyName) {
|
||||
int index = getIndex(propertyName);
|
||||
if (index > -1) {
|
||||
return getValueByIndex(index);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of a property by its ordinal
|
||||
* @param index the index of a property
|
||||
* @return value of a property
|
||||
*/
|
||||
public String getValueByIndex(int index) {
|
||||
return values[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the index by property name
|
||||
* @param propertyName property name
|
||||
* @return the index of the property if found; return -1 if not
|
||||
*/
|
||||
public abstract int getIndex(String propertyName);
|
||||
|
||||
public <E extends Enum<E>> int getIndex(Class<E> property, String propertyName) {
|
||||
for (Enum<E> enumItem : property.getEnumConstants()) {
|
||||
if (enumItem.toString().equals(propertyName)) {
|
||||
//internally, ordinal is used as index
|
||||
return enumItem.ordinal();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read from system properties, or those in jaxp.properties
|
||||
*
|
||||
* @param property the property
|
||||
* @param systemProperty the name of the system property
|
||||
*/
|
||||
void getSystemProperty(Enum property, String systemProperty) {
|
||||
try {
|
||||
String value = SecuritySupport.getSystemProperty(systemProperty);
|
||||
if (value != null) {
|
||||
values[property.ordinal()] = value;
|
||||
states[property.ordinal()] = State.SYSTEMPROPERTY;
|
||||
return;
|
||||
}
|
||||
|
||||
value = SecuritySupport.readJAXPProperty(systemProperty);
|
||||
if (value != null) {
|
||||
values[property.ordinal()] = value;
|
||||
states[property.ordinal()] = State.JAXPDOTPROPERTIES;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
//invalid setting ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.utils;
|
||||
|
||||
/**
|
||||
* This class is duplicated for each JAXP subpackage so keep it in sync.
|
||||
* It is package private and therefore is not exposed as part of the JAXP
|
||||
* API.
|
||||
* <p>
|
||||
* This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
|
||||
* class and modified to be used as a general utility for creating objects
|
||||
* dynamically.
|
||||
*
|
||||
*/
|
||||
public class ObjectFactory {
|
||||
|
||||
//
|
||||
// Constants
|
||||
//
|
||||
private static final String JAXP_INTERNAL = "com.sun.org.apache";
|
||||
private static final String STAX_INTERNAL = "com.sun.xml.internal";
|
||||
|
||||
/** Set to true for debugging */
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
|
||||
/** Prints a message to standard error if debugging is enabled. */
|
||||
private static void debugPrintln(String msg) {
|
||||
if (DEBUG) {
|
||||
System.err.println("JAXP: " + msg);
|
||||
}
|
||||
} // debugPrintln(String)
|
||||
|
||||
/**
|
||||
* Figure out which ClassLoader to use. For JDK 1.2 and later use
|
||||
* the context ClassLoader.
|
||||
*/
|
||||
public static ClassLoader findClassLoader()
|
||||
{
|
||||
if (System.getSecurityManager()!=null) {
|
||||
//this will ensure bootclassloader is used
|
||||
return null;
|
||||
}
|
||||
|
||||
// Figure out which ClassLoader to use for loading the provider
|
||||
// class. If there is a Context ClassLoader then use it.
|
||||
ClassLoader context = SecuritySupport.getContextClassLoader();
|
||||
ClassLoader system = SecuritySupport.getSystemClassLoader();
|
||||
|
||||
ClassLoader chain = system;
|
||||
while (true) {
|
||||
if (context == chain) {
|
||||
// Assert: we are on JDK 1.1 or we have no Context ClassLoader
|
||||
// or any Context ClassLoader in chain of system classloader
|
||||
// (including extension ClassLoader) so extend to widest
|
||||
// ClassLoader (always look in system ClassLoader if Xalan
|
||||
// is in boot/extension/system classpath and in current
|
||||
// ClassLoader otherwise); normal classloaders delegate
|
||||
// back to system ClassLoader first so this widening doesn't
|
||||
// change the fact that context ClassLoader will be consulted
|
||||
ClassLoader current = ObjectFactory.class.getClassLoader();
|
||||
|
||||
chain = system;
|
||||
while (true) {
|
||||
if (current == chain) {
|
||||
// Assert: Current ClassLoader in chain of
|
||||
// boot/extension/system ClassLoaders
|
||||
return system;
|
||||
}
|
||||
if (chain == null) {
|
||||
break;
|
||||
}
|
||||
chain = SecuritySupport.getParentClassLoader(chain);
|
||||
}
|
||||
|
||||
// Assert: Current ClassLoader not in chain of
|
||||
// boot/extension/system ClassLoaders
|
||||
return current;
|
||||
}
|
||||
|
||||
if (chain == null) {
|
||||
// boot ClassLoader reached
|
||||
break;
|
||||
}
|
||||
|
||||
// Check for any extension ClassLoaders in chain up to
|
||||
// boot ClassLoader
|
||||
chain = SecuritySupport.getParentClassLoader(chain);
|
||||
}
|
||||
|
||||
// Assert: Context ClassLoader not in chain of
|
||||
// boot/extension/system ClassLoaders
|
||||
return context;
|
||||
} // findClassLoader():ClassLoader
|
||||
|
||||
/**
|
||||
* Create an instance of a class using the same class loader for the ObjectFactory by default
|
||||
* or boot class loader when Security Manager is in place
|
||||
*/
|
||||
public static Object newInstance(String className, boolean doFallback)
|
||||
throws ConfigurationError
|
||||
{
|
||||
if (System.getSecurityManager()!=null) {
|
||||
return newInstance(className, null, doFallback);
|
||||
} else {
|
||||
return newInstance(className,
|
||||
findClassLoader (), doFallback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of a class using the specified ClassLoader
|
||||
*/
|
||||
static Object newInstance(String className, ClassLoader cl,
|
||||
boolean doFallback)
|
||||
throws ConfigurationError
|
||||
{
|
||||
// assert(className != null);
|
||||
try{
|
||||
Class providerClass = findProviderClass(className, cl, doFallback);
|
||||
Object instance = providerClass.newInstance();
|
||||
if (DEBUG) debugPrintln("created new instance of " + providerClass +
|
||||
" using ClassLoader: " + cl);
|
||||
return instance;
|
||||
} catch (ClassNotFoundException x) {
|
||||
throw new ConfigurationError(
|
||||
"Provider " + className + " not found", x);
|
||||
} catch (Exception x) {
|
||||
throw new ConfigurationError(
|
||||
"Provider " + className + " could not be instantiated: " + x,
|
||||
x);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a Class using the same class loader for the ObjectFactory by default
|
||||
* or boot class loader when Security Manager is in place
|
||||
*/
|
||||
public static Class<?> findProviderClass(String className, boolean doFallback)
|
||||
throws ClassNotFoundException, ConfigurationError
|
||||
{
|
||||
return findProviderClass (className,
|
||||
findClassLoader (), doFallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a Class using the specified ClassLoader
|
||||
*/
|
||||
private static Class<?> findProviderClass(String className, ClassLoader cl,
|
||||
boolean doFallback)
|
||||
throws ClassNotFoundException, ConfigurationError
|
||||
{
|
||||
//throw security exception if the calling thread is not allowed to access the
|
||||
//class. Restrict the access to the package classes as specified in java.security policy.
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
try{
|
||||
if (security != null){
|
||||
if (className.startsWith(JAXP_INTERNAL) ||
|
||||
className.startsWith(STAX_INTERNAL)) {
|
||||
cl = null;
|
||||
} else {
|
||||
final int lastDot = className.lastIndexOf(".");
|
||||
String packageName = className;
|
||||
if (lastDot != -1) packageName = className.substring(0, lastDot);
|
||||
security.checkPackageAccess(packageName);
|
||||
}
|
||||
}
|
||||
}catch(SecurityException e){
|
||||
throw e;
|
||||
}
|
||||
|
||||
Class<?> providerClass;
|
||||
if (cl == null) {
|
||||
providerClass = Class.forName(className, false, ObjectFactory.class.getClassLoader());
|
||||
} else {
|
||||
try {
|
||||
providerClass = cl.loadClass(className);
|
||||
} catch (ClassNotFoundException x) {
|
||||
if (doFallback) {
|
||||
// Fall back to current classloader
|
||||
ClassLoader current = ObjectFactory.class.getClassLoader();
|
||||
if (current == null) {
|
||||
providerClass = Class.forName(className);
|
||||
} else if (cl != current) {
|
||||
cl = current;
|
||||
providerClass = cl.loadClass(className);
|
||||
} else {
|
||||
throw x;
|
||||
}
|
||||
} else {
|
||||
throw x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return providerClass;
|
||||
}
|
||||
|
||||
} // class ObjectFactory
|
||||
@@ -0,0 +1,324 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.ListResourceBundle;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* This class is duplicated for each subpackage so keep it in sync. It is
|
||||
* package private and therefore is not exposed as part of any API.
|
||||
*
|
||||
* @xerces.internal
|
||||
*/
|
||||
public final class SecuritySupport {
|
||||
|
||||
private static final SecuritySupport securitySupport = new SecuritySupport();
|
||||
|
||||
/**
|
||||
* Return an instance of this class.
|
||||
*/
|
||||
public static SecuritySupport getInstance() {
|
||||
return securitySupport;
|
||||
}
|
||||
|
||||
public static ClassLoader getContextClassLoader() {
|
||||
return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader cl = null;
|
||||
try {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static ClassLoader getSystemClassLoader() {
|
||||
return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader cl = null;
|
||||
try {
|
||||
cl = ClassLoader.getSystemClassLoader();
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static ClassLoader getParentClassLoader(final ClassLoader cl) {
|
||||
return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader parent = null;
|
||||
try {
|
||||
parent = cl.getParent();
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
|
||||
// eliminate loops in case of the boot
|
||||
// ClassLoader returning itself as a parent
|
||||
return (parent == cl) ? null : parent;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String getSystemProperty(final String propName) {
|
||||
return (String) AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return System.getProperty(propName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String getSystemProperty(final String propName, final String def) {
|
||||
return (String) AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return System.getProperty(propName, def);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static FileInputStream getFileInputStream(final File file)
|
||||
throws FileNotFoundException {
|
||||
try {
|
||||
return (FileInputStream) AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws FileNotFoundException {
|
||||
return new FileInputStream(file);
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw (FileNotFoundException)e.getException();
|
||||
}
|
||||
}
|
||||
|
||||
public static InputStream getResourceAsStream(final String name) {
|
||||
return (InputStream) AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return SecuritySupport.class.getResourceAsStream("/"+name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a resource bundle using the specified base name, the default locale, and the caller's class loader.
|
||||
* @param bundle the base name of the resource bundle, a fully qualified class name
|
||||
* @return a resource bundle for the given base name and the default locale
|
||||
*/
|
||||
public static ListResourceBundle getResourceBundle(String bundle) {
|
||||
return getResourceBundle(bundle, Locale.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a resource bundle using the specified base name and locale, and the caller's class loader.
|
||||
* @param bundle the base name of the resource bundle, a fully qualified class name
|
||||
* @param locale the locale for which a resource bundle is desired
|
||||
* @return a resource bundle for the given base name and locale
|
||||
*/
|
||||
public static ListResourceBundle getResourceBundle(final String bundle, final Locale locale) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<ListResourceBundle>() {
|
||||
public ListResourceBundle run() {
|
||||
try {
|
||||
return (ListResourceBundle)ResourceBundle.getBundle(bundle, locale);
|
||||
} catch (MissingResourceException e) {
|
||||
try {
|
||||
return (ListResourceBundle)ResourceBundle.getBundle(bundle, new Locale("en", "US"));
|
||||
} catch (MissingResourceException e2) {
|
||||
throw new MissingResourceException(
|
||||
"Could not load any resource bundle by " + bundle, bundle, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean getFileExists(final File f) {
|
||||
return ((Boolean) AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return f.exists() ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
})).booleanValue();
|
||||
}
|
||||
|
||||
static long getLastModified(final File f) {
|
||||
return ((Long) AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return new Long(f.lastModified());
|
||||
}
|
||||
})).longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip off path from an URI
|
||||
*
|
||||
* @param uri an URI with full path
|
||||
* @return the file name only
|
||||
*/
|
||||
public static String sanitizePath(String uri) {
|
||||
if (uri == null) {
|
||||
return "";
|
||||
}
|
||||
int i = uri.lastIndexOf("/");
|
||||
if (i > 0) {
|
||||
return uri.substring(i+1, uri.length());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the protocol used in the systemId against allowed protocols
|
||||
*
|
||||
* @param systemId the Id of the URI
|
||||
* @param allowedProtocols a list of allowed protocols separated by comma
|
||||
* @param accessAny keyword to indicate allowing any protocol
|
||||
* @return the name of the protocol if rejected, null otherwise
|
||||
*/
|
||||
public static String checkAccess(String systemId, String allowedProtocols, String accessAny) throws IOException {
|
||||
if (systemId == null || (allowedProtocols != null &&
|
||||
allowedProtocols.equalsIgnoreCase(accessAny))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String protocol;
|
||||
if (systemId.indexOf(":")==-1) {
|
||||
protocol = "file";
|
||||
} else {
|
||||
URL url = new URL(systemId);
|
||||
protocol = url.getProtocol();
|
||||
if (protocol.equalsIgnoreCase("jar")) {
|
||||
String path = url.getPath();
|
||||
protocol = path.substring(0, path.indexOf(":"));
|
||||
}
|
||||
}
|
||||
|
||||
if (isProtocolAllowed(protocol, allowedProtocols)) {
|
||||
//access allowed
|
||||
return null;
|
||||
} else {
|
||||
return protocol;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the protocol is in the allowed list of protocols. The check
|
||||
* is case-insensitive while ignoring whitespaces.
|
||||
*
|
||||
* @param protocol a protocol
|
||||
* @param allowedProtocols a list of allowed protocols
|
||||
* @return true if the protocol is in the list
|
||||
*/
|
||||
private static boolean isProtocolAllowed(String protocol, String allowedProtocols) {
|
||||
if (allowedProtocols == null) {
|
||||
return false;
|
||||
}
|
||||
String temp[] = allowedProtocols.split(",");
|
||||
for (String t : temp) {
|
||||
t = t.trim();
|
||||
if (t.equalsIgnoreCase(protocol)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read JAXP system property in this order: system property,
|
||||
* $java.home/lib/jaxp.properties if the system property is not specified
|
||||
*
|
||||
* @param propertyId the Id of the property
|
||||
* @return the value of the property
|
||||
*/
|
||||
public static String getJAXPSystemProperty(String sysPropertyId) {
|
||||
String accessExternal = getSystemProperty(sysPropertyId);
|
||||
if (accessExternal == null) {
|
||||
accessExternal = readJAXPProperty(sysPropertyId);
|
||||
}
|
||||
return accessExternal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from $java.home/lib/jaxp.properties for the specified property
|
||||
* The program
|
||||
*
|
||||
* @param propertyId the Id of the property
|
||||
* @return the value of the property
|
||||
*/
|
||||
static String readJAXPProperty(String propertyId) {
|
||||
String value = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
if (firstTime) {
|
||||
synchronized (cacheProps) {
|
||||
if (firstTime) {
|
||||
String configFile = getSystemProperty("java.home") + File.separator +
|
||||
"lib" + File.separator + "jaxp.properties";
|
||||
File f = new File(configFile);
|
||||
if (getFileExists(f)) {
|
||||
is = getFileInputStream(f);
|
||||
cacheProps.load(is);
|
||||
}
|
||||
firstTime = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
value = cacheProps.getProperty(propertyId);
|
||||
|
||||
}
|
||||
catch (Exception ex) {}
|
||||
finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException ex) {}
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache for properties in java.home/lib/jaxp.properties
|
||||
*/
|
||||
static final Properties cacheProps = new Properties();
|
||||
|
||||
/**
|
||||
* Flag indicating if the program has tried reading java.home/lib/jaxp.properties
|
||||
*/
|
||||
static volatile boolean firstTime = true;
|
||||
|
||||
private SecuritySupport () {}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.utils;
|
||||
|
||||
|
||||
import com.sun.org.apache.xalan.internal.XalanConstants;
|
||||
import javax.xml.XMLConstants;
|
||||
|
||||
/**
|
||||
* This class manages security related properties
|
||||
*
|
||||
*/
|
||||
public final class XMLSecurityPropertyManager extends FeaturePropertyBase {
|
||||
|
||||
/**
|
||||
* Properties managed by the security property manager
|
||||
*/
|
||||
public static enum Property {
|
||||
ACCESS_EXTERNAL_DTD(XMLConstants.ACCESS_EXTERNAL_DTD,
|
||||
XalanConstants.EXTERNAL_ACCESS_DEFAULT),
|
||||
ACCESS_EXTERNAL_STYLESHEET(XMLConstants.ACCESS_EXTERNAL_STYLESHEET,
|
||||
XalanConstants.EXTERNAL_ACCESS_DEFAULT);
|
||||
|
||||
final String name;
|
||||
final String defaultValue;
|
||||
|
||||
Property(String name, String value) {
|
||||
this.name = name;
|
||||
this.defaultValue = value;
|
||||
}
|
||||
|
||||
public boolean equalsName(String propertyName) {
|
||||
return (propertyName == null) ? false : name.equals(propertyName);
|
||||
}
|
||||
|
||||
String defaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor. Establishes default values
|
||||
*/
|
||||
public XMLSecurityPropertyManager() {
|
||||
values = new String[Property.values().length];
|
||||
for (Property property : Property.values()) {
|
||||
values[property.ordinal()] = property.defaultValue();
|
||||
}
|
||||
//read system properties or jaxp.properties
|
||||
readSystemProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the index by property name
|
||||
* @param propertyName property name
|
||||
* @return the index of the property if found; return -1 if not
|
||||
*/
|
||||
public int getIndex(String propertyName){
|
||||
for (Property property : Property.values()) {
|
||||
if (property.equalsName(propertyName)) {
|
||||
//internally, ordinal is used as index
|
||||
return property.ordinal();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from system properties, or those in jaxp.properties
|
||||
*/
|
||||
private void readSystemProperties() {
|
||||
getSystemProperty(Property.ACCESS_EXTERNAL_DTD,
|
||||
XalanConstants.SP_ACCESS_EXTERNAL_DTD);
|
||||
getSystemProperty(Property.ACCESS_EXTERNAL_STYLESHEET,
|
||||
XalanConstants.SP_ACCESS_EXTERNAL_STYLESHEET);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
1226
jdkSrc/jdk8/com/sun/org/apache/xalan/internal/xslt/Process.java
Normal file
1226
jdkSrc/jdk8/com/sun/org/apache/xalan/internal/xslt/Process.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author W. Eliot Kimber (eliot@isogen.com)
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
public interface CollatorFactory {
|
||||
|
||||
public Collator getCollator(String lang, String country);
|
||||
public Collator getCollator(Locale locale);
|
||||
}
|
||||
103
jdkSrc/jdk8/com/sun/org/apache/xalan/internal/xsltc/DOM.java
Normal file
103
jdkSrc/jdk8/com/sun/org/apache/xalan/internal/xsltc/DOM.java
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc;
|
||||
|
||||
import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
|
||||
import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
|
||||
import java.util.Map;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
public interface DOM {
|
||||
public final static int FIRST_TYPE = 0;
|
||||
|
||||
public final static int NO_TYPE = -1;
|
||||
|
||||
// 0 is reserved for NodeIterator.END
|
||||
public final static int NULL = 0;
|
||||
|
||||
// used by some node iterators to know which node to return
|
||||
public final static int RETURN_CURRENT = 0;
|
||||
public final static int RETURN_PARENT = 1;
|
||||
|
||||
// Constants used by getResultTreeFrag to indicate the types of the RTFs.
|
||||
public final static int SIMPLE_RTF = 0;
|
||||
public final static int ADAPTIVE_RTF = 1;
|
||||
public final static int TREE_RTF = 2;
|
||||
|
||||
/** returns singleton iterator containg the document root */
|
||||
public DTMAxisIterator getIterator();
|
||||
public String getStringValue();
|
||||
|
||||
public DTMAxisIterator getChildren(final int node);
|
||||
public DTMAxisIterator getTypedChildren(final int type);
|
||||
public DTMAxisIterator getAxisIterator(final int axis);
|
||||
public DTMAxisIterator getTypedAxisIterator(final int axis, final int type);
|
||||
public DTMAxisIterator getNthDescendant(int node, int n, boolean includeself);
|
||||
public DTMAxisIterator getNamespaceAxisIterator(final int axis, final int ns);
|
||||
public DTMAxisIterator getNodeValueIterator(DTMAxisIterator iter, int returnType,
|
||||
String value, boolean op);
|
||||
public DTMAxisIterator orderNodes(DTMAxisIterator source, int node);
|
||||
public String getNodeName(final int node);
|
||||
public String getNodeNameX(final int node);
|
||||
public String getNamespaceName(final int node);
|
||||
public int getExpandedTypeID(final int node);
|
||||
public int getNamespaceType(final int node);
|
||||
public int getParent(final int node);
|
||||
public int getAttributeNode(final int gType, final int element);
|
||||
public String getStringValueX(final int node);
|
||||
public void copy(final int node, SerializationHandler handler)
|
||||
throws TransletException;
|
||||
public void copy(DTMAxisIterator nodes, SerializationHandler handler)
|
||||
throws TransletException;
|
||||
public String shallowCopy(final int node, SerializationHandler handler)
|
||||
throws TransletException;
|
||||
public boolean lessThan(final int node1, final int node2);
|
||||
public void characters(final int textNode, SerializationHandler handler)
|
||||
throws TransletException;
|
||||
public Node makeNode(int index);
|
||||
public Node makeNode(DTMAxisIterator iter);
|
||||
public NodeList makeNodeList(int index);
|
||||
public NodeList makeNodeList(DTMAxisIterator iter);
|
||||
public String getLanguage(int node);
|
||||
public int getSize();
|
||||
public String getDocumentURI(int node);
|
||||
public void setFilter(StripFilter filter);
|
||||
public void setupMapping(String[] names, String[] urisArray, int[] typesArray, String[] namespaces);
|
||||
public boolean isElement(final int node);
|
||||
public boolean isAttribute(final int node);
|
||||
public String lookupNamespace(int node, String prefix)
|
||||
throws TransletException;
|
||||
public int getNodeIdent(final int nodehandle);
|
||||
public int getNodeHandle(final int nodeId);
|
||||
public DOM getResultTreeFrag(int initialSize, int rtfType);
|
||||
public DOM getResultTreeFrag(int initialSize, int rtfType, boolean addToDTMManager);
|
||||
public SerializationHandler getOutputDomBuilder();
|
||||
public int getNSType(int node);
|
||||
public int getDocument();
|
||||
public String getUnparsedEntityURI(String name);
|
||||
public Map<String, Integer> getElementsWithIDs();
|
||||
public void release();
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc;
|
||||
|
||||
|
||||
/**
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
public interface DOMCache {
|
||||
|
||||
/**
|
||||
* This method is responsible for:
|
||||
*
|
||||
* (1) building the DOMImpl tree
|
||||
*
|
||||
* Parser _parser = new Parser();
|
||||
* DOMImpl _dom = new DOMImpl();
|
||||
* _parser.setDocumentHandler(_dom.getBuilder());
|
||||
* _parser.setDTDHandler(_dom.getBuilder());
|
||||
* _parser.parse(uri);
|
||||
*
|
||||
* (2) giving the translet an early opportunity to extract anything from
|
||||
* the DOMImpl that it would like
|
||||
*
|
||||
* translet.documentPrepass(_dom);
|
||||
*
|
||||
* (3) setting the document URI:
|
||||
*
|
||||
* _dom.setDocumentURI(uri);
|
||||
*
|
||||
* @param baseURI The base URI used by the document call.
|
||||
* @param href The href argument passed to the document function.
|
||||
* @param translet A reference to the translet requesting the document
|
||||
*/
|
||||
public DOM retrieveDocument(String baseURI, String href, Translet translet);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc;
|
||||
|
||||
/**
|
||||
* Interface for SAXImpl which adds methods used at run-time, over and above
|
||||
* those provided by the XSLTC DOM interface. An attempt to avoid the current
|
||||
* "Is the DTM a DOM, if so is it a SAXImpl, . . .
|
||||
* which was producing some ugly replicated code
|
||||
* and introducing bugs where that multipathing had not been
|
||||
* done. This makes it easier to provide other DOM/DOMEnhancedForDTM
|
||||
* implementations, rather than hard-wiring XSLTC to SAXImpl.
|
||||
*
|
||||
* @author Joseph Kesselman
|
||||
*
|
||||
*/
|
||||
public interface DOMEnhancedForDTM extends DOM {
|
||||
public short[] getMapping(String[] names, String[] uris, int[] types);
|
||||
public int[] getReverseMapping(String[] names, String[] uris, int[] types);
|
||||
public short[] getNamespaceMapping(String[] namespaces);
|
||||
public short[] getReverseNamespaceMapping(String[] namespaces);
|
||||
public String getDocumentURI();
|
||||
public void setDocumentURI(String uri);
|
||||
public int getExpandedTypeID2(int nodeHandle);
|
||||
public boolean hasDOMSource();
|
||||
public int getElementById(String idString);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc;
|
||||
|
||||
import com.sun.org.apache.xml.internal.dtm.DTM;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
public interface NodeIterator extends Cloneable {
|
||||
public static final int END = DTM.NULL;
|
||||
|
||||
/**
|
||||
* Callers should not call next() after it returns END.
|
||||
*/
|
||||
public int next();
|
||||
|
||||
/**
|
||||
* Resets the iterator to the last start node.
|
||||
*/
|
||||
public NodeIterator reset();
|
||||
|
||||
/**
|
||||
* Returns the number of elements in this iterator.
|
||||
*/
|
||||
public int getLast();
|
||||
|
||||
/**
|
||||
* Returns the position of the current node in the set.
|
||||
*/
|
||||
public int getPosition();
|
||||
|
||||
/**
|
||||
* Remembers the current node for the next call to gotoMark().
|
||||
*/
|
||||
public void setMark();
|
||||
|
||||
/**
|
||||
* Restores the current node remembered by setMark().
|
||||
*/
|
||||
public void gotoMark();
|
||||
|
||||
/**
|
||||
* Set start to END should 'close' the iterator,
|
||||
* i.e. subsequent call to next() should return END.
|
||||
*/
|
||||
public NodeIterator setStartNode(int node);
|
||||
|
||||
/**
|
||||
* True if this iterator has a reversed axis.
|
||||
*/
|
||||
public boolean isReverse();
|
||||
|
||||
/**
|
||||
* Returns a deep copy of this iterator.
|
||||
*/
|
||||
public NodeIterator cloneIterator();
|
||||
|
||||
/**
|
||||
* Prevents or allows iterator restarts.
|
||||
*/
|
||||
public void setRestartable(boolean isRestartable);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc;
|
||||
|
||||
|
||||
/**
|
||||
* Admin class that assigns a version number to the XSLTC software.
|
||||
* The version number is made up from three fields as in:
|
||||
* MAJOR.MINOR[.DELTA]. Fields are incremented based on the following:
|
||||
* DELTA field: changes for each bug fix, developer fixing the bug should
|
||||
* increment this field.
|
||||
* MINOR field: API changes or a milestone culminating from several
|
||||
* bug fixes. DELTA field goes to zero and MINOR is
|
||||
* incremented such as: {1.0,1.0.1,1.0.2,1.0.3,...1.0.18,1.1}
|
||||
* MAJOR field: milestone culminating in fundamental API changes or
|
||||
* architectural changes. MINOR field goes to zero
|
||||
* and MAJOR is incremented such as: {...,1.1.14,1.2,2.0}
|
||||
* Stability of a release follows: X.0 > X.X > X.X.X
|
||||
* @author G. Todd Miller
|
||||
*/
|
||||
public class ProcessorVersion {
|
||||
private static int MAJOR = 1;
|
||||
private static int MINOR = 0;
|
||||
private static int DELTA = 0;
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("XSLTC version " + MAJOR + "." + MINOR +
|
||||
((DELTA > 0) ? ("."+DELTA) : ("")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc;
|
||||
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
public interface StripFilter {
|
||||
public boolean stripSpace(DOM dom, int node, int type);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc;
|
||||
|
||||
import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
|
||||
import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
public interface Translet {
|
||||
|
||||
public void transform(DOM document, SerializationHandler handler)
|
||||
throws TransletException;
|
||||
public void transform(DOM document, SerializationHandler[] handlers)
|
||||
throws TransletException;
|
||||
public void transform(DOM document, DTMAxisIterator iterator,
|
||||
SerializationHandler handler)
|
||||
throws TransletException;
|
||||
|
||||
public Object addParameter(String name, Object value);
|
||||
|
||||
public void buildKeys(DOM document, DTMAxisIterator iterator,
|
||||
SerializationHandler handler, int root)
|
||||
throws TransletException;
|
||||
public void addAuxiliaryClass(Class auxClass);
|
||||
public Class getAuxiliaryClass(String className);
|
||||
public String[] getNamesArray();
|
||||
public String[] getUrisArray();
|
||||
public int[] getTypesArray();
|
||||
public String[] getNamespaceArray();
|
||||
public boolean overrideDefaultParser();
|
||||
public void setOverrideDefaultParser(boolean flag);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
public final class TransletException extends SAXException {
|
||||
static final long serialVersionUID = -878916829521217293L;
|
||||
|
||||
public TransletException() {
|
||||
super("Translet error");
|
||||
}
|
||||
|
||||
public TransletException(Exception e) {
|
||||
super(e.toString());
|
||||
initCause(e);
|
||||
}
|
||||
|
||||
public TransletException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2001-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.
|
||||
*/
|
||||
/*
|
||||
* $Id: Compile.java,v 1.2.4.1 2005/08/31 11:24:13 pvedula Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.cmdline;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.Vector;
|
||||
import jdk.xml.internal.JdkXmlFeatures;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt.GetOpt;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt.GetOptsException;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author G. Todd Miller
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
public final class Compile {
|
||||
|
||||
// Versioning numbers for the compiler -v option output
|
||||
private static int VERSION_MAJOR = 1;
|
||||
private static int VERSION_MINOR = 4;
|
||||
private static int VERSION_DELTA = 0;
|
||||
|
||||
|
||||
|
||||
// This variable should be set to false to prevent any methods in this
|
||||
// class from calling System.exit(). As this is a command-line tool,
|
||||
// calling System.exit() is normally OK, but we also want to allow for
|
||||
// this class being used in other ways as well.
|
||||
private static boolean _allowExit = true;
|
||||
|
||||
|
||||
public static void printUsage() {
|
||||
System.err.println("XSLTC version " +
|
||||
VERSION_MAJOR + "." + VERSION_MINOR +
|
||||
((VERSION_DELTA > 0) ? ("." + VERSION_DELTA) : ("")) + "\n" +
|
||||
new ErrorMsg(ErrorMsg.COMPILE_USAGE_STR));
|
||||
if (_allowExit) System.exit(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method implements the command line compiler. See the USAGE_STRING
|
||||
* constant for a description. It may make sense to move the command-line
|
||||
* handling to a separate package (ie. make one xsltc.cmdline.Compiler
|
||||
* class that contains this main() method and one xsltc.cmdline.Transform
|
||||
* class that contains the DefaultRun stuff).
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
boolean inputIsURL = false;
|
||||
boolean useStdIn = false;
|
||||
boolean classNameSet = false;
|
||||
final GetOpt getopt = new GetOpt(args, "o:d:j:p:uxhsinv");
|
||||
if (args.length < 1) printUsage();
|
||||
|
||||
final XSLTC xsltc = new XSLTC(new JdkXmlFeatures(false));
|
||||
xsltc.init();
|
||||
|
||||
int c;
|
||||
while ((c = getopt.getNextOption()) != -1) {
|
||||
switch(c) {
|
||||
case 'i':
|
||||
useStdIn = true;
|
||||
break;
|
||||
case 'o':
|
||||
xsltc.setClassName(getopt.getOptionArg());
|
||||
classNameSet = true;
|
||||
break;
|
||||
case 'd':
|
||||
xsltc.setDestDirectory(getopt.getOptionArg());
|
||||
break;
|
||||
case 'p':
|
||||
xsltc.setPackageName(getopt.getOptionArg());
|
||||
break;
|
||||
case 'j':
|
||||
xsltc.setJarFileName(getopt.getOptionArg());
|
||||
break;
|
||||
case 'x':
|
||||
xsltc.setDebug(true);
|
||||
break;
|
||||
case 'u':
|
||||
inputIsURL = true;
|
||||
break;
|
||||
case 's':
|
||||
_allowExit = false;
|
||||
break;
|
||||
case 'n':
|
||||
xsltc.setTemplateInlining(true); // used to be 'false'
|
||||
break;
|
||||
case 'v':
|
||||
// fall through to case h
|
||||
case 'h':
|
||||
default:
|
||||
printUsage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
boolean compileOK;
|
||||
|
||||
if (useStdIn) {
|
||||
if (!classNameSet) {
|
||||
System.err.println(new ErrorMsg(ErrorMsg.COMPILE_STDIN_ERR));
|
||||
if (_allowExit) System.exit(-1);
|
||||
}
|
||||
compileOK = xsltc.compile(System.in, xsltc.getClassName());
|
||||
}
|
||||
else {
|
||||
// Generate a vector containg URLs for all stylesheets specified
|
||||
final String[] stylesheetNames = getopt.getCmdArgs();
|
||||
final Vector stylesheetVector = new Vector();
|
||||
for (int i = 0; i < stylesheetNames.length; i++) {
|
||||
final String name = stylesheetNames[i];
|
||||
URL url;
|
||||
if (inputIsURL)
|
||||
url = new URL(name);
|
||||
else
|
||||
url = (new File(name)).toURI().toURL();
|
||||
stylesheetVector.addElement(url);
|
||||
}
|
||||
compileOK = xsltc.compile(stylesheetVector);
|
||||
}
|
||||
|
||||
// Compile the stylesheet and output class/jar file(s)
|
||||
if (compileOK) {
|
||||
xsltc.printWarnings();
|
||||
if (xsltc.getJarFileName() != null) xsltc.outputToJar();
|
||||
if (_allowExit) System.exit(0);
|
||||
}
|
||||
else {
|
||||
xsltc.printWarnings();
|
||||
xsltc.printErrors();
|
||||
if (_allowExit) System.exit(-1);
|
||||
}
|
||||
}
|
||||
catch (GetOptsException ex) {
|
||||
System.err.println(ex);
|
||||
printUsage(); // exits with code '-1'
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (_allowExit) System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 2001-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.
|
||||
*/
|
||||
/*
|
||||
* $Id: Transform.java,v 1.2.4.1 2005/09/12 09:07:33 pvedula Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.cmdline;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.DOMEnhancedForDTM;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.StripFilter;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.TransletException;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.dom.DOMWSFilter;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.runtime.Constants;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.runtime.Parameter;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputHandlerFactory;
|
||||
import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;
|
||||
import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Vector;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author G. Todd Miller
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
final public class Transform {
|
||||
|
||||
private SerializationHandler _handler;
|
||||
|
||||
private String _fileName;
|
||||
private String _className;
|
||||
private String _jarFileSrc;
|
||||
private boolean _isJarFileSpecified = false;
|
||||
private Vector _params = null;
|
||||
private boolean _uri, _debug;
|
||||
private int _iterations;
|
||||
|
||||
public Transform(String className, String fileName,
|
||||
boolean uri, boolean debug, int iterations) {
|
||||
_fileName = fileName;
|
||||
_className = className;
|
||||
_uri = uri;
|
||||
_debug = debug;
|
||||
_iterations = iterations;
|
||||
}
|
||||
|
||||
public String getFileName(){return _fileName;}
|
||||
public String getClassName(){return _className;}
|
||||
|
||||
public void setParameters(Vector params) {
|
||||
_params = params;
|
||||
}
|
||||
|
||||
private void setJarFileInputSrc(boolean flag, String jarFile) {
|
||||
// TODO: at this time we do not do anything with this
|
||||
// information, attempts to add the jarfile to the CLASSPATH
|
||||
// were successful via System.setProperty, but the effects
|
||||
// were not visible to the running JVM. For now we add jarfile
|
||||
// to CLASSPATH in the wrapper script that calls this program.
|
||||
_isJarFileSpecified = flag;
|
||||
// TODO verify jarFile exists...
|
||||
_jarFileSrc = jarFile;
|
||||
}
|
||||
|
||||
private void doTransform() {
|
||||
try {
|
||||
final Class clazz = ObjectFactory.findProviderClass(_className, true);
|
||||
final AbstractTranslet translet = (AbstractTranslet)clazz.newInstance();
|
||||
translet.postInitialization();
|
||||
|
||||
// Create a SAX parser and get the XMLReader object it uses
|
||||
final SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
try {
|
||||
factory.setFeature(Constants.NAMESPACE_FEATURE,true);
|
||||
}
|
||||
catch (Exception e) {
|
||||
factory.setNamespaceAware(true);
|
||||
}
|
||||
final SAXParser parser = factory.newSAXParser();
|
||||
final XMLReader reader = parser.getXMLReader();
|
||||
|
||||
// Set the DOM's DOM builder as the XMLReader's SAX2 content handler
|
||||
XSLTCDTMManager dtmManager =
|
||||
XSLTCDTMManager.createNewDTMManagerInstance();
|
||||
|
||||
DTMWSFilter wsfilter;
|
||||
if (translet != null && translet instanceof StripFilter) {
|
||||
wsfilter = new DOMWSFilter(translet);
|
||||
} else {
|
||||
wsfilter = null;
|
||||
}
|
||||
|
||||
final DOMEnhancedForDTM dom =
|
||||
(DOMEnhancedForDTM)dtmManager.getDTM(
|
||||
new SAXSource(reader, new InputSource(_fileName)),
|
||||
false, wsfilter, true, false, translet.hasIdCall());
|
||||
|
||||
dom.setDocumentURI(_fileName);
|
||||
translet.prepassDocument(dom);
|
||||
|
||||
// Pass global parameters
|
||||
int n = _params.size();
|
||||
for (int i = 0; i < n; i++) {
|
||||
Parameter param = (Parameter) _params.elementAt(i);
|
||||
translet.addParameter(param._name, param._value);
|
||||
}
|
||||
|
||||
// Transform the document
|
||||
TransletOutputHandlerFactory tohFactory =
|
||||
TransletOutputHandlerFactory.newInstance();
|
||||
tohFactory.setOutputType(TransletOutputHandlerFactory.STREAM);
|
||||
tohFactory.setEncoding(translet._encoding);
|
||||
tohFactory.setOutputMethod(translet._method);
|
||||
|
||||
if (_iterations == -1) {
|
||||
translet.transform(dom, tohFactory.getSerializationHandler());
|
||||
}
|
||||
else if (_iterations > 0) {
|
||||
long mm = System.currentTimeMillis();
|
||||
for (int i = 0; i < _iterations; i++) {
|
||||
translet.transform(dom,
|
||||
tohFactory.getSerializationHandler());
|
||||
}
|
||||
mm = System.currentTimeMillis() - mm;
|
||||
|
||||
System.err.println("\n<!--");
|
||||
System.err.println(" transform = "
|
||||
+ (((double) mm) / ((double) _iterations))
|
||||
+ " ms");
|
||||
System.err.println(" throughput = "
|
||||
+ (1000.0 / (((double) mm)
|
||||
/ ((double) _iterations)))
|
||||
+ " tps");
|
||||
System.err.println("-->");
|
||||
}
|
||||
}
|
||||
catch (TransletException e) {
|
||||
if (_debug) e.printStackTrace();
|
||||
System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+
|
||||
e.getMessage());
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
if (_debug) e.printStackTrace();
|
||||
System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+
|
||||
e.getMessage());
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
if (_debug) e.printStackTrace();
|
||||
ErrorMsg err = new ErrorMsg(ErrorMsg.FILE_NOT_FOUND_ERR, _fileName);
|
||||
System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+
|
||||
err.toString());
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
if (_debug) e.printStackTrace();
|
||||
ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, _fileName);
|
||||
System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+
|
||||
err.toString());
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
if (_debug) e.printStackTrace();
|
||||
ErrorMsg err= new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR,_className);
|
||||
System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+
|
||||
err.toString());
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
if (_debug) e.printStackTrace();
|
||||
ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, _fileName);
|
||||
System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+
|
||||
err.toString());
|
||||
}
|
||||
catch (SAXException e) {
|
||||
Exception ex = e.getException();
|
||||
if (_debug) {
|
||||
if (ex != null) ex.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.err.print(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY));
|
||||
if (ex != null)
|
||||
System.err.println(ex.getMessage());
|
||||
else
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (_debug) e.printStackTrace();
|
||||
System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void printUsage() {
|
||||
System.err.println(new ErrorMsg(ErrorMsg.TRANSFORM_USAGE_STR));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
if (args.length > 0) {
|
||||
int i;
|
||||
int iterations = -1;
|
||||
boolean uri = false, debug = false;
|
||||
boolean isJarFileSpecified = false;
|
||||
String jarFile = null;
|
||||
|
||||
// Parse options starting with '-'
|
||||
for (i = 0; i < args.length && args[i].charAt(0) == '-'; i++) {
|
||||
if (args[i].equals("-u")) {
|
||||
uri = true;
|
||||
}
|
||||
else if (args[i].equals("-x")) {
|
||||
debug = true;
|
||||
}
|
||||
else if (args[i].equals("-j")) {
|
||||
isJarFileSpecified = true;
|
||||
jarFile = args[++i];
|
||||
}
|
||||
else if (args[i].equals("-n")) {
|
||||
try {
|
||||
iterations = Integer.parseInt(args[++i]);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
else {
|
||||
printUsage();
|
||||
}
|
||||
}
|
||||
|
||||
// Enough arguments left ?
|
||||
if (args.length - i < 2) printUsage();
|
||||
|
||||
// Get document file and class name
|
||||
Transform handler = new Transform(args[i+1], args[i], uri,
|
||||
debug, iterations);
|
||||
handler.setJarFileInputSrc(isJarFileSpecified, jarFile);
|
||||
|
||||
// Parse stylesheet parameters
|
||||
Vector params = new Vector();
|
||||
for (i += 2; i < args.length; i++) {
|
||||
final int equal = args[i].indexOf('=');
|
||||
if (equal > 0) {
|
||||
final String name = args[i].substring(0, equal);
|
||||
final String value = args[i].substring(equal+1);
|
||||
params.addElement(new Parameter(name, value));
|
||||
}
|
||||
else {
|
||||
printUsage();
|
||||
}
|
||||
}
|
||||
|
||||
if (i == args.length) {
|
||||
handler.setParameters(params);
|
||||
handler.doTransform();
|
||||
}
|
||||
} else {
|
||||
printUsage();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 2001-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.
|
||||
*/
|
||||
/*
|
||||
* $Id: GetOpt.java,v 1.2.4.1 2005/08/31 11:46:04 pvedula Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
|
||||
|
||||
/**
|
||||
* GetOpt is a Java equivalent to the C getopt() library function
|
||||
* discussed in man page getopt(3C). It provides command line
|
||||
* parsing for Java applications. It supports the most rules of the
|
||||
* command line standard (see man page intro(1)) including stacked
|
||||
* options such as '-sxm' (which is equivalent to -s -x -m); it
|
||||
* handles special '--' option that signifies the end of options.
|
||||
* Additionally this implementation of getopt will check for
|
||||
* mandatory arguments to options such as in the case of
|
||||
* '-d <file>' it will throw a MissingOptArgException if the
|
||||
* option argument '<file>' is not included on the commandline.
|
||||
* getopt(3C) does not check for this.
|
||||
* @author G Todd Miller
|
||||
*/
|
||||
public class GetOpt{
|
||||
public GetOpt(String[] args, String optString){
|
||||
theOptions = new ArrayList();
|
||||
int currOptIndex = 0;
|
||||
theCmdArgs = new ArrayList();
|
||||
theOptionMatcher = new OptionMatcher(optString);
|
||||
// fill in the options list
|
||||
for(int i=0; i<args.length; i++){
|
||||
String token = args[i];
|
||||
int tokenLength = token.length();
|
||||
if(token.equals("--")){ // end of opts
|
||||
currOptIndex = i+1; // set index of first operand
|
||||
break; // end of options
|
||||
}
|
||||
else if(token.startsWith("-") && tokenLength == 2){
|
||||
// simple option token such as '-s' found
|
||||
theOptions.add(new Option(token.charAt(1)));
|
||||
}
|
||||
else if(token.startsWith("-") && tokenLength > 2){
|
||||
// stacked options found, such as '-shm'
|
||||
// iterate thru the tokens after the dash and
|
||||
// add them to theOptions list
|
||||
for(int j=1; j<tokenLength; j++){
|
||||
theOptions.add(new Option(token.charAt(j)));
|
||||
}
|
||||
}
|
||||
else if(!token.startsWith("-")){
|
||||
// case 1- there are not options stored yet therefore
|
||||
// this must be an command argument, not an option argument
|
||||
if(theOptions.size() == 0){
|
||||
currOptIndex = i;
|
||||
break; // stop processing options
|
||||
}
|
||||
else {
|
||||
// case 2-
|
||||
// there are options stored, check to see if
|
||||
// this arg belong to the last arg stored
|
||||
int indexoflast=0;
|
||||
indexoflast = theOptions.size()-1;
|
||||
Option op = (Option)theOptions.get(indexoflast);
|
||||
char opLetter = op.getArgLetter();
|
||||
if(!op.hasArg() && theOptionMatcher.hasArg(opLetter)){
|
||||
op.setArg(token);
|
||||
}
|
||||
else{
|
||||
// case 3 -
|
||||
// the last option stored does not take
|
||||
// an argument, so again, this argument
|
||||
// must be a command argument, not
|
||||
// an option argument
|
||||
currOptIndex = i;
|
||||
break; // end of options
|
||||
}
|
||||
}
|
||||
}// end option does not start with "-"
|
||||
} // end for args loop
|
||||
|
||||
// attach an iterator to list of options
|
||||
theOptionsIterator = theOptions.listIterator();
|
||||
|
||||
// options are done, now fill out cmd arg list with remaining args
|
||||
for(int i=currOptIndex; i<args.length; i++){
|
||||
String token = args[i];
|
||||
theCmdArgs.add(token);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* debugging routine to print out all options collected
|
||||
*/
|
||||
public void printOptions(){
|
||||
for(ListIterator it=theOptions.listIterator(); it.hasNext();){
|
||||
Option opt = (Option)it.next();
|
||||
System.out.print("OPT =" + opt.getArgLetter());
|
||||
String arg = opt.getArgument();
|
||||
if(arg != null){
|
||||
System.out.print(" " + arg);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the next option found in the commandline. Distinguishes
|
||||
* between two bad cases, one case is when an illegal option
|
||||
* is found, and then other case is when an option takes an
|
||||
* argument but no argument was found for that option.
|
||||
* If the option found was not declared in the optString, then
|
||||
* an IllegalArgumentException will be thrown (case 1).
|
||||
* If the next option found has been declared to take an argument,
|
||||
* and no such argument exists, then a MissingOptArgException
|
||||
* is thrown (case 2).
|
||||
* @param none
|
||||
* @return int - the next option found.
|
||||
* @throws IllegalArgumentException, MissingOptArgException.
|
||||
*/
|
||||
public int getNextOption() throws IllegalArgumentException,
|
||||
MissingOptArgException
|
||||
{
|
||||
int retval = -1;
|
||||
if(theOptionsIterator.hasNext()){
|
||||
theCurrentOption = (Option)theOptionsIterator.next();
|
||||
char c = theCurrentOption.getArgLetter();
|
||||
boolean shouldHaveArg = theOptionMatcher.hasArg(c);
|
||||
String arg = theCurrentOption.getArgument();
|
||||
if(!theOptionMatcher.match(c)) {
|
||||
ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_CMDLINE_OPTION_ERR,
|
||||
new Character(c));
|
||||
throw (new IllegalArgumentException(msg.toString()));
|
||||
}
|
||||
else if(shouldHaveArg && (arg == null)) {
|
||||
ErrorMsg msg = new ErrorMsg(ErrorMsg.CMDLINE_OPT_MISSING_ARG_ERR,
|
||||
new Character(c));
|
||||
throw (new MissingOptArgException(msg.toString()));
|
||||
}
|
||||
retval = c;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the argument for the current parsed option. For example,
|
||||
* in case of '-d <file>', if current option parsed is 'd' then
|
||||
* getOptionArg() would return '<file>'.
|
||||
* @return String - argument for current parsed option.
|
||||
* @param none
|
||||
*/
|
||||
public String getOptionArg(){
|
||||
String retval = null;
|
||||
String tmp = theCurrentOption.getArgument();
|
||||
char c = theCurrentOption.getArgLetter();
|
||||
if(theOptionMatcher.hasArg(c)){
|
||||
retval = tmp;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets list of the commandline arguments. For example, in command
|
||||
* such as 'cmd -s -d file file2 file3 file4' with the usage
|
||||
* 'cmd [-s] [-d <file>] <file>...', getCmdArgs() would return
|
||||
* the list {file2, file3, file4}.
|
||||
* @return String[] - list of command arguments that may appear
|
||||
* after options and option arguments.
|
||||
* @params none
|
||||
*/
|
||||
public String[] getCmdArgs(){
|
||||
String[] retval = new String[theCmdArgs.size()];
|
||||
int i=0;
|
||||
for(ListIterator it=theCmdArgs.listIterator(); it.hasNext();){
|
||||
retval[i++] = (String)it.next();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
private Option theCurrentOption = null;
|
||||
private ListIterator theOptionsIterator;
|
||||
private List theOptions = null;
|
||||
private List theCmdArgs = null;
|
||||
private OptionMatcher theOptionMatcher = null;
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
//
|
||||
// Inner Classes
|
||||
//
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
// inner class to model an option
|
||||
class Option{
|
||||
private char theArgLetter;
|
||||
private String theArgument = null;
|
||||
public Option(char argLetter) { theArgLetter = argLetter; }
|
||||
public void setArg(String arg) {
|
||||
theArgument = arg;
|
||||
}
|
||||
public boolean hasArg() { return (theArgument != null); }
|
||||
public char getArgLetter() { return theArgLetter; }
|
||||
public String getArgument() { return theArgument; }
|
||||
} // end class Option
|
||||
|
||||
|
||||
// inner class to query optString for a possible option match,
|
||||
// and whether or not a given legal option takes an argument.
|
||||
//
|
||||
class OptionMatcher{
|
||||
public OptionMatcher(String optString){
|
||||
theOptString = optString;
|
||||
}
|
||||
public boolean match(char c){
|
||||
boolean retval = false;
|
||||
if(theOptString.indexOf(c) != -1){
|
||||
retval = true;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
public boolean hasArg(char c){
|
||||
boolean retval = false;
|
||||
int index = theOptString.indexOf(c)+1;
|
||||
if (index == theOptString.length()){
|
||||
// reached end of theOptString
|
||||
retval = false;
|
||||
}
|
||||
else if(theOptString.charAt(index) == ':'){
|
||||
retval = true;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
private String theOptString = null;
|
||||
} // end class OptionMatcher
|
||||
}// end class GetOpt
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 2001-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.
|
||||
*/
|
||||
/*
|
||||
* $Id: GetOptsException.java,v 1.2.4.1 2005/08/31 11:47:06 pvedula Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt;
|
||||
|
||||
/**
|
||||
* @author G Todd Miller
|
||||
*/
|
||||
public class GetOptsException extends Exception{
|
||||
static final long serialVersionUID = 8736874967183039804L;
|
||||
public GetOptsException(String msg){
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 2001-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.
|
||||
*/
|
||||
/*
|
||||
* $Id: IllegalArgumentException.java,v 1.2.4.1 2005/08/31 11:47:56 pvedula Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt;
|
||||
|
||||
|
||||
class IllegalArgumentException extends GetOptsException{
|
||||
static final long serialVersionUID = 8642122427294793651L;
|
||||
public IllegalArgumentException(String msg){
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 2001-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.
|
||||
*/
|
||||
/*
|
||||
* $Id: MissingOptArgException.java,v 1.2.4.1 2005/08/31 11:49:21 pvedula Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt;
|
||||
|
||||
|
||||
/**
|
||||
* @author G Todd Miller
|
||||
*/
|
||||
class MissingOptArgException extends GetOptsException{
|
||||
static final long serialVersionUID = -1972471465394544822L;
|
||||
public MissingOptArgException(String msg){
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ALOAD;
|
||||
import com.sun.org.apache.bcel.internal.generic.ASTORE;
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class AbsoluteLocationPath extends Expression {
|
||||
private Expression _path; // may be null
|
||||
|
||||
public AbsoluteLocationPath() {
|
||||
_path = null;
|
||||
}
|
||||
|
||||
public AbsoluteLocationPath(Expression path) {
|
||||
_path = path;
|
||||
if (path != null) {
|
||||
_path.setParent(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void setParser(Parser parser) {
|
||||
super.setParser(parser);
|
||||
if (_path != null) {
|
||||
_path.setParser(parser);
|
||||
}
|
||||
}
|
||||
|
||||
public Expression getPath() {
|
||||
return(_path);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "AbsoluteLocationPath(" +
|
||||
(_path != null ? _path.toString() : "null") + ')';
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
if (_path != null) {
|
||||
final Type ptype = _path.typeCheck(stable);
|
||||
if (ptype instanceof NodeType) { // promote to node-set
|
||||
_path = new CastExpr(_path, Type.NodeSet);
|
||||
}
|
||||
}
|
||||
return _type = Type.NodeSet;
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
if (_path != null) {
|
||||
final int initAI = cpg.addMethodref(ABSOLUTE_ITERATOR,
|
||||
"<init>",
|
||||
"("
|
||||
+ NODE_ITERATOR_SIG
|
||||
+ ")V");
|
||||
|
||||
// Compile relative path iterator(s)
|
||||
//
|
||||
// Backwards branches are prohibited if an uninitialized object is
|
||||
// on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
|
||||
// We don't know whether this code might contain backwards branches,
|
||||
// so we mustn't create the new object until after we've created
|
||||
// this argument to its constructor. Instead we calculate the
|
||||
// value of the argument to the constructor first, store it in
|
||||
// a temporary variable, create the object and reload the argument
|
||||
// from the temporary to avoid the problem.
|
||||
_path.translate(classGen, methodGen);
|
||||
LocalVariableGen relPathIterator
|
||||
= methodGen.addLocalVariable("abs_location_path_tmp",
|
||||
Util.getJCRefType(NODE_ITERATOR_SIG),
|
||||
null, null);
|
||||
relPathIterator.setStart(
|
||||
il.append(new ASTORE(relPathIterator.getIndex())));
|
||||
|
||||
// Create new AbsoluteIterator
|
||||
il.append(new NEW(cpg.addClass(ABSOLUTE_ITERATOR)));
|
||||
il.append(DUP);
|
||||
relPathIterator.setEnd(
|
||||
il.append(new ALOAD(relPathIterator.getIndex())));
|
||||
|
||||
// Initialize AbsoluteIterator with iterator from the stack
|
||||
il.append(new INVOKESPECIAL(initAI));
|
||||
}
|
||||
else {
|
||||
final int gitr = cpg.addInterfaceMethodref(DOM_INTF,
|
||||
"getIterator",
|
||||
"()"+NODE_ITERATOR_SIG);
|
||||
il.append(methodGen.loadDOM());
|
||||
il.append(new INVOKEINTERFACE(gitr, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.BranchHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.GOTO_W;
|
||||
import com.sun.org.apache.bcel.internal.generic.IF_ICMPEQ;
|
||||
import com.sun.org.apache.bcel.internal.generic.ILOAD;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
||||
import com.sun.org.apache.bcel.internal.generic.ISTORE;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.PUSH;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
import com.sun.org.apache.xml.internal.dtm.DTM;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class AbsolutePathPattern extends LocationPathPattern {
|
||||
private final RelativePathPattern _left; // may be null
|
||||
|
||||
public AbsolutePathPattern(RelativePathPattern left) {
|
||||
_left = left;
|
||||
if (left != null) {
|
||||
left.setParent(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void setParser(Parser parser) {
|
||||
super.setParser(parser);
|
||||
if (_left != null)
|
||||
_left.setParser(parser);
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
return _left == null ? Type.Root : _left.typeCheck(stable);
|
||||
}
|
||||
|
||||
public boolean isWildcard() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public StepPattern getKernelPattern() {
|
||||
return _left != null ? _left.getKernelPattern() : null;
|
||||
}
|
||||
|
||||
public void reduceKernelPattern() {
|
||||
_left.reduceKernelPattern();
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
if (_left != null) {
|
||||
if (_left instanceof StepPattern) {
|
||||
final LocalVariableGen local =
|
||||
// absolute path pattern temporary
|
||||
methodGen.addLocalVariable2("apptmp",
|
||||
Util.getJCRefType(NODE_SIG),
|
||||
null);
|
||||
il.append(DUP);
|
||||
local.setStart(il.append(new ISTORE(local.getIndex())));
|
||||
_left.translate(classGen, methodGen);
|
||||
il.append(methodGen.loadDOM());
|
||||
local.setEnd(il.append(new ILOAD(local.getIndex())));
|
||||
methodGen.removeLocalVariable(local);
|
||||
}
|
||||
else {
|
||||
_left.translate(classGen, methodGen);
|
||||
}
|
||||
}
|
||||
|
||||
final int getParent = cpg.addInterfaceMethodref(DOM_INTF,
|
||||
GET_PARENT,
|
||||
GET_PARENT_SIG);
|
||||
final int getType = cpg.addInterfaceMethodref(DOM_INTF,
|
||||
"getExpandedTypeID",
|
||||
"(I)I");
|
||||
|
||||
InstructionHandle begin = il.append(methodGen.loadDOM());
|
||||
il.append(SWAP);
|
||||
il.append(new INVOKEINTERFACE(getParent, 2));
|
||||
if (_left instanceof AncestorPattern) {
|
||||
il.append(methodGen.loadDOM());
|
||||
il.append(SWAP);
|
||||
}
|
||||
il.append(new INVOKEINTERFACE(getType, 2));
|
||||
il.append(new PUSH(cpg, DTM.DOCUMENT_NODE));
|
||||
|
||||
final BranchHandle skip = il.append(new IF_ICMPEQ(null));
|
||||
_falseList.add(il.append(new GOTO_W(null)));
|
||||
skip.setTarget(il.append(NOP));
|
||||
|
||||
if (_left != null) {
|
||||
_left.backPatchTrueList(begin);
|
||||
|
||||
/*
|
||||
* If _left is an ancestor pattern, backpatch this pattern's false
|
||||
* list to the loop that searches for more ancestors.
|
||||
*/
|
||||
if (_left instanceof AncestorPattern) {
|
||||
final AncestorPattern ancestor = (AncestorPattern) _left;
|
||||
_falseList.backPatch(ancestor.getLoopHandle()); // clears list
|
||||
}
|
||||
_falseList.append(_left._falseList);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "absolutePathPattern(" + (_left != null ? _left.toString() : ")");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.GOTO;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class AlternativePattern extends Pattern {
|
||||
private final Pattern _left;
|
||||
private final Pattern _right;
|
||||
|
||||
/**
|
||||
* Construct an alternative pattern. The method <code>setParent</code>
|
||||
* should not be called in this case.
|
||||
*/
|
||||
public AlternativePattern(Pattern left, Pattern right) {
|
||||
_left = left;
|
||||
_right = right;
|
||||
}
|
||||
|
||||
public void setParser(Parser parser) {
|
||||
super.setParser(parser);
|
||||
_left.setParser(parser);
|
||||
_right.setParser(parser);
|
||||
}
|
||||
|
||||
public Pattern getLeft() {
|
||||
return _left;
|
||||
}
|
||||
|
||||
public Pattern getRight() {
|
||||
return _right;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of an '|' is not really defined, hence null is returned.
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
_left.typeCheck(stable);
|
||||
_right.typeCheck(stable);
|
||||
return null;
|
||||
}
|
||||
|
||||
public double getPriority() {
|
||||
double left = _left.getPriority();
|
||||
double right = _right.getPriority();
|
||||
|
||||
if (left < right)
|
||||
return(left);
|
||||
else
|
||||
return(right);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "alternative(" + _left + ", " + _right + ')';
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
_left.translate(classGen, methodGen);
|
||||
final InstructionHandle gotot = il.append(new GOTO(null));
|
||||
il.append(methodGen.loadContextNode());
|
||||
_right.translate(classGen, methodGen);
|
||||
|
||||
_left._trueList.backPatch(gotot);
|
||||
_left._falseList.backPatch(gotot.getNext());
|
||||
|
||||
_trueList.append(_right._trueList.add(gotot));
|
||||
_falseList.append(_right._falseList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.BranchHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.GOTO;
|
||||
import com.sun.org.apache.bcel.internal.generic.IFLT;
|
||||
import com.sun.org.apache.bcel.internal.generic.ILOAD;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
||||
import com.sun.org.apache.bcel.internal.generic.ISTORE;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Erwin Bolwidt <ejb@klomp.org>
|
||||
*/
|
||||
final class AncestorPattern extends RelativePathPattern {
|
||||
|
||||
private final Pattern _left; // may be null
|
||||
private final RelativePathPattern _right;
|
||||
private InstructionHandle _loop;
|
||||
|
||||
public AncestorPattern(RelativePathPattern right) {
|
||||
this(null, right);
|
||||
}
|
||||
|
||||
public AncestorPattern(Pattern left, RelativePathPattern right) {
|
||||
_left = left;
|
||||
(_right = right).setParent(this);
|
||||
if (left != null) {
|
||||
left.setParent(this);
|
||||
}
|
||||
}
|
||||
|
||||
public InstructionHandle getLoopHandle() {
|
||||
return _loop;
|
||||
}
|
||||
|
||||
public void setParser(Parser parser) {
|
||||
super.setParser(parser);
|
||||
if (_left != null) {
|
||||
_left.setParser(parser);
|
||||
}
|
||||
_right.setParser(parser);
|
||||
}
|
||||
|
||||
public boolean isWildcard() {
|
||||
//!!! can be wildcard
|
||||
return false;
|
||||
}
|
||||
|
||||
public StepPattern getKernelPattern() {
|
||||
return _right.getKernelPattern();
|
||||
}
|
||||
|
||||
public void reduceKernelPattern() {
|
||||
_right.reduceKernelPattern();
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
if (_left != null) {
|
||||
_left.typeCheck(stable);
|
||||
}
|
||||
return _right.typeCheck(stable);
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
InstructionHandle parent;
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
/*
|
||||
* The scope of this local var must be the entire method since
|
||||
* a another pattern may decide to jump back into the loop
|
||||
*/
|
||||
final LocalVariableGen local =
|
||||
methodGen.addLocalVariable2("app", Util.getJCRefType(NODE_SIG),
|
||||
il.getEnd());
|
||||
|
||||
final com.sun.org.apache.bcel.internal.generic.Instruction loadLocal =
|
||||
new ILOAD(local.getIndex());
|
||||
final com.sun.org.apache.bcel.internal.generic.Instruction storeLocal =
|
||||
new ISTORE(local.getIndex());
|
||||
|
||||
if (_right instanceof StepPattern) {
|
||||
il.append(DUP);
|
||||
il.append(storeLocal);
|
||||
_right.translate(classGen, methodGen);
|
||||
il.append(methodGen.loadDOM());
|
||||
il.append(loadLocal);
|
||||
}
|
||||
else {
|
||||
_right.translate(classGen, methodGen);
|
||||
|
||||
if (_right instanceof AncestorPattern) {
|
||||
il.append(methodGen.loadDOM());
|
||||
il.append(SWAP);
|
||||
}
|
||||
}
|
||||
|
||||
if (_left != null) {
|
||||
final int getParent = cpg.addInterfaceMethodref(DOM_INTF,
|
||||
GET_PARENT,
|
||||
GET_PARENT_SIG);
|
||||
parent = il.append(new INVOKEINTERFACE(getParent, 2));
|
||||
|
||||
il.append(DUP);
|
||||
il.append(storeLocal);
|
||||
_falseList.add(il.append(new IFLT(null)));
|
||||
il.append(loadLocal);
|
||||
|
||||
_left.translate(classGen, methodGen);
|
||||
|
||||
final SyntaxTreeNode p = getParent();
|
||||
if (p == null || p instanceof Instruction ||
|
||||
p instanceof TopLevelElement)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
il.append(loadLocal);
|
||||
}
|
||||
|
||||
final BranchHandle exit = il.append(new GOTO(null));
|
||||
_loop = il.append(methodGen.loadDOM());
|
||||
il.append(loadLocal);
|
||||
local.setEnd(_loop);
|
||||
il.append(new GOTO(parent));
|
||||
exit.setTarget(il.append(NOP));
|
||||
_left.backPatchFalseList(_loop);
|
||||
|
||||
_trueList.append(_left._trueList);
|
||||
}
|
||||
else {
|
||||
il.append(POP2);
|
||||
}
|
||||
|
||||
/*
|
||||
* If _right is an ancestor pattern, backpatch this pattern's false
|
||||
* list to the loop that searches for more ancestors.
|
||||
*/
|
||||
if (_right instanceof AncestorPattern) {
|
||||
final AncestorPattern ancestor = (AncestorPattern) _right;
|
||||
_falseList.backPatch(ancestor.getLoopHandle()); // clears list
|
||||
}
|
||||
|
||||
_trueList.append(_right._trueList);
|
||||
_falseList.append(_right._falseList);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "AncestorPattern(" + _left + ", " + _right + ')';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
|
||||
final class ApplyImports extends Instruction {
|
||||
|
||||
private QName _modeName;
|
||||
private int _precedence;
|
||||
|
||||
public void display(int indent) {
|
||||
indent(indent);
|
||||
Util.println("ApplyTemplates");
|
||||
indent(indent + IndentIncrement);
|
||||
if (_modeName != null) {
|
||||
indent(indent + IndentIncrement);
|
||||
Util.println("mode " + _modeName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this <xsl:apply-imports/> element has parameters
|
||||
*/
|
||||
public boolean hasWithParams() {
|
||||
return hasContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the lowest import precedence for any stylesheet imported
|
||||
* or included by the stylesheet in which this <xsl:apply-imports/>
|
||||
* element occured. The templates that are imported by the stylesheet in
|
||||
* which this element occured will all have higher import precedence than
|
||||
* the integer returned by this method.
|
||||
*/
|
||||
private int getMinPrecedence(int max) {
|
||||
// Move to root of include tree
|
||||
Stylesheet includeRoot = getStylesheet();
|
||||
while (includeRoot._includedFrom != null) {
|
||||
includeRoot = includeRoot._includedFrom;
|
||||
}
|
||||
|
||||
return includeRoot.getMinimumDescendantPrecedence();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the attributes and contents of an <xsl:apply-imports/> element.
|
||||
*/
|
||||
public void parseContents(Parser parser) {
|
||||
// Indicate to the top-level stylesheet that all templates must be
|
||||
// compiled into separate methods.
|
||||
Stylesheet stylesheet = getStylesheet();
|
||||
stylesheet.setTemplateInlining(false);
|
||||
|
||||
// Get the mode we are currently in (might not be any)
|
||||
Template template = getTemplate();
|
||||
_modeName = template.getModeName();
|
||||
_precedence = template.getImportPrecedence();
|
||||
|
||||
// Get the method name for <xsl:apply-imports/> in this mode
|
||||
stylesheet = parser.getTopLevelStylesheet();
|
||||
|
||||
parseChildren(parser); // with-params
|
||||
}
|
||||
|
||||
/**
|
||||
* Type-check the attributes/contents of an <xsl:apply-imports/> element.
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
typeCheckContents(stable); // with-params
|
||||
return Type.Void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate call-template. A parameter frame is pushed only if
|
||||
* some template in the stylesheet uses parameters.
|
||||
*/
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final Stylesheet stylesheet = classGen.getStylesheet();
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
final int current = methodGen.getLocalIndex("current");
|
||||
|
||||
// Push the arguments that are passed to applyTemplates()
|
||||
il.append(classGen.loadTranslet());
|
||||
il.append(methodGen.loadDOM());
|
||||
il.append(methodGen.loadIterator());
|
||||
il.append(methodGen.loadHandler());
|
||||
il.append(methodGen.loadCurrentNode());
|
||||
|
||||
// Push a new parameter frame in case imported template might expect
|
||||
// parameters. The apply-imports has nothing that it can pass.
|
||||
if (stylesheet.hasLocalParams()) {
|
||||
il.append(classGen.loadTranslet());
|
||||
final int pushFrame = cpg.addMethodref(TRANSLET_CLASS,
|
||||
PUSH_PARAM_FRAME,
|
||||
PUSH_PARAM_FRAME_SIG);
|
||||
il.append(new INVOKEVIRTUAL(pushFrame));
|
||||
}
|
||||
|
||||
// Get the [min,max> precedence of all templates imported under the
|
||||
// current stylesheet
|
||||
final int maxPrecedence = _precedence;
|
||||
final int minPrecedence = getMinPrecedence(maxPrecedence);
|
||||
final Mode mode = stylesheet.getMode(_modeName);
|
||||
|
||||
// Get name of appropriate apply-templates function for this
|
||||
// xsl:apply-imports instruction
|
||||
String functionName = mode.functionName(minPrecedence, maxPrecedence);
|
||||
|
||||
// Construct the translet class-name and the signature of the method
|
||||
final String className = classGen.getStylesheet().getClassName();
|
||||
final String signature = classGen.getApplyTemplatesSigForImport();
|
||||
final int applyTemplates = cpg.addMethodref(className,
|
||||
functionName,
|
||||
signature);
|
||||
il.append(new INVOKEVIRTUAL(applyTemplates));
|
||||
|
||||
// Pop any parameter frame that was pushed above.
|
||||
if (stylesheet.hasLocalParams()) {
|
||||
il.append(classGen.loadTranslet());
|
||||
final int pushFrame = cpg.addMethodref(TRANSLET_CLASS,
|
||||
POP_PARAM_FRAME,
|
||||
POP_PARAM_FRAME_SIG);
|
||||
il.append(new INVOKEVIRTUAL(pushFrame));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSetType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ReferenceType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ResultTreeType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
import com.sun.org.apache.xml.internal.utils.XML11Char;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class ApplyTemplates extends Instruction {
|
||||
private Expression _select;
|
||||
private Type _type = null;
|
||||
private QName _modeName;
|
||||
private String _functionName;
|
||||
|
||||
public void display(int indent) {
|
||||
indent(indent);
|
||||
Util.println("ApplyTemplates");
|
||||
indent(indent + IndentIncrement);
|
||||
Util.println("select " + _select.toString());
|
||||
if (_modeName != null) {
|
||||
indent(indent + IndentIncrement);
|
||||
Util.println("mode " + _modeName);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasWithParams() {
|
||||
return hasContents();
|
||||
}
|
||||
|
||||
public void parseContents(Parser parser) {
|
||||
final String select = getAttribute("select");
|
||||
final String mode = getAttribute("mode");
|
||||
|
||||
if (select.length() > 0) {
|
||||
_select = parser.parseExpression(this, "select", null);
|
||||
|
||||
}
|
||||
|
||||
if (mode.length() > 0) {
|
||||
if (!XML11Char.isXML11ValidQName(mode)) {
|
||||
ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, mode, this);
|
||||
parser.reportError(Constants.ERROR, err);
|
||||
}
|
||||
_modeName = parser.getQNameIgnoreDefaultNs(mode);
|
||||
}
|
||||
|
||||
// instantiate Mode if needed, cache (apply temp) function name
|
||||
_functionName =
|
||||
parser.getTopLevelStylesheet().getMode(_modeName).functionName();
|
||||
parseChildren(parser);// with-params
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
if (_select != null) {
|
||||
_type = _select.typeCheck(stable);
|
||||
if (_type instanceof NodeType || _type instanceof ReferenceType) {
|
||||
_select = new CastExpr(_select, Type.NodeSet);
|
||||
_type = Type.NodeSet;
|
||||
}
|
||||
if (_type instanceof NodeSetType||_type instanceof ResultTreeType) {
|
||||
typeCheckContents(stable); // with-params
|
||||
return Type.Void;
|
||||
}
|
||||
throw new TypeCheckError(this);
|
||||
}
|
||||
else {
|
||||
typeCheckContents(stable); // with-params
|
||||
return Type.Void;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate call-template. A parameter frame is pushed only if
|
||||
* some template in the stylesheet uses parameters.
|
||||
*/
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
boolean setStartNodeCalled = false;
|
||||
final Stylesheet stylesheet = classGen.getStylesheet();
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
final int current = methodGen.getLocalIndex("current");
|
||||
|
||||
// check if sorting nodes is required
|
||||
final Vector<Sort> sortObjects = new Vector<>();
|
||||
for (final SyntaxTreeNode child : getContents()) {
|
||||
if (child instanceof Sort) {
|
||||
sortObjects.addElement((Sort)child);
|
||||
}
|
||||
}
|
||||
|
||||
// Push a new parameter frame
|
||||
if (stylesheet.hasLocalParams() || hasContents()) {
|
||||
il.append(classGen.loadTranslet());
|
||||
final int pushFrame = cpg.addMethodref(TRANSLET_CLASS,
|
||||
PUSH_PARAM_FRAME,
|
||||
PUSH_PARAM_FRAME_SIG);
|
||||
il.append(new INVOKEVIRTUAL(pushFrame));
|
||||
// translate with-params
|
||||
translateContents(classGen, methodGen);
|
||||
}
|
||||
|
||||
|
||||
il.append(classGen.loadTranslet());
|
||||
|
||||
// The 'select' expression is a result-tree
|
||||
if ((_type != null) && (_type instanceof ResultTreeType)) {
|
||||
// <xsl:sort> cannot be applied to a result tree - issue warning
|
||||
if (sortObjects.size() > 0) {
|
||||
ErrorMsg err = new ErrorMsg(ErrorMsg.RESULT_TREE_SORT_ERR,this);
|
||||
getParser().reportError(WARNING, err);
|
||||
}
|
||||
// Put the result tree (a DOM adapter) on the stack
|
||||
_select.translate(classGen, methodGen);
|
||||
// Get back the DOM and iterator (not just iterator!!!)
|
||||
_type.translateTo(classGen, methodGen, Type.NodeSet);
|
||||
}
|
||||
else {
|
||||
il.append(methodGen.loadDOM());
|
||||
|
||||
// compute node iterator for applyTemplates
|
||||
if (sortObjects.size() > 0) {
|
||||
Sort.translateSortIterator(classGen, methodGen,
|
||||
_select, sortObjects);
|
||||
int setStartNode = cpg.addInterfaceMethodref(NODE_ITERATOR,
|
||||
SET_START_NODE,
|
||||
"(I)"+
|
||||
NODE_ITERATOR_SIG);
|
||||
il.append(methodGen.loadCurrentNode());
|
||||
il.append(new INVOKEINTERFACE(setStartNode,2));
|
||||
setStartNodeCalled = true;
|
||||
}
|
||||
else {
|
||||
if (_select == null)
|
||||
Mode.compileGetChildren(classGen, methodGen, current);
|
||||
else
|
||||
_select.translate(classGen, methodGen);
|
||||
}
|
||||
}
|
||||
|
||||
if (_select != null && !setStartNodeCalled) {
|
||||
_select.startIterator(classGen, methodGen);
|
||||
}
|
||||
|
||||
//!!! need to instantiate all needed modes
|
||||
final String className = classGen.getStylesheet().getClassName();
|
||||
il.append(methodGen.loadHandler());
|
||||
final String applyTemplatesSig = classGen.getApplyTemplatesSig();
|
||||
final int applyTemplates = cpg.addMethodref(className,
|
||||
_functionName,
|
||||
applyTemplatesSig);
|
||||
il.append(new INVOKEVIRTUAL(applyTemplates));
|
||||
|
||||
// unmap parameters to release temporary result trees
|
||||
for (final SyntaxTreeNode child : getContents()) {
|
||||
if (child instanceof WithParam) {
|
||||
((WithParam)child).releaseResultTree(classGen, methodGen);
|
||||
}
|
||||
}
|
||||
|
||||
// Pop parameter frame
|
||||
if (stylesheet.hasLocalParams() || hasContents()) {
|
||||
il.append(classGen.loadTranslet());
|
||||
final int popFrame = cpg.addMethodref(TRANSLET_CLASS,
|
||||
POP_PARAM_FRAME,
|
||||
POP_PARAM_FRAME_SIG);
|
||||
il.append(new INVOKEVIRTUAL(popFrame));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class ArgumentList {
|
||||
private final Expression _arg;
|
||||
private final ArgumentList _rest;
|
||||
|
||||
public ArgumentList(Expression arg, ArgumentList rest) {
|
||||
_arg = arg;
|
||||
_rest = rest;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return _rest == null
|
||||
? _arg.toString()
|
||||
: _arg.toString() + ", " + _rest.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class Attribute extends Instruction {
|
||||
private QName _name;
|
||||
|
||||
public void display(int indent) {
|
||||
indent(indent);
|
||||
Util.println("Attribute " + _name);
|
||||
displayContents(indent + IndentIncrement);
|
||||
}
|
||||
|
||||
public void parseContents(Parser parser) {
|
||||
_name = parser.getQName(getAttribute("name"));
|
||||
parseChildren(parser);
|
||||
//!!! add text nodes
|
||||
//!!! take care of value templates
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
/*
|
||||
* $Id: AttributeSet.java,v 1.5 2005/09/28 13:48:04 pvedula Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.AttributeSetMethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
import com.sun.org.apache.xml.internal.utils.XML11Char;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
final class AttributeSet extends TopLevelElement {
|
||||
|
||||
// This prefix is used for the method name of attribute set methods
|
||||
private static final String AttributeSetPrefix = "$as$";
|
||||
|
||||
// Element contents
|
||||
private QName _name;
|
||||
private UseAttributeSets _useSets;
|
||||
private AttributeSet _mergeSet;
|
||||
private String _method;
|
||||
private boolean _ignore = false;
|
||||
|
||||
/**
|
||||
* Returns the QName of this attribute set
|
||||
*/
|
||||
public QName getName() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the method name of this attribute set. This method name is
|
||||
* generated by the compiler (XSLTC)
|
||||
*/
|
||||
public String getMethodName() {
|
||||
return _method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method to prevent a method for being compiled for this set.
|
||||
* This is used in case several <xsl:attribute-set...> elements constitute
|
||||
* a single set (with one name). The last element will merge itself with
|
||||
* any previous set(s) with the same name and disable the other set(s).
|
||||
*/
|
||||
public void ignore() {
|
||||
_ignore = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the contents of this attribute set. Recognised attributes are
|
||||
* "name" (required) and "use-attribute-sets" (optional).
|
||||
*/
|
||||
public void parseContents(Parser parser) {
|
||||
|
||||
// Get this attribute set's name
|
||||
final String name = getAttribute("name");
|
||||
|
||||
if (!XML11Char.isXML11ValidQName(name)) {
|
||||
ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, name, this);
|
||||
parser.reportError(Constants.ERROR, err);
|
||||
}
|
||||
_name = parser.getQNameIgnoreDefaultNs(name);
|
||||
if ((_name == null) || (_name.equals(EMPTYSTRING))) {
|
||||
ErrorMsg msg = new ErrorMsg(ErrorMsg.UNNAMED_ATTRIBSET_ERR, this);
|
||||
parser.reportError(Constants.ERROR, msg);
|
||||
}
|
||||
|
||||
// Get any included attribute sets (similar to inheritance...)
|
||||
final String useSets = getAttribute("use-attribute-sets");
|
||||
if (useSets.length() > 0) {
|
||||
if (!Util.isValidQNames(useSets)) {
|
||||
ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, useSets, this);
|
||||
parser.reportError(Constants.ERROR, err);
|
||||
}
|
||||
_useSets = new UseAttributeSets(useSets, parser);
|
||||
}
|
||||
|
||||
// Parse the contents of this node. All child elements must be
|
||||
// <xsl:attribute> elements. Other elements cause an error.
|
||||
final List<SyntaxTreeNode> contents = getContents();
|
||||
final int count = contents.size();
|
||||
for (int i=0; i<count; i++) {
|
||||
SyntaxTreeNode child = contents.get(i);
|
||||
if (child instanceof XslAttribute) {
|
||||
parser.getSymbolTable().setCurrentNode(child);
|
||||
child.parseContents(parser);
|
||||
}
|
||||
else if (child instanceof Text) {
|
||||
// ignore
|
||||
}
|
||||
else {
|
||||
ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_CHILD_ERR, this);
|
||||
parser.reportError(Constants.ERROR, msg);
|
||||
}
|
||||
}
|
||||
|
||||
// Point the symbol table back at us...
|
||||
parser.getSymbolTable().setCurrentNode(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type check the contents of this element
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
|
||||
if (_ignore) return (Type.Void);
|
||||
|
||||
// _mergeSet Point to any previous definition of this attribute set
|
||||
_mergeSet = stable.addAttributeSet(this);
|
||||
|
||||
_method = AttributeSetPrefix + getXSLTC().nextAttributeSetSerial();
|
||||
|
||||
if (_useSets != null) _useSets.typeCheck(stable);
|
||||
typeCheckContents(stable);
|
||||
return Type.Void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a method that outputs the attributes in this set
|
||||
*/
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
|
||||
if (_ignore) return;
|
||||
|
||||
// Create a new method generator for an attribute set method
|
||||
methodGen = new AttributeSetMethodGenerator(_method, classGen);
|
||||
|
||||
// Generate a reference to previous attribute-set definitions with the
|
||||
// same name first. Those later in the stylesheet take precedence.
|
||||
if (_mergeSet != null) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
final String methodName = _mergeSet.getMethodName();
|
||||
|
||||
il.append(classGen.loadTranslet());
|
||||
il.append(methodGen.loadDOM());
|
||||
il.append(methodGen.loadIterator());
|
||||
il.append(methodGen.loadHandler());
|
||||
il.append(methodGen.loadCurrentNode());
|
||||
final int method = cpg.addMethodref(classGen.getClassName(),
|
||||
methodName, ATTR_SET_SIG);
|
||||
il.append(new INVOKESPECIAL(method));
|
||||
}
|
||||
|
||||
// Translate other used attribute sets first, as local attributes
|
||||
// take precedence (last attributes overrides first)
|
||||
if (_useSets != null) _useSets.translate(classGen, methodGen);
|
||||
|
||||
// Translate all local attributes
|
||||
final Iterator<SyntaxTreeNode> attributes = elements();
|
||||
while (attributes.hasNext()) {
|
||||
SyntaxTreeNode element = attributes.next();
|
||||
if (element instanceof XslAttribute) {
|
||||
final XslAttribute attribute = (XslAttribute)element;
|
||||
attribute.translate(classGen, methodGen);
|
||||
}
|
||||
}
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
il.append(RETURN);
|
||||
|
||||
classGen.addMethod(methodGen);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer("attribute-set: ");
|
||||
// Translate all local attributes
|
||||
final Iterator<SyntaxTreeNode> attributes = elements();
|
||||
while (attributes.hasNext()) {
|
||||
final XslAttribute attribute =
|
||||
(XslAttribute)attributes.next();
|
||||
buf.append(attribute);
|
||||
}
|
||||
return(buf.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
abstract class AttributeValue extends Expression {
|
||||
|
||||
public static final AttributeValue create(SyntaxTreeNode parent,
|
||||
String text, Parser parser) {
|
||||
|
||||
AttributeValue result;
|
||||
if (text.indexOf('{') != -1) {
|
||||
result = new AttributeValueTemplate(text, parser, parent);
|
||||
}
|
||||
else if (text.indexOf('}') != -1) {
|
||||
result = new AttributeValueTemplate(text, parser, parent);
|
||||
}
|
||||
else {
|
||||
result = new SimpleAttributeValue(text);
|
||||
result.setParser(parser);
|
||||
result.setParent(parent);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
/*
|
||||
* $Id: AttributeValueTemplate.java,v 1.2.4.1 2005/09/01 10:26:57 pvedula Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.Instruction;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class AttributeValueTemplate extends AttributeValue {
|
||||
|
||||
final static int OUT_EXPR = 0;
|
||||
final static int IN_EXPR = 1;
|
||||
final static int IN_EXPR_SQUOTES = 2;
|
||||
final static int IN_EXPR_DQUOTES = 3;
|
||||
final static String DELIMITER = "\uFFFE"; // A Unicode nonchar
|
||||
|
||||
public AttributeValueTemplate(String value, Parser parser,
|
||||
SyntaxTreeNode parent)
|
||||
{
|
||||
setParent(parent);
|
||||
setParser(parser);
|
||||
|
||||
try {
|
||||
parseAVTemplate(value, parser);
|
||||
}
|
||||
catch (NoSuchElementException e) {
|
||||
reportError(parent, parser,
|
||||
ErrorMsg.ATTR_VAL_TEMPLATE_ERR, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Two-pass parsing of ATVs. In the first pass, double curly braces are
|
||||
* replaced by one, and expressions are delimited using DELIMITER. The
|
||||
* second pass splits up the resulting buffer into literal and non-literal
|
||||
* expressions. Errors are reported during the first pass.
|
||||
*/
|
||||
private void parseAVTemplate(String text, Parser parser) {
|
||||
StringTokenizer tokenizer =
|
||||
new StringTokenizer(text, "{}\"\'", true);
|
||||
|
||||
/*
|
||||
* First pass: replace double curly braces and delimit expressions
|
||||
* Simple automaton to parse ATVs, delimit expressions and report
|
||||
* errors.
|
||||
*/
|
||||
String t = null;
|
||||
String lookahead = null;
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int state = OUT_EXPR;
|
||||
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
// Use lookahead if available
|
||||
if (lookahead != null) {
|
||||
t = lookahead;
|
||||
lookahead = null;
|
||||
}
|
||||
else {
|
||||
t = tokenizer.nextToken();
|
||||
}
|
||||
|
||||
if (t.length() == 1) {
|
||||
switch (t.charAt(0)) {
|
||||
case '{':
|
||||
switch (state) {
|
||||
case OUT_EXPR:
|
||||
lookahead = tokenizer.nextToken();
|
||||
if (lookahead.equals("{")) {
|
||||
buffer.append(lookahead); // replace {{ by {
|
||||
lookahead = null;
|
||||
}
|
||||
else {
|
||||
buffer.append(DELIMITER);
|
||||
state = IN_EXPR;
|
||||
}
|
||||
break;
|
||||
case IN_EXPR:
|
||||
case IN_EXPR_SQUOTES:
|
||||
case IN_EXPR_DQUOTES:
|
||||
reportError(getParent(), parser,
|
||||
ErrorMsg.ATTR_VAL_TEMPLATE_ERR, text);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '}':
|
||||
switch (state) {
|
||||
case OUT_EXPR:
|
||||
lookahead = tokenizer.nextToken();
|
||||
if (lookahead.equals("}")) {
|
||||
buffer.append(lookahead); // replace }} by }
|
||||
lookahead = null;
|
||||
}
|
||||
else {
|
||||
reportError(getParent(), parser,
|
||||
ErrorMsg.ATTR_VAL_TEMPLATE_ERR, text);
|
||||
}
|
||||
break;
|
||||
case IN_EXPR:
|
||||
buffer.append(DELIMITER);
|
||||
state = OUT_EXPR;
|
||||
break;
|
||||
case IN_EXPR_SQUOTES:
|
||||
case IN_EXPR_DQUOTES:
|
||||
buffer.append(t);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '\'':
|
||||
switch (state) {
|
||||
case IN_EXPR:
|
||||
state = IN_EXPR_SQUOTES;
|
||||
break;
|
||||
case IN_EXPR_SQUOTES:
|
||||
state = IN_EXPR;
|
||||
break;
|
||||
case OUT_EXPR:
|
||||
case IN_EXPR_DQUOTES:
|
||||
break;
|
||||
}
|
||||
buffer.append(t);
|
||||
break;
|
||||
case '\"':
|
||||
switch (state) {
|
||||
case IN_EXPR:
|
||||
state = IN_EXPR_DQUOTES;
|
||||
break;
|
||||
case IN_EXPR_DQUOTES:
|
||||
state = IN_EXPR;
|
||||
break;
|
||||
case OUT_EXPR:
|
||||
case IN_EXPR_SQUOTES:
|
||||
break;
|
||||
}
|
||||
buffer.append(t);
|
||||
break;
|
||||
default:
|
||||
buffer.append(t);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
buffer.append(t);
|
||||
}
|
||||
}
|
||||
|
||||
// Must be in OUT_EXPR at the end of parsing
|
||||
if (state != OUT_EXPR) {
|
||||
reportError(getParent(), parser,
|
||||
ErrorMsg.ATTR_VAL_TEMPLATE_ERR, text);
|
||||
}
|
||||
|
||||
/*
|
||||
* Second pass: split up buffer into literal and non-literal expressions.
|
||||
*/
|
||||
tokenizer = new StringTokenizer(buffer.toString(), DELIMITER, true);
|
||||
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
t = tokenizer.nextToken();
|
||||
|
||||
if (t.equals(DELIMITER)) {
|
||||
addElement(parser.parseExpression(this, tokenizer.nextToken()));
|
||||
tokenizer.nextToken(); // consume other delimiter
|
||||
}
|
||||
else {
|
||||
addElement(new LiteralExpr(t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
final List<SyntaxTreeNode> contents = getContents();
|
||||
final int n = contents.size();
|
||||
for (int i = 0; i < n; i++) {
|
||||
final Expression exp = (Expression)contents.get(i);
|
||||
if (!exp.typeCheck(stable).identicalTo(Type.String)) {
|
||||
contents.set(i, new CastExpr(exp, Type.String));
|
||||
}
|
||||
}
|
||||
return _type = Type.String;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
final StringBuffer buffer = new StringBuffer("AVT:[");
|
||||
final int count = elementCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
buffer.append(elementAt(i).toString());
|
||||
if (i < count - 1)
|
||||
buffer.append(' ');
|
||||
}
|
||||
return buffer.append(']').toString();
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
if (elementCount() == 1) {
|
||||
final Expression exp = (Expression)elementAt(0);
|
||||
exp.translate(classGen, methodGen);
|
||||
}
|
||||
else {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
final int initBuffer = cpg.addMethodref(STRING_BUFFER_CLASS,
|
||||
"<init>", "()V");
|
||||
final Instruction append =
|
||||
new INVOKEVIRTUAL(cpg.addMethodref(STRING_BUFFER_CLASS,
|
||||
"append",
|
||||
"(" + STRING_SIG + ")"
|
||||
+ STRING_BUFFER_SIG));
|
||||
|
||||
final int toString = cpg.addMethodref(STRING_BUFFER_CLASS,
|
||||
"toString",
|
||||
"()"+STRING_SIG);
|
||||
il.append(new NEW(cpg.addClass(STRING_BUFFER_CLASS)));
|
||||
il.append(DUP);
|
||||
il.append(new INVOKESPECIAL(initBuffer));
|
||||
// StringBuffer is on the stack
|
||||
final Iterator<SyntaxTreeNode> elements = elements();
|
||||
while (elements.hasNext()) {
|
||||
final Expression exp = (Expression)elements.next();
|
||||
exp.translate(classGen, methodGen);
|
||||
il.append(append);
|
||||
}
|
||||
il.append(new INVOKEVIRTUAL(toString));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class BinOpExpr extends Expression {
|
||||
public static final int PLUS = 0;
|
||||
public static final int MINUS = 1;
|
||||
public static final int TIMES = 2;
|
||||
public static final int DIV = 3;
|
||||
public static final int MOD = 4;
|
||||
|
||||
private static final String[] Ops = {
|
||||
"+", "-", "*", "/", "%"
|
||||
};
|
||||
|
||||
private int _op;
|
||||
private Expression _left, _right;
|
||||
|
||||
public BinOpExpr(int op, Expression left, Expression right) {
|
||||
_op = op;
|
||||
(_left = left).setParent(this);
|
||||
(_right = right).setParent(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this expressions contains a call to position(). This is
|
||||
* needed for context changes in node steps containing multiple predicates.
|
||||
*/
|
||||
public boolean hasPositionCall() {
|
||||
if (_left.hasPositionCall()) return true;
|
||||
if (_right.hasPositionCall()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this expressions contains a call to last()
|
||||
*/
|
||||
public boolean hasLastCall() {
|
||||
return (_left.hasLastCall() || _right.hasLastCall());
|
||||
}
|
||||
|
||||
public void setParser(Parser parser) {
|
||||
super.setParser(parser);
|
||||
_left.setParser(parser);
|
||||
_right.setParser(parser);
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
final Type tleft = _left.typeCheck(stable);
|
||||
final Type tright = _right.typeCheck(stable);
|
||||
final MethodType ptype = lookupPrimop(stable, Ops[_op],
|
||||
new MethodType(Type.Void,
|
||||
tleft, tright));
|
||||
if (ptype != null) {
|
||||
final Type arg1 = (Type) ptype.argsType().elementAt(0);
|
||||
if (!arg1.identicalTo(tleft)) {
|
||||
_left = new CastExpr(_left, arg1);
|
||||
}
|
||||
final Type arg2 = (Type) ptype.argsType().elementAt(1);
|
||||
if (!arg2.identicalTo(tright)) {
|
||||
_right = new CastExpr(_right, arg1);
|
||||
}
|
||||
return _type = ptype.resultType();
|
||||
}
|
||||
throw new TypeCheckError(this);
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
_left.translate(classGen, methodGen);
|
||||
_right.translate(classGen, methodGen);
|
||||
|
||||
switch (_op) {
|
||||
case PLUS:
|
||||
il.append(_type.ADD());
|
||||
break;
|
||||
case MINUS:
|
||||
il.append(_type.SUB());
|
||||
break;
|
||||
case TIMES:
|
||||
il.append(_type.MUL());
|
||||
break;
|
||||
case DIV:
|
||||
il.append(_type.DIV());
|
||||
break;
|
||||
case MOD:
|
||||
il.append(_type.REM());
|
||||
break;
|
||||
default:
|
||||
ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_BINARY_OP_ERR, this);
|
||||
getParser().reportError(Constants.ERROR, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return Ops[_op] + '(' + _left + ", " + _right + ')';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class BooleanCall extends FunctionCall {
|
||||
|
||||
private Expression _arg = null;
|
||||
|
||||
public BooleanCall(QName fname, Vector arguments) {
|
||||
super(fname, arguments);
|
||||
_arg = argument(0);
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
_arg.typeCheck(stable);
|
||||
return _type = Type.Boolean;
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
_arg.translate(classGen, methodGen);
|
||||
final Type targ = _arg.getType();
|
||||
if (!targ.identicalTo(Type.Boolean)) {
|
||||
_arg.startIterator(classGen, methodGen);
|
||||
targ.translateTo(classGen, methodGen, Type.Boolean);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.GOTO;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.PUSH;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* This class implements inlined calls to the XSLT standard functions
|
||||
* true() and false().
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class BooleanExpr extends Expression {
|
||||
private boolean _value;
|
||||
|
||||
public BooleanExpr(boolean value) {
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
_type = Type.Boolean;
|
||||
return _type;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return _value ? "true()" : "false()";
|
||||
}
|
||||
|
||||
public boolean getValue() {
|
||||
return _value;
|
||||
}
|
||||
|
||||
public boolean contextDependent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
InstructionList il = methodGen.getInstructionList();
|
||||
il.append(new PUSH(cpg, _value));
|
||||
}
|
||||
|
||||
public void translateDesynthesized(ClassGenerator classGen,
|
||||
MethodGenerator methodGen) {
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
if (_value) {
|
||||
il.append(NOP); // true list falls through
|
||||
}
|
||||
else {
|
||||
_falseList.add(il.append(new GOTO(null)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
import com.sun.org.apache.xml.internal.utils.XML11Char;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Erwin Bolwidt <ejb@klomp.org>
|
||||
*/
|
||||
final class CallTemplate extends Instruction {
|
||||
|
||||
/**
|
||||
* Name of template to call.
|
||||
*/
|
||||
private QName _name;
|
||||
|
||||
/**
|
||||
* The array of effective parameters in this CallTemplate. An object in
|
||||
* this array can be either a WithParam or a Param if no WithParam
|
||||
* exists for a particular parameter.
|
||||
*/
|
||||
private SyntaxTreeNode[] _parameters = null;
|
||||
|
||||
/**
|
||||
* The corresponding template which this CallTemplate calls.
|
||||
*/
|
||||
private Template _calleeTemplate = null;
|
||||
|
||||
public void display(int indent) {
|
||||
indent(indent);
|
||||
System.out.print("CallTemplate");
|
||||
Util.println(" name " + _name);
|
||||
displayContents(indent + IndentIncrement);
|
||||
}
|
||||
|
||||
public boolean hasWithParams() {
|
||||
return elementCount() > 0;
|
||||
}
|
||||
|
||||
public void parseContents(Parser parser) {
|
||||
final String name = getAttribute("name");
|
||||
if (name.length() > 0) {
|
||||
if (!XML11Char.isXML11ValidQName(name)) {
|
||||
ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, name, this);
|
||||
parser.reportError(Constants.ERROR, err);
|
||||
}
|
||||
_name = parser.getQNameIgnoreDefaultNs(name);
|
||||
}
|
||||
else {
|
||||
reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "name");
|
||||
}
|
||||
parseChildren(parser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that a template with this name exists.
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
final Template template = stable.lookupTemplate(_name);
|
||||
if (template != null) {
|
||||
typeCheckContents(stable);
|
||||
}
|
||||
else {
|
||||
ErrorMsg err = new ErrorMsg(ErrorMsg.TEMPLATE_UNDEF_ERR,_name,this);
|
||||
throw new TypeCheckError(err);
|
||||
}
|
||||
return Type.Void;
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final Stylesheet stylesheet = classGen.getStylesheet();
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
// If there are Params in the stylesheet or WithParams in this call?
|
||||
if (stylesheet.hasLocalParams() || hasContents()) {
|
||||
_calleeTemplate = getCalleeTemplate();
|
||||
|
||||
// Build the parameter list if the called template is simple named
|
||||
if (_calleeTemplate != null) {
|
||||
buildParameterList();
|
||||
}
|
||||
// This is only needed when the called template is not
|
||||
// a simple named template.
|
||||
else {
|
||||
// Push parameter frame
|
||||
final int push = cpg.addMethodref(TRANSLET_CLASS,
|
||||
PUSH_PARAM_FRAME,
|
||||
PUSH_PARAM_FRAME_SIG);
|
||||
il.append(classGen.loadTranslet());
|
||||
il.append(new INVOKEVIRTUAL(push));
|
||||
translateContents(classGen, methodGen);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a valid Java method name
|
||||
final String className = stylesheet.getClassName();
|
||||
String methodName = Util.escape(_name.toString());
|
||||
|
||||
// Load standard arguments
|
||||
il.append(classGen.loadTranslet());
|
||||
il.append(methodGen.loadDOM());
|
||||
il.append(methodGen.loadIterator());
|
||||
il.append(methodGen.loadHandler());
|
||||
il.append(methodGen.loadCurrentNode());
|
||||
|
||||
// Initialize prefix of method signature
|
||||
StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG
|
||||
+ NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG);
|
||||
|
||||
// If calling a simply named template, push actual arguments
|
||||
if (_calleeTemplate != null) {
|
||||
int numParams = _parameters.length;
|
||||
|
||||
for (int i = 0; i < numParams; i++) {
|
||||
SyntaxTreeNode node = _parameters[i];
|
||||
methodSig.append(OBJECT_SIG); // append Object to signature
|
||||
|
||||
// Push 'null' if Param to indicate no actual parameter specified
|
||||
if (node instanceof Param) {
|
||||
il.append(ACONST_NULL);
|
||||
}
|
||||
else { // translate WithParam
|
||||
node.translate(classGen, methodGen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Complete signature and generate invokevirtual call
|
||||
methodSig.append(")V");
|
||||
il.append(new INVOKEVIRTUAL(cpg.addMethodref(className,
|
||||
methodName,
|
||||
methodSig.toString())));
|
||||
|
||||
// release temporary result trees
|
||||
if (_parameters != null) {
|
||||
for (int i = 0; i < _parameters.length; i++) {
|
||||
if (_parameters[i] instanceof WithParam) {
|
||||
((WithParam)_parameters[i]).releaseResultTree(classGen, methodGen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do not need to call Translet.popParamFrame() if we are
|
||||
// calling a simple named template.
|
||||
if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) {
|
||||
// Pop parameter frame
|
||||
final int pop = cpg.addMethodref(TRANSLET_CLASS,
|
||||
POP_PARAM_FRAME,
|
||||
POP_PARAM_FRAME_SIG);
|
||||
il.append(classGen.loadTranslet());
|
||||
il.append(new INVOKEVIRTUAL(pop));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the simple named template which this CallTemplate calls.
|
||||
* Return false if there is no matched template or the matched
|
||||
* template is not a simple named template.
|
||||
*/
|
||||
public Template getCalleeTemplate() {
|
||||
Template foundTemplate
|
||||
= getXSLTC().getParser().getSymbolTable().lookupTemplate(_name);
|
||||
|
||||
return foundTemplate.isSimpleNamedTemplate() ? foundTemplate : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the list of effective parameters in this CallTemplate.
|
||||
* The parameters of the called template are put into the array first.
|
||||
* Then we visit the WithParam children of this CallTemplate and replace
|
||||
* the Param with a corresponding WithParam having the same name.
|
||||
*/
|
||||
private void buildParameterList() {
|
||||
// Put the parameters from the called template into the array first.
|
||||
// This is to ensure the order of the parameters.
|
||||
Vector<Param> defaultParams = _calleeTemplate.getParameters();
|
||||
int numParams = defaultParams.size();
|
||||
_parameters = new SyntaxTreeNode[numParams];
|
||||
for (int i = 0; i < numParams; i++) {
|
||||
_parameters[i] = defaultParams.elementAt(i);
|
||||
}
|
||||
|
||||
// Replace a Param with a WithParam if they have the same name.
|
||||
int count = elementCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
Object node = elementAt(i);
|
||||
|
||||
// Ignore if not WithParam
|
||||
if (node instanceof WithParam) {
|
||||
WithParam withParam = (WithParam)node;
|
||||
QName name = withParam.getName();
|
||||
|
||||
// Search for a Param with the same name
|
||||
for (int k = 0; k < numParams; k++) {
|
||||
SyntaxTreeNode parm = _parameters[k];
|
||||
if (parm instanceof Param
|
||||
&& ((Param)parm).getName().equals(name)) {
|
||||
withParam.setDoParameterOptimization(true);
|
||||
_parameters[k] = withParam;
|
||||
break;
|
||||
}
|
||||
else if (parm instanceof WithParam
|
||||
&& ((WithParam)parm).getName().equals(name)) {
|
||||
withParam.setDoParameterOptimization(true);
|
||||
_parameters[k] = withParam;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.CHECKCAST;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ObjectType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class CastCall extends FunctionCall {
|
||||
|
||||
/**
|
||||
* Name of the class that is the target of the cast. Must be a
|
||||
* fully-qualified Java class Name.
|
||||
*/
|
||||
private String _className;
|
||||
|
||||
/**
|
||||
* A reference to the expression being casted.
|
||||
*/
|
||||
private Expression _right;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public CastCall(QName fname, Vector arguments) {
|
||||
super(fname, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type check the two parameters for this function
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
// Check that the function was passed exactly two arguments
|
||||
if (argumentCount() != 2) {
|
||||
throw new TypeCheckError(new ErrorMsg(ErrorMsg.ILLEGAL_ARG_ERR,
|
||||
getName(), this));
|
||||
}
|
||||
|
||||
// The first argument must be a literal String
|
||||
Expression exp = argument(0);
|
||||
if (exp instanceof LiteralExpr) {
|
||||
_className = ((LiteralExpr) exp).getValue();
|
||||
_type = Type.newObjectType(_className);
|
||||
}
|
||||
else {
|
||||
throw new TypeCheckError(new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR,
|
||||
getName(), this));
|
||||
}
|
||||
|
||||
// Second argument must be of type reference or object
|
||||
_right = argument(1);
|
||||
Type tright = _right.typeCheck(stable);
|
||||
if (tright != Type.Reference &&
|
||||
tright instanceof ObjectType == false)
|
||||
{
|
||||
throw new TypeCheckError(new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
|
||||
tright, _type, this));
|
||||
}
|
||||
|
||||
return _type;
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
_right.translate(classGen, methodGen);
|
||||
il.append(new CHECKCAST(cpg.addClass(_className)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
/*
|
||||
* $Id: CastExpr.java,v 1.2.4.1 2005/09/12 10:06:35 pvedula Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.IF_ICMPNE;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.SIPUSH;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.BooleanType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MultiHashtable;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ResultTreeType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xml.internal.dtm.Axis;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Morten Jorgensen
|
||||
* @author Erwin Bolwidt <ejb@klomp.org>
|
||||
*/
|
||||
final class CastExpr extends Expression {
|
||||
private final Expression _left;
|
||||
|
||||
/**
|
||||
* Legal conversions between internal types.
|
||||
*/
|
||||
private static final MultiHashtable<Type, Type> InternalTypeMap = new MultiHashtable<>();
|
||||
|
||||
static {
|
||||
// Possible type conversions between internal types
|
||||
InternalTypeMap.put(Type.Boolean, Type.Boolean);
|
||||
InternalTypeMap.put(Type.Boolean, Type.Real);
|
||||
InternalTypeMap.put(Type.Boolean, Type.String);
|
||||
InternalTypeMap.put(Type.Boolean, Type.Reference);
|
||||
InternalTypeMap.put(Type.Boolean, Type.Object);
|
||||
|
||||
InternalTypeMap.put(Type.Real, Type.Real);
|
||||
InternalTypeMap.put(Type.Real, Type.Int);
|
||||
InternalTypeMap.put(Type.Real, Type.Boolean);
|
||||
InternalTypeMap.put(Type.Real, Type.String);
|
||||
InternalTypeMap.put(Type.Real, Type.Reference);
|
||||
InternalTypeMap.put(Type.Real, Type.Object);
|
||||
|
||||
InternalTypeMap.put(Type.Int, Type.Int);
|
||||
InternalTypeMap.put(Type.Int, Type.Real);
|
||||
InternalTypeMap.put(Type.Int, Type.Boolean);
|
||||
InternalTypeMap.put(Type.Int, Type.String);
|
||||
InternalTypeMap.put(Type.Int, Type.Reference);
|
||||
InternalTypeMap.put(Type.Int, Type.Object);
|
||||
|
||||
InternalTypeMap.put(Type.String, Type.String);
|
||||
InternalTypeMap.put(Type.String, Type.Boolean);
|
||||
InternalTypeMap.put(Type.String, Type.Real);
|
||||
InternalTypeMap.put(Type.String, Type.Reference);
|
||||
InternalTypeMap.put(Type.String, Type.Object);
|
||||
|
||||
InternalTypeMap.put(Type.NodeSet, Type.NodeSet);
|
||||
InternalTypeMap.put(Type.NodeSet, Type.Boolean);
|
||||
InternalTypeMap.put(Type.NodeSet, Type.Real);
|
||||
InternalTypeMap.put(Type.NodeSet, Type.String);
|
||||
InternalTypeMap.put(Type.NodeSet, Type.Node);
|
||||
InternalTypeMap.put(Type.NodeSet, Type.Reference);
|
||||
InternalTypeMap.put(Type.NodeSet, Type.Object);
|
||||
|
||||
InternalTypeMap.put(Type.Node, Type.Node);
|
||||
InternalTypeMap.put(Type.Node, Type.Boolean);
|
||||
InternalTypeMap.put(Type.Node, Type.Real);
|
||||
InternalTypeMap.put(Type.Node, Type.String);
|
||||
InternalTypeMap.put(Type.Node, Type.NodeSet);
|
||||
InternalTypeMap.put(Type.Node, Type.Reference);
|
||||
InternalTypeMap.put(Type.Node, Type.Object);
|
||||
|
||||
InternalTypeMap.put(Type.ResultTree, Type.ResultTree);
|
||||
InternalTypeMap.put(Type.ResultTree, Type.Boolean);
|
||||
InternalTypeMap.put(Type.ResultTree, Type.Real);
|
||||
InternalTypeMap.put(Type.ResultTree, Type.String);
|
||||
InternalTypeMap.put(Type.ResultTree, Type.NodeSet);
|
||||
InternalTypeMap.put(Type.ResultTree, Type.Reference);
|
||||
InternalTypeMap.put(Type.ResultTree, Type.Object);
|
||||
|
||||
InternalTypeMap.put(Type.Reference, Type.Reference);
|
||||
InternalTypeMap.put(Type.Reference, Type.Boolean);
|
||||
InternalTypeMap.put(Type.Reference, Type.Int);
|
||||
InternalTypeMap.put(Type.Reference, Type.Real);
|
||||
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.Reference, Type.Object);
|
||||
|
||||
InternalTypeMap.put(Type.Object, Type.String);
|
||||
|
||||
InternalTypeMap.put(Type.Void, Type.String);
|
||||
|
||||
InternalTypeMap.makeUnmodifiable();
|
||||
}
|
||||
|
||||
private boolean _typeTest = false;
|
||||
|
||||
/**
|
||||
* Construct a cast expression and check that the conversion is
|
||||
* valid by calling typeCheck().
|
||||
*/
|
||||
public CastExpr(Expression left, Type type) throws TypeCheckError {
|
||||
_left = left;
|
||||
_type = type; // use inherited field
|
||||
|
||||
if ((_left instanceof Step) && (_type == Type.Boolean)) {
|
||||
Step step = (Step)_left;
|
||||
if ((step.getAxis() == Axis.SELF) && (step.getNodeType() != -1))
|
||||
_typeTest = true;
|
||||
}
|
||||
|
||||
// check if conversion is valid
|
||||
setParser(left.getParser());
|
||||
setParent(left.getParent());
|
||||
left.setParent(this);
|
||||
typeCheck(left.getParser().getSymbolTable());
|
||||
}
|
||||
|
||||
public Expression getExpr() {
|
||||
return _left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this expressions contains a call to position(). This is
|
||||
* needed for context changes in node steps containing multiple predicates.
|
||||
*/
|
||||
public boolean hasPositionCall() {
|
||||
return(_left.hasPositionCall());
|
||||
}
|
||||
|
||||
public boolean hasLastCall() {
|
||||
return(_left.hasLastCall());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "cast(" + _left + ", " + _type + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Type checking a cast expression amounts to verifying that the
|
||||
* type conversion is legal. Cast expressions are created during
|
||||
* type checking, but typeCheck() is usually not called on them.
|
||||
* As a result, this method is called from the constructor.
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
Type tleft = _left.getType();
|
||||
if (tleft == null) {
|
||||
tleft = _left.typeCheck(stable);
|
||||
}
|
||||
if (tleft instanceof NodeType) {
|
||||
tleft = Type.Node; // multiple instances
|
||||
}
|
||||
else if (tleft instanceof ResultTreeType) {
|
||||
tleft = Type.ResultTree; // multiple instances
|
||||
}
|
||||
if (InternalTypeMap.maps(tleft, _type) != null) {
|
||||
return _type;
|
||||
}
|
||||
// throw new TypeCheckError(this);
|
||||
throw new TypeCheckError(new ErrorMsg(
|
||||
ErrorMsg.DATA_CONVERSION_ERR, tleft.toString(), _type.toString()));
|
||||
}
|
||||
|
||||
public void translateDesynthesized(ClassGenerator classGen,
|
||||
MethodGenerator methodGen) {
|
||||
FlowList fl;
|
||||
final Type ltype = _left.getType();
|
||||
|
||||
// This is a special case for the self:: axis. Instead of letting
|
||||
// the Step object create and iterator that we cast back to a single
|
||||
// node, we simply ask the DOM for the node type.
|
||||
if (_typeTest) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
final int idx = cpg.addInterfaceMethodref(DOM_INTF,
|
||||
"getExpandedTypeID",
|
||||
"(I)I");
|
||||
il.append(new SIPUSH((short)((Step)_left).getNodeType()));
|
||||
il.append(methodGen.loadDOM());
|
||||
il.append(methodGen.loadContextNode());
|
||||
il.append(new INVOKEINTERFACE(idx, 2));
|
||||
_falseList.add(il.append(new IF_ICMPNE(null)));
|
||||
}
|
||||
else {
|
||||
|
||||
_left.translate(classGen, methodGen);
|
||||
if (_type != ltype) {
|
||||
_left.startIterator(classGen, methodGen);
|
||||
if (_type instanceof BooleanType) {
|
||||
fl = ltype.translateToDesynthesized(classGen, methodGen,
|
||||
_type);
|
||||
if (fl != null) {
|
||||
_falseList.append(fl);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ltype.translateTo(classGen, methodGen, _type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final Type ltype = _left.getType();
|
||||
_left.translate(classGen, methodGen);
|
||||
if (_type.identicalTo(ltype) == false) {
|
||||
_left.startIterator(classGen, methodGen);
|
||||
ltype.translateTo(classGen, methodGen, _type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class CeilingCall extends FunctionCall {
|
||||
public CeilingCall(QName fname, Vector arguments) {
|
||||
super(fname, arguments);
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
argument(0).translate(classGen, methodGen);
|
||||
il.append(new INVOKESTATIC(cpg.addMethodref(MATH_CLASS,
|
||||
"ceil", "(D)D")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
/*
|
||||
* $Id: Choose.java,v 1.2.4.1 2005/09/01 12:00:14 pvedula Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.BranchHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.GOTO;
|
||||
import com.sun.org.apache.bcel.internal.generic.IFEQ;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
final class Choose extends Instruction {
|
||||
|
||||
/**
|
||||
* Display the element contents (a lot of when's and an otherwise)
|
||||
*/
|
||||
public void display(int indent) {
|
||||
indent(indent);
|
||||
Util.println("Choose");
|
||||
indent(indent + IndentIncrement);
|
||||
displayContents(indent + IndentIncrement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate this Choose element. Generate a test-chain for the various
|
||||
* <xsl:when> elements and default to the <xsl:otherwise> if present.
|
||||
*/
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final Vector whenElements = new Vector();
|
||||
Otherwise otherwise = null;
|
||||
Iterator<SyntaxTreeNode> elements = elements();
|
||||
|
||||
// These two are for reporting errors only
|
||||
ErrorMsg error = null;
|
||||
final int line = getLineNumber();
|
||||
|
||||
// Traverse all child nodes - must be either When or Otherwise
|
||||
while (elements.hasNext()) {
|
||||
SyntaxTreeNode element = elements.next();
|
||||
// Add a When child element
|
||||
if (element instanceof When) {
|
||||
whenElements.addElement(element);
|
||||
}
|
||||
// Add an Otherwise child element
|
||||
else if (element instanceof Otherwise) {
|
||||
if (otherwise == null) {
|
||||
otherwise = (Otherwise)element;
|
||||
}
|
||||
else {
|
||||
error = new ErrorMsg(ErrorMsg.MULTIPLE_OTHERWISE_ERR, this);
|
||||
getParser().reportError(Constants.ERROR, error);
|
||||
}
|
||||
}
|
||||
else if (element instanceof Text) {
|
||||
((Text)element).ignore();
|
||||
}
|
||||
// It is an error if we find some other element here
|
||||
else {
|
||||
error = new ErrorMsg(ErrorMsg.WHEN_ELEMENT_ERR, this);
|
||||
getParser().reportError(Constants.ERROR, error);
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure that there is at least one <xsl:when> element
|
||||
if (whenElements.size() == 0) {
|
||||
error = new ErrorMsg(ErrorMsg.MISSING_WHEN_ERR, this);
|
||||
getParser().reportError(Constants.ERROR, error);
|
||||
return;
|
||||
}
|
||||
|
||||
InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
// next element will hold a handle to the beginning of next
|
||||
// When/Otherwise if test on current When fails
|
||||
BranchHandle nextElement = null;
|
||||
Vector exitHandles = new Vector();
|
||||
InstructionHandle exit = null;
|
||||
|
||||
Enumeration whens = whenElements.elements();
|
||||
while (whens.hasMoreElements()) {
|
||||
final When when = (When)whens.nextElement();
|
||||
final Expression test = when.getTest();
|
||||
|
||||
InstructionHandle truec = il.getEnd();
|
||||
|
||||
if (nextElement != null)
|
||||
nextElement.setTarget(il.append(NOP));
|
||||
test.translateDesynthesized(classGen, methodGen);
|
||||
|
||||
if (test instanceof FunctionCall) {
|
||||
FunctionCall call = (FunctionCall)test;
|
||||
try {
|
||||
Type type = call.typeCheck(getParser().getSymbolTable());
|
||||
if (type != Type.Boolean) {
|
||||
test._falseList.add(il.append(new IFEQ(null)));
|
||||
}
|
||||
}
|
||||
catch (TypeCheckError e) {
|
||||
// handled later!
|
||||
}
|
||||
}
|
||||
// remember end of condition
|
||||
truec = il.getEnd();
|
||||
|
||||
// The When object should be ignored completely in case it tests
|
||||
// for the support of a non-available element
|
||||
if (!when.ignore()) when.translateContents(classGen, methodGen);
|
||||
|
||||
// goto exit after executing the body of when
|
||||
exitHandles.addElement(il.append(new GOTO(null)));
|
||||
if (whens.hasMoreElements() || otherwise != null) {
|
||||
nextElement = il.append(new GOTO(null));
|
||||
test.backPatchFalseList(nextElement);
|
||||
}
|
||||
else
|
||||
test.backPatchFalseList(exit = il.append(NOP));
|
||||
test.backPatchTrueList(truec.getNext());
|
||||
}
|
||||
|
||||
// Translate any <xsl:otherwise> element
|
||||
if (otherwise != null) {
|
||||
nextElement.setTarget(il.append(NOP));
|
||||
otherwise.translateContents(classGen, methodGen);
|
||||
exit = il.append(NOP);
|
||||
}
|
||||
|
||||
// now that end is known set targets of exit gotos
|
||||
Enumeration exitGotos = exitHandles.elements();
|
||||
while (exitGotos.hasMoreElements()) {
|
||||
BranchHandle gotoExit = (BranchHandle)exitGotos.nextElement();
|
||||
gotoExit.setTarget(exit);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
/**
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
public interface Closure {
|
||||
|
||||
/**
|
||||
* Returns true if this closure is compiled in an inner class (i.e.
|
||||
* if this is a real closure).
|
||||
*/
|
||||
public boolean inInnerClass();
|
||||
|
||||
/**
|
||||
* Returns a reference to its parent closure or null if outermost.
|
||||
*/
|
||||
public Closure getParentClosure();
|
||||
|
||||
/**
|
||||
* Returns the name of the auxiliary class or null if this predicate
|
||||
* is compiled inside the Translet.
|
||||
*/
|
||||
public String getInnerClassName();
|
||||
|
||||
/**
|
||||
* Add new variable to the closure.
|
||||
*/
|
||||
public void addVariable(VariableRefBase variableRef);
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.GETFIELD;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.PUSH;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
final class Comment extends Instruction {
|
||||
|
||||
public void parseContents(Parser parser) {
|
||||
parseChildren(parser);
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
typeCheckContents(stable);
|
||||
return Type.String;
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
// Shortcut for literal strings
|
||||
Text rawText = null;
|
||||
if (elementCount() == 1) {
|
||||
Object content = elementAt(0);
|
||||
if (content instanceof Text) {
|
||||
rawText = (Text) content;
|
||||
}
|
||||
}
|
||||
|
||||
// If the content is literal text, call comment(char[],int,int) or
|
||||
// comment(String), as appropriate. Otherwise, use a
|
||||
// StringValueHandler to gather the textual content of the xsl:comment
|
||||
// and call comment(String) with the result.
|
||||
if (rawText != null) {
|
||||
il.append(methodGen.loadHandler());
|
||||
|
||||
if (rawText.canLoadAsArrayOffsetLength()) {
|
||||
rawText.loadAsArrayOffsetLength(classGen, methodGen);
|
||||
final int comment =
|
||||
cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
|
||||
"comment",
|
||||
"([CII)V");
|
||||
il.append(new INVOKEINTERFACE(comment, 4));
|
||||
} else {
|
||||
il.append(new PUSH(cpg, rawText.getText()));
|
||||
final int comment =
|
||||
cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
|
||||
"comment",
|
||||
"(" + STRING_SIG + ")V");
|
||||
il.append(new INVOKEINTERFACE(comment, 2));
|
||||
}
|
||||
} else {
|
||||
// Save the current handler base on the stack
|
||||
il.append(methodGen.loadHandler());
|
||||
il.append(DUP); // first arg to "comment" call
|
||||
|
||||
// Get the translet's StringValueHandler
|
||||
il.append(classGen.loadTranslet());
|
||||
il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS,
|
||||
"stringValueHandler",
|
||||
STRING_VALUE_HANDLER_SIG)));
|
||||
il.append(DUP);
|
||||
il.append(methodGen.storeHandler());
|
||||
|
||||
// translate contents with substituted handler
|
||||
translateContents(classGen, methodGen);
|
||||
|
||||
// get String out of the handler
|
||||
il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_VALUE_HANDLER,
|
||||
"getValue",
|
||||
"()" + STRING_SIG)));
|
||||
// call "comment"
|
||||
final int comment =
|
||||
cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
|
||||
"comment",
|
||||
"(" + STRING_SIG + ")V");
|
||||
il.append(new INVOKEINTERFACE(comment, 2));
|
||||
// Restore old handler base from stack
|
||||
il.append(methodGen.storeHandler());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
/**
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
public final class CompilerException extends Exception {
|
||||
static final long serialVersionUID = 1732939618562742663L;
|
||||
|
||||
private String _msg;
|
||||
|
||||
public CompilerException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CompilerException(Exception e) {
|
||||
super(e.toString());
|
||||
_msg = e.toString();
|
||||
}
|
||||
|
||||
public CompilerException(String message) {
|
||||
super(message);
|
||||
_msg = message;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
final int col = _msg.indexOf(':');
|
||||
|
||||
if (col > -1)
|
||||
return(_msg.substring(col));
|
||||
else
|
||||
return(_msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.Instruction;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import com.sun.org.apache.bcel.internal.generic.PUSH;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class ConcatCall extends FunctionCall {
|
||||
public ConcatCall(QName fname, Vector arguments) {
|
||||
super(fname, arguments);
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
for (int i = 0; i < argumentCount(); i++) {
|
||||
final Expression exp = argument(i);
|
||||
if (!exp.typeCheck(stable).identicalTo(Type.String)) {
|
||||
setArgument(i, new CastExpr(exp, Type.String));
|
||||
}
|
||||
}
|
||||
return _type = Type.String;
|
||||
}
|
||||
|
||||
/** translate leaves a String on the stack */
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
final int nArgs = argumentCount();
|
||||
|
||||
switch (nArgs) {
|
||||
case 0:
|
||||
il.append(new PUSH(cpg, EMPTYSTRING));
|
||||
break;
|
||||
|
||||
case 1:
|
||||
argument().translate(classGen, methodGen);
|
||||
break;
|
||||
|
||||
default:
|
||||
final int initBuffer = cpg.addMethodref(STRING_BUFFER_CLASS,
|
||||
"<init>", "()V");
|
||||
final Instruction append =
|
||||
new INVOKEVIRTUAL(cpg.addMethodref(STRING_BUFFER_CLASS,
|
||||
"append",
|
||||
"("+STRING_SIG+")"
|
||||
+STRING_BUFFER_SIG));
|
||||
|
||||
final int toString = cpg.addMethodref(STRING_BUFFER_CLASS,
|
||||
"toString",
|
||||
"()"+STRING_SIG);
|
||||
|
||||
il.append(new NEW(cpg.addClass(STRING_BUFFER_CLASS)));
|
||||
il.append(DUP);
|
||||
il.append(new INVOKESPECIAL(initBuffer));
|
||||
for (int i = 0; i < nArgs; i++) {
|
||||
argument(i).translate(classGen, methodGen);
|
||||
il.append(append);
|
||||
}
|
||||
il.append(new INVOKEVIRTUAL(toString));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,508 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 2001-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.
|
||||
*/
|
||||
/*
|
||||
* $Id: Constants.java,v 1.7 2006/06/19 19:49:04 spericas Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionConstants;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
public interface Constants extends InstructionConstants {
|
||||
|
||||
// Error categories used to report errors to Parser.reportError()
|
||||
|
||||
// Unexpected internal errors, such as null-ptr exceptions, etc.
|
||||
// Immediately terminates compilation, no translet produced
|
||||
public final int INTERNAL = 0;
|
||||
// XSLT elements that are not implemented and unsupported ext.
|
||||
// Immediately terminates compilation, no translet produced
|
||||
public final int UNSUPPORTED = 1;
|
||||
// Fatal error in the stylesheet input (parsing or content)
|
||||
// Immediately terminates compilation, no translet produced
|
||||
public final int FATAL = 2;
|
||||
// Other error in the stylesheet input (parsing or content)
|
||||
// Does not terminate compilation, no translet produced
|
||||
public final int ERROR = 3;
|
||||
// Other error in the stylesheet input (content errors only)
|
||||
// Does not terminate compilation, a translet is produced
|
||||
public final int WARNING = 4;
|
||||
|
||||
public static final String EMPTYSTRING = "";
|
||||
|
||||
public static final String NAMESPACE_FEATURE =
|
||||
"http://xml.org/sax/features/namespaces";
|
||||
|
||||
public static final String TRANSLET_INTF
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.Translet";
|
||||
public static final String TRANSLET_INTF_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/Translet;";
|
||||
|
||||
public static final String ATTRIBUTES_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/runtime/Attributes;";
|
||||
public static final String NODE_ITERATOR_SIG
|
||||
= "Lcom/sun/org/apache/xml/internal/dtm/DTMAxisIterator;";
|
||||
public static final String DOM_INTF_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/DOM;";
|
||||
public static final String DOM_IMPL_CLASS
|
||||
= "com/sun/org/apache/xalan/internal/xsltc/DOM"; // xml/dtm/ref/DTMDefaultBaseIterators"; //xalan/xsltc/dom/DOMImpl";
|
||||
public static final String SAX_IMPL_CLASS
|
||||
= "com/sun/org/apache/xalan/internal/xsltc/DOM/SAXImpl";
|
||||
public static final String DOM_IMPL_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/dom/SAXImpl;"; //xml/dtm/ref/DTMDefaultBaseIterators"; //xalan/xsltc/dom/DOMImpl;";
|
||||
public static final String SAX_IMPL_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/dom/SAXImpl;";
|
||||
public static final String DOM_ADAPTER_CLASS
|
||||
= "com/sun/org/apache/xalan/internal/xsltc/dom/DOMAdapter";
|
||||
public static final String DOM_ADAPTER_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/dom/DOMAdapter;";
|
||||
public static final String MULTI_DOM_CLASS
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.MultiDOM";
|
||||
public static final String MULTI_DOM_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/dom/MultiDOM;";
|
||||
|
||||
public static final String STRING
|
||||
= "java.lang.String";
|
||||
|
||||
public static final int ACC_PUBLIC
|
||||
= com.sun.org.apache.bcel.internal.Constants.ACC_PUBLIC;
|
||||
public static final int ACC_SUPER
|
||||
= com.sun.org.apache.bcel.internal.Constants.ACC_SUPER;
|
||||
public static final int ACC_FINAL
|
||||
= com.sun.org.apache.bcel.internal.Constants.ACC_FINAL;
|
||||
public static final int ACC_PRIVATE
|
||||
= com.sun.org.apache.bcel.internal.Constants.ACC_PRIVATE;
|
||||
public static final int ACC_PROTECTED
|
||||
= com.sun.org.apache.bcel.internal.Constants.ACC_PROTECTED;
|
||||
public static final int ACC_STATIC
|
||||
= com.sun.org.apache.bcel.internal.Constants.ACC_STATIC;
|
||||
|
||||
public static final String STRING_SIG
|
||||
= "Ljava/lang/String;";
|
||||
public static final String STRING_BUFFER_SIG
|
||||
= "Ljava/lang/StringBuffer;";
|
||||
public static final String OBJECT_SIG
|
||||
= "Ljava/lang/Object;";
|
||||
public static final String DOUBLE_SIG
|
||||
= "Ljava/lang/Double;";
|
||||
public static final String INTEGER_SIG
|
||||
= "Ljava/lang/Integer;";
|
||||
public static final String COLLATOR_CLASS
|
||||
= "java/text/Collator";
|
||||
public static final String COLLATOR_SIG
|
||||
= "Ljava/text/Collator;";
|
||||
|
||||
public static final String NODE
|
||||
= "int";
|
||||
public static final String NODE_ITERATOR
|
||||
= "com.sun.org.apache.xml.internal.dtm.DTMAxisIterator";
|
||||
public static final String NODE_ITERATOR_BASE
|
||||
= "com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIteratorBase";
|
||||
public static final String SORT_ITERATOR
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.SortingIterator";
|
||||
public static final String SORT_ITERATOR_SIG
|
||||
= "Lcom.sun.org.apache.xalan.internal.xsltc.dom.SortingIterator;";
|
||||
public static final String NODE_SORT_RECORD
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.NodeSortRecord";
|
||||
public static final String NODE_SORT_FACTORY
|
||||
= "com/sun/org/apache/xalan/internal/xsltc/dom/NodeSortRecordFactory";
|
||||
public static final String NODE_SORT_RECORD_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/dom/NodeSortRecord;";
|
||||
public static final String NODE_SORT_FACTORY_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/dom/NodeSortRecordFactory;";
|
||||
public static final String LOCALE_CLASS
|
||||
= "java.util.Locale";
|
||||
public static final String LOCALE_SIG
|
||||
= "Ljava/util/Locale;";
|
||||
public static final String STRING_VALUE_HANDLER
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.runtime.StringValueHandler";
|
||||
public static final String STRING_VALUE_HANDLER_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/runtime/StringValueHandler;";
|
||||
public static final String OUTPUT_HANDLER
|
||||
= "com/sun/org/apache/xml/internal/serializer/SerializationHandler";
|
||||
public static final String OUTPUT_HANDLER_SIG
|
||||
= "Lcom/sun/org/apache/xml/internal/serializer/SerializationHandler;";
|
||||
public static final String FILTER_INTERFACE
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.Filter";
|
||||
public static final String FILTER_INTERFACE_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/dom/Filter;";
|
||||
public static final String UNION_ITERATOR_CLASS
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.UnionIterator";
|
||||
public static final String STEP_ITERATOR_CLASS
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.StepIterator";
|
||||
public static final String CACHED_NODE_LIST_ITERATOR_CLASS
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.CachedNodeListIterator";
|
||||
public static final String NTH_ITERATOR_CLASS
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.NthIterator";
|
||||
public static final String ABSOLUTE_ITERATOR
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.AbsoluteIterator";
|
||||
public static final String DUP_FILTERED_ITERATOR
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.DupFilterIterator";
|
||||
public static final String CURRENT_NODE_LIST_ITERATOR
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.CurrentNodeListIterator";
|
||||
public static final String CURRENT_NODE_LIST_FILTER
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.CurrentNodeListFilter";
|
||||
public static final String CURRENT_NODE_LIST_ITERATOR_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/dom/CurrentNodeListIterator;";
|
||||
public static final String CURRENT_NODE_LIST_FILTER_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/dom/CurrentNodeListFilter;";
|
||||
public static final String FILTER_STEP_ITERATOR
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.FilteredStepIterator";
|
||||
public static final String FILTER_ITERATOR
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.FilterIterator";
|
||||
public static final String SINGLETON_ITERATOR
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.SingletonIterator";
|
||||
public static final String MATCHING_ITERATOR
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.MatchingIterator";
|
||||
public static final String NODE_SIG
|
||||
= "I";
|
||||
public static final String GET_PARENT
|
||||
= "getParent";
|
||||
public static final String GET_PARENT_SIG
|
||||
= "(" + NODE_SIG + ")" + NODE_SIG;
|
||||
public static final String NEXT_SIG
|
||||
= "()" + NODE_SIG;
|
||||
public static final String NEXT
|
||||
= "next";
|
||||
public static final String NEXTID
|
||||
= "nextNodeID";
|
||||
public static final String MAKE_NODE
|
||||
= "makeNode";
|
||||
public static final String MAKE_NODE_LIST
|
||||
= "makeNodeList";
|
||||
public static final String GET_UNPARSED_ENTITY_URI
|
||||
= "getUnparsedEntityURI";
|
||||
public static final String STRING_TO_REAL
|
||||
= "stringToReal";
|
||||
public static final String STRING_TO_REAL_SIG
|
||||
= "(" + STRING_SIG + ")D";
|
||||
public static final String STRING_TO_INT
|
||||
= "stringToInt";
|
||||
public static final String STRING_TO_INT_SIG
|
||||
= "(" + STRING_SIG + ")I";
|
||||
|
||||
public static final String XSLT_PACKAGE
|
||||
= "com.sun.org.apache.xalan.internal.xsltc";
|
||||
public static final String COMPILER_PACKAGE
|
||||
= XSLT_PACKAGE + ".compiler";
|
||||
public static final String RUNTIME_PACKAGE
|
||||
= XSLT_PACKAGE + ".runtime";
|
||||
public static final String TRANSLET_CLASS
|
||||
= RUNTIME_PACKAGE + ".AbstractTranslet";
|
||||
|
||||
public static final String TRANSLET_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet;";
|
||||
public static final String UNION_ITERATOR_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/dom/UnionIterator;";
|
||||
public static final String TRANSLET_OUTPUT_SIG
|
||||
= "Lcom/sun/org/apache/xml/internal/serializer/SerializationHandler;";
|
||||
public static final String MAKE_NODE_SIG
|
||||
= "(I)Lorg/w3c/dom/Node;";
|
||||
public static final String MAKE_NODE_SIG2
|
||||
= "(" + NODE_ITERATOR_SIG + ")Lorg/w3c/dom/Node;";
|
||||
public static final String MAKE_NODE_LIST_SIG
|
||||
= "(I)Lorg/w3c/dom/NodeList;";
|
||||
public static final String MAKE_NODE_LIST_SIG2
|
||||
= "(" + NODE_ITERATOR_SIG + ")Lorg/w3c/dom/NodeList;";
|
||||
|
||||
public static final String STREAM_XML_OUTPUT
|
||||
= "com.sun.org.apache.xml.internal.serializer.ToXMLStream";
|
||||
|
||||
public static final String OUTPUT_BASE
|
||||
= "com.sun.org.apache.xml.internal.serializer.SerializerBase";
|
||||
|
||||
public static final String LOAD_DOCUMENT_CLASS
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.LoadDocument";
|
||||
|
||||
public static final String KEY_INDEX_CLASS
|
||||
= "com/sun/org/apache/xalan/internal/xsltc/dom/KeyIndex";
|
||||
public static final String KEY_INDEX_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/dom/KeyIndex;";
|
||||
|
||||
public static final String KEY_INDEX_ITERATOR_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/dom/KeyIndex$KeyIndexIterator;";
|
||||
public static final String DOM_INTF
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.DOM";
|
||||
public static final String DOM_IMPL
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl";
|
||||
public static final String SAX_IMPL
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl";
|
||||
public static final String STRING_CLASS
|
||||
= "java.lang.String";
|
||||
public static final String OBJECT_CLASS
|
||||
= "java.lang.Object";
|
||||
public static final String BOOLEAN_CLASS
|
||||
= "java.lang.Boolean";
|
||||
public static final String STRING_BUFFER_CLASS
|
||||
= "java.lang.StringBuffer";
|
||||
public static final String STRING_WRITER
|
||||
= "java.io.StringWriter";
|
||||
public static final String WRITER_SIG
|
||||
= "Ljava/io/Writer;";
|
||||
|
||||
public static final String TRANSLET_OUTPUT_BASE
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.TransletOutputBase";
|
||||
// output interface
|
||||
public static final String TRANSLET_OUTPUT_INTERFACE
|
||||
= "com.sun.org.apache.xml.internal.serializer.SerializationHandler";
|
||||
public static final String BASIS_LIBRARY_CLASS
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary";
|
||||
public static final String ATTRIBUTE_LIST_IMPL_CLASS
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.runtime.AttributeListImpl";
|
||||
public static final String DOUBLE_CLASS
|
||||
= "java.lang.Double";
|
||||
public static final String INTEGER_CLASS
|
||||
= "java.lang.Integer";
|
||||
public static final String RUNTIME_NODE_CLASS
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.runtime.Node";
|
||||
public static final String MATH_CLASS
|
||||
= "java.lang.Math";
|
||||
|
||||
public static final String BOOLEAN_VALUE
|
||||
= "booleanValue";
|
||||
public static final String BOOLEAN_VALUE_SIG
|
||||
= "()Z";
|
||||
public static final String INT_VALUE
|
||||
= "intValue";
|
||||
public static final String INT_VALUE_SIG
|
||||
= "()I";
|
||||
public static final String DOUBLE_VALUE
|
||||
= "doubleValue";
|
||||
public static final String DOUBLE_VALUE_SIG
|
||||
= "()D";
|
||||
|
||||
public static final String DOM_PNAME
|
||||
= "dom";
|
||||
public static final String NODE_PNAME
|
||||
= "node";
|
||||
public static final String TRANSLET_OUTPUT_PNAME
|
||||
= "handler";
|
||||
public static final String ITERATOR_PNAME
|
||||
= "iterator";
|
||||
public static final String DOCUMENT_PNAME
|
||||
= "document";
|
||||
public static final String TRANSLET_PNAME
|
||||
= "translet";
|
||||
|
||||
public static final String INVOKE_METHOD
|
||||
= "invokeMethod";
|
||||
public static final String GET_NODE_NAME
|
||||
= "getNodeNameX";
|
||||
public static final String CHARACTERSW
|
||||
= "characters";
|
||||
public static final String GET_CHILDREN
|
||||
= "getChildren";
|
||||
public static final String GET_TYPED_CHILDREN
|
||||
= "getTypedChildren";
|
||||
public static final String CHARACTERS
|
||||
= "characters";
|
||||
public static final String APPLY_TEMPLATES
|
||||
= "applyTemplates";
|
||||
public static final String GET_NODE_TYPE
|
||||
= "getNodeType";
|
||||
public static final String GET_NODE_VALUE
|
||||
= "getStringValueX";
|
||||
public static final String GET_ELEMENT_VALUE
|
||||
= "getElementValue";
|
||||
public static final String GET_ATTRIBUTE_VALUE
|
||||
= "getAttributeValue";
|
||||
public static final String HAS_ATTRIBUTE
|
||||
= "hasAttribute";
|
||||
public static final String ADD_ITERATOR
|
||||
= "addIterator";
|
||||
public static final String SET_START_NODE
|
||||
= "setStartNode";
|
||||
public static final String RESET
|
||||
= "reset";
|
||||
|
||||
public static final String ATTR_SET_SIG
|
||||
= "(" + DOM_INTF_SIG + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + "I)V";
|
||||
|
||||
public static final String GET_NODE_NAME_SIG
|
||||
= "(" + NODE_SIG + ")" + STRING_SIG;
|
||||
public static final String CHARACTERSW_SIG
|
||||
= "(" + STRING_SIG + TRANSLET_OUTPUT_SIG + ")V";
|
||||
public static final String CHARACTERS_SIG
|
||||
= "(" + NODE_SIG + TRANSLET_OUTPUT_SIG + ")V";
|
||||
public static final String GET_CHILDREN_SIG
|
||||
= "(" + NODE_SIG +")" + NODE_ITERATOR_SIG;
|
||||
public static final String GET_TYPED_CHILDREN_SIG
|
||||
= "(I)" + NODE_ITERATOR_SIG;
|
||||
public static final String GET_NODE_TYPE_SIG
|
||||
= "()S";
|
||||
public static final String GET_NODE_VALUE_SIG
|
||||
= "(I)" + STRING_SIG;
|
||||
public static final String GET_ELEMENT_VALUE_SIG
|
||||
= "(I)" + STRING_SIG;
|
||||
public static final String GET_ATTRIBUTE_VALUE_SIG
|
||||
= "(II)" + STRING_SIG;
|
||||
public static final String HAS_ATTRIBUTE_SIG
|
||||
= "(II)Z";
|
||||
public static final String GET_ITERATOR_SIG
|
||||
= "()" + NODE_ITERATOR_SIG;
|
||||
|
||||
public static final String NAMES_INDEX
|
||||
= "namesArray";
|
||||
public static final String NAMES_INDEX_SIG
|
||||
= "[" + STRING_SIG;
|
||||
public static final String URIS_INDEX
|
||||
= "urisArray";
|
||||
public static final String URIS_INDEX_SIG
|
||||
= "[" + STRING_SIG;
|
||||
public static final String TYPES_INDEX
|
||||
= "typesArray";
|
||||
public static final String TYPES_INDEX_SIG
|
||||
= "[I";
|
||||
public static final String NAMESPACE_INDEX
|
||||
= "namespaceArray";
|
||||
public static final String NAMESPACE_INDEX_SIG
|
||||
= "[" + STRING_SIG;
|
||||
public static final String HASIDCALL_INDEX
|
||||
= "_hasIdCall";
|
||||
public static final String HASIDCALL_INDEX_SIG
|
||||
= "Z";
|
||||
public static final String TRANSLET_VERSION_INDEX
|
||||
= "transletVersion";
|
||||
public static final String TRANSLET_VERSION_INDEX_SIG
|
||||
= "I";
|
||||
|
||||
public static final String DOM_FIELD
|
||||
= "_dom";
|
||||
public static final String STATIC_NAMES_ARRAY_FIELD
|
||||
= "_sNamesArray";
|
||||
public static final String STATIC_URIS_ARRAY_FIELD
|
||||
= "_sUrisArray";
|
||||
public static final String STATIC_TYPES_ARRAY_FIELD
|
||||
= "_sTypesArray";
|
||||
public static final String STATIC_NAMESPACE_ARRAY_FIELD
|
||||
= "_sNamespaceArray";
|
||||
public static final String STATIC_CHAR_DATA_FIELD
|
||||
= "_scharData";
|
||||
public static final String STATIC_CHAR_DATA_FIELD_SIG
|
||||
= "[C";
|
||||
public static final String FORMAT_SYMBOLS_FIELD
|
||||
= "format_symbols";
|
||||
|
||||
public static final String ITERATOR_FIELD_SIG
|
||||
= NODE_ITERATOR_SIG;
|
||||
public static final String NODE_FIELD
|
||||
= "node";
|
||||
public static final String NODE_FIELD_SIG
|
||||
= "I";
|
||||
|
||||
public static final String EMPTYATTR_FIELD
|
||||
= "EmptyAttributes";
|
||||
public static final String ATTRIBUTE_LIST_FIELD
|
||||
= "attributeList";
|
||||
public static final String CLEAR_ATTRIBUTES
|
||||
= "clear";
|
||||
public static final String ADD_ATTRIBUTE
|
||||
= "addAttribute";
|
||||
public static final String ATTRIBUTE_LIST_IMPL_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/runtime/AttributeListImpl;";
|
||||
public static final String CLEAR_ATTRIBUTES_SIG
|
||||
= "()" + ATTRIBUTE_LIST_IMPL_SIG;
|
||||
public static final String ADD_ATTRIBUTE_SIG
|
||||
= "(" + STRING_SIG + STRING_SIG + ")" + ATTRIBUTE_LIST_IMPL_SIG;
|
||||
|
||||
public static final String ADD_ITERATOR_SIG
|
||||
= "(" + NODE_ITERATOR_SIG +")" + UNION_ITERATOR_SIG;
|
||||
|
||||
public static final String ORDER_ITERATOR
|
||||
= "orderNodes";
|
||||
public static final String ORDER_ITERATOR_SIG
|
||||
= "("+NODE_ITERATOR_SIG+"I)"+NODE_ITERATOR_SIG;
|
||||
|
||||
public static final String SET_START_NODE_SIG
|
||||
= "(" + NODE_SIG + ")" + NODE_ITERATOR_SIG;
|
||||
|
||||
public static final String NODE_COUNTER
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.NodeCounter";
|
||||
public static final String NODE_COUNTER_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/dom/NodeCounter;";
|
||||
public static final String DEFAULT_NODE_COUNTER
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.dom.DefaultNodeCounter";
|
||||
public static final String DEFAULT_NODE_COUNTER_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/dom/DefaultNodeCounter;";
|
||||
public static final String TRANSLET_FIELD
|
||||
= "translet";
|
||||
public static final String TRANSLET_FIELD_SIG
|
||||
= TRANSLET_SIG;
|
||||
|
||||
public static final String RESET_SIG
|
||||
= "()" + NODE_ITERATOR_SIG;
|
||||
public static final String GET_PARAMETER
|
||||
= "getParameter";
|
||||
public static final String ADD_PARAMETER
|
||||
= "addParameter";
|
||||
public static final String PUSH_PARAM_FRAME
|
||||
= "pushParamFrame";
|
||||
public static final String PUSH_PARAM_FRAME_SIG
|
||||
= "()V";
|
||||
public static final String POP_PARAM_FRAME
|
||||
= "popParamFrame";
|
||||
public static final String POP_PARAM_FRAME_SIG
|
||||
= "()V";
|
||||
public static final String GET_PARAMETER_SIG
|
||||
= "(" + STRING_SIG + ")" + OBJECT_SIG;
|
||||
public static final String ADD_PARAMETER_SIG
|
||||
= "(" + STRING_SIG + OBJECT_SIG + "Z)" + OBJECT_SIG;
|
||||
|
||||
public static final String STRIP_SPACE
|
||||
= "stripSpace";
|
||||
public static final String STRIP_SPACE_INTF
|
||||
= "com/sun/org/apache/xalan/internal/xsltc/StripFilter";
|
||||
public static final String STRIP_SPACE_SIG
|
||||
= "Lcom/sun/org/apache/xalan/internal/xsltc/StripFilter;";
|
||||
public static final String STRIP_SPACE_PARAMS
|
||||
= "(Lcom/sun/org/apache/xalan/internal/xsltc/DOM;II)Z";
|
||||
|
||||
public static final String GET_NODE_VALUE_ITERATOR
|
||||
= "getNodeValueIterator";
|
||||
public static final String GET_NODE_VALUE_ITERATOR_SIG
|
||||
= "("+NODE_ITERATOR_SIG+"I"+STRING_SIG+"Z)"+NODE_ITERATOR_SIG;
|
||||
|
||||
public static final String GET_UNPARSED_ENTITY_URI_SIG
|
||||
= "("+STRING_SIG+")"+STRING_SIG;
|
||||
|
||||
public static final int POSITION_INDEX = 2;
|
||||
public static final int LAST_INDEX = 3;
|
||||
|
||||
public static final String XMLNS_PREFIX = "xmlns";
|
||||
public static final String XMLNS_STRING = "xmlns:";
|
||||
public static final String XMLNS_URI
|
||||
= "http://www.w3.org/2000/xmlns/";
|
||||
public static final String XSLT_URI
|
||||
= "http://www.w3.org/1999/XSL/Transform";
|
||||
public static final String XHTML_URI
|
||||
= "http://www.w3.org/1999/xhtml";
|
||||
public static final String TRANSLET_URI
|
||||
= "http://xml.apache.org/xalan/xsltc";
|
||||
public static final String REDIRECT_URI
|
||||
= "http://xml.apache.org/xalan/redirect";
|
||||
public static final String FALLBACK_CLASS
|
||||
= "com.sun.org.apache.xalan.internal.xsltc.compiler.Fallback";
|
||||
|
||||
public static final int RTF_INITIAL_SIZE = 32;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.IFLT;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
final class ContainsCall extends FunctionCall {
|
||||
|
||||
private Expression _base = null;
|
||||
private Expression _token = null;
|
||||
|
||||
/**
|
||||
* Create a contains() call - two arguments, both strings
|
||||
*/
|
||||
public ContainsCall(QName fname, Vector arguments) {
|
||||
super(fname, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* This XPath function returns true/false values
|
||||
*/
|
||||
public boolean isBoolean() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type check the two parameters for this function
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
|
||||
// Check that the function was passed exactly two arguments
|
||||
if (argumentCount() != 2) {
|
||||
throw new TypeCheckError(ErrorMsg.ILLEGAL_ARG_ERR, getName(), this);
|
||||
}
|
||||
|
||||
// The first argument must be a String, or cast to a String
|
||||
_base = argument(0);
|
||||
Type baseType = _base.typeCheck(stable);
|
||||
if (baseType != Type.String)
|
||||
_base = new CastExpr(_base, Type.String);
|
||||
|
||||
// The second argument must also be a String, or cast to a String
|
||||
_token = argument(1);
|
||||
Type tokenType = _token.typeCheck(stable);
|
||||
if (tokenType != Type.String)
|
||||
_token = new CastExpr(_token, Type.String);
|
||||
|
||||
return _type = Type.Boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the expression - leave boolean expression on stack
|
||||
*/
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
translateDesynthesized(classGen, methodGen);
|
||||
synthesize(classGen, methodGen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile expression and update true/false-lists
|
||||
*/
|
||||
public void translateDesynthesized(ClassGenerator classGen,
|
||||
MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
_base.translate(classGen, methodGen);
|
||||
_token.translate(classGen, methodGen);
|
||||
il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_CLASS,
|
||||
"indexOf",
|
||||
"("+STRING_SIG+")I")));
|
||||
_falseList.add(il.append(new IFLT(null)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ALOAD;
|
||||
import com.sun.org.apache.bcel.internal.generic.ASTORE;
|
||||
import com.sun.org.apache.bcel.internal.generic.BranchHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.IFEQ;
|
||||
import com.sun.org.apache.bcel.internal.generic.IFNULL;
|
||||
import com.sun.org.apache.bcel.internal.generic.ILOAD;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.ISTORE;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class Copy extends Instruction {
|
||||
private UseAttributeSets _useSets;
|
||||
|
||||
public void parseContents(Parser parser) {
|
||||
final String useSets = getAttribute("use-attribute-sets");
|
||||
if (useSets.length() > 0) {
|
||||
if (!Util.isValidQNames(useSets)) {
|
||||
ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, useSets, this);
|
||||
parser.reportError(Constants.ERROR, err);
|
||||
}
|
||||
_useSets = new UseAttributeSets(useSets, parser);
|
||||
}
|
||||
parseChildren(parser);
|
||||
}
|
||||
|
||||
public void display(int indent) {
|
||||
indent(indent);
|
||||
Util.println("Copy");
|
||||
indent(indent + IndentIncrement);
|
||||
displayContents(indent + IndentIncrement);
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
if (_useSets != null) {
|
||||
_useSets.typeCheck(stable);
|
||||
}
|
||||
typeCheckContents(stable);
|
||||
return Type.Void;
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
final LocalVariableGen name =
|
||||
methodGen.addLocalVariable2("name",
|
||||
Util.getJCRefType(STRING_SIG),
|
||||
null);
|
||||
final LocalVariableGen length =
|
||||
methodGen.addLocalVariable2("length",
|
||||
Util.getJCRefType("I"),
|
||||
null);
|
||||
|
||||
// Get the name of the node to copy and save for later
|
||||
il.append(methodGen.loadDOM());
|
||||
il.append(methodGen.loadCurrentNode());
|
||||
il.append(methodGen.loadHandler());
|
||||
final int cpy = cpg.addInterfaceMethodref(DOM_INTF,
|
||||
"shallowCopy",
|
||||
"("
|
||||
+ NODE_SIG
|
||||
+ TRANSLET_OUTPUT_SIG
|
||||
+ ")" + STRING_SIG);
|
||||
il.append(new INVOKEINTERFACE(cpy, 3));
|
||||
il.append(DUP);
|
||||
name.setStart(il.append(new ASTORE(name.getIndex())));
|
||||
final BranchHandle ifBlock1 = il.append(new IFNULL(null));
|
||||
|
||||
// Get the length of the node name and save for later
|
||||
il.append(new ALOAD(name.getIndex()));
|
||||
final int lengthMethod = cpg.addMethodref(STRING_CLASS,"length","()I");
|
||||
il.append(new INVOKEVIRTUAL(lengthMethod));
|
||||
il.append(DUP);
|
||||
length.setStart(il.append(new ISTORE(length.getIndex())));
|
||||
|
||||
// Ignore attribute sets if current node is ROOT. DOM.shallowCopy()
|
||||
// returns "" for ROOT, so skip attribute sets if length == 0
|
||||
final BranchHandle ifBlock4 = il.append(new IFEQ(null));
|
||||
|
||||
// Copy in attribute sets if specified
|
||||
if (_useSets != null) {
|
||||
// If the parent of this element will result in an element being
|
||||
// output then we know that it is safe to copy out the attributes
|
||||
final SyntaxTreeNode parent = getParent();
|
||||
if ((parent instanceof LiteralElement) ||
|
||||
(parent instanceof LiteralElement)) {
|
||||
_useSets.translate(classGen, methodGen);
|
||||
}
|
||||
// If not we have to check to see if the copy will result in an
|
||||
// element being output.
|
||||
else {
|
||||
// check if element; if not skip to translate body
|
||||
il.append(new ILOAD(length.getIndex()));
|
||||
final BranchHandle ifBlock2 = il.append(new IFEQ(null));
|
||||
// length != 0 -> element -> do attribute sets
|
||||
_useSets.translate(classGen, methodGen);
|
||||
// not an element; root
|
||||
ifBlock2.setTarget(il.append(NOP));
|
||||
}
|
||||
}
|
||||
|
||||
// Instantiate body of xsl:copy
|
||||
ifBlock4.setTarget(il.append(NOP));
|
||||
translateContents(classGen, methodGen);
|
||||
|
||||
// Call the output handler's endElement() if we copied an element
|
||||
// (The DOM.shallowCopy() method calls startElement().)
|
||||
length.setEnd(il.append(new ILOAD(length.getIndex())));
|
||||
final BranchHandle ifBlock3 = il.append(new IFEQ(null));
|
||||
il.append(methodGen.loadHandler());
|
||||
name.setEnd(il.append(new ALOAD(name.getIndex())));
|
||||
il.append(methodGen.endElement());
|
||||
|
||||
final InstructionHandle end = il.append(NOP);
|
||||
ifBlock1.setTarget(end);
|
||||
ifBlock3.setTarget(end);
|
||||
methodGen.removeLocalVariable(name);
|
||||
methodGen.removeLocalVariable(length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSetType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ReferenceType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ResultTreeType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class CopyOf extends Instruction {
|
||||
private Expression _select;
|
||||
|
||||
public void display(int indent) {
|
||||
indent(indent);
|
||||
Util.println("CopyOf");
|
||||
indent(indent + IndentIncrement);
|
||||
Util.println("select " + _select.toString());
|
||||
}
|
||||
|
||||
public void parseContents(Parser parser) {
|
||||
_select = parser.parseExpression(this, "select", null);
|
||||
// make sure required attribute(s) have been set
|
||||
if (_select.isDummy()) {
|
||||
reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "select");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
final Type tselect = _select.typeCheck(stable);
|
||||
if (tselect instanceof NodeType ||
|
||||
tselect instanceof NodeSetType ||
|
||||
tselect instanceof ReferenceType ||
|
||||
tselect instanceof ResultTreeType) {
|
||||
// falls through
|
||||
}
|
||||
else {
|
||||
_select = new CastExpr(_select, Type.String);
|
||||
}
|
||||
return Type.Void;
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
final Type tselect = _select.getType();
|
||||
|
||||
final String CPY1_SIG = "("+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+")V";
|
||||
final int cpy1 = cpg.addInterfaceMethodref(DOM_INTF, "copy", CPY1_SIG);
|
||||
|
||||
final String CPY2_SIG = "("+NODE_SIG+TRANSLET_OUTPUT_SIG+")V";
|
||||
final int cpy2 = cpg.addInterfaceMethodref(DOM_INTF, "copy", CPY2_SIG);
|
||||
|
||||
final String getDoc_SIG = "()"+NODE_SIG;
|
||||
final int getDoc = cpg.addInterfaceMethodref(DOM_INTF, "getDocument", getDoc_SIG);
|
||||
|
||||
|
||||
if (tselect instanceof NodeSetType) {
|
||||
il.append(methodGen.loadDOM());
|
||||
|
||||
// push NodeIterator
|
||||
_select.translate(classGen, methodGen);
|
||||
_select.startIterator(classGen, methodGen);
|
||||
|
||||
// call copy from the DOM 'library'
|
||||
il.append(methodGen.loadHandler());
|
||||
il.append(new INVOKEINTERFACE(cpy1, 3));
|
||||
}
|
||||
else if (tselect instanceof NodeType) {
|
||||
il.append(methodGen.loadDOM());
|
||||
_select.translate(classGen, methodGen);
|
||||
il.append(methodGen.loadHandler());
|
||||
il.append(new INVOKEINTERFACE(cpy2, 3));
|
||||
}
|
||||
else if (tselect instanceof ResultTreeType) {
|
||||
_select.translate(classGen, methodGen);
|
||||
// We want the whole tree, so we start with the root node
|
||||
il.append(DUP); //need a pointer to the DOM ;
|
||||
il.append(new INVOKEINTERFACE(getDoc,1)); //ICONST_0);
|
||||
il.append(methodGen.loadHandler());
|
||||
il.append(new INVOKEINTERFACE(cpy2, 3));
|
||||
}
|
||||
else if (tselect instanceof ReferenceType) {
|
||||
_select.translate(classGen, methodGen);
|
||||
il.append(methodGen.loadHandler());
|
||||
il.append(methodGen.loadCurrentNode());
|
||||
il.append(methodGen.loadDOM());
|
||||
final int copy = cpg.addMethodref(BASIS_LIBRARY_CLASS, "copy",
|
||||
"("
|
||||
+ OBJECT_SIG
|
||||
+ TRANSLET_OUTPUT_SIG
|
||||
+ NODE_SIG
|
||||
+ DOM_INTF_SIG
|
||||
+ ")V");
|
||||
il.append(new INVOKESTATIC(copy));
|
||||
}
|
||||
else {
|
||||
il.append(classGen.loadTranslet());
|
||||
_select.translate(classGen, methodGen);
|
||||
il.append(methodGen.loadHandler());
|
||||
il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
|
||||
CHARACTERSW,
|
||||
CHARACTERSW_SIG)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class CurrentCall extends FunctionCall {
|
||||
public CurrentCall(QName fname) {
|
||||
super(fname);
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
methodGen.getInstructionList().append(methodGen.loadCurrentNode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.GETSTATIC;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import com.sun.org.apache.bcel.internal.generic.PUSH;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xml.internal.utils.XML11Char;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
final class DecimalFormatting extends TopLevelElement {
|
||||
|
||||
private static final String DFS_CLASS = "java.text.DecimalFormatSymbols";
|
||||
private static final String DFS_SIG = "Ljava/text/DecimalFormatSymbols;";
|
||||
|
||||
private QName _name = null;
|
||||
|
||||
/**
|
||||
* No type check needed for the <xsl:decimal-formatting/> element
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
return Type.Void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the name of the <xsl:decimal-formatting/> element
|
||||
*/
|
||||
public void parseContents(Parser parser) {
|
||||
// Get the name of these decimal formatting symbols
|
||||
final String name = getAttribute("name");
|
||||
if (name.length() > 0) {
|
||||
if (!XML11Char.isXML11ValidQName(name)){
|
||||
ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, name, this);
|
||||
parser.reportError(Constants.ERROR, err);
|
||||
}
|
||||
}
|
||||
_name = parser.getQNameIgnoreDefaultNs(name);
|
||||
if (_name == null) {
|
||||
_name = parser.getQNameIgnoreDefaultNs(EMPTYSTRING);
|
||||
}
|
||||
|
||||
// Check if a set of symbols has already been registered under this name
|
||||
SymbolTable stable = parser.getSymbolTable();
|
||||
if (stable.getDecimalFormatting(_name) != null) {
|
||||
reportWarning(this, parser, ErrorMsg.SYMBOLS_REDEF_ERR,
|
||||
_name.toString());
|
||||
}
|
||||
else {
|
||||
stable.addDecimalFormatting(_name, this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the constructor is compiled in
|
||||
* Stylesheet.compileConstructor() and not as the syntax tree is traversed.
|
||||
*/
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
|
||||
ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
// DecimalFormatSymbols.<init>(Locale);
|
||||
// xsl:decimal-format - except for the NaN and infinity attributes.
|
||||
final int init = cpg.addMethodref(DFS_CLASS, "<init>",
|
||||
"("+LOCALE_SIG+")V");
|
||||
|
||||
// Push the format name on the stack for call to addDecimalFormat()
|
||||
il.append(classGen.loadTranslet());
|
||||
il.append(new PUSH(cpg, _name.toString()));
|
||||
|
||||
// Manufacture a DecimalFormatSymbols on the stack
|
||||
// for call to addDecimalFormat()
|
||||
// Use the US Locale as the default, as most of its settings
|
||||
// are equivalent to the default settings required of
|
||||
il.append(new NEW(cpg.addClass(DFS_CLASS)));
|
||||
il.append(DUP);
|
||||
il.append(new GETSTATIC(cpg.addFieldref(LOCALE_CLASS, "US",
|
||||
LOCALE_SIG)));
|
||||
il.append(new INVOKESPECIAL(init));
|
||||
|
||||
String tmp = getAttribute("NaN");
|
||||
if ((tmp == null) || (tmp.equals(EMPTYSTRING))) {
|
||||
int nan = cpg.addMethodref(DFS_CLASS,
|
||||
"setNaN", "(Ljava/lang/String;)V");
|
||||
il.append(DUP);
|
||||
il.append(new PUSH(cpg, "NaN"));
|
||||
il.append(new INVOKEVIRTUAL(nan));
|
||||
}
|
||||
|
||||
tmp = getAttribute("infinity");
|
||||
if ((tmp == null) || (tmp.equals(EMPTYSTRING))) {
|
||||
int inf = cpg.addMethodref(DFS_CLASS,
|
||||
"setInfinity",
|
||||
"(Ljava/lang/String;)V");
|
||||
il.append(DUP);
|
||||
il.append(new PUSH(cpg, "Infinity"));
|
||||
il.append(new INVOKEVIRTUAL(inf));
|
||||
}
|
||||
|
||||
final int nAttributes = _attributes.getLength();
|
||||
for (int i = 0; i < nAttributes; i++) {
|
||||
final String name = _attributes.getQName(i);
|
||||
final String value = _attributes.getValue(i);
|
||||
|
||||
boolean valid = true;
|
||||
int method = 0;
|
||||
|
||||
if (name.equals("decimal-separator")) {
|
||||
// DecimalFormatSymbols.setDecimalSeparator();
|
||||
method = cpg.addMethodref(DFS_CLASS,
|
||||
"setDecimalSeparator", "(C)V");
|
||||
}
|
||||
else if (name.equals("grouping-separator")) {
|
||||
method = cpg.addMethodref(DFS_CLASS,
|
||||
"setGroupingSeparator", "(C)V");
|
||||
}
|
||||
else if (name.equals("minus-sign")) {
|
||||
method = cpg.addMethodref(DFS_CLASS,
|
||||
"setMinusSign", "(C)V");
|
||||
}
|
||||
else if (name.equals("percent")) {
|
||||
method = cpg.addMethodref(DFS_CLASS,
|
||||
"setPercent", "(C)V");
|
||||
}
|
||||
else if (name.equals("per-mille")) {
|
||||
method = cpg.addMethodref(DFS_CLASS,
|
||||
"setPerMill", "(C)V");
|
||||
}
|
||||
else if (name.equals("zero-digit")) {
|
||||
method = cpg.addMethodref(DFS_CLASS,
|
||||
"setZeroDigit", "(C)V");
|
||||
}
|
||||
else if (name.equals("digit")) {
|
||||
method = cpg.addMethodref(DFS_CLASS,
|
||||
"setDigit", "(C)V");
|
||||
}
|
||||
else if (name.equals("pattern-separator")) {
|
||||
method = cpg.addMethodref(DFS_CLASS,
|
||||
"setPatternSeparator", "(C)V");
|
||||
}
|
||||
else if (name.equals("NaN")) {
|
||||
method = cpg.addMethodref(DFS_CLASS,
|
||||
"setNaN", "(Ljava/lang/String;)V");
|
||||
il.append(DUP);
|
||||
il.append(new PUSH(cpg, value));
|
||||
il.append(new INVOKEVIRTUAL(method));
|
||||
valid = false;
|
||||
}
|
||||
else if (name.equals("infinity")) {
|
||||
method = cpg.addMethodref(DFS_CLASS,
|
||||
"setInfinity",
|
||||
"(Ljava/lang/String;)V");
|
||||
il.append(DUP);
|
||||
il.append(new PUSH(cpg, value));
|
||||
il.append(new INVOKEVIRTUAL(method));
|
||||
valid = false;
|
||||
}
|
||||
else {
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
il.append(DUP);
|
||||
il.append(new PUSH(cpg, value.charAt(0)));
|
||||
il.append(new INVOKEVIRTUAL(method));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final int put = cpg.addMethodref(TRANSLET_CLASS,
|
||||
"addDecimalFormat",
|
||||
"("+STRING_SIG+DFS_SIG+")V");
|
||||
il.append(new INVOKEVIRTUAL(put));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the default, nameless, DecimalFormat object in
|
||||
* AbstractTranslet's format_symbols hashtable.
|
||||
* This should be called for every stylesheet, and the entry
|
||||
* may be overridden by later nameless xsl:decimal-format instructions.
|
||||
*/
|
||||
public static void translateDefaultDFS(ClassGenerator classGen,
|
||||
MethodGenerator methodGen) {
|
||||
|
||||
ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
InstructionList il = methodGen.getInstructionList();
|
||||
final int init = cpg.addMethodref(DFS_CLASS, "<init>",
|
||||
"("+LOCALE_SIG+")V");
|
||||
|
||||
// Push the format name, which is empty, on the stack
|
||||
// for call to addDecimalFormat()
|
||||
il.append(classGen.loadTranslet());
|
||||
il.append(new PUSH(cpg, EMPTYSTRING));
|
||||
|
||||
// Manufacture a DecimalFormatSymbols on the stack for
|
||||
// call to addDecimalFormat(). Use the US Locale as the
|
||||
// default, as most of its settings are equivalent to
|
||||
// the default settings required of xsl:decimal-format -
|
||||
// except for the NaN and infinity attributes.
|
||||
il.append(new NEW(cpg.addClass(DFS_CLASS)));
|
||||
il.append(DUP);
|
||||
il.append(new GETSTATIC(cpg.addFieldref(LOCALE_CLASS, "US",
|
||||
LOCALE_SIG)));
|
||||
il.append(new INVOKESPECIAL(init));
|
||||
|
||||
int nan = cpg.addMethodref(DFS_CLASS,
|
||||
"setNaN", "(Ljava/lang/String;)V");
|
||||
il.append(DUP);
|
||||
il.append(new PUSH(cpg, "NaN"));
|
||||
il.append(new INVOKEVIRTUAL(nan));
|
||||
|
||||
int inf = cpg.addMethodref(DFS_CLASS,
|
||||
"setInfinity",
|
||||
"(Ljava/lang/String;)V");
|
||||
il.append(DUP);
|
||||
il.append(new PUSH(cpg, "Infinity"));
|
||||
il.append(new INVOKEVIRTUAL(inf));
|
||||
|
||||
final int put = cpg.addMethodref(TRANSLET_CLASS,
|
||||
"addDecimalFormat",
|
||||
"("+STRING_SIG+DFS_SIG+")V");
|
||||
il.append(new INVOKEVIRTUAL(put));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.GETFIELD;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.PUSH;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
final class DocumentCall extends FunctionCall {
|
||||
|
||||
private Expression _arg1 = null;
|
||||
private Expression _arg2 = null;
|
||||
private Type _arg1Type;
|
||||
|
||||
/**
|
||||
* Default function call constructor
|
||||
*/
|
||||
public DocumentCall(QName fname, Vector arguments) {
|
||||
super(fname, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type checks the arguments passed to the document() function. The first
|
||||
* argument can be any type (we must cast it to a string) and contains the
|
||||
* URI of the document
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
// At least one argument - two at most
|
||||
final int ac = argumentCount();
|
||||
if ((ac < 1) || (ac > 2)) {
|
||||
ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_ARG_ERR, this);
|
||||
throw new TypeCheckError(msg);
|
||||
}
|
||||
if (getStylesheet() == null) {
|
||||
ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_ARG_ERR, this);
|
||||
throw new TypeCheckError(msg);
|
||||
}
|
||||
|
||||
// Parse the first argument
|
||||
_arg1 = argument(0);
|
||||
|
||||
if (_arg1 == null) {// should not happened
|
||||
ErrorMsg msg = new ErrorMsg(ErrorMsg.DOCUMENT_ARG_ERR, this);
|
||||
throw new TypeCheckError(msg);
|
||||
}
|
||||
|
||||
_arg1Type = _arg1.typeCheck(stable);
|
||||
if ((_arg1Type != Type.NodeSet) && (_arg1Type != Type.String)) {
|
||||
_arg1 = new CastExpr(_arg1, Type.String);
|
||||
}
|
||||
|
||||
// Parse the second argument
|
||||
if (ac == 2) {
|
||||
_arg2 = argument(1);
|
||||
|
||||
if (_arg2 == null) {// should not happened
|
||||
ErrorMsg msg = new ErrorMsg(ErrorMsg.DOCUMENT_ARG_ERR, this);
|
||||
throw new TypeCheckError(msg);
|
||||
}
|
||||
|
||||
final Type arg2Type = _arg2.typeCheck(stable);
|
||||
|
||||
if (arg2Type.identicalTo(Type.Node)) {
|
||||
_arg2 = new CastExpr(_arg2, Type.NodeSet);
|
||||
} else if (arg2Type.identicalTo(Type.NodeSet)) {
|
||||
// falls through
|
||||
} else {
|
||||
ErrorMsg msg = new ErrorMsg(ErrorMsg.DOCUMENT_ARG_ERR, this);
|
||||
throw new TypeCheckError(msg);
|
||||
}
|
||||
}
|
||||
|
||||
return _type = Type.NodeSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the document() function call to a call to LoadDocument()'s
|
||||
* static method document().
|
||||
*/
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
final int ac = argumentCount();
|
||||
|
||||
final int domField = cpg.addFieldref(classGen.getClassName(),
|
||||
DOM_FIELD,
|
||||
DOM_INTF_SIG);
|
||||
|
||||
String docParamList = null;
|
||||
if (ac == 1) {
|
||||
// documentF(Object,String,AbstractTranslet,DOM)
|
||||
docParamList = "("+OBJECT_SIG+STRING_SIG+TRANSLET_SIG+DOM_INTF_SIG
|
||||
+")"+NODE_ITERATOR_SIG;
|
||||
} else { //ac == 2; ac < 1 or as >2 was tested in typeChec()
|
||||
// documentF(Object,DTMAxisIterator,String,AbstractTranslet,DOM)
|
||||
docParamList = "("+OBJECT_SIG+NODE_ITERATOR_SIG+STRING_SIG
|
||||
+TRANSLET_SIG+DOM_INTF_SIG+")"+NODE_ITERATOR_SIG;
|
||||
}
|
||||
final int docIdx = cpg.addMethodref(LOAD_DOCUMENT_CLASS, "documentF",
|
||||
docParamList);
|
||||
|
||||
|
||||
// The URI can be either a node-set or something else cast to a string
|
||||
_arg1.translate(classGen, methodGen);
|
||||
if (_arg1Type == Type.NodeSet) {
|
||||
_arg1.startIterator(classGen, methodGen);
|
||||
}
|
||||
|
||||
if (ac == 2) {
|
||||
//_arg2 == null was tested in typeChec()
|
||||
_arg2.translate(classGen, methodGen);
|
||||
_arg2.startIterator(classGen, methodGen);
|
||||
}
|
||||
|
||||
// Feck the rest of the parameters on the stack
|
||||
il.append(new PUSH(cpg, getStylesheet().getSystemId()));
|
||||
il.append(classGen.loadTranslet());
|
||||
il.append(DUP);
|
||||
il.append(new GETFIELD(domField));
|
||||
il.append(new INVOKESTATIC(docIdx));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.PUSH;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class ElementAvailableCall extends FunctionCall {
|
||||
|
||||
public ElementAvailableCall(QName fname, Vector arguments) {
|
||||
super(fname, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the argument to this function to be a literal string.
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
if (argument() instanceof LiteralExpr) {
|
||||
return _type = Type.Boolean;
|
||||
}
|
||||
ErrorMsg err = new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR,
|
||||
"element-available", this);
|
||||
throw new TypeCheckError(err);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object representing the compile-time evaluation
|
||||
* of an expression. We are only using this for function-available
|
||||
* and element-available at this time.
|
||||
*/
|
||||
public Object evaluateAtCompileTime() {
|
||||
return getResult() ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result that this function will return
|
||||
*/
|
||||
public boolean getResult() {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls to 'element-available' are resolved at compile time since
|
||||
* the namespaces declared in the stylsheet are not available at run
|
||||
* time. Consequently, arguments to this function must be literals.
|
||||
*/
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final boolean result = getResult();
|
||||
methodGen.getInstructionList().append(new PUSH(cpg, result));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,359 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.BranchHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.BranchInstruction;
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.GOTO;
|
||||
import com.sun.org.apache.bcel.internal.generic.IFEQ;
|
||||
import com.sun.org.apache.bcel.internal.generic.IFNE;
|
||||
import com.sun.org.apache.bcel.internal.generic.IF_ICMPEQ;
|
||||
import com.sun.org.apache.bcel.internal.generic.IF_ICMPNE;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.PUSH;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.BooleanType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.IntType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSetType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NumberType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.RealType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ReferenceType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ResultTreeType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.StringType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.runtime.Operators;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Morten Jorgensen
|
||||
* @author Erwin Bolwidt <ejb@klomp.org>
|
||||
*/
|
||||
final class EqualityExpr extends Expression {
|
||||
|
||||
private final int _op;
|
||||
private Expression _left;
|
||||
private Expression _right;
|
||||
|
||||
public EqualityExpr(int op, Expression left, Expression right) {
|
||||
_op = op;
|
||||
(_left = left).setParent(this);
|
||||
(_right = right).setParent(this);
|
||||
}
|
||||
|
||||
public void setParser(Parser parser) {
|
||||
super.setParser(parser);
|
||||
_left.setParser(parser);
|
||||
_right.setParser(parser);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return Operators.getOpNames(_op) + '(' + _left + ", " + _right + ')';
|
||||
}
|
||||
|
||||
public Expression getLeft() {
|
||||
return _left;
|
||||
}
|
||||
|
||||
public Expression getRight() {
|
||||
return _right;
|
||||
}
|
||||
|
||||
public boolean getOp() {
|
||||
return (_op != Operators.NE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this expressions contains a call to position(). This is
|
||||
* needed for context changes in node steps containing multiple predicates.
|
||||
*/
|
||||
public boolean hasPositionCall() {
|
||||
if (_left.hasPositionCall()) return true;
|
||||
if (_right.hasPositionCall()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasLastCall() {
|
||||
if (_left.hasLastCall()) return true;
|
||||
if (_right.hasLastCall()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void swapArguments() {
|
||||
final Expression temp = _left;
|
||||
_left = _right;
|
||||
_right = temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Typing rules: see XSLT Reference by M. Kay page 345.
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
final Type tleft = _left.typeCheck(stable);
|
||||
final Type tright = _right.typeCheck(stable);
|
||||
|
||||
if (tleft.isSimple() && tright.isSimple()) {
|
||||
if (tleft != tright) {
|
||||
if (tleft instanceof BooleanType) {
|
||||
_right = new CastExpr(_right, Type.Boolean);
|
||||
}
|
||||
else if (tright instanceof BooleanType) {
|
||||
_left = new CastExpr(_left, Type.Boolean);
|
||||
}
|
||||
else if (tleft instanceof NumberType ||
|
||||
tright instanceof NumberType) {
|
||||
_left = new CastExpr(_left, Type.Real);
|
||||
_right = new CastExpr(_right, Type.Real);
|
||||
}
|
||||
else { // both compared as strings
|
||||
_left = new CastExpr(_left, Type.String);
|
||||
_right = new CastExpr(_right, Type.String);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tleft instanceof ReferenceType) {
|
||||
_right = new CastExpr(_right, Type.Reference);
|
||||
}
|
||||
else if (tright instanceof ReferenceType) {
|
||||
_left = new CastExpr(_left, Type.Reference);
|
||||
}
|
||||
// the following 2 cases optimize @attr|.|.. = 'string'
|
||||
else if (tleft instanceof NodeType && tright == Type.String) {
|
||||
_left = new CastExpr(_left, Type.String);
|
||||
}
|
||||
else if (tleft == Type.String && tright instanceof NodeType) {
|
||||
_right = new CastExpr(_right, Type.String);
|
||||
}
|
||||
// optimize node/node
|
||||
else if (tleft instanceof NodeType && tright instanceof NodeType) {
|
||||
_left = new CastExpr(_left, Type.String);
|
||||
_right = new CastExpr(_right, Type.String);
|
||||
}
|
||||
else if (tleft instanceof NodeType && tright instanceof NodeSetType) {
|
||||
// compare(Node, NodeSet) will be invoked
|
||||
}
|
||||
else if (tleft instanceof NodeSetType && tright instanceof NodeType) {
|
||||
swapArguments(); // for compare(Node, NodeSet)
|
||||
}
|
||||
else {
|
||||
// At least one argument is of type node, node-set or result-tree
|
||||
|
||||
// Promote an expression of type node to node-set
|
||||
if (tleft instanceof NodeType) {
|
||||
_left = new CastExpr(_left, Type.NodeSet);
|
||||
}
|
||||
if (tright instanceof NodeType) {
|
||||
_right = new CastExpr(_right, Type.NodeSet);
|
||||
}
|
||||
|
||||
// If one arg is a node-set then make it the left one
|
||||
if (tleft.isSimple() ||
|
||||
tleft instanceof ResultTreeType &&
|
||||
tright instanceof NodeSetType) {
|
||||
swapArguments();
|
||||
}
|
||||
|
||||
// Promote integers to doubles to have fewer compares
|
||||
if (_right.getType() instanceof IntType) {
|
||||
_right = new CastExpr(_right, Type.Real);
|
||||
}
|
||||
}
|
||||
return _type = Type.Boolean;
|
||||
}
|
||||
|
||||
public void translateDesynthesized(ClassGenerator classGen,
|
||||
MethodGenerator methodGen) {
|
||||
final Type tleft = _left.getType();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
if (tleft instanceof BooleanType) {
|
||||
_left.translate(classGen, methodGen);
|
||||
_right.translate(classGen, methodGen);
|
||||
_falseList.add(il.append(_op == Operators.EQ ?
|
||||
(BranchInstruction)new IF_ICMPNE(null) :
|
||||
(BranchInstruction)new IF_ICMPEQ(null)));
|
||||
}
|
||||
else if (tleft instanceof NumberType) {
|
||||
_left.translate(classGen, methodGen);
|
||||
_right.translate(classGen, methodGen);
|
||||
|
||||
if (tleft instanceof RealType) {
|
||||
il.append(DCMPG);
|
||||
_falseList.add(il.append(_op == Operators.EQ ?
|
||||
(BranchInstruction)new IFNE(null) :
|
||||
(BranchInstruction)new IFEQ(null)));
|
||||
}
|
||||
else {
|
||||
_falseList.add(il.append(_op == Operators.EQ ?
|
||||
(BranchInstruction)new IF_ICMPNE(null) :
|
||||
(BranchInstruction)new IF_ICMPEQ(null)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
translate(classGen, methodGen);
|
||||
desynthesize(classGen, methodGen);
|
||||
}
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
final Type tleft = _left.getType();
|
||||
Type tright = _right.getType();
|
||||
|
||||
if (tleft instanceof BooleanType || tleft instanceof NumberType) {
|
||||
translateDesynthesized(classGen, methodGen);
|
||||
synthesize(classGen, methodGen);
|
||||
return;
|
||||
}
|
||||
|
||||
if (tleft instanceof StringType) {
|
||||
final int equals = cpg.addMethodref(STRING_CLASS,
|
||||
"equals",
|
||||
"(" + OBJECT_SIG +")Z");
|
||||
_left.translate(classGen, methodGen);
|
||||
_right.translate(classGen, methodGen);
|
||||
il.append(new INVOKEVIRTUAL(equals));
|
||||
|
||||
if (_op == Operators.NE) {
|
||||
il.append(ICONST_1);
|
||||
il.append(IXOR); // not x <-> x xor 1
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
BranchHandle truec, falsec;
|
||||
|
||||
if (tleft instanceof ResultTreeType) {
|
||||
if (tright instanceof BooleanType) {
|
||||
_right.translate(classGen, methodGen);
|
||||
if (_op == Operators.NE) {
|
||||
il.append(ICONST_1);
|
||||
il.append(IXOR); // not x <-> x xor 1
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (tright instanceof RealType) {
|
||||
_left.translate(classGen, methodGen);
|
||||
tleft.translateTo(classGen, methodGen, Type.Real);
|
||||
_right.translate(classGen, methodGen);
|
||||
|
||||
il.append(DCMPG);
|
||||
falsec = il.append(_op == Operators.EQ ?
|
||||
(BranchInstruction) new IFNE(null) :
|
||||
(BranchInstruction) new IFEQ(null));
|
||||
il.append(ICONST_1);
|
||||
truec = il.append(new GOTO(null));
|
||||
falsec.setTarget(il.append(ICONST_0));
|
||||
truec.setTarget(il.append(NOP));
|
||||
return;
|
||||
}
|
||||
|
||||
// Next, result-tree/string and result-tree/result-tree comparisons
|
||||
|
||||
_left.translate(classGen, methodGen);
|
||||
tleft.translateTo(classGen, methodGen, Type.String);
|
||||
_right.translate(classGen, methodGen);
|
||||
|
||||
if (tright instanceof ResultTreeType) {
|
||||
tright.translateTo(classGen, methodGen, Type.String);
|
||||
}
|
||||
|
||||
final int equals = cpg.addMethodref(STRING_CLASS,
|
||||
"equals",
|
||||
"(" +OBJECT_SIG+ ")Z");
|
||||
il.append(new INVOKEVIRTUAL(equals));
|
||||
|
||||
if (_op == Operators.NE) {
|
||||
il.append(ICONST_1);
|
||||
il.append(IXOR); // not x <-> x xor 1
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (tleft instanceof NodeSetType && tright instanceof BooleanType) {
|
||||
_left.translate(classGen, methodGen);
|
||||
_left.startIterator(classGen, methodGen);
|
||||
Type.NodeSet.translateTo(classGen, methodGen, Type.Boolean);
|
||||
_right.translate(classGen, methodGen);
|
||||
|
||||
il.append(IXOR); // x != y <-> x xor y
|
||||
if (_op == Operators.EQ) {
|
||||
il.append(ICONST_1);
|
||||
il.append(IXOR); // not x <-> x xor 1
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (tleft instanceof NodeSetType && tright instanceof StringType) {
|
||||
_left.translate(classGen, methodGen);
|
||||
_left.startIterator(classGen, methodGen); // needed ?
|
||||
_right.translate(classGen, methodGen);
|
||||
il.append(new PUSH(cpg, _op));
|
||||
il.append(methodGen.loadDOM());
|
||||
final int cmp = cpg.addMethodref(BASIS_LIBRARY_CLASS,
|
||||
"compare",
|
||||
"("
|
||||
+ tleft.toSignature()
|
||||
+ tright.toSignature()
|
||||
+ "I"
|
||||
+ DOM_INTF_SIG
|
||||
+ ")Z");
|
||||
il.append(new INVOKESTATIC(cmp));
|
||||
return;
|
||||
}
|
||||
|
||||
// Next, node-set/t for t in {real, string, node-set, result-tree}
|
||||
_left.translate(classGen, methodGen);
|
||||
_left.startIterator(classGen, methodGen);
|
||||
_right.translate(classGen, methodGen);
|
||||
_right.startIterator(classGen, methodGen);
|
||||
|
||||
// Cast a result tree to a string to use an existing compare
|
||||
if (tright instanceof ResultTreeType) {
|
||||
tright.translateTo(classGen, methodGen, Type.String);
|
||||
tright = Type.String;
|
||||
}
|
||||
|
||||
// Call the appropriate compare() from the BasisLibrary
|
||||
il.append(new PUSH(cpg, _op));
|
||||
il.append(methodGen.loadDOM());
|
||||
|
||||
final int compare = cpg.addMethodref(BASIS_LIBRARY_CLASS,
|
||||
"compare",
|
||||
"("
|
||||
+ tleft.toSignature()
|
||||
+ tright.toSignature()
|
||||
+ "I"
|
||||
+ DOM_INTF_SIG
|
||||
+ ")Z");
|
||||
il.append(new INVOKESTATIC(compare));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.BranchHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.GOTO_W;
|
||||
import com.sun.org.apache.bcel.internal.generic.IFEQ;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.BooleanType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSetType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Morten Jorgensen
|
||||
* @author Erwin Bolwidt <ejb@klomp.org>
|
||||
*/
|
||||
abstract class Expression extends SyntaxTreeNode {
|
||||
/**
|
||||
* The type of this expression. It is set after calling
|
||||
* <code>typeCheck()</code>.
|
||||
*/
|
||||
protected Type _type;
|
||||
|
||||
/**
|
||||
* Instruction handles that comprise the true list.
|
||||
*/
|
||||
protected FlowList _trueList = new FlowList();
|
||||
|
||||
/**
|
||||
* Instruction handles that comprise the false list.
|
||||
*/
|
||||
protected FlowList _falseList = new FlowList();
|
||||
|
||||
public Type getType() {
|
||||
return _type;
|
||||
}
|
||||
|
||||
public abstract String toString();
|
||||
|
||||
public boolean hasPositionCall() {
|
||||
return false; // default should be 'false' for StepPattern
|
||||
}
|
||||
|
||||
public boolean hasLastCall() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object representing the compile-time evaluation
|
||||
* of an expression. We are only using this for function-available
|
||||
* and element-available at this time.
|
||||
*/
|
||||
public Object evaluateAtCompileTime() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type check all the children of this node.
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
return typeCheckContents(stable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate this node into JVM bytecodes.
|
||||
*/
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
ErrorMsg msg = new ErrorMsg(ErrorMsg.NOT_IMPLEMENTED_ERR,
|
||||
getClass(), this);
|
||||
getParser().reportError(FATAL, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate this node into a fresh instruction list.
|
||||
* The original instruction list is saved and restored.
|
||||
*/
|
||||
public final InstructionList compile(ClassGenerator classGen,
|
||||
MethodGenerator methodGen) {
|
||||
final InstructionList result, save = methodGen.getInstructionList();
|
||||
methodGen.setInstructionList(result = new InstructionList());
|
||||
translate(classGen, methodGen);
|
||||
methodGen.setInstructionList(save);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefined by expressions of type boolean that use flow lists.
|
||||
*/
|
||||
public void translateDesynthesized(ClassGenerator classGen,
|
||||
MethodGenerator methodGen) {
|
||||
translate(classGen, methodGen);
|
||||
if (_type instanceof BooleanType) {
|
||||
desynthesize(classGen, methodGen);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If this expression is of type node-set and it is not a variable
|
||||
* reference, then call setStartNode() passing the context node.
|
||||
*/
|
||||
public void startIterator(ClassGenerator classGen,
|
||||
MethodGenerator methodGen) {
|
||||
// Ignore if type is not node-set
|
||||
if (_type instanceof NodeSetType == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// setStartNode() should not be called if expr is a variable ref
|
||||
Expression expr = this;
|
||||
if (expr instanceof CastExpr) {
|
||||
expr = ((CastExpr) expr).getExpr();
|
||||
}
|
||||
if (expr instanceof VariableRefBase == false) {
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
il.append(methodGen.loadContextNode());
|
||||
il.append(methodGen.setStartNode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Synthesize a boolean expression, i.e., either push a 0 or 1 onto the
|
||||
* operand stack for the next statement to succeed. Returns the handle
|
||||
* of the instruction to be backpatched.
|
||||
*/
|
||||
public void synthesize(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
_trueList.backPatch(il.append(ICONST_1));
|
||||
final BranchHandle truec = il.append(new GOTO_W(null));
|
||||
_falseList.backPatch(il.append(ICONST_0));
|
||||
truec.setTarget(il.append(NOP));
|
||||
}
|
||||
|
||||
public void desynthesize(ClassGenerator classGen,
|
||||
MethodGenerator methodGen) {
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
_falseList.add(il.append(new IFEQ(null)));
|
||||
}
|
||||
|
||||
public FlowList getFalseList() {
|
||||
return _falseList;
|
||||
}
|
||||
|
||||
public FlowList getTrueList() {
|
||||
return _trueList;
|
||||
}
|
||||
|
||||
public void backPatchFalseList(InstructionHandle ih) {
|
||||
_falseList.backPatch(ih);
|
||||
}
|
||||
|
||||
public void backPatchTrueList(InstructionHandle ih) {
|
||||
_trueList.backPatch(ih);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a primop in the symbol table that matches the method type
|
||||
* <code>ctype</code>. Two methods match if they have the same arity.
|
||||
* If a primop is overloaded then the "closest match" is returned. The
|
||||
* first entry in the vector of primops that has the right arity is
|
||||
* considered to be the default one.
|
||||
*/
|
||||
public MethodType lookupPrimop(SymbolTable stable, String op,
|
||||
MethodType ctype) {
|
||||
MethodType result = null;
|
||||
final Vector primop = stable.lookupPrimop(op);
|
||||
if (primop != null) {
|
||||
final int n = primop.size();
|
||||
int minDistance = Integer.MAX_VALUE;
|
||||
for (int i = 0; i < n; i++) {
|
||||
final MethodType ptype = (MethodType) primop.elementAt(i);
|
||||
// Skip if different arity
|
||||
if (ptype.argsCount() != ctype.argsCount()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// The first method with the right arity is the default
|
||||
if (result == null) {
|
||||
result = ptype; // default method
|
||||
}
|
||||
|
||||
// Check if better than last one found
|
||||
final int distance = ctype.distanceTo(ptype);
|
||||
if (distance < minDistance) {
|
||||
minDistance = distance;
|
||||
result = ptype;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
final class Fallback extends Instruction {
|
||||
|
||||
private boolean _active = false;
|
||||
|
||||
/**
|
||||
* This element never produces any data on the stack
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
if (_active) {
|
||||
return(typeCheckContents(stable));
|
||||
}
|
||||
else {
|
||||
return Type.Void;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate this fallback element
|
||||
*/
|
||||
public void activate() {
|
||||
_active = true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return("fallback");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse contents only if this fallback element is put in place of
|
||||
* some unsupported element or non-XSLTC extension element
|
||||
*/
|
||||
public void parseContents(Parser parser) {
|
||||
if (_active) parseChildren(parser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate contents only if this fallback element is put in place of
|
||||
* some unsupported element or non-XSLTC extension element
|
||||
*/
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
if (_active) translateContents(classGen, methodGen);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ALOAD;
|
||||
import com.sun.org.apache.bcel.internal.generic.ASTORE;
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.ILOAD;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.ISTORE;
|
||||
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSetType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ReferenceType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
class FilterExpr extends Expression {
|
||||
|
||||
/**
|
||||
* Primary expression of this filter. I.e., 'e' in '(e)[p1]...[pn]'.
|
||||
*/
|
||||
private Expression _primary;
|
||||
|
||||
/**
|
||||
* Array of predicates in '(e)[p1]...[pn]'.
|
||||
*/
|
||||
private final Vector _predicates;
|
||||
|
||||
public FilterExpr(Expression primary, Vector predicates) {
|
||||
_primary = primary;
|
||||
_predicates = predicates;
|
||||
primary.setParent(this);
|
||||
}
|
||||
|
||||
protected Expression getExpr() {
|
||||
if (_primary instanceof CastExpr)
|
||||
return ((CastExpr)_primary).getExpr();
|
||||
else
|
||||
return _primary;
|
||||
}
|
||||
|
||||
public void setParser(Parser parser) {
|
||||
super.setParser(parser);
|
||||
_primary.setParser(parser);
|
||||
if (_predicates != null) {
|
||||
final int n = _predicates.size();
|
||||
for (int i = 0; i < n; i++) {
|
||||
final Expression exp = (Expression)_predicates.elementAt(i);
|
||||
exp.setParser(parser);
|
||||
exp.setParent(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "filter-expr(" + _primary + ", " + _predicates + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Type check a FilterParentPath. If the filter is not a node-set add a
|
||||
* cast to node-set only if it is of reference type. This type coercion
|
||||
* is needed for expressions like $x where $x is a parameter reference.
|
||||
* All optimizations are turned off before type checking underlying
|
||||
* predicates.
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
Type ptype = _primary.typeCheck(stable);
|
||||
boolean canOptimize = _primary instanceof KeyCall;
|
||||
|
||||
if (ptype instanceof NodeSetType == false) {
|
||||
if (ptype instanceof ReferenceType) {
|
||||
_primary = new CastExpr(_primary, Type.NodeSet);
|
||||
}
|
||||
else {
|
||||
throw new TypeCheckError(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Type check predicates and turn all optimizations off if appropriate
|
||||
int n = _predicates.size();
|
||||
for (int i = 0; i < n; i++) {
|
||||
Predicate pred = (Predicate) _predicates.elementAt(i);
|
||||
|
||||
if (!canOptimize) {
|
||||
pred.dontOptimize();
|
||||
}
|
||||
pred.typeCheck(stable);
|
||||
}
|
||||
return _type = Type.NodeSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a filter expression by pushing the appropriate iterator
|
||||
* onto the stack.
|
||||
*/
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
translateFilterExpr(classGen, methodGen, _predicates == null ? -1 : _predicates.size() - 1);
|
||||
}
|
||||
|
||||
private void translateFilterExpr(ClassGenerator classGen,
|
||||
MethodGenerator methodGen,
|
||||
int predicateIndex) {
|
||||
if (predicateIndex >= 0) {
|
||||
translatePredicates(classGen, methodGen, predicateIndex);
|
||||
}
|
||||
else {
|
||||
_primary.translate(classGen, methodGen);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a sequence of predicates. Each predicate is translated
|
||||
* by constructing an instance of <code>CurrentNodeListIterator</code>
|
||||
* which is initialized from another iterator (recursive call), a
|
||||
* filter and a closure (call to translate on the predicate) and "this".
|
||||
*/
|
||||
public void translatePredicates(ClassGenerator classGen,
|
||||
MethodGenerator methodGen,
|
||||
int predicateIndex) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
// If not predicates left, translate primary expression
|
||||
if (predicateIndex < 0) {
|
||||
translateFilterExpr(classGen, methodGen, predicateIndex);
|
||||
}
|
||||
else {
|
||||
// Get the next predicate to be translated
|
||||
Predicate predicate = (Predicate) _predicates.get(predicateIndex--);
|
||||
|
||||
// Translate the rest of the predicates from right to left
|
||||
translatePredicates(classGen, methodGen, predicateIndex);
|
||||
|
||||
if (predicate.isNthPositionFilter()) {
|
||||
int nthIteratorIdx = cpg.addMethodref(NTH_ITERATOR_CLASS,
|
||||
"<init>",
|
||||
"("+NODE_ITERATOR_SIG+"I)V");
|
||||
|
||||
// Backwards branches are prohibited if an uninitialized object
|
||||
// is on the stack by section 4.9.4 of the JVM Specification,
|
||||
// 2nd Ed. We don't know whether this code might contain
|
||||
// backwards branches, so we mustn't create the new object unti
|
||||
|
||||
// after we've created the suspect arguments to its constructor
|
||||
|
||||
// Instead we calculate the values of the arguments to the
|
||||
// constructor first, store them in temporary variables, create
|
||||
// the object and reload the arguments from the temporaries to
|
||||
// avoid the problem.
|
||||
LocalVariableGen iteratorTemp
|
||||
= methodGen.addLocalVariable("filter_expr_tmp1",
|
||||
Util.getJCRefType(NODE_ITERATOR_SIG),
|
||||
null, null);
|
||||
iteratorTemp.setStart(
|
||||
il.append(new ASTORE(iteratorTemp.getIndex())));
|
||||
|
||||
predicate.translate(classGen, methodGen);
|
||||
LocalVariableGen predicateValueTemp
|
||||
= methodGen.addLocalVariable("filter_expr_tmp2",
|
||||
Util.getJCRefType("I"),
|
||||
null, null);
|
||||
predicateValueTemp.setStart(
|
||||
il.append(new ISTORE(predicateValueTemp.getIndex())));
|
||||
|
||||
il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS)));
|
||||
il.append(DUP);
|
||||
iteratorTemp.setEnd(
|
||||
il.append(new ALOAD(iteratorTemp.getIndex())));
|
||||
predicateValueTemp.setEnd(
|
||||
il.append(new ILOAD(predicateValueTemp.getIndex())));
|
||||
il.append(new INVOKESPECIAL(nthIteratorIdx));
|
||||
} else {
|
||||
// Translate predicates from right to left
|
||||
final int initCNLI = cpg.addMethodref(CURRENT_NODE_LIST_ITERATOR,
|
||||
"<init>",
|
||||
"("+NODE_ITERATOR_SIG+"Z"+
|
||||
CURRENT_NODE_LIST_FILTER_SIG +
|
||||
NODE_SIG+TRANSLET_SIG+")V");
|
||||
|
||||
// Backwards branches are prohibited if an uninitialized object is
|
||||
// on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
|
||||
// We don't know whether this code might contain backwards branches,
|
||||
// so we mustn't create the new object until after we've created
|
||||
// the suspect arguments to its constructor. Instead we calculate
|
||||
// the values of the arguments to the constructor first, store them
|
||||
// in temporary variables, create the object and reload the
|
||||
// arguments from the temporaries to avoid the problem.
|
||||
|
||||
|
||||
LocalVariableGen nodeIteratorTemp =
|
||||
methodGen.addLocalVariable("filter_expr_tmp1",
|
||||
Util.getJCRefType(NODE_ITERATOR_SIG),
|
||||
null, null);
|
||||
nodeIteratorTemp.setStart(
|
||||
il.append(new ASTORE(nodeIteratorTemp.getIndex())));
|
||||
|
||||
predicate.translate(classGen, methodGen);
|
||||
LocalVariableGen filterTemp =
|
||||
methodGen.addLocalVariable("filter_expr_tmp2",
|
||||
Util.getJCRefType(CURRENT_NODE_LIST_FILTER_SIG),
|
||||
null, null);
|
||||
filterTemp.setStart(il.append(new ASTORE(filterTemp.getIndex())));
|
||||
|
||||
// Create a CurrentNodeListIterator
|
||||
il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));
|
||||
il.append(DUP);
|
||||
|
||||
// Initialize CurrentNodeListIterator
|
||||
nodeIteratorTemp.setEnd(
|
||||
il.append(new ALOAD(nodeIteratorTemp.getIndex())));
|
||||
il.append(ICONST_1);
|
||||
filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
|
||||
il.append(methodGen.loadCurrentNode());
|
||||
il.append(classGen.loadTranslet());
|
||||
il.append(new INVOKESPECIAL(initCNLI));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ALOAD;
|
||||
import com.sun.org.apache.bcel.internal.generic.ASTORE;
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSetType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ReferenceType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class FilterParentPath extends Expression {
|
||||
|
||||
private Expression _filterExpr;
|
||||
private Expression _path;
|
||||
private boolean _hasDescendantAxis = false;
|
||||
|
||||
public FilterParentPath(Expression filterExpr, Expression path) {
|
||||
(_path = path).setParent(this);
|
||||
(_filterExpr = filterExpr).setParent(this);
|
||||
}
|
||||
|
||||
public void setParser(Parser parser) {
|
||||
super.setParser(parser);
|
||||
_filterExpr.setParser(parser);
|
||||
_path.setParser(parser);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "FilterParentPath(" + _filterExpr + ", " + _path + ')';
|
||||
}
|
||||
|
||||
public void setDescendantAxis() {
|
||||
_hasDescendantAxis = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type check a FilterParentPath. If the filter is not a node-set add a
|
||||
* cast to node-set only if it is of reference type. This type coercion is
|
||||
* needed for expressions like $x/LINE where $x is a parameter reference.
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
final Type ftype = _filterExpr.typeCheck(stable);
|
||||
if (ftype instanceof NodeSetType == false) {
|
||||
if (ftype instanceof ReferenceType) {
|
||||
_filterExpr = new CastExpr(_filterExpr, Type.NodeSet);
|
||||
}
|
||||
/*
|
||||
else if (ftype instanceof ResultTreeType) {
|
||||
_filterExpr = new CastExpr(_filterExpr, Type.NodeSet);
|
||||
}
|
||||
*/
|
||||
else if (ftype instanceof NodeType) {
|
||||
_filterExpr = new CastExpr(_filterExpr, Type.NodeSet);
|
||||
}
|
||||
else {
|
||||
throw new TypeCheckError(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Wrap single node path in a node set
|
||||
final Type ptype = _path.typeCheck(stable);
|
||||
if (!(ptype instanceof NodeSetType)) {
|
||||
_path = new CastExpr(_path, Type.NodeSet);
|
||||
}
|
||||
|
||||
return _type = Type.NodeSet;
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
// Create new StepIterator
|
||||
final int initSI = cpg.addMethodref(STEP_ITERATOR_CLASS,
|
||||
"<init>",
|
||||
"("
|
||||
+NODE_ITERATOR_SIG
|
||||
+NODE_ITERATOR_SIG
|
||||
+")V");
|
||||
|
||||
// Backwards branches are prohibited if an uninitialized object is
|
||||
// on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
|
||||
// We don't know whether this code might contain backwards branches,
|
||||
// so we mustn't create the new object until after we've created
|
||||
// the suspect arguments to its constructor. Instead we calculate
|
||||
// the values of the arguments to the constructor first, store them
|
||||
// in temporary variables, create the object and reload the
|
||||
// arguments from the temporaries to avoid the problem.
|
||||
|
||||
// Recursively compile 2 iterators
|
||||
_filterExpr.translate(classGen, methodGen);
|
||||
LocalVariableGen filterTemp =
|
||||
methodGen.addLocalVariable("filter_parent_path_tmp1",
|
||||
Util.getJCRefType(NODE_ITERATOR_SIG),
|
||||
null, null);
|
||||
filterTemp.setStart(il.append(new ASTORE(filterTemp.getIndex())));
|
||||
|
||||
_path.translate(classGen, methodGen);
|
||||
LocalVariableGen pathTemp =
|
||||
methodGen.addLocalVariable("filter_parent_path_tmp2",
|
||||
Util.getJCRefType(NODE_ITERATOR_SIG),
|
||||
null, null);
|
||||
pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));
|
||||
|
||||
il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
|
||||
il.append(DUP);
|
||||
filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
|
||||
pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
|
||||
|
||||
// Initialize StepIterator with iterators from the stack
|
||||
il.append(new INVOKESPECIAL(initSI));
|
||||
|
||||
// This is a special case for the //* path with or without predicates
|
||||
if (_hasDescendantAxis) {
|
||||
final int incl = cpg.addMethodref(NODE_ITERATOR_BASE,
|
||||
"includeSelf",
|
||||
"()" + NODE_ITERATOR_SIG);
|
||||
il.append(new INVOKEVIRTUAL(incl));
|
||||
}
|
||||
|
||||
SyntaxTreeNode parent = getParent();
|
||||
|
||||
boolean parentAlreadyOrdered =
|
||||
(parent instanceof RelativeLocationPath)
|
||||
|| (parent instanceof FilterParentPath)
|
||||
|| (parent instanceof KeyCall)
|
||||
|| (parent instanceof CurrentCall)
|
||||
|| (parent instanceof DocumentCall);
|
||||
|
||||
if (!parentAlreadyOrdered) {
|
||||
final int order = cpg.addInterfaceMethodref(DOM_INTF,
|
||||
ORDER_ITERATOR,
|
||||
ORDER_ITERATOR_SIG);
|
||||
il.append(methodGen.loadDOM());
|
||||
il.append(SWAP);
|
||||
il.append(methodGen.loadContextNode());
|
||||
il.append(new INVOKEINTERFACE(order, 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ALOAD;
|
||||
import com.sun.org.apache.bcel.internal.generic.ASTORE;
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
|
||||
/**
|
||||
* @author G. Todd Miller
|
||||
*/
|
||||
final class FilteredAbsoluteLocationPath extends Expression {
|
||||
private Expression _path; // may be null
|
||||
|
||||
public FilteredAbsoluteLocationPath() {
|
||||
_path = null;
|
||||
}
|
||||
|
||||
public FilteredAbsoluteLocationPath(Expression path) {
|
||||
_path = path;
|
||||
if (path != null) {
|
||||
_path.setParent(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void setParser(Parser parser) {
|
||||
super.setParser(parser);
|
||||
if (_path != null) {
|
||||
_path.setParser(parser);
|
||||
}
|
||||
}
|
||||
|
||||
public Expression getPath() {
|
||||
return(_path);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "FilteredAbsoluteLocationPath(" +
|
||||
(_path != null ? _path.toString() : "null") + ')';
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
if (_path != null) {
|
||||
final Type ptype = _path.typeCheck(stable);
|
||||
if (ptype instanceof NodeType) { // promote to node-set
|
||||
_path = new CastExpr(_path, Type.NodeSet);
|
||||
}
|
||||
}
|
||||
return _type = Type.NodeSet;
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
if (_path != null) {
|
||||
final int initDFI = cpg.addMethodref(DUP_FILTERED_ITERATOR,
|
||||
"<init>",
|
||||
"("
|
||||
+ NODE_ITERATOR_SIG
|
||||
+ ")V");
|
||||
|
||||
// Backwards branches are prohibited if an uninitialized object is
|
||||
// on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
|
||||
// We don't know whether this code might contain backwards branches,
|
||||
// so we mustn't create the new object until after we've created
|
||||
// the suspect arguments to its constructor. Instead we calculate
|
||||
// the values of the arguments to the constructor first, store them
|
||||
// in temporary variables, create the object and reload the
|
||||
// arguments from the temporaries to avoid the problem.
|
||||
|
||||
// Compile relative path iterator(s)
|
||||
LocalVariableGen pathTemp =
|
||||
methodGen.addLocalVariable("filtered_absolute_location_path_tmp",
|
||||
Util.getJCRefType(NODE_ITERATOR_SIG),
|
||||
null, null);
|
||||
_path.translate(classGen, methodGen);
|
||||
pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));
|
||||
|
||||
// Create new Dup Filter Iterator
|
||||
il.append(new NEW(cpg.addClass(DUP_FILTERED_ITERATOR)));
|
||||
il.append(DUP);
|
||||
pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
|
||||
|
||||
// Initialize Dup Filter Iterator with iterator from the stack
|
||||
il.append(new INVOKESPECIAL(initDFI));
|
||||
}
|
||||
else {
|
||||
final int git = cpg.addInterfaceMethodref(DOM_INTF,
|
||||
"getIterator",
|
||||
"()"+NODE_ITERATOR_SIG);
|
||||
il.append(methodGen.loadDOM());
|
||||
il.append(new INVOKEINTERFACE(git, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class FloorCall extends FunctionCall {
|
||||
public FloorCall(QName fname, Vector arguments) {
|
||||
super(fname, arguments);
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
argument().translate(classGen, methodGen);
|
||||
methodGen.getInstructionList()
|
||||
.append(new INVOKESTATIC(classGen.getConstantPool()
|
||||
.addMethodref(MATH_CLASS,
|
||||
"floor", "(D)D")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.BranchHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
public final class FlowList {
|
||||
private Vector _elements;
|
||||
|
||||
public FlowList() {
|
||||
_elements = null;
|
||||
}
|
||||
|
||||
public FlowList(InstructionHandle bh) {
|
||||
_elements = new Vector();
|
||||
_elements.addElement(bh);
|
||||
}
|
||||
|
||||
public FlowList(FlowList list) {
|
||||
_elements = list._elements;
|
||||
}
|
||||
|
||||
public FlowList add(InstructionHandle bh) {
|
||||
if (_elements == null) {
|
||||
_elements = new Vector();
|
||||
}
|
||||
_elements.addElement(bh);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FlowList append(FlowList right) {
|
||||
if (_elements == null) {
|
||||
_elements = right._elements;
|
||||
}
|
||||
else {
|
||||
final Vector temp = right._elements;
|
||||
if (temp != null) {
|
||||
final int n = temp.size();
|
||||
for (int i = 0; i < n; i++) {
|
||||
_elements.addElement(temp.elementAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Back patch a flow list. All instruction handles must be branch handles.
|
||||
*/
|
||||
public void backPatch(InstructionHandle target) {
|
||||
if (_elements != null) {
|
||||
final int n = _elements.size();
|
||||
for (int i = 0; i < n; i++) {
|
||||
BranchHandle bh = (BranchHandle)_elements.elementAt(i);
|
||||
bh.setTarget(target);
|
||||
}
|
||||
_elements.clear(); // avoid backpatching more than once
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect the handles from oldList to newList. "This" flow list
|
||||
* is assumed to be relative to oldList.
|
||||
*/
|
||||
public FlowList copyAndRedirect(InstructionList oldList,
|
||||
InstructionList newList)
|
||||
{
|
||||
final FlowList result = new FlowList();
|
||||
if (_elements == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
final int n = _elements.size();
|
||||
final Iterator oldIter = oldList.iterator();
|
||||
final Iterator newIter = newList.iterator();
|
||||
|
||||
while (oldIter.hasNext()) {
|
||||
final InstructionHandle oldIh = (InstructionHandle) oldIter.next();
|
||||
final InstructionHandle newIh = (InstructionHandle) newIter.next();
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (_elements.elementAt(i) == oldIh) {
|
||||
result.add(newIh);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
/*
|
||||
* $Id: ForEach.java,v 1.2.4.1 2005/09/01 15:23:46 pvedula Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.BranchHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.GOTO;
|
||||
import com.sun.org.apache.bcel.internal.generic.IFGT;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSetType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ReferenceType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ResultTreeType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
final class ForEach extends Instruction {
|
||||
|
||||
private Expression _select;
|
||||
private Type _type;
|
||||
|
||||
public void display(int indent) {
|
||||
indent(indent);
|
||||
Util.println("ForEach");
|
||||
indent(indent + IndentIncrement);
|
||||
Util.println("select " + _select.toString());
|
||||
displayContents(indent + IndentIncrement);
|
||||
}
|
||||
|
||||
public void parseContents(Parser parser) {
|
||||
_select = parser.parseExpression(this, "select", null);
|
||||
|
||||
parseChildren(parser);
|
||||
|
||||
// make sure required attribute(s) have been set
|
||||
if (_select.isDummy()) {
|
||||
reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "select");
|
||||
}
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
_type = _select.typeCheck(stable);
|
||||
|
||||
if (_type instanceof ReferenceType || _type instanceof NodeType) {
|
||||
_select = new CastExpr(_select, Type.NodeSet);
|
||||
typeCheckContents(stable);
|
||||
return Type.Void;
|
||||
}
|
||||
if (_type instanceof NodeSetType||_type instanceof ResultTreeType) {
|
||||
typeCheckContents(stable);
|
||||
return Type.Void;
|
||||
}
|
||||
throw new TypeCheckError(this);
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
// Save current node and current iterator on the stack
|
||||
il.append(methodGen.loadCurrentNode());
|
||||
il.append(methodGen.loadIterator());
|
||||
|
||||
// Collect sort objects associated with this instruction
|
||||
final Vector sortObjects = new Vector();
|
||||
Iterator<SyntaxTreeNode> children = elements();
|
||||
while (children.hasNext()) {
|
||||
final SyntaxTreeNode child = children.next();
|
||||
if (child instanceof Sort) {
|
||||
sortObjects.addElement(child);
|
||||
}
|
||||
}
|
||||
|
||||
if ((_type != null) && (_type instanceof ResultTreeType)) {
|
||||
// Store existing DOM on stack - must be restored when loop is done
|
||||
il.append(methodGen.loadDOM());
|
||||
|
||||
// <xsl:sort> cannot be applied to a result tree - issue warning
|
||||
if (sortObjects.size() > 0) {
|
||||
ErrorMsg msg = new ErrorMsg(ErrorMsg.RESULT_TREE_SORT_ERR,this);
|
||||
getParser().reportError(WARNING, msg);
|
||||
}
|
||||
|
||||
// Put the result tree on the stack (DOM)
|
||||
_select.translate(classGen, methodGen);
|
||||
// Get an iterator for the whole DOM - excluding the root node
|
||||
_type.translateTo(classGen, methodGen, Type.NodeSet);
|
||||
// Store the result tree as the default DOM
|
||||
il.append(SWAP);
|
||||
il.append(methodGen.storeDOM());
|
||||
}
|
||||
else {
|
||||
// Compile node iterator
|
||||
if (sortObjects.size() > 0) {
|
||||
Sort.translateSortIterator(classGen, methodGen,
|
||||
_select, sortObjects);
|
||||
}
|
||||
else {
|
||||
_select.translate(classGen, methodGen);
|
||||
}
|
||||
|
||||
if (_type instanceof ReferenceType == false) {
|
||||
il.append(methodGen.loadContextNode());
|
||||
il.append(methodGen.setStartNode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Overwrite current iterator
|
||||
il.append(methodGen.storeIterator());
|
||||
|
||||
// Give local variables (if any) default values before starting loop
|
||||
initializeVariables(classGen, methodGen);
|
||||
|
||||
final BranchHandle nextNode = il.append(new GOTO(null));
|
||||
final InstructionHandle loop = il.append(NOP);
|
||||
|
||||
translateContents(classGen, methodGen);
|
||||
|
||||
nextNode.setTarget(il.append(methodGen.loadIterator()));
|
||||
il.append(methodGen.nextNode());
|
||||
il.append(DUP);
|
||||
il.append(methodGen.storeCurrentNode());
|
||||
il.append(new IFGT(loop));
|
||||
|
||||
// Restore current DOM (if result tree was used instead for this loop)
|
||||
if ((_type != null) && (_type instanceof ResultTreeType)) {
|
||||
il.append(methodGen.storeDOM());
|
||||
}
|
||||
|
||||
// Restore current node and current iterator from the stack
|
||||
il.append(methodGen.storeIterator());
|
||||
il.append(methodGen.storeCurrentNode());
|
||||
}
|
||||
|
||||
/**
|
||||
* The code that is generated by nested for-each loops can appear to some
|
||||
* JVMs as if it is accessing un-initialized variables. We must add some
|
||||
* code that pushes the default variable value on the stack and pops it
|
||||
* into the variable slot. This is done by the Variable.initialize()
|
||||
* method. The code that we compile for this loop looks like this:
|
||||
*
|
||||
* initialize iterator
|
||||
* initialize variables <-- HERE!!!
|
||||
* goto Iterate
|
||||
* Loop: :
|
||||
* : (code for <xsl:for-each> contents)
|
||||
* :
|
||||
* Iterate: node = iterator.next();
|
||||
* if (node != END) goto Loop
|
||||
*/
|
||||
public void initializeVariables(ClassGenerator classGen,
|
||||
MethodGenerator methodGen) {
|
||||
final int n = elementCount();
|
||||
for (int i = 0; i < n; i++) {
|
||||
final SyntaxTreeNode child = getContents().get(i);
|
||||
if (child instanceof Variable) {
|
||||
Variable var = (Variable)child;
|
||||
var.initialize(classGen, methodGen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.PUSH;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.RealType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.StringType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
final class FormatNumberCall extends FunctionCall {
|
||||
private Expression _value;
|
||||
private Expression _format;
|
||||
private Expression _name;
|
||||
private QName _resolvedQName = null;
|
||||
|
||||
public FormatNumberCall(QName fname, Vector arguments) {
|
||||
super(fname, arguments);
|
||||
_value = argument(0);
|
||||
_format = argument(1);
|
||||
_name = argumentCount() == 3 ? argument(2) : null;
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
|
||||
// Inform stylesheet to instantiate a DecimalFormat object
|
||||
getStylesheet().numberFormattingUsed();
|
||||
|
||||
final Type tvalue = _value.typeCheck(stable);
|
||||
if (tvalue instanceof RealType == false) {
|
||||
_value = new CastExpr(_value, Type.Real);
|
||||
}
|
||||
final Type tformat = _format.typeCheck(stable);
|
||||
if (tformat instanceof StringType == false) {
|
||||
_format = new CastExpr(_format, Type.String);
|
||||
}
|
||||
if (argumentCount() == 3) {
|
||||
final Type tname = _name.typeCheck(stable);
|
||||
|
||||
if (_name instanceof LiteralExpr) {
|
||||
final LiteralExpr literal = (LiteralExpr) _name;
|
||||
_resolvedQName =
|
||||
getParser().getQNameIgnoreDefaultNs(literal.getValue());
|
||||
}
|
||||
else if (tname instanceof StringType == false) {
|
||||
_name = new CastExpr(_name, Type.String);
|
||||
}
|
||||
}
|
||||
return _type = Type.String;
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
_value.translate(classGen, methodGen);
|
||||
_format.translate(classGen, methodGen);
|
||||
|
||||
final int fn3arg = cpg.addMethodref(BASIS_LIBRARY_CLASS,
|
||||
"formatNumber",
|
||||
"(DLjava/lang/String;"+
|
||||
"Ljava/text/DecimalFormat;)"+
|
||||
"Ljava/lang/String;");
|
||||
final int get = cpg.addMethodref(TRANSLET_CLASS,
|
||||
"getDecimalFormat",
|
||||
"(Ljava/lang/String;)"+
|
||||
"Ljava/text/DecimalFormat;");
|
||||
|
||||
il.append(classGen.loadTranslet());
|
||||
if (_name == null) {
|
||||
il.append(new PUSH(cpg, EMPTYSTRING));
|
||||
}
|
||||
else if (_resolvedQName != null) {
|
||||
il.append(new PUSH(cpg, _resolvedQName.toString()));
|
||||
}
|
||||
else {
|
||||
_name.translate(classGen, methodGen);
|
||||
}
|
||||
il.append(new INVOKEVIRTUAL(get));
|
||||
il.append(new INVOKESTATIC(fn3arg));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.PUSH;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
|
||||
|
||||
/**
|
||||
* @author G. Todd Miller
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class FunctionAvailableCall extends FunctionCall {
|
||||
|
||||
private Expression _arg;
|
||||
private String _nameOfFunct = null;
|
||||
private String _namespaceOfFunct = null;
|
||||
private boolean _isFunctionAvailable = false;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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 (!isInternalNamespace()) {
|
||||
_isFunctionAvailable = hasMethods();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (_type != null) {
|
||||
return _type;
|
||||
}
|
||||
if (_arg instanceof LiteralExpr) {
|
||||
return _type = Type.Boolean;
|
||||
}
|
||||
ErrorMsg err = new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR,
|
||||
"function-available", this);
|
||||
throw new TypeCheckError(err);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object representing the compile-time evaluation
|
||||
* of an expression. We are only using this for function-available
|
||||
* and element-available at this time.
|
||||
*/
|
||||
public Object evaluateAtCompileTime() {
|
||||
return getResult() ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* for external java functions only: reports on whether or not
|
||||
* the specified method is found in the specifed class.
|
||||
*/
|
||||
private boolean hasMethods() {
|
||||
|
||||
// Get the class name from the namespace uri
|
||||
String className = getClassNameFromUri(_namespaceOfFunct);
|
||||
|
||||
// Get the method name from the argument to function-available
|
||||
String methodName = null;
|
||||
int colonIndex = _nameOfFunct.indexOf(':');
|
||||
if (colonIndex > 0) {
|
||||
String functionName = _nameOfFunct.substring(colonIndex+1);
|
||||
int lastDotIndex = functionName.lastIndexOf('.');
|
||||
if (lastDotIndex > 0) {
|
||||
methodName = functionName.substring(lastDotIndex+1);
|
||||
if (className != null && className.length() != 0)
|
||||
className = className + "." + functionName.substring(0, lastDotIndex);
|
||||
else
|
||||
className = functionName.substring(0, lastDotIndex);
|
||||
}
|
||||
else
|
||||
methodName = functionName;
|
||||
}
|
||||
else
|
||||
methodName = _nameOfFunct;
|
||||
|
||||
if (className == null || methodName == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Replace the '-' characters in the method name
|
||||
if (methodName.indexOf('-') > 0)
|
||||
methodName = replaceDash(methodName);
|
||||
|
||||
try {
|
||||
final Class clazz = ObjectFactory.findProviderClass(className, true);
|
||||
|
||||
if (clazz == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Method[] methods = clazz.getMethods();
|
||||
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports on whether the function specified in the argument to
|
||||
* xslt function 'function-available' was found.
|
||||
*/
|
||||
public boolean getResult() {
|
||||
if (_nameOfFunct == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isInternalNamespace()) {
|
||||
final Parser parser = getParser();
|
||||
_isFunctionAvailable =
|
||||
parser.functionSupported(Util.getLocalName(_nameOfFunct));
|
||||
}
|
||||
return _isFunctionAvailable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the namespace uri is null or it is the XSLTC translet uri.
|
||||
*/
|
||||
private boolean isInternalNamespace() {
|
||||
return (_namespaceOfFunct == null ||
|
||||
_namespaceOfFunct.equals(EMPTYSTRING) ||
|
||||
_namespaceOfFunct.equals(TRANSLET_URI));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls to 'function-available' are resolved at compile time since
|
||||
* the namespaces declared in the stylsheet are not available at run
|
||||
* time. Consequently, arguments to this function must be literals.
|
||||
*/
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
methodGen.getInstructionList().append(new PUSH(cpg, getResult()));
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class GenerateIdCall extends FunctionCall {
|
||||
public GenerateIdCall(QName fname, Vector arguments) {
|
||||
super(fname, arguments);
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
if (argumentCount() == 0) {
|
||||
il.append(methodGen.loadContextNode());
|
||||
}
|
||||
else { // one argument
|
||||
argument().translate(classGen, methodGen);
|
||||
}
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS,
|
||||
"generate_idF",
|
||||
// reuse signature
|
||||
GET_NODE_NAME_SIG)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.GOTO;
|
||||
import com.sun.org.apache.bcel.internal.generic.IFNE;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.PUSH;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
abstract class IdKeyPattern extends LocationPathPattern {
|
||||
|
||||
protected RelativePathPattern _left = null;;
|
||||
private String _index = null;
|
||||
private String _value = null;;
|
||||
|
||||
public IdKeyPattern(String index, String value) {
|
||||
_index = index;
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public String getIndexName() {
|
||||
return(_index);
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
return Type.NodeSet;
|
||||
}
|
||||
|
||||
public boolean isWildcard() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setLeft(RelativePathPattern left) {
|
||||
_left = left;
|
||||
}
|
||||
|
||||
public StepPattern getKernelPattern() {
|
||||
return(null);
|
||||
}
|
||||
|
||||
public void reduceKernelPattern() { }
|
||||
|
||||
public String toString() {
|
||||
return "id/keyPattern(" + _index + ", " + _value + ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the constructor is compiled in
|
||||
* Stylesheet.compileConstructor() and not as the syntax tree is traversed.
|
||||
*/
|
||||
public void translate(ClassGenerator classGen,
|
||||
MethodGenerator methodGen) {
|
||||
|
||||
final ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
|
||||
// Returns the KeyIndex object of a given name
|
||||
final int getKeyIndex = cpg.addMethodref(TRANSLET_CLASS,
|
||||
"getKeyIndex",
|
||||
"(Ljava/lang/String;)"+
|
||||
KEY_INDEX_SIG);
|
||||
|
||||
// Initialises a KeyIndex to return nodes with specific values
|
||||
final int lookupId = cpg.addMethodref(KEY_INDEX_CLASS,
|
||||
"containsID",
|
||||
"(ILjava/lang/Object;)I");
|
||||
final int lookupKey = cpg.addMethodref(KEY_INDEX_CLASS,
|
||||
"containsKey",
|
||||
"(ILjava/lang/Object;)I");
|
||||
final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF,
|
||||
"getNodeIdent",
|
||||
"(I)"+NODE_SIG);
|
||||
|
||||
// Call getKeyIndex in AbstractTranslet with the name of the key
|
||||
// to get the index for this key (which is also a node iterator).
|
||||
il.append(classGen.loadTranslet());
|
||||
il.append(new PUSH(cpg,_index));
|
||||
il.append(new INVOKEVIRTUAL(getKeyIndex));
|
||||
|
||||
// Now use the value in the second argument to determine what nodes
|
||||
// the iterator should return.
|
||||
il.append(SWAP);
|
||||
il.append(new PUSH(cpg,_value));
|
||||
if (this instanceof IdPattern)
|
||||
{
|
||||
il.append(new INVOKEVIRTUAL(lookupId));
|
||||
}
|
||||
else
|
||||
{
|
||||
il.append(new INVOKEVIRTUAL(lookupKey));
|
||||
}
|
||||
|
||||
_trueList.add(il.append(new IFNE(null)));
|
||||
_falseList.add(il.append(new GOTO(null)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class IdPattern extends IdKeyPattern {
|
||||
|
||||
public IdPattern(String id) {
|
||||
super("##id",id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.BooleanType;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
* @author Morten Jorgensen
|
||||
*/
|
||||
final class If extends Instruction {
|
||||
|
||||
private Expression _test;
|
||||
private boolean _ignore = false;
|
||||
|
||||
/**
|
||||
* Display the contents of this element
|
||||
*/
|
||||
public void display(int indent) {
|
||||
indent(indent);
|
||||
Util.println("If");
|
||||
indent(indent + IndentIncrement);
|
||||
System.out.print("test ");
|
||||
Util.println(_test.toString());
|
||||
displayContents(indent + IndentIncrement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the "test" expression and contents of this element.
|
||||
*/
|
||||
public void parseContents(Parser parser) {
|
||||
// Parse the "test" expression
|
||||
_test = parser.parseExpression(this, "test", null);
|
||||
|
||||
// Make sure required attribute(s) have been set
|
||||
if (_test.isDummy()) {
|
||||
reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "test");
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore xsl:if when test is false (function-available() and
|
||||
// element-available())
|
||||
Object result = _test.evaluateAtCompileTime();
|
||||
if (result != null && result instanceof Boolean) {
|
||||
_ignore = !((Boolean) result).booleanValue();
|
||||
}
|
||||
|
||||
parseChildren(parser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type-check the "test" expression and contents of this element.
|
||||
* The contents will be ignored if we know the test will always fail.
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
// Type-check the "test" expression
|
||||
if (_test.typeCheck(stable) instanceof BooleanType == false) {
|
||||
_test = new CastExpr(_test, Type.Boolean);
|
||||
}
|
||||
// Type check the element contents
|
||||
if (!_ignore) {
|
||||
typeCheckContents(stable);
|
||||
}
|
||||
return Type.Void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the "test" expression and contents of this element.
|
||||
* The contents will be ignored if we know the test will always fail.
|
||||
*/
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
final InstructionList il = methodGen.getInstructionList();
|
||||
_test.translateDesynthesized(classGen, methodGen);
|
||||
// remember end of condition
|
||||
final InstructionHandle truec = il.getEnd();
|
||||
if (!_ignore) {
|
||||
translateContents(classGen, methodGen);
|
||||
}
|
||||
_test.backPatchFalseList(il.append(NOP));
|
||||
_test.backPatchTrueList(truec.getNext());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
class IllegalCharException extends Exception {
|
||||
static final long serialVersionUID = -667236676706226266L;
|
||||
public IllegalCharException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
/*
|
||||
* $Id: Import.java,v 1.8 2007/04/09 21:30:40 joehw Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.XalanConstants;
|
||||
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
|
||||
import java.util.Iterator;
|
||||
import javax.xml.XMLConstants;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Morten Jorgensen
|
||||
* @author Erwin Bolwidt <ejb@klomp.org>
|
||||
* @author Gunnlaugur Briem <gthb@dimon.is>
|
||||
*/
|
||||
final class Import extends TopLevelElement {
|
||||
|
||||
private Stylesheet _imported = null;
|
||||
|
||||
public Stylesheet getImportedStylesheet() {
|
||||
return _imported;
|
||||
}
|
||||
|
||||
public void parseContents(final Parser parser) {
|
||||
final XSLTC xsltc = parser.getXSLTC();
|
||||
final Stylesheet context = parser.getCurrentStylesheet();
|
||||
|
||||
try {
|
||||
String docToLoad = getAttribute("href");
|
||||
if (context.checkForLoop(docToLoad)) {
|
||||
final ErrorMsg msg = new ErrorMsg(ErrorMsg.CIRCULAR_INCLUDE_ERR,
|
||||
docToLoad, this);
|
||||
parser.reportError(Constants.FATAL, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
InputSource input = null;
|
||||
XMLReader reader = null;
|
||||
String currLoadedDoc = context.getSystemId();
|
||||
SourceLoader loader = context.getSourceLoader();
|
||||
|
||||
// Use SourceLoader if available
|
||||
if (loader != null) {
|
||||
input = loader.loadSource(docToLoad, currLoadedDoc, xsltc);
|
||||
if (input != null) {
|
||||
docToLoad = input.getSystemId();
|
||||
reader = xsltc.getXMLReader();
|
||||
} else if (parser.errorsFound()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// No SourceLoader or not resolved by SourceLoader
|
||||
if (input == null) {
|
||||
docToLoad = SystemIDResolver.getAbsoluteURI(docToLoad, currLoadedDoc);
|
||||
String accessError = SecuritySupport.checkAccess(docToLoad,
|
||||
(String)xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET),
|
||||
XalanConstants.ACCESS_EXTERNAL_ALL);
|
||||
|
||||
if (accessError != null) {
|
||||
final ErrorMsg msg = new ErrorMsg(ErrorMsg.ACCESSING_XSLT_TARGET_ERR,
|
||||
SecuritySupport.sanitizePath(docToLoad), accessError,
|
||||
this);
|
||||
parser.reportError(Constants.FATAL, msg);
|
||||
return;
|
||||
}
|
||||
input = new InputSource(docToLoad);
|
||||
}
|
||||
|
||||
// Return if we could not resolve the URL
|
||||
if (input == null) {
|
||||
final ErrorMsg msg =
|
||||
new ErrorMsg(ErrorMsg.FILE_NOT_FOUND_ERR, docToLoad, this);
|
||||
parser.reportError(Constants.FATAL, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
final SyntaxTreeNode root;
|
||||
if (reader != null) {
|
||||
root = parser.parse(reader,input);
|
||||
}
|
||||
else {
|
||||
root = parser.parse(input);
|
||||
}
|
||||
|
||||
if (root == null) return;
|
||||
_imported = parser.makeStylesheet(root);
|
||||
if (_imported == null) return;
|
||||
|
||||
_imported.setSourceLoader(loader);
|
||||
_imported.setSystemId(docToLoad);
|
||||
_imported.setParentStylesheet(context);
|
||||
_imported.setImportingStylesheet(context);
|
||||
_imported.setTemplateInlining(context.getTemplateInlining());
|
||||
|
||||
// precedence for the including stylesheet
|
||||
final int currPrecedence = parser.getCurrentImportPrecedence();
|
||||
final int nextPrecedence = parser.getNextImportPrecedence();
|
||||
_imported.setImportPrecedence(currPrecedence);
|
||||
context.setImportPrecedence(nextPrecedence);
|
||||
parser.setCurrentStylesheet(_imported);
|
||||
_imported.parseContents(parser);
|
||||
|
||||
final Iterator<SyntaxTreeNode> elements = _imported.elements();
|
||||
final Stylesheet topStylesheet = parser.getTopLevelStylesheet();
|
||||
while (elements.hasNext()) {
|
||||
final SyntaxTreeNode element = elements.next();
|
||||
if (element instanceof TopLevelElement) {
|
||||
if (element instanceof Variable) {
|
||||
topStylesheet.addVariable((Variable) element);
|
||||
}
|
||||
else if (element instanceof Param) {
|
||||
topStylesheet.addParam((Param) element);
|
||||
}
|
||||
else {
|
||||
topStylesheet.addElement((TopLevelElement) element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
parser.setCurrentStylesheet(context);
|
||||
}
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
return Type.Void;
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
/*
|
||||
* $Id: Include.java,v 1.8 2007/04/09 21:30:41 joehw Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.XalanConstants;
|
||||
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
|
||||
import java.util.Iterator;
|
||||
import javax.xml.XMLConstants;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Morten Jorgensen
|
||||
* @author Erwin Bolwidt <ejb@klomp.org>
|
||||
* @author Gunnlaugur Briem <gthb@dimon.is>
|
||||
*/
|
||||
final class Include extends TopLevelElement {
|
||||
|
||||
private Stylesheet _included = null;
|
||||
|
||||
public Stylesheet getIncludedStylesheet() {
|
||||
return _included;
|
||||
}
|
||||
|
||||
public void parseContents(final Parser parser) {
|
||||
XSLTC xsltc = parser.getXSLTC();
|
||||
Stylesheet context = parser.getCurrentStylesheet();
|
||||
|
||||
String docToLoad = getAttribute("href");
|
||||
try {
|
||||
if (context.checkForLoop(docToLoad)) {
|
||||
final ErrorMsg msg = new ErrorMsg(ErrorMsg.CIRCULAR_INCLUDE_ERR,
|
||||
docToLoad, this);
|
||||
parser.reportError(Constants.FATAL, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
InputSource input = null;
|
||||
XMLReader reader = null;
|
||||
String currLoadedDoc = context.getSystemId();
|
||||
SourceLoader loader = context.getSourceLoader();
|
||||
|
||||
// Use SourceLoader if available
|
||||
if (loader != null) {
|
||||
input = loader.loadSource(docToLoad, currLoadedDoc, xsltc);
|
||||
if (input != null) {
|
||||
docToLoad = input.getSystemId();
|
||||
reader = xsltc.getXMLReader();
|
||||
} else if (parser.errorsFound()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// No SourceLoader or not resolved by SourceLoader
|
||||
if (input == null) {
|
||||
docToLoad = SystemIDResolver.getAbsoluteURI(docToLoad, currLoadedDoc);
|
||||
String accessError = SecuritySupport.checkAccess(docToLoad,
|
||||
(String)xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET),
|
||||
XalanConstants.ACCESS_EXTERNAL_ALL);
|
||||
|
||||
if (accessError != null) {
|
||||
final ErrorMsg msg = new ErrorMsg(ErrorMsg.ACCESSING_XSLT_TARGET_ERR,
|
||||
SecuritySupport.sanitizePath(docToLoad), accessError,
|
||||
this);
|
||||
parser.reportError(Constants.FATAL, msg);
|
||||
return;
|
||||
}
|
||||
input = new InputSource(docToLoad);
|
||||
}
|
||||
|
||||
// Return if we could not resolve the URL
|
||||
if (input == null) {
|
||||
final ErrorMsg msg =
|
||||
new ErrorMsg(ErrorMsg.FILE_NOT_FOUND_ERR, docToLoad, this);
|
||||
parser.reportError(Constants.FATAL, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
final SyntaxTreeNode root;
|
||||
if (reader != null) {
|
||||
root = parser.parse(reader,input);
|
||||
}
|
||||
else {
|
||||
root = parser.parse(input);
|
||||
}
|
||||
|
||||
if (root == null) return;
|
||||
_included = parser.makeStylesheet(root);
|
||||
if (_included == null) return;
|
||||
|
||||
_included.setSourceLoader(loader);
|
||||
_included.setSystemId(docToLoad);
|
||||
_included.setParentStylesheet(context);
|
||||
_included.setIncludingStylesheet(context);
|
||||
_included.setTemplateInlining(context.getTemplateInlining());
|
||||
|
||||
// An included stylesheet gets the same import precedence
|
||||
// as the stylesheet that included it.
|
||||
final int precedence = context.getImportPrecedence();
|
||||
_included.setImportPrecedence(precedence);
|
||||
parser.setCurrentStylesheet(_included);
|
||||
_included.parseContents(parser);
|
||||
|
||||
final Iterator<SyntaxTreeNode> elements = _included.elements();
|
||||
final Stylesheet topStylesheet = parser.getTopLevelStylesheet();
|
||||
while (elements.hasNext()) {
|
||||
final SyntaxTreeNode element = elements.next();
|
||||
if (element instanceof TopLevelElement) {
|
||||
if (element instanceof Variable) {
|
||||
topStylesheet.addVariable((Variable) element);
|
||||
}
|
||||
else if (element instanceof Param) {
|
||||
topStylesheet.addParam((Param) element);
|
||||
}
|
||||
else {
|
||||
topStylesheet.addElement((TopLevelElement) element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
parser.setCurrentStylesheet(context);
|
||||
}
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
return Type.Void;
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
abstract class Instruction extends SyntaxTreeNode {
|
||||
/**
|
||||
* Type check all the children of this node.
|
||||
*/
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
return typeCheckContents(stable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate this node into JVM bytecodes.
|
||||
*/
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
ErrorMsg msg = new ErrorMsg(ErrorMsg.NOT_IMPLEMENTED_ERR,
|
||||
getClass(), this);
|
||||
getParser().reportError(FATAL, msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.bcel.internal.generic.PUSH;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
||||
|
||||
/**
|
||||
* @author Jacek Ambroziak
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
final class IntExpr extends Expression {
|
||||
private final int _value;
|
||||
|
||||
public IntExpr(int value) {
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
||||
return _type = Type.Int;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "int-expr(" + _value + ')';
|
||||
}
|
||||
|
||||
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
||||
ConstantPoolGen cpg = classGen.getConstantPool();
|
||||
InstructionList il = methodGen.getInstructionList();
|
||||
il.append(new PUSH(cpg, _value));
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user