From 587877fcbd358e233f653e01c4b3ed3354203626 Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:06:30 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835118 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/javax/xml/XMLConstants.java | 196 ++++++++ .../src/javax/xml/namespace/QName.java | 515 +++++++++++++++++++++ .../src/javax/xml/transform/Result.java | 70 +++ .../src/javax/xml/transform/Source.java | 36 ++ .../src/javax/xml/transform/dom/DOMSource.java | 122 +++++ .../src/javax/xml/transform/sax/SAXSource.java | 195 ++++++++ .../tuscany/sca/android/ContextRegistry.java | 55 +++ .../apache/tuscany/sca/android/DexResource.java | 190 ++++++++ .../tuscany/sca/android/DexURLConnection.java | 128 +++++ .../tuscany/sca/android/DexURLStreamHandler.java | 15 + .../sca/android/DexURLStreamHandlerFactory.java | 33 ++ 11 files changed, 1555 insertions(+) create mode 100644 sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/XMLConstants.java create mode 100644 sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/namespace/QName.java create mode 100644 sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/Result.java create mode 100644 sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/Source.java create mode 100644 sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/dom/DOMSource.java create mode 100644 sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/sax/SAXSource.java create mode 100644 sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/ContextRegistry.java create mode 100644 sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexResource.java create mode 100644 sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexURLConnection.java create mode 100644 sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexURLStreamHandler.java create mode 100644 sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexURLStreamHandlerFactory.java (limited to 'sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src') diff --git a/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/XMLConstants.java b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/XMLConstants.java new file mode 100644 index 0000000000..2159723b20 --- /dev/null +++ b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/XMLConstants.java @@ -0,0 +1,196 @@ +/* + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * https://jaxp.dev.java.net/CDDLv1.0.html. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * https://jaxp.dev.java.net/CDDLv1.0.html + * If applicable add the following below this CDDL HEADER + * with the fields enclosed by brackets "[]" replaced with + * your own identifying information: Portions Copyright + * [year] [name of copyright owner] + */ + +/* + * $Id: XMLEntityReader.java,v 1.3 2005/11/03 17:02:21 jeffsuttor Exp $ + * @(#)XMLConstants.java 1.15 05/11/17 + * + * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. + */ + +package javax.xml; + +/** + *

Utility class to contain basic XML values as constants.

+ * + * @author Jeff Suttor + * @version $Revision: 1.2 $, $Date: 2005/06/10 03:50:26 $ + * @see Extensible Markup Language (XML) 1.1 + * @see Extensible Markup Language (XML) 1.0 (Second Edition) + * @see XML 1.0 Second Edition Specification Errata + * @see Namespaces in XML 1.1 + * @see Namespaces in XML + * @see Namespaces in XML Errata + * @see XML Schema Part 1: Structures + * @since 1.5 + **/ + +public final class XMLConstants { + + /** + *

Private constructor to prevent instantiation.

+ */ + private XMLConstants() { + } + + /** + *

Namespace URI to use to represent that there is no Namespace.

+ * + *

Defined by the Namespace specification to be "".

+ * + * @see + * Namespaces in XML, 5.2 Namespace Defaulting + */ + public static final String NULL_NS_URI = ""; + + /** + *

Prefix to use to represent the default XML Namespace.

+ * + *

Defined by the XML specification to be "".

+ * + * @see + * Namespaces in XML, 3. Qualified Names + */ + public static final String DEFAULT_NS_PREFIX = ""; + + /** + *

The official XML Namespace name URI.

+ * + *

Defined by the XML specification to be + * "http://www.w3.org/XML/1998/namespace".

+ * + * @see + * Namespaces in XML, 3. Qualified Names + */ + public static final String XML_NS_URI = + "http://www.w3.org/XML/1998/namespace"; + + /** + *

The official XML Namespace prefix.

+ * + *

Defined by the XML specification to be "xml".

+ * + * @see + * Namespaces in XML, 3. Qualified Names< + */ + public static final String XML_NS_PREFIX = "xml"; + + /** + *

The official XML attribute used for specifying XML Namespace + * declarations, {@link #XMLNS_ATTRIBUTE + * XMLConstants.XMLNS_ATTRIBUTE}, Namespace name URI.

+ * + *

Defined by the XML specification to be + * "http://www.w3.org/2000/xmlns/".

+ * + * @see + * Namespaces in XML, 3. Qualified Names + * @see + * Namespaces in XML Errata + */ + public static final String XMLNS_ATTRIBUTE_NS_URI = + "http://www.w3.org/2000/xmlns/"; + + /** + *

The official XML attribute used for specifying XML Namespace + * declarations.

+ * + *

It is NOT valid to use as a + * prefix. Defined by the XML specification to be + * "xmlns".

+ * + * @see + * Namespaces in XML, 3. Qualified Names + */ + public static final String XMLNS_ATTRIBUTE = "xmlns"; + + /** + *

W3C XML Schema Namespace URI.

+ * + *

Defined to be "http://www.w3.org/2001/XMLSchema". + * + * @see + * XML Schema Part 1: + * Structures, 2.6 Schema-Related Markup in Documents Being Validated + */ + public static final String W3C_XML_SCHEMA_NS_URI = + "http://www.w3.org/2001/XMLSchema"; + + /** + *

W3C XML Schema Instance Namespace URI.

+ * + *

Defined to be "http://www.w3.org/2001/XMLSchema-instance".

+ * + * @see + * XML Schema Part 1: + * Structures, 2.6 Schema-Related Markup in Documents Being Validated + */ + public static final String W3C_XML_SCHEMA_INSTANCE_NS_URI = + "http://www.w3.org/2001/XMLSchema-instance"; + + /** + *

W3C XPath Datatype Namespace URI.

+ * + *

Defined to be "http://www.w3.org/2003/11/xpath-datatypes".

+ * + * @see XQuery 1.0 and XPath 2.0 Data Model + */ + public static final String W3C_XPATH_DATATYPE_NS_URI = "http://www.w3.org/2003/11/xpath-datatypes"; + + /** + *

XML Document Type Declaration Namespace URI as an arbitrary value.

+ * + *

Since not formally defined by any existing standard, arbitrarily define to be "http://www.w3.org/TR/REC-xml". + */ + public static final String XML_DTD_NS_URI = "http://www.w3.org/TR/REC-xml"; + + /** + *

RELAX NG Namespace URI.

+ * + *

Defined to be "http://relaxng.org/ns/structure/1.0".

+ * + * @see RELAX NG Specification + */ + public static final String RELAXNG_NS_URI = "http://relaxng.org/ns/structure/1.0"; + + /** + *

Feature for secure processing.

+ * + * + */ + public static final String FEATURE_SECURE_PROCESSING = "http://javax.xml.XMLConstants/feature/secure-processing"; +} diff --git a/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/namespace/QName.java b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/namespace/QName.java new file mode 100644 index 0000000000..3461dd1cab --- /dev/null +++ b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/namespace/QName.java @@ -0,0 +1,515 @@ + +/* + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * https://jaxp.dev.java.net/CDDLv1.0.html. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * https://jaxp.dev.java.net/CDDLv1.0.html + * If applicable add the following below this CDDL HEADER + * with the fields enclosed by brackets "[]" replaced with + * your own identifying information: Portions Copyright + * [year] [name of copyright owner] + */ + +/* + * $Id: QName.java,v 1.5 2005/11/03 19:34:20 jeffsuttor Exp $ + * @(#)QName.java 1.17 06/04/07 + * + * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. + */ + +package javax.xml.namespace; + +import java.io.Serializable; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import javax.xml.XMLConstants; + +/** + *

QName represents a qualified name + * as defined in the XML specifications: XML Schema Part2: + * Datatypes specification, Namespaces + * in XML, Namespaces + * in XML Errata.

+ * + *

The value of a QName contains a Namespace + * URI, local part and + * prefix.

+ * + *

The prefix is included in QName to retain lexical + * information when present in an {@link + * javax.xml.transform.Source XML input source}. The prefix is + * NOT used in {@link #equals(Object) + * QName.equals(Object)} or to compute the {@link #hashCode() + * QName.hashCode()}. Equality and the hash code are defined using + * only the Namespace URI and local part.

+ * + *

If not specified, the Namespace URI is set to {@link + * javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI}. + * If not specified, the prefix is set to {@link + * javax.xml.XMLConstants#DEFAULT_NS_PREFIX + * XMLConstants.DEFAULT_NS_PREFIX}.

+ * + *

QName is immutable.

+ * + * @author Jeff Suttor + * @version $Revision: 1.5 $, $Date: 2005/11/03 19:34:20 $ + * @see + * XML Schema Part2: Datatypes specification + * @see + * Namespaces in XML + * @see + * Namespaces in XML Errata + * @since 1.5 + */ + +public class QName implements Serializable { + + /** + *

Stream Unique Identifier.

+ * + *

Due to a historical defect, QName was released with multiple + * serialVersionUID values even though its serialization was the + * same.

+ * + *

To workaround this issue, serialVersionUID is set with either + * a default value or a compatibility value. To use the + * compatiblity value, set the system property:

+ * + * com.sun.xml.namespace.QName.useCompatibleSerialVersionUID=1.0 + * + *

This workaround was inspired by classes in the javax.management + * package, e.g. ObjectName, etc. + * See CR6267224 for original defect report.

+ */ + private static final long serialVersionUID; + /** + *

Default serialVersionUID value.

+ */ + private static final long defaultSerialVersionUID = -9120448754896609940L; + /** + *

Compatibility serialVersionUID value.

+ */ + private static final long compatibleSerialVersionUID = 4418622981026545151L; + /** + *

Flag to use default or campatible serialVersionUID.

+ */ + private static boolean useDefaultSerialVersionUID = true; + static { + try { + // use a privileged block as reading a system property + String valueUseCompatibleSerialVersionUID = (String) AccessController.doPrivileged( + new PrivilegedAction() { + public Object run() { + return System.getProperty("com.sun.xml.namespace.QName.useCompatibleSerialVersionUID"); + } + } + ); + useDefaultSerialVersionUID = (valueUseCompatibleSerialVersionUID != null && valueUseCompatibleSerialVersionUID.equals("1.0")) ? false : true; + } catch (Exception exception) { + // use default if any Exceptions + useDefaultSerialVersionUID = true; + } + + // set serialVersionUID to desired value + if (useDefaultSerialVersionUID) { + serialVersionUID = defaultSerialVersionUID; + } else { + serialVersionUID = compatibleSerialVersionUID; + } + } + + /** + *

Namespace URI of this QName.

+ */ + private final String namespaceURI; + + /** + *

local part of this QName.

+ */ + private final String localPart; + + /** + *

prefix of this QName.

+ */ + private final String prefix; + + /** + *

QName constructor specifying the Namespace URI + * and local part.

+ * + *

If the Namespace URI is null, it is set to + * {@link javax.xml.XMLConstants#NULL_NS_URI + * XMLConstants.NULL_NS_URI}. This value represents no + * explicitly defined Namespace as defined by the Namespaces + * in XML specification. This action preserves compatible + * behavior with QName 1.0. Explicitly providing the {@link + * javax.xml.XMLConstants#NULL_NS_URI + * XMLConstants.NULL_NS_URI} value is the preferred coding + * style.

+ * + *

If the local part is null an + * IllegalArgumentException is thrown. + * A local part of "" is allowed to preserve + * compatible behavior with QName 1.0.

+ * + *

When using this constructor, the prefix is set to {@link + * javax.xml.XMLConstants#DEFAULT_NS_PREFIX + * XMLConstants.DEFAULT_NS_PREFIX}.

+ * + *

The Namespace URI is not validated as a + * URI reference. + * The local part is not validated as a + * NCName + * as specified in Namespaces + * in XML.

+ * + * @param namespaceURI Namespace URI of the QName + * @param localPart local part of the QName + * + * @throws IllegalArgumentException When localPart is + * null + * + * @see #QName(String namespaceURI, String localPart, String + * prefix) QName(String namespaceURI, String localPart, String + * prefix) + */ + public QName(final String namespaceURI, final String localPart) { + this(namespaceURI, localPart, XMLConstants.DEFAULT_NS_PREFIX); + } + + /** + *

QName constructor specifying the Namespace URI, + * local part and prefix.

+ * + *

If the Namespace URI is null, it is set to + * {@link javax.xml.XMLConstants#NULL_NS_URI + * XMLConstants.NULL_NS_URI}. This value represents no + * explicitly defined Namespace as defined by the Namespaces + * in XML specification. This action preserves compatible + * behavior with QName 1.0. Explicitly providing the {@link + * javax.xml.XMLConstants#NULL_NS_URI + * XMLConstants.NULL_NS_URI} value is the preferred coding + * style.

+ * + *

If the local part is null an + * IllegalArgumentException is thrown. + * A local part of "" is allowed to preserve + * compatible behavior with QName 1.0.

+ * + *

If the prefix is null, an + * IllegalArgumentException is thrown. Use {@link + * javax.xml.XMLConstants#DEFAULT_NS_PREFIX + * XMLConstants.DEFAULT_NS_PREFIX} to explicitly indicate that no + * prefix is present or the prefix is not relevant.

+ * + *

The Namespace URI is not validated as a + * URI reference. + * The local part and prefix are not validated as a + * NCName + * as specified in Namespaces + * in XML.

+ * + * @param namespaceURI Namespace URI of the QName + * @param localPart local part of the QName + * @param prefix prefix of the QName + * + * @throws IllegalArgumentException When localPart + * or prefix is null + */ + public QName(String namespaceURI, String localPart, String prefix) { + + // map null Namespace URI to default + // to preserve compatibility with QName 1.0 + if (namespaceURI == null) { + this.namespaceURI = XMLConstants.NULL_NS_URI; + } else { + this.namespaceURI = namespaceURI; + } + + // local part is required. + // "" is allowed to preserve compatibility with QName 1.0 + if (localPart == null) { + throw new IllegalArgumentException( + "local part cannot be \"null\" when creating a QName"); + } + this.localPart = localPart; + + // prefix is required + if (prefix == null) { + throw new IllegalArgumentException( + "prefix cannot be \"null\" when creating a QName"); + } + this.prefix = prefix; + } + + /** + *

QName constructor specifying the local part.

+ * + *

If the local part is null an + * IllegalArgumentException is thrown. + * A local part of "" is allowed to preserve + * compatible behavior with QName 1.0.

+ * + *

When using this constructor, the Namespace URI is set to + * {@link javax.xml.XMLConstants#NULL_NS_URI + * XMLConstants.NULL_NS_URI} and the prefix is set to {@link + * javax.xml.XMLConstants#DEFAULT_NS_PREFIX + * XMLConstants.DEFAULT_NS_PREFIX}.

+ * + *

In an XML context, all Element and Attribute names exist + * in the context of a Namespace. Making this explicit during the + * construction of a QName helps prevent hard to + * diagnosis XML validity errors. The constructors {@link + * #QName(String namespaceURI, String localPart) QName(String + * namespaceURI, String localPart)} and + * {@link #QName(String namespaceURI, String localPart, String prefix)} + * are preferred.

+ * + *

The local part is not validated as a + * NCName + * as specified in Namespaces + * in XML.

+ * + * @param localPart local part of the QName + * + * @throws IllegalArgumentException When localPart is + * null + * + * @see #QName(String namespaceURI, String localPart) QName(String + * namespaceURI, String localPart) + * @see #QName(String namespaceURI, String localPart, String + * prefix) QName(String namespaceURI, String localPart, String + * prefix) + */ + public QName(String localPart) { + this( + XMLConstants.NULL_NS_URI, + localPart, + XMLConstants.DEFAULT_NS_PREFIX); + } + + /** + *

Get the Namespace URI of this QName.

+ * + * @return Namespace URI of this QName + */ + public String getNamespaceURI() { + return namespaceURI; + } + + /** + *

Get the local part of this QName.

+ * + * @return local part of this QName + */ + public String getLocalPart() { + return localPart; + } + + /** + *

Get the prefix of this QName.

+ * + *

The prefix assigned to a QName might + * NOT be valid in a different + * context. For example, a QName may be assigned a + * prefix in the context of parsing a document but that prefix may + * be invalid in the context of a different document.

+ * + * @return prefix of this QName + */ + public String getPrefix() { + return prefix; + } + + /** + *

Test this QName for equality with another + * Object.

+ * + *

If the Object to be tested is not a + * QName or is null, then this method + * returns false.

+ * + *

Two QNames are considered equal if and only if + * both the Namespace URI and local part are equal. This method + * uses String.equals() to check equality of the + * Namespace URI and local part. The prefix is + * NOT used to determine equality.

+ * + *

This method satisfies the general contract of {@link + * java.lang.Object#equals(Object) Object.equals(Object)}

+ * + * @param objectToTest the Object to test for + * equality with this QName + * @return true if the given Object is + * equal to this QName else false + */ + public final boolean equals(Object objectToTest) { + if (objectToTest == null || !(objectToTest instanceof QName)) { + return false; + } + + QName qName = (QName) objectToTest; + + return namespaceURI.equals(qName.namespaceURI) + && localPart.equals(qName.localPart); + } + + /** + *

Generate the hash code for this QName.

+ * + *

The hash code is calculated using both the Namespace URI and + * the local part of the QName. The prefix is + * NOT used to calculate the hash + * code.

+ * + *

This method satisfies the general contract of {@link + * java.lang.Object#hashCode() Object.hashCode()}.

+ * + * @return hash code for this QName Object + */ + public final int hashCode() { + return namespaceURI.hashCode() ^ localPart.hashCode(); + } + + /** + *

String representation of this + * QName.

+ * + *

The commonly accepted way of representing a QName + * as a String was + * defined + * by James Clark. Although this is not a standard + * specification, it is in common use, e.g. {@link + * javax.xml.transform.Transformer#setParameter(String name, Object value)}. + * This implementation represents a QName as: + * "{" + Namespace URI + "}" + local part. If the Namespace URI + * .equals(XMLConstants.NULL_NS_URI), only the + * local part is returned. An appropriate use of this method is + * for debugging or logging for human consumption.

+ * + *

Note the prefix value is NOT + * returned as part of the String representation.

+ * + *

This method satisfies the general contract of {@link + * java.lang.Object#toString() Object.toString()}.

+ * + * @return String representation of this QName + */ + public String toString() { + if (namespaceURI.equals(XMLConstants.NULL_NS_URI)) { + return localPart; + } else { + return "{" + namespaceURI + "}" + localPart; + } + } + + /** + *

QName derived from parsing the formatted + * String.

+ * + *

If the String is null or does not conform to + * {@link #toString() QName.toString()} formatting, an + * IllegalArgumentException is thrown.

+ * + *

The String MUST be in the + * form returned by {@link #toString() QName.toString()}.

+ * + *

The commonly accepted way of representing a QName + * as a String was + * defined + * by James Clark. Although this is not a standard + * specification, it is in common use, e.g. {@link + * javax.xml.transform.Transformer#setParameter(String name, Object value)}. + * This implementation parses a String formatted + * as: "{" + Namespace URI + "}" + local part. If the Namespace + * URI .equals(XMLConstants.NULL_NS_URI), only the + * local part should be provided.

+ * + *

The prefix value CANNOT be + * represented in the String and will be set to + * {@link javax.xml.XMLConstants#DEFAULT_NS_PREFIX + * XMLConstants.DEFAULT_NS_PREFIX}.

+ * + *

This method does not do full validation of the resulting + * QName. + *

The Namespace URI is not validated as a + * URI reference. + * The local part is not validated as a + * NCName + * as specified in + * Namespaces in XML.

+ * + * @param qNameAsString String representation + * of the QName + * + * @throws IllegalArgumentException When qNameAsString is + * null or malformed + * + * @return QName corresponding to the given String + * @see #toString() QName.toString() + */ + public static QName valueOf(String qNameAsString) { + + // null is not valid + if (qNameAsString == null) { + throw new IllegalArgumentException( + "cannot create QName from \"null\" or \"\" String"); + } + + // "" local part is valid to preserve compatible behavior with QName 1.0 + if (qNameAsString.length() == 0) { + return new QName( + XMLConstants.NULL_NS_URI, + qNameAsString, + XMLConstants.DEFAULT_NS_PREFIX); + } + + // local part only? + if (qNameAsString.charAt(0) != '{') { + return new QName( + XMLConstants.NULL_NS_URI, + qNameAsString, + XMLConstants.DEFAULT_NS_PREFIX); + } + + // Namespace URI improperly specified? + if (qNameAsString.startsWith("{" + XMLConstants.NULL_NS_URI + "}")) { + throw new IllegalArgumentException( + "Namespace URI .equals(XMLConstants.NULL_NS_URI), " + + ".equals(\"" + XMLConstants.NULL_NS_URI + "\"), " + + "only the local part, " + + "\"" + + qNameAsString.substring(2 + XMLConstants.NULL_NS_URI.length()) + + "\", " + + "should be provided."); + } + + // Namespace URI and local part specified + int endOfNamespaceURI = qNameAsString.indexOf('}'); + if (endOfNamespaceURI == -1) { + throw new IllegalArgumentException( + "cannot create QName from \"" + + qNameAsString + + "\", missing closing \"}\""); + } + return new QName( + qNameAsString.substring(1, endOfNamespaceURI), + qNameAsString.substring(endOfNamespaceURI + 1), + XMLConstants.DEFAULT_NS_PREFIX); + } +} diff --git a/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/Result.java b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/Result.java new file mode 100644 index 0000000000..dd3517c8cc --- /dev/null +++ b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/Result.java @@ -0,0 +1,70 @@ +// $Id: Result.java,v 1.2 2003/10/22 03:53:16 jsuttor Exp $ + +/* + * @(#)Result.java 1.13 04/07/26 + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +package javax.xml.transform; + +/** + *

An object that implements this interface contains the information + * needed to build a transformation result tree.

+ * + * @author Jeff Suttor + */ +public interface Result { + + /** + * The name of the processing instruction that is sent if the + * result tree disables output escaping. + * + *

Normally, result tree serialization escapes & and < (and + * possibly other characters) when outputting text nodes. + * This ensures that the output is well-formed XML. However, + * it is sometimes convenient to be able to produce output that is + * almost, but not quite well-formed XML; for example, + * the output may include ill-formed sections that will + * be transformed into well-formed XML by a subsequent non-XML aware + * process. If a processing instruction is sent with this name, + * serialization should be output without any escaping.

+ * + *

Result DOM trees may also have PI_DISABLE_OUTPUT_ESCAPING and + * PI_ENABLE_OUTPUT_ESCAPING inserted into the tree.

+ * + * @see disable-output-escaping in XSLT Specification + */ + public static final String PI_DISABLE_OUTPUT_ESCAPING = + "javax.xml.transform.disable-output-escaping"; + + /** + * The name of the processing instruction that is sent + * if the result tree enables output escaping at some point after having + * received a PI_DISABLE_OUTPUT_ESCAPING processing instruction. + * + * @see disable-output-escaping in XSLT Specification + */ + public static final String PI_ENABLE_OUTPUT_ESCAPING = + "javax.xml.transform.enable-output-escaping"; + + /** + * Set the system identifier for this Result. + * + *

If the Result is not to be written to a file, the system identifier is optional. + * The application may still want to provide one, however, for use in error messages + * and warnings, or to resolve relative output identifiers.

+ * + * @param systemId The system identifier as a URI string. + */ + public void setSystemId(String systemId); + + /** + * Get the system identifier that was set with setSystemId. + * + * @return The system identifier that was set with setSystemId, + * or null if setSystemId was not called. + */ + public String getSystemId(); +} diff --git a/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/Source.java b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/Source.java new file mode 100644 index 0000000000..5467229cc7 --- /dev/null +++ b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/Source.java @@ -0,0 +1,36 @@ +// $Id: Source.java,v 1.2 2003/09/07 23:02:09 jsuttor Exp $ +/* + * @(#)Source.java 1.14 04/07/26 + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +package javax.xml.transform; + +/** + * An object that implements this interface contains the information + * needed to act as source input (XML source or transformation instructions). + */ +public interface Source { + + /** + * Set the system identifier for this Source. + * + *

The system identifier is optional if the source does not + * get its data from a URL, but it may still be useful to provide one. + * The application can use a system identifier, for example, to resolve + * relative URIs and to include in error messages and warnings.

+ * + * @param systemId The system identifier as a URL string. + */ + public void setSystemId(String systemId); + + /** + * Get the system identifier that was set with setSystemId. + * + * @return The system identifier that was set with setSystemId, or null + * if setSystemId was not called. + */ + public String getSystemId(); +} diff --git a/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/dom/DOMSource.java b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/dom/DOMSource.java new file mode 100644 index 0000000000..a55864a04c --- /dev/null +++ b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/dom/DOMSource.java @@ -0,0 +1,122 @@ +// $Id: DOMSource.java,v 1.5.14.1.2.2 2004/07/13 22:27:49 jsuttor Exp $ +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +/* + * @(#)DOMSource.java 1.16 04/07/13 + */ +package javax.xml.transform.dom; + +import javax.xml.transform.Source; + +import org.w3c.dom.Node; + +/** + *

Acts as a holder for a transformation Source tree in the + * form of a Document Object Model (DOM) tree.

+ * + *

Note that XSLT requires namespace support. Attempting to transform a DOM + * that was not contructed with a namespace-aware parser may result in errors. + * Parsers can be made namespace aware by calling + * {@link javax.xml.parsers.DocumentBuilderFactory#setNamespaceAware(boolean awareness)}.

+ * + * @author Jeff Suttor + * @version $Revision: 1.5.14.1.2.2 $, $Date: 2004/07/13 22:27:49 $ + * @see Document Object Model (DOM) Level 2 Specification + */ +public class DOMSource implements Source { + + /** + *

Node to serve as DOM source.

+ */ + private Node node; + + /** + *

The base ID (URL or system ID) from where URLs + * will be resolved.

+ */ + private String systemID; + + /** If {@link javax.xml.transform.TransformerFactory#getFeature} + * returns true when passed this value as an argument, + * the Transformer supports Source input of this type. + */ + public static final String FEATURE = + "http://javax.xml.transform.dom.DOMSource/feature"; + + /** + *

Zero-argument default constructor. If this constructor is used, and + * no DOM source is set using {@link #setNode(Node node)} , then the + * Transformer will + * create an empty source {@link org.w3c.dom.Document} using + * {@link javax.xml.parsers.DocumentBuilder#newDocument()}.

+ * + * @see javax.xml.transform.Transformer#transform(Source xmlSource, Result outputTarget) + */ + public DOMSource() { } + + /** + * Create a new input source with a DOM node. The operation + * will be applied to the subtree rooted at this node. In XSLT, + * a "/" pattern still means the root of the tree (not the subtree), + * and the evaluation of global variables and parameters is done + * from the root node also. + * + * @param n The DOM node that will contain the Source tree. + */ + public DOMSource(Node n) { + setNode(n); + } + + /** + * Create a new input source with a DOM node, and with the + * system ID also passed in as the base URI. + * + * @param node The DOM node that will contain the Source tree. + * @param systemID Specifies the base URI associated with node. + */ + public DOMSource(Node node, String systemID) { + setNode(node); + setSystemId(systemID); + } + + /** + * Set the node that will represents a Source DOM tree. + * + * @param node The node that is to be transformed. + */ + public void setNode(Node node) { + this.node = node; + } + + /** + * Get the node that represents a Source DOM tree. + * + * @return The node that is to be transformed. + */ + public Node getNode() { + return node; + } + + /** + * Set the base ID (URL or system ID) from where URLs + * will be resolved. + * + * @param systemID Base URL for this DOM tree. + */ + public void setSystemId(String systemID) { + this.systemID = systemID; + } + + /** + * Get the base ID (URL or system ID) from where URLs + * will be resolved. + * + * @return Base URL for this DOM tree. + */ + public String getSystemId() { + return this.systemID; + } +} diff --git a/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/sax/SAXSource.java b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/sax/SAXSource.java new file mode 100644 index 0000000000..cc09fee0ae --- /dev/null +++ b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/javax/xml/transform/sax/SAXSource.java @@ -0,0 +1,195 @@ +// $Id: SAXSource.java,v 1.7.14.1.2.2 2004/07/13 22:27:50 jsuttor Exp $ +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +/* + * @(#)SAXSource.java 1.15 04/07/13 + */ +package javax.xml.transform.sax; + +import javax.xml.transform.Source; +//import javax.xml.transform.stream.StreamSource; + +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; + +/** + *

Acts as an holder for SAX-style Source.

+ * + *

Note that XSLT requires namespace support. Attempting to transform an + * input source that is not + * generated with a namespace-aware parser may result in errors. + * Parsers can be made namespace aware by calling the + * {@link javax.xml.parsers.SAXParserFactory#setNamespaceAware(boolean awareness)} method.

+ * + * @author Jeff Suttor + * @version $Revision: 1.7.14.1.2.2 $, $Date: 2004/07/13 22:27:50 $ + */ +public class SAXSource implements Source { + + /** + * If {@link javax.xml.transform.TransformerFactory#getFeature} + * returns true when passed this value as an argument, + * the Transformer supports Source input of this type. + */ + public static final String FEATURE = + "http://javax.xml.transform.sax.SAXSource/feature"; + + /** + *

Zero-argument default constructor. If this constructor is used, and + * no SAX source is set using + * {@link #setInputSource(InputSource inputSource)} , then the + * Transformer will + * create an empty source {@link org.xml.sax.InputSource} using + * {@link org.xml.sax.InputSource#InputSource() new InputSource()}.

+ * + * @see javax.xml.transform.Transformer#transform(Source xmlSource, Result outputTarget) + */ + public SAXSource() { } + + /** + * Create a SAXSource, using an {@link org.xml.sax.XMLReader} + * and a SAX InputSource. The {@link javax.xml.transform.Transformer} + * or {@link javax.xml.transform.sax.SAXTransformerFactory} will set itself + * to be the reader's {@link org.xml.sax.ContentHandler}, and then will call + * reader.parse(inputSource). + * + * @param reader An XMLReader to be used for the parse. + * @param inputSource A SAX input source reference that must be non-null + * and that will be passed to the reader parse method. + */ + public SAXSource(XMLReader reader, InputSource inputSource) { + this.reader = reader; + this.inputSource = inputSource; + } + + /** + * Create a SAXSource, using a SAX InputSource. + * The {@link javax.xml.transform.Transformer} or + * {@link javax.xml.transform.sax.SAXTransformerFactory} creates a + * reader via {@link org.xml.sax.helpers.XMLReaderFactory} + * (if setXMLReader is not used), sets itself as + * the reader's {@link org.xml.sax.ContentHandler}, and calls + * reader.parse(inputSource). + * + * @param inputSource An input source reference that must be non-null + * and that will be passed to the parse method of the reader. + */ + public SAXSource(InputSource inputSource) { + this.inputSource = inputSource; + } + + /** + * Set the XMLReader to be used for the Source. + * + * @param reader A valid XMLReader or XMLFilter reference. + */ + public void setXMLReader(XMLReader reader) { + this.reader = reader; + } + + /** + * Get the XMLReader to be used for the Source. + * + * @return A valid XMLReader or XMLFilter reference, or null. + */ + public XMLReader getXMLReader() { + return reader; + } + + /** + * Set the SAX InputSource to be used for the Source. + * + * @param inputSource A valid InputSource reference. + */ + public void setInputSource(InputSource inputSource) { + this.inputSource = inputSource; + } + + /** + * Get the SAX InputSource to be used for the Source. + * + * @return A valid InputSource reference, or null. + */ + public InputSource getInputSource() { + return inputSource; + } + + /** + * Set the system identifier for this Source. If an input source + * has already been set, it will set the system ID or that + * input source, otherwise it will create a new input source. + * + *

The system identifier is optional if there is a byte stream + * or a character stream, but it is still useful to provide one, + * since the application can use it to resolve relative URIs + * and can include it in error messages and warnings (the parser + * will attempt to open a connection to the URI only if + * no byte stream or character stream is specified).

+ * + * @param systemId The system identifier as a URI string. + */ + public void setSystemId(String systemId) { + + if (null == inputSource) { + inputSource = new InputSource(systemId); + } else { + inputSource.setSystemId(systemId); + } + } + + /** + *

Get the base ID (URI or system ID) from where URIs + * will be resolved.

+ * + * @return Base URL for the Source, or null. + */ + public String getSystemId() { + + if (inputSource == null) { + return null; + } else { + return inputSource.getSystemId(); + } + } + + /** + * The XMLReader to be used for the source tree input. May be null. + */ + private XMLReader reader; + + /** + *

The SAX InputSource to be used for the source tree input. + * Should not be null.

+ */ + private InputSource inputSource; +/* + *//** + * Attempt to obtain a SAX InputSource object from a Source + * object. + * + * @param source Must be a non-null Source reference. + * + * @return An InputSource, or null if Source can not be converted. + *//* + public static InputSource sourceToInputSource(Source source) { + + if (source instanceof SAXSource) { + return ((SAXSource) source).getInputSource(); + } else if (source instanceof StreamSource) { + StreamSource ss = (StreamSource) source; + InputSource isource = new InputSource(ss.getSystemId()); + + isource.setByteStream(ss.getInputStream()); + isource.setCharacterStream(ss.getReader()); + isource.setPublicId(ss.getPublicId()); + + return isource; + } else { + return null; + } + }*/ +} + diff --git a/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/ContextRegistry.java b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/ContextRegistry.java new file mode 100644 index 0000000000..312c0059db --- /dev/null +++ b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/ContextRegistry.java @@ -0,0 +1,55 @@ +package org.apache.tuscany.sca.android; + +import java.util.HashSet; +import java.util.Hashtable; + +import android.content.Context; + +public class ContextRegistry { + + private static Hashtable> contexts = new Hashtable>(); + + public static void registerContext(Context context) { + String packageName = context.getPackageName(); + HashSet packContexts = contexts.get(packageName); + + if (packContexts == null) { + packContexts = new HashSet(); + contexts.put(packageName, packContexts); + + } + + packContexts.add(context); + + } + + public static void unregisterContext(Context context) { + String packageName = context.getPackageName(); + HashSet packContexts = contexts.get(packageName); + + if (packContexts != null) { + packContexts.remove(context); + + if (packContexts.isEmpty()) { + contexts.remove(packageName); + } + + } + + } + + public static Context[] getContexts(String packageName) { + HashSet packageContexts = contexts.get(packageName); + + if (packageContexts == null) { + return new Context[0]; + } + + Context[] ret = new Context[packageContexts.size()]; + packageContexts.toArray(ret); + + return ret; + + } + +} diff --git a/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexResource.java b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexResource.java new file mode 100644 index 0000000000..fb9029547f --- /dev/null +++ b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexResource.java @@ -0,0 +1,190 @@ +package org.apache.tuscany.sca.android; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; + +import android.content.Context; + +public class DexResource { + + private URL url; + + private String folder; + + private String file; + + public DexResource(URL url) { + String protocol = url.getProtocol(); + + if (!"dex".equals(protocol)) { + throw new IllegalArgumentException("The URL protocol should be \"dex\""); + } + + String host = url.getHost(); + + if ("".equals(host)) { + throw new IllegalArgumentException("The host should not be empty!"); + } + + String path = url.getPath(); + file = getFile(path); + folder = getFolder(path); + + if (file != null && file.indexOf('/') != -1) { + throw new IllegalArgumentException("The dex URL format should be: dex://[]/[] only"); + } + + this.url = url; + + } + + public static String getFolder(String path) { + String file = path.trim(); + + int firstSlashIndex = file.indexOf('/'); + + if ("".equals(file) || "/".equals(file) || firstSlashIndex == -1 || firstSlashIndex >= file.length() - 1) { + return null; + } + + int secondSlashIndex = file.indexOf("/", firstSlashIndex + 1); + + if (secondSlashIndex == -1 || secondSlashIndex >= file.length() - 1 || firstSlashIndex == secondSlashIndex - 1) { + return null; + } + + return file.substring(firstSlashIndex + 1, secondSlashIndex); + + } + + public static String getFile(String path) { + String file = path.trim(); + + int firstSlashIndex = file.indexOf('/'); + + if ("".equals(file) || "/".equals(file) || firstSlashIndex == -1 || firstSlashIndex >= file.length() - 1) { + return null; + } + + int secondSlashIndex = file.indexOf("/", firstSlashIndex + 1); + + if (secondSlashIndex == -1 || secondSlashIndex >= file.length() - 1 || firstSlashIndex == secondSlashIndex - 1) { + return null; + } + + return file.substring(secondSlashIndex + 1); + + } + + public String getFolderName() { + return folder; + } + + public Context getContext() { + Context[] contexts = ContextRegistry.getContexts(url.getHost()); + + if (contexts.length == 0) { + return null; + } + + return contexts[0]; + + } + + public String getFileName() { + return file; + } + + public boolean isPackage() { + return folder == null; + } + + public boolean isFolder() { + return file == null && folder != null; + } + + public boolean isFile() { + return file != null; + } + + public String getPackageName() { + return url.getHost(); + } + + public URI[] getContentFiles() throws IOException { + + if (isFile()) { + throw new UnsupportedOperationException("Not supported when the resource is a file!"); + } + + String packageName = url.getHost(); + + Context[] contexts = ContextRegistry.getContexts(packageName); + + if (contexts.length == 0) { + throw new IOException("Android context not found!"); + } + + Context context = contexts[0]; + + ArrayList files = new ArrayList(); + StringBuffer className = new StringBuffer(packageName).append(".R"); + + if (isPackage()) { + ClassLoader classLoader = context.getClass().getClassLoader(); + + try { + + for (String folderName : new String[] {"raw", "xml"}) { + Class clazz = classLoader.loadClass(className.toString() + '$' + folderName); + folderName = '/' + folderName + '/'; + Field[] fields = clazz.getFields(); + + for (Field field : fields) { + try { + files.add(new URI("dex://" + packageName + folderName + field.getName())); + } catch (URISyntaxException e) {} + } + + } + + } catch (ClassNotFoundException e) {} + + } else { + + try { + className.append('$').append(folder); + Class clazz = getClass().getClassLoader().loadClass(className.toString()); + String folderName = '/' + clazz.getSimpleName() + '/'; + Field[] fields = clazz.getFields(); + + for (Field field : fields) { + try { + files.add(new URI("dex://" + packageName + folderName + field.getName())); + } catch (URISyntaxException e) {} + } + + } catch (ClassNotFoundException e) { + throw new IOException("Resource not found!"); + } + + } + + + + URI[] ret = new URI[files.size()]; + files.toArray(ret); + + return ret; + + } + + public URL getURL() { + return url; + } + +} diff --git a/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexURLConnection.java b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexURLConnection.java new file mode 100644 index 0000000000..af0e93b043 --- /dev/null +++ b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexURLConnection.java @@ -0,0 +1,128 @@ +package org.apache.tuscany.sca.android; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.reflect.Field; +import java.net.URL; +import java.net.URLConnection; +import java.net.UnknownServiceException; + +import android.content.Context; + +public class DexURLConnection extends URLConnection { + + private InputStream input; + + protected DexURLConnection(URL url) { + super(url); + setAllowUserInteraction(false); + setUseCaches(false); + setDefaultUseCaches(false); + setConnectTimeout(0); + setReadTimeout(0); + setDoInput(true); + setDoOutput(false); + + } + + public InputStream getInputStream() throws IOException { + + if (input == null) { + connect(); + } + + return input; + + } + + private String guessContentTypeFromInput() { + + if (!connected) { + + try { + connect(); + } catch (IOException e) { + return null; + } + + } + + try { + return guessContentTypeFromStream(input); + } catch (IOException e) { + return null; + } + + } + + @Override + public String getContentType() { + + if (DexResource.getFolder(url.getPath()) == null || DexResource.getFile(url.getPath()) == null) { + return "application/x-dex"; + } + + return guessContentTypeFromInput(); + + } + + public OutputStream getOutputStream() throws IOException { + throw new UnknownServiceException("Output not supported!"); + } + + public void connect() throws IOException { + + if (!connected) { + String host = url.getHost(); + Context[] contexts = ContextRegistry.getContexts(host); + + if (contexts.length == 0) { + throw new IOException("Android context not found!"); + } + + Context context = contexts[0]; + + if ("".equals(host)) { + throw new IOException("not valid host name: \"\""); + } + + String path = url.getPath(); + String file = DexResource.getFile(path); + String folder = DexResource.getFolder(path); + + if (file == null) { + return; + } + + file = file.replace('.', '_'); + + try { + + StringBuffer sb = new StringBuffer(context.getPackageName()); + sb.append('.').append('R').append('$').append(folder); + + Class clazz = getClass().getClassLoader().loadClass(sb.toString()); + Field field = clazz.getDeclaredField(file); + + int id = field.getInt(null); + input = context.getResources().openRawResource(id); + connected = true; + + } catch (ClassNotFoundException e) { + throw new IOException(e.getMessage()); + } catch (SecurityException e) { + throw new IOException(e.getMessage()); + } catch (NoSuchFieldException e) { + throw new IOException(e.getMessage()); + } catch (IllegalArgumentException e) { + throw new IOException(e.getMessage()); + } catch (IllegalAccessException e) { + throw new IOException(e.getMessage()); + } + + } + + } + +} diff --git a/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexURLStreamHandler.java b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexURLStreamHandler.java new file mode 100644 index 0000000000..a5c1507e0d --- /dev/null +++ b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexURLStreamHandler.java @@ -0,0 +1,15 @@ +package org.apache.tuscany.sca.android; + +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLStreamHandler; + +public class DexURLStreamHandler extends URLStreamHandler { + + @Override + protected URLConnection openConnection(URL url) throws IOException { + return new DexURLConnection(url); + } + +} diff --git a/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexURLStreamHandlerFactory.java b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexURLStreamHandlerFactory.java new file mode 100644 index 0000000000..5bb53dcd2e --- /dev/null +++ b/sca-java-1.x/branches/sca-android-r643746/modules/android-jdk-classes/src/org/apache/tuscany/sca/android/DexURLStreamHandlerFactory.java @@ -0,0 +1,33 @@ +package org.apache.tuscany.sca.android; + +import java.net.URLStreamHandler; +import java.net.URLStreamHandlerFactory; + +public class DexURLStreamHandlerFactory implements URLStreamHandlerFactory { + + private static DexURLStreamHandlerFactory instance; + + public static DexURLStreamHandlerFactory getInstance() { + + if (instance == null) { + instance = new DexURLStreamHandlerFactory(); + } + + return instance; + + } + + public DexURLStreamHandlerFactory() {} + + public URLStreamHandler createURLStreamHandler(String protocol) { + URLStreamHandler urlStreamHandler = null; + + if ("dex".equals(protocol)) { + urlStreamHandler = new DexURLStreamHandler(); + } + + return urlStreamHandler; + + } + +} -- cgit v1.2.3