<tag></tag> (which is equivalent to <tag/>
* both input can be parsed with the same code:
*
* p.nextTag()
* p.requireEvent(p.START_TAG, "", "tag");
* String content = p.nextText();
* p.requireEvent(p.END_TAG, "", "tag");
*
* This function together with nextTag make it very easy to parse XML that has
* no mixed content.
*
*
* Essentially it does this
*
* if(getEventType() != START_TAG) {
* throw new XmlPullParserException(
* "parser must be on START_TAG to read next text", this, null);
* }
* int eventType = next();
* if(eventType == TEXT) {
* String result = getText();
* eventType = next();
* if(eventType != END_TAG) {
* throw new XmlPullParserException(
* "event TEXT it must be immediately followed by END_TAG", this, null);
* }
* return result;
* } else if(eventType == END_TAG) {
* return "";
* } else {
* throw new XmlPullParserException(
* "parser must be on START_TAG or TEXT to read text", this, null);
* }
*
*/
String nextText() throws XmlPullParserException, IOException;
/**
* Call next() and return event if it is START_TAG or END_TAG
* otherwise throw an exception.
* It will skip whitespace TEXT before actual tag if any.
*
* essentially it does this
*
* int eventType = next();
* if(eventType == TEXT && isWhitespace()) { // skip whitespace
* eventType = next();
* }
* if (eventType != START_TAG && eventType != END_TAG) {
* throw new XmlPullParserException("expected start or end tag", this, null);
* }
* return eventType;
*
*/
int nextTag() throws XmlPullParserException, IOException;
// /**
// * Skip sub tree on which the parser is currently positioned on.
// * NOTE: parser must be on START_TAG and when function returns
// * parser will be positioned on matching END_TAG
// *
// * This method is typically optimized by parser but the its logic should follow this:
// *
// * require(XmlPullParser.START_TAG, null, null);
// * int level = 1;
// * while(level > 0) {
// * int eventType = next();
// * if(eventType == XmlPullParser.END_TAG) {
// * --level;
// * } else if(eventType == XmlPullParser.START_TAG) {
// * ++level;
// * }
// * }
// *
// */
// public void skipSubTree() throws XmlPullParserException, IOException;
}
xpp3-1.1.4c/src/java/api/org/xmlpull/v1/XmlPullParserException.java 100644 0 0 4334 10525225062 24241 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1;
/**
* This exception is thrown to signal XML Pull Parser related faults.
*
* @author Aleksander Slominski
*/
public class XmlPullParserException extends Exception {
protected Throwable detail;
protected int row = -1;
protected int column = -1;
/* public XmlPullParserException() {
}*/
public XmlPullParserException(String s) {
super(s);
}
/*
public XmlPullParserException(String s, Throwable thrwble) {
super(s);
this.detail = thrwble;
}
public XmlPullParserException(String s, int row, int column) {
super(s);
this.row = row;
this.column = column;
}
*/
public XmlPullParserException(String msg, XmlPullParser parser, Throwable chain) {
super ((msg == null ? "" : msg+" ")
+ (parser == null ? "" : "(position:"+parser.getPositionDescription()+") ")
+ (chain == null ? "" : "caused by: "+chain));
if (parser != null) {
this.row = parser.getLineNumber();
this.column = parser.getColumnNumber();
}
this.detail = chain;
}
public Throwable getDetail() { return detail; }
// public void setDetail(Throwable cause) { this.detail = cause; }
public int getLineNumber() { return row; }
public int getColumnNumber() { return column; }
/*
public String getMessage() {
if(detail == null)
return super.getMessage();
else
return super.getMessage() + "; nested exception is: \n\t"
+ detail.getMessage();
}
*/
//NOTE: code that prints this and detail is difficult in J2ME
public void printStackTrace() {
if (detail == null) {
super.printStackTrace();
} else {
synchronized(System.err) {
System.err.println(super.getMessage() + "; nested exception is:");
detail.printStackTrace();
}
}
}
}
xpp3-1.1.4c/src/java/api/org/xmlpull/v1/XmlPullParserFactory.java 100644 0 0 31406 10525225062 23732 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
/**
* This class is used to create implementations of XML Pull Parser defined in XMPULL V1 API.
* The name of actual factory class will be determined based on several parameters.
* It works similar to JAXP but tailored to work in J2ME environments
* (no access to system properties or file system) so name of parser class factory to use
* and its class used for loading (no class loader - on J2ME no access to context class loaders)
* must be passed explicitly. If no name of parser factory was passed (or is null)
* it will try to find name by searching in CLASSPATH for
* META-INF/services/org.xmlpull.v1.XmlPullParserFactory resource that should contain
* a comma separated list of class names of factories or parsers to try (in order from
* left to the right). If none found, it will throw an exception.
*
* NOTE: In J2SE or J2EE environments, you may want to use
* newInstance(property, classLoaderCtx)
* where first argument is
* System.getProperty(XmlPullParserFactory.PROPERTY_NAME)
* and second is Thread.getContextClassLoader().getClass()
.
*
* @see XmlPullParser
*
* @author Aleksander Slominski
* @author Stefan Haustein
*/
public class XmlPullParserFactory {
/** used as default class to server as context class in newInstance() */
final static Class referenceContextClass;
static {
XmlPullParserFactory f = new XmlPullParserFactory();
referenceContextClass = f.getClass();
}
/** Name of the system or midlet property that should be used for
a system property containing a comma separated list of factory
or parser class names (value:
org.xmlpull.v1.XmlPullParserFactory). */
public static final String PROPERTY_NAME =
"org.xmlpull.v1.XmlPullParserFactory";
private static final String RESOURCE_NAME =
"/META-INF/services/" + PROPERTY_NAME;
// public static final String DEFAULT_PROPERTY =
// "org.xmlpull.xpp3.XmlPullParser,org.kxml2.io.KXmlParser";
protected Vector parserClasses;
protected String classNamesLocation;
protected Vector serializerClasses;
// features are kept there
protected Hashtable features = new Hashtable();
/**
* Protected constructor to be called by factory implementations.
*/
protected XmlPullParserFactory() {
}
/**
* Set the features to be set when XML Pull Parser is created by this factory.
* NOTE: factory features are not used for XML Serializer.
*
* @param name string with URI identifying feature
* @param state if true feature will be set; if false will be ignored
*/
public void setFeature(String name,
boolean state) throws XmlPullParserException {
features.put(name, new Boolean(state));
}
/**
* Return the current value of the feature with given name.
*
NOTE: factory features are not used for XML Serializer.
*
* @param name The name of feature to be retrieved.
* @return The value of named feature.
* Unknown features are always returned as false
*/
public boolean getFeature (String name) {
Boolean value = (Boolean) features.get(name);
return value != null ? value.booleanValue() : false;
}
/**
* Specifies that the parser produced by this factory will provide
* support for XML namespaces.
* By default the value of this is set to false.
*
* @param awareness true if the parser produced by this code
* will provide support for XML namespaces; false otherwise.
*/
public void setNamespaceAware(boolean awareness) {
features.put (XmlPullParser.FEATURE_PROCESS_NAMESPACES, new Boolean (awareness));
}
/**
* Indicates whether or not the factory is configured to produce
* parsers which are namespace aware
* (it simply set feature XmlPullParser.FEATURE_PROCESS_NAMESPACES to true or false).
*
* @return true if the factory is configured to produce parsers
* which are namespace aware; false otherwise.
*/
public boolean isNamespaceAware() {
return getFeature (XmlPullParser.FEATURE_PROCESS_NAMESPACES);
}
/**
* Specifies that the parser produced by this factory will be validating
* (it simply set feature XmlPullParser.FEATURE_VALIDATION to true or false).
*
* By default the value of this is set to false.
*
* @param validating - if true the parsers created by this factory must be validating.
*/
public void setValidating(boolean validating) {
features.put (XmlPullParser.FEATURE_VALIDATION, new Boolean (validating));
}
/**
* Indicates whether or not the factory is configured to produce parsers
* which validate the XML content during parse.
*
* @return true if the factory is configured to produce parsers
* which validate the XML content during parse; false otherwise.
*/
public boolean isValidating() {
return getFeature (XmlPullParser.FEATURE_VALIDATION);
}
/**
* Creates a new instance of a XML Pull Parser
* using the currently configured factory features.
*
* @return A new instance of a XML Pull Parser.
* @throws XmlPullParserException if a parser cannot be created which satisfies the
* requested configuration.
*/
public XmlPullParser newPullParser() throws XmlPullParserException {
if (parserClasses == null) throw new XmlPullParserException
("Factory initialization was incomplete - has not tried "+classNamesLocation);
if (parserClasses.size() == 0) throw new XmlPullParserException
("No valid parser classes found in "+classNamesLocation);
final StringBuffer issues = new StringBuffer ();
for (int i = 0; i < parserClasses.size (); i++) {
final Class ppClass = (Class) parserClasses.elementAt (i);
try {
final XmlPullParser pp = (XmlPullParser) ppClass.newInstance();
// if( ! features.isEmpty() ) {
//Enumeration keys = features.keys();
// while(keys.hasMoreElements()) {
for (Enumeration e = features.keys (); e.hasMoreElements ();) {
final String key = (String) e.nextElement();
final Boolean value = (Boolean) features.get(key);
if(value != null && value.booleanValue()) {
pp.setFeature(key, true);
}
}
return pp;
} catch(Exception ex) {
issues.append (ppClass.getName () + ": "+ ex.toString ()+"; ");
}
}
throw new XmlPullParserException ("could not create parser: "+issues);
}
/**
* Creates a new instance of a XML Serializer.
*
* NOTE: factory features are not used for XML Serializer.
*
* @return A new instance of a XML Serializer.
* @throws XmlPullParserException if a parser cannot be created which satisfies the
* requested configuration.
*/
public XmlSerializer newSerializer() throws XmlPullParserException {
if (serializerClasses == null) {
throw new XmlPullParserException
("Factory initialization incomplete - has not tried "+classNamesLocation);
}
if(serializerClasses.size() == 0) {
throw new XmlPullParserException
("No valid serializer classes found in "+classNamesLocation);
}
final StringBuffer issues = new StringBuffer ();
for (int i = 0; i < serializerClasses.size (); i++) {
final Class ppClass = (Class) serializerClasses.elementAt (i);
try {
final XmlSerializer ser = (XmlSerializer) ppClass.newInstance();
// for (Enumeration e = features.keys (); e.hasMoreElements ();) {
// String key = (String) e.nextElement();
// Boolean value = (Boolean) features.get(key);
// if(value != null && value.booleanValue()) {
// ser.setFeature(key, true);
// }
// }
return ser;
} catch(Exception ex) {
issues.append (ppClass.getName () + ": "+ ex.toString ()+"; ");
}
}
throw new XmlPullParserException ("could not create serializer: "+issues);
}
/**
* Create a new instance of a PullParserFactory that can be used
* to create XML pull parsers (see class description for more
* details).
*
* @return a new instance of a PullParserFactory, as returned by newInstance (null, null);
*/
public static XmlPullParserFactory newInstance () throws XmlPullParserException {
return newInstance(null, null);
}
public static XmlPullParserFactory newInstance (String classNames, Class context)
throws XmlPullParserException {
if (context == null) {
//NOTE: make sure context uses the same class loader as API classes
// this is the best we can do without having access to context classloader in J2ME
// if API is in the same classloader as implementation then this will work
context = referenceContextClass;
}
String classNamesLocation = null;
if (classNames == null || classNames.length() == 0 || "DEFAULT".equals(classNames)) {
try {
InputStream is = context.getResourceAsStream (RESOURCE_NAME);
if (is == null) throw new XmlPullParserException
("resource not found: "+RESOURCE_NAME
+" make sure that parser implementing XmlPull API is available");
final StringBuffer sb = new StringBuffer();
while (true) {
final int ch = is.read();
if (ch < 0) break;
else if (ch > ' ')
sb.append((char) ch);
}
is.close ();
classNames = sb.toString ();
}
catch (Exception e) {
throw new XmlPullParserException (null, null, e);
}
classNamesLocation = "resource "+RESOURCE_NAME+" that contained '"+classNames+"'";
} else {
classNamesLocation =
"parameter classNames to newInstance() that contained '"+classNames+"'";
}
XmlPullParserFactory factory = null;
final Vector parserClasses = new Vector ();
final Vector serializerClasses = new Vector ();
int pos = 0;
while (pos < classNames.length ()) {
int cut = classNames.indexOf (',', pos);
if (cut == -1) cut = classNames.length ();
final String name = classNames.substring (pos, cut);
Class candidate = null;
Object instance = null;
try {
candidate = Class.forName (name);
// necessary because of J2ME .class issue
instance = candidate.newInstance ();
}
catch (Exception e) {}
if (candidate != null) {
boolean recognized = false;
if (instance instanceof XmlPullParser) {
parserClasses.addElement (candidate);
recognized = true;
}
if (instance instanceof XmlSerializer) {
serializerClasses.addElement (candidate);
recognized = true;
}
if (instance instanceof XmlPullParserFactory) {
if (factory == null) {
factory = (XmlPullParserFactory) instance;
}
recognized = true;
}
if (!recognized) {
throw new XmlPullParserException ("incompatible class: "+name);
}
}
pos = cut + 1;
}
if (factory == null) {
factory = new XmlPullParserFactory ();
}
factory.parserClasses = parserClasses;
factory.serializerClasses = serializerClasses;
factory.classNamesLocation = classNamesLocation;
return factory;
}
}
xpp3-1.1.4c/src/java/api/org/xmlpull/v1/XmlSerializer.java 100644 0 0 35067 10525225062 22431 0 ustar aslom ewww 0 0 package org.xmlpull.v1;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
/**
* Define an interface to serialziation of XML Infoset.
* This interface abstracts away if serialized XML is XML 1.0 comaptible text or
* other formats of XML 1.0 serializations (such as binary XML for example with WBXML).
*
*
PLEASE NOTE: This interface will be part of XmlPull 1.2 API.
* It is included as basis for discussion. It may change in any way.
*
*
Exceptions that may be thrown are: IOException or runtime exception
* (more runtime exceptions can be thrown but are not declared and as such
* have no semantics defined for this interface):
*
* IllegalArgumentException - for almost all methods to signal that
* argument is illegal
* IllegalStateException - to signal that call has good arguments but
* is not expected here (violation of contract) and for features/properties
* when requesting setting unimplemented feature/property
* (UnsupportedOperationException would be better but it is not in MIDP)
*
*
* NOTE: writing CDSECT, ENTITY_REF, IGNORABLE_WHITESPACE,
* PROCESSING_INSTRUCTION, COMMENT, and DOCDECL in some implementations
* may not be supported (for example when serializing to WBXML).
* In such case IllegalStateException will be thrown and it is recommened
* to use an optional feature to signal that implementation is not
* supporting this kind of output.
*/
public interface XmlSerializer {
/**
* Set feature identified by name (recommended to be URI for uniqueness).
* Some well known optional features are defined in
*
* http://www.xmlpull.org/v1/doc/features.html .
*
* If feature is not recocgnized or can not be set
* then IllegalStateException MUST be thrown.
*
* @exception IllegalStateException If the feature is not supported or can not be set
*/
void setFeature(String name,
boolean state)
throws IllegalArgumentException, IllegalStateException;
/**
* Return the current value of the feature with given name.
*
NOTE: unknown properties are always returned as null
*
* @param name The name of feature to be retrieved.
* @return The value of named feature.
* @exception IllegalArgumentException if feature string is null
*/
boolean getFeature(String name);
/**
* Set the value of a property.
* (the property name is recommened to be URI for uniqueness).
* Some well known optional properties are defined in
*
* http://www.xmlpull.org/v1/doc/properties.html .
*
* If property is not recocgnized or can not be set
* then IllegalStateException MUST be thrown.
*
* @exception IllegalStateException if the property is not supported or can not be set
*/
void setProperty(String name,
Object value)
throws IllegalArgumentException, IllegalStateException;
/**
* Look up the value of a property.
*
* The property name is any fully-qualified URI. I
*
NOTE: unknown properties are always returned as null
*
* @param name The name of property to be retrieved.
* @return The value of named property.
*/
Object getProperty(String name);
/**
* Set to use binary output stream with given encoding.
*/
void setOutput (OutputStream os, String encoding)
throws IOException, IllegalArgumentException, IllegalStateException;
/**
* Set the output to the given writer.
* WARNING no information about encoding is available!
*/
void setOutput (Writer writer)
throws IOException, IllegalArgumentException, IllegalStateException;
/**
* Write <?xml declaration with encoding (if encoding not null)
* and standalone flag (if standalone not null)
* This method can only be called just after setOutput.
*/
void startDocument (String encoding, Boolean standalone)
throws IOException, IllegalArgumentException, IllegalStateException;
/**
* Finish writing. All unclosed start tags will be closed and output
* will be flushed. After calling this method no more output can be
* serialized until next call to setOutput()
*/
void endDocument ()
throws IOException, IllegalArgumentException, IllegalStateException;
/**
* Binds the given prefix to the given namespace.
* This call is valid for the next element including child elements.
* The prefix and namespace MUST be always declared even if prefix
* is not used in element (startTag() or attribute()) - for XML 1.0
* it must result in declaring xmlns:prefix='namespace'
* (or xmlns:prefix="namespace"
depending what character is used
* to quote attribute value).
*
*
NOTE: this method MUST be called directly before startTag()
* and if anything but startTag() or setPrefix() is called next there will be exception.
*
NOTE: prefixes "xml" and "xmlns" are already bound
* and can not be redefined see:
* Namespaces in XML Errata .
*
NOTE: to set default namespace use as prefix empty string.
*
* @param prefix must be not null (or IllegalArgumentException is thrown)
* @param namespace must be not null
*/
void setPrefix (String prefix, String namespace)
throws IOException, IllegalArgumentException, IllegalStateException;
/**
* Return namespace that corresponds to given prefix
* If there is no prefix bound to this namespace return null
* but if generatePrefix is false then return generated prefix.
*
*
NOTE: if the prefix is empty string "" and defualt namespace is bound
* to this prefix then empty string ("") is returned.
*
*
NOTE: prefixes "xml" and "xmlns" are already bound
* will have values as defined
* Namespaces in XML specification
*/
String getPrefix (String namespace, boolean generatePrefix)
throws IllegalArgumentException;
/**
* Returns the current depth of the element.
* Outside the root element, the depth is 0. The
* depth is incremented by 1 when startTag() is called.
* The depth is decremented after the call to endTag()
* event was observed.
*
*
* <!-- outside --> 0
* <root> 1
* sometext 1
* <foobar> 2
* </foobar> 2
* </root> 1
* <!-- outside --> 0
*
*/
int getDepth();
/**
* Returns the namespace URI of the current element as set by startTag().
*
* NOTE: that measn in particaulr that:
* if there was startTag("", ...) then getNamespace() returns ""
* if there was startTag(null, ...) then getNamespace() returns null
*
*
* @return namespace set by startTag() that is currently in scope
*/
String getNamespace ();
/**
* Returns the name of the current element as set by startTag().
* It can only be null before first call to startTag()
* or when last endTag() is called to close first startTag().
*
* @return namespace set by startTag() that is currently in scope
*/
String getName();
/**
* Writes a start tag with the given namespace and name.
* If there is no prefix defined for the given namespace,
* a prefix will be defined automatically.
* The explicit prefixes for namespaces can be established by calling setPrefix()
* immediately before this method.
* If namespace is null no namespace prefix is printed but just name.
* If namespace is empty string then serialzier will make sure that
* default empty namespace is declared (in XML 1.0 xmlns='')
* or throw IllegalStateException if default namespace is already bound
* to non-empty string.
*/
XmlSerializer startTag (String namespace, String name)
throws IOException, IllegalArgumentException, IllegalStateException;
/**
* Write an attribute. Calls to attribute() MUST follow a call to
* startTag() immediately. If there is no prefix defined for the
* given namespace, a prefix will be defined automatically.
* If namespace is null or empty string
* no namespace prefix is printed but just name.
*/
XmlSerializer attribute (String namespace, String name, String value)
throws IOException, IllegalArgumentException, IllegalStateException;
/**
* Write end tag. Repetition of namespace and name is just for avoiding errors.
* Background: in kXML endTag had no arguments, and non matching tags were
* very difficult to find...
* If namespace is null no namespace prefix is printed but just name.
* If namespace is empty string then serialzier will make sure that
* default empty namespace is declared (in XML 1.0 xmlns='').
*/
XmlSerializer endTag (String namespace, String name)
throws IOException, IllegalArgumentException, IllegalStateException;
// /**
// * Writes a start tag with the given namespace and name.
// * If there is no prefix defined (prefix == null) for the given namespace,
// * a prefix will be defined automatically.
// * If explicit prefixes is passed (prefix != null) then it will be used
// *and namespace declared if not already declared or
// * throw IllegalStateException the same prefix was already set on this
// * element (setPrefix()) and was bound to different namespace.
// * If namespace is null then prefix must be null too or IllegalStateException is thrown.
// * If namespace is null then no namespace prefix is printed but just name.
// * If namespace is empty string then serializer will make sure that
// * default empty namespace is declared (in XML 1.0 xmlns='')
// * or throw IllegalStateException if default namespace is already bound
// * to non-empty string.
// */
// XmlSerializer startTag (String prefix, String namespace, String name)
// throws IOException, IllegalArgumentException, IllegalStateException;
//
// /**
// * Write an attribute. Calls to attribute() MUST follow a call to
// * startTag() immediately.
// * If there is no prefix defined (prefix == null) for the given namespace,
// * a prefix will be defined automatically.
// * If explicit prefixes is passed (prefix != null) then it will be used
// * and namespace declared if not already declared or
// * throw IllegalStateException the same prefix was already set on this
// * element (setPrefix()) and was bound to different namespace.
// * If namespace is null then prefix must be null too or IllegalStateException is thrown.
// * If namespace is null then no namespace prefix is printed but just name.
// * If namespace is empty string then serializer will make sure that
// * default empty namespace is declared (in XML 1.0 xmlns='')
// * or throw IllegalStateException if default namespace is already bound
// * to non-empty string.
// */
// XmlSerializer attribute (String prefix, String namespace, String name, String value)
// throws IOException, IllegalArgumentException, IllegalStateException;
//
// /**
// * Write end tag. Repetition of namespace, prefix, and name is just for avoiding errors.
// * If namespace or name arguments are different from corresponding startTag call
// * then IllegalArgumentException is thrown, if prefix argument is not null and is different
// * from corresponding starTag then IllegalArgumentException is thrown.
// * If namespace is null then prefix must be null too or IllegalStateException is thrown.
// * If namespace is null then no namespace prefix is printed but just name.
// * If namespace is empty string then serializer will make sure that
// * default empty namespace is declared (in XML 1.0 xmlns='').
// *
Background: in kXML endTag had no arguments, and non matching tags were
// * very difficult to find...
// */
// ALEK: This is really optional as prefix in end tag MUST correspond to start tag but good for error checking
// XmlSerializer endTag (String prefix, String namespace, String name)
// throws IOException, IllegalArgumentException, IllegalStateException;
/**
* Writes text, where special XML chars are escaped automatically
*/
XmlSerializer text (String text)
throws IOException, IllegalArgumentException, IllegalStateException;
/**
* Writes text, where special XML chars are escaped automatically
*/
XmlSerializer text (char [] buf, int start, int len)
throws IOException, IllegalArgumentException, IllegalStateException;
void cdsect (String text)
throws IOException, IllegalArgumentException, IllegalStateException;
void entityRef (String text) throws IOException,
IllegalArgumentException, IllegalStateException;
void processingInstruction (String text)
throws IOException, IllegalArgumentException, IllegalStateException;
void comment (String text)
throws IOException, IllegalArgumentException, IllegalStateException;
void docdecl (String text)
throws IOException, IllegalArgumentException, IllegalStateException;
void ignorableWhitespace (String text)
throws IOException, IllegalArgumentException, IllegalStateException;
/**
* Write all pending output to the stream.
* If method startTag() or attribute() was called then start tag is closed (final >)
* before flush() is called on underlying output stream.
*
* NOTE: if there is need to close start tag
* (so no more attribute() calls are allowed) but without flushinging output
* call method text() with empty string (text("")).
*
*/
void flush ()
throws IOException;
}
xpp3-1.1.4c/src/java/builder/javax/xml/namespace/QName.java 100644 0 0 21435 10525225063 22543 0 ustar aslom ewww 0 0 /*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Axis" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* .
*/
package javax.xml.namespace;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
/**
* NOTE: copied from Apache AXIS until QName is really standard in some JDK version ...
*
* QName
class represents the value of a qualified name
* as specified in XML
* Schema Part2: Datatypes specification .
*
* The value of a QName contains a namespaceURI , a localPart and a prefix .
* The localPart provides the local part of the qualified name. The
* namespaceURI is a URI reference identifying the namespace.
*
* @version 1.1
*/
public class QName implements Serializable {
/** comment/shared empty string */
private static final String emptyString = "".intern();
/** Field namespaceURI */
private String namespaceURI;
/** Field localPart */
private String localPart;
/** Field prefix */
private String prefix;
/**
* Constructor for the QName.
*
* @param localPart Local part of the QName
*/
public QName(String localPart) {
this(emptyString, localPart, emptyString);
}
/**
* Constructor for the QName.
*
* @param namespaceURI Namespace URI for the QName
* @param localPart Local part of the QName.
*/
public QName(String namespaceURI, String localPart) {
this(namespaceURI, localPart, emptyString);
}
/**
* Constructor for the QName.
*
* @param namespaceURI Namespace URI for the QName
* @param localPart Local part of the QName.
* @param prefix Prefix of the QName.
*/
public QName(String namespaceURI, String localPart, String prefix) {
this.namespaceURI = (namespaceURI == null)
? emptyString
: namespaceURI.intern();
if (localPart == null) {
throw new IllegalArgumentException("invalid QName local part");
} else {
this.localPart = localPart.intern();
}
if (prefix == null) {
throw new IllegalArgumentException("invalid QName prefix");
} else {
this.prefix = prefix.intern();
}
}
/**
* Gets the Namespace URI for this QName
*
* @return Namespace URI
*/
public String getNamespaceURI() {
return namespaceURI;
}
/**
* Gets the Local part for this QName
*
* @return Local part
*/
public String getLocalPart() {
return localPart;
}
/**
* Gets the Prefix for this QName
*
* @return Prefix
*/
public String getPrefix() {
return prefix;
}
/**
* Returns a string representation of this QName
*
* @return a string representation of the QName
*/
public String toString() {
return ((namespaceURI == emptyString)
? localPart
: '{' + namespaceURI + '}' + localPart);
}
/**
* Tests this QName for equality with another object.
*
* If the given object is not a QName or is null then this method
* returns false .
*
* For two QNames to be considered equal requires that both
* localPart and namespaceURI must be equal. This method uses
* String.equals
to check equality of localPart
* and namespaceURI. Any class that extends QName is required
* to satisfy this equality contract.
*
* This method satisfies the general contract of the Object.equals
method.
*
* @param obj the reference object with which to compare
*
* @return true
if the given object is identical to this
* QName: false
otherwise.
*/
public final boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof QName)) {
return false;
}
if ((namespaceURI == ((QName) obj).namespaceURI)
&& (localPart == ((QName) obj).localPart)) {
return true;
}
return false;
}
/**
* Returns a QName holding the value of the specified String.
*
* The string must be in the form returned by the QName.toString()
* method, i.e. "{namespaceURI}localPart", with the "{namespaceURI}"
* part being optional.
*
* This method doesn't do a full validation of the resulting QName.
* In particular, it doesn't check that the resulting namespace URI
* is a legal URI (per RFC 2396 and RFC 2732), nor that the resulting
* local part is a legal NCName per the XML Namespaces specification.
*
* @param s the string to be parsed
* @throws java.lang.IllegalArgumentException If the specified String cannot be parsed as a QName
* @return QName corresponding to the given String
*/
public static QName valueOf(String s) {
if ((s == null) || s.equals("")) {
throw new IllegalArgumentException("invalid QName literal");
}
if (s.charAt(0) == '{') {
int i = s.indexOf('}');
if (i == -1) {
throw new IllegalArgumentException("invalid QName literal");
}
if (i == s.length() - 1) {
throw new IllegalArgumentException("invalid QName literal");
} else {
return new QName(s.substring(1, i), s.substring(i + 1));
}
} else {
return new QName(s);
}
}
/**
* Returns a hash code value for this QName object. The hash code
* is based on both the localPart and namespaceURI parts of the
* QName. This method satisfies the general contract of the
* Object.hashCode
method.
*
* @return a hash code value for this Qname object
*/
public final int hashCode() {
return namespaceURI.hashCode() ^ localPart.hashCode();
}
/**
* Ensure that deserialization properly interns the results.
* @param in the ObjectInputStream to be read
*/
private void readObject(ObjectInputStream in) throws
IOException, ClassNotFoundException {
in.defaultReadObject();
namespaceURI = namespaceURI.intern();
localPart = localPart.intern();
prefix = prefix.intern();
}
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/Iterable.java 100644 0 0 553 10525225063 23622 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
import java.util.Iterator;
//JDK15 remove and replace usage with real Iterable
/**
* Use java.lang.Iterable instead when JDK 1.5 comes out ...*
*
* @version $Revision: 1.3 $
* @author Aleksander Slominski
*/
public interface Iterable
{
public Iterator iterator();
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlAttribute.java 100644 0 0 3034 10525225063 24534 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
/**
* This is immutable value object that represents
* Attribute
* Information Item
* with exception of references property.
* Note: namespace and prefix properties are folded into XmlNamespace value object.
*
* @version $Revision: 1.6 $
* @author Aleksander Slominski
*/
public interface XmlAttribute extends Cloneable
{
/**
* Method clone
*
* @return an Object
*
* @exception CloneNotSupportedException
*
*/
public Object clone() throws CloneNotSupportedException;
/**
* XML Infoset [owner element] property
*/
public XmlElement getOwner();
//public XmlElement setOwner(XmlElement newOwner);
//public String getPrefix();
/**
* return XML Infoset [namespace name] property (namespaceName from getNamespace()
* or null if attribute has no namespace
*/
public String getNamespaceName();
/**
* Combination of XML Infoset [namespace name] and [prefix] properties
*/
public XmlNamespace getNamespace();
/**
* XML Infoset [local name] property
*/
public String getName();
/**
* XML Infoset [normalized value] property
*/
public String getValue();
/**
* XML Infoset [attribute type]
*/
public String getType();
/**
* XML Infoset [specified] flag
*/
public boolean isSpecified();
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlBuilderException.java 100644 0 0 3434 10525225063 26042 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.builder;
/**
* This exception is thrown to signal XB1 related exceptions.
*
* @version $Revision: 1.2 $
* @author Aleksander Slominski
*/
public class XmlBuilderException extends RuntimeException {
protected Throwable detail;
//protected int row = -1;
//protected int column = -1;
public XmlBuilderException(String s) {
super(s);
}
public XmlBuilderException(String s, Throwable thrwble) {
super(s);
this.detail = thrwble;
}
public Throwable getDetail() { return detail; }
// public void setDetail(Throwable cause) { this.detail = cause; }
public String getMessage() {
if(detail == null)
return super.getMessage();
else
return super.getMessage() + "; nested exception is: \n\t"
+ detail.getMessage();
}
public void printStackTrace(java.io.PrintStream ps) {
if (detail == null) {
super.printStackTrace(ps);
} else {
synchronized(ps) {
//ps.println(this);
ps.println(super.getMessage() + "; nested exception is:");
detail.printStackTrace(ps);
}
}
}
public void printStackTrace() {
printStackTrace(System.err);
}
public void printStackTrace(java.io.PrintWriter pw){
if (detail == null) {
super.printStackTrace(pw);
} else {
synchronized(pw) {
//pw.println(this);
pw.println(super.getMessage() + "; nested exception is:");
detail.printStackTrace(pw);
}
}
}
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlCharacters.java 100644 0 0 1020 10525225063 24641 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
/**
* Represents otrdered colection of
* Character Information Items
* where character code properties are put together into Java String.
*
* @version $Revision: 1.5 $
* @author Aleksander Slominski
*/
public interface XmlCharacters extends XmlContained
{
public String getText();
public Boolean isWhitespaceContent();
//public XmlElement getParent();
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlComment.java 100644 0 0 1136 10525225063 24174 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
/**
* Represents
* Comment Information Item .
*
*
* @version $Revision: 1.5 $
* @author Aleksander Slominski
*/
public interface XmlComment //extends XmlContainer
{
/**
* A string representing the content of the comment.
*/
public String getContent();
/**
* The document or element information item which contains this information item
* in its [children] property.
*/
public XmlContainer getParent();
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlContained.java 100644 0 0 1160 10525225063 24473 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
/**
* Common abstraction to represent XML infoset item that are contained in other infoet items
* This is useful so parent can be updated on contained items when container is cloned ...
*
* @version $Revision: 1.3 $
* @author Aleksander Slominski
*/
public interface XmlContained
{
//Object getPrent() -- requires covariant return to work both in
/// XmlElement (returns XmlContainer) and XmlComment (returns XmlContainer) ...
public XmlContainer getParent();
public void setParent(XmlContainer el);
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlContainer.java 100644 0 0 646 10525225063 24501 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
/**
* Common abstraction shared between XmlElement, XmlDocument and XmlDoctype
* to represent XML Infoset item that can contain other Infoset items
* This is useful so getParent() operation will return this instead of Object ...
*
* @version $Revision: 1.4 $
* @author Aleksander Slominski
*/
public interface XmlContainer
{
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlDoctype.java 100644 0 0 3737 10525225063 24212 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
import java.util.Iterator;
/**
* Represents
* Document Type Declaration
* Information Item .
* If the XML document has a document type declaration,
* then the information set contains a single document type declaration information item.
* Note that entities and notations are provided as properties of the document information item,
* not the document type declaration information item.
*
* @version $Revision: 1.2 $
* @author Aleksander Slominski
*/
public interface XmlDoctype extends XmlContainer
{
/**
* The system identifier of the external subset, as it appears in the DOCTYPE declaration,
* without any additional URI escaping applied by the processor.
* If there is no external subset this property has no value.
*/
public String getSystemIdentifier();
/**
* The public identifier of the external subset, normalized as described in
* 4.2.2 External Entities [XML] .
* If there is no external subset or if it has no public identifier,
* this property has no value.
*/
public String getPublicIdentifier();
/**
* An ordered list of processing instruction information items representing processing
* instructions appearing in the DTD, in the original document order.
* Items from the internal DTD subset appear before those in the external subset.
*/
public Iterator children();
/**
* The document information item.
*/
public XmlDocument getParent();
// manipulate children
/**
* Add to list of children (only processing instruction information items are allowed).
*/
public XmlProcessingInstruction addProcessingInstruction(String target, String content);
/**
* Remove all children.
*/
public void removeAllProcessingInstructions();
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlDocument.java 100644 0 0 6402 10525225063 24351 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
/**
* Represents
* Document Information Item
* .
*
* @version $Revision: 1.6 $
* @author Aleksander Slominski
*/
public interface XmlDocument extends XmlContainer, Cloneable
{
//JDK15 covariant public XmlDocument clone() throws CloneNotSupportedException
public Object clone() throws CloneNotSupportedException;
/**
* An ordered list of child information items, in document order.
* The list contains exactly one element information item.
* The list also contains one processing instruction information item
* for each processing instruction outside the document element,
* and one comment information item for each comment outside the document element.
* Processing instructions and comments within the DTD are excluded.
* If there is a document type declaration,
* the list also contains a document type declaration information item.
*/
public Iterable children();
public XmlElement getDocumentElement();
public XmlElement requiredElement(XmlNamespace n, String name);
public XmlElement element(XmlNamespace n, String name);
public XmlElement element(XmlNamespace n, String name, boolean create);
/**
* An unordered set of notation information items,
* one for each notation declared in the DTD.
*/
public Iterable notations();
/**
* An unordered set of unparsed entity information items,
* one for each unparsed entity declared in the DTD.
*/
public Iterable unparsedEntities();
public String getBaseUri();
public String getCharacterEncodingScheme();
public void setCharacterEncodingScheme(String characterEncoding);
public Boolean isStandalone();
public String getVersion();
//public String setVersion();
public boolean isAllDeclarationsProcessed();
// manipulate children
public void setDocumentElement(XmlElement rootElement);
public void addChild(Object child);
public void insertChild(int pos, Object child);
//removeChild
public void removeAllChildren();
public XmlComment newComment(String content);
public XmlComment addComment(String content);
public XmlDoctype newDoctype(String systemIdentifier, String publicIdentifier);
public XmlDoctype addDoctype(String systemIdentifier, String publicIdentifier);
//public XmlElement newDocumentElement(String name);
public XmlElement addDocumentElement(String name);
public XmlElement addDocumentElement(XmlNamespace namespace, String name);
public XmlProcessingInstruction newProcessingInstruction(String target, String content);
public XmlProcessingInstruction addProcessingInstruction(String target, String content);
//addDoctype
// manipulate unparsed entities
//addUnparsedEntity
public void removeAllUnparsedEntities();
// manipulate notations
public XmlNotation addNotation(String name,
String systemIdentifier,
String publicIdentifier,
String declarationBaseUri);
public void removeAllNotations();
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlElement.java 100644 0 0 41776 10525225063 24221 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
import java.util.Iterator;
//setText() instead of replaceChildrenWithText
//setAttribute*() instead of addAtrribute*()
//TODO add method attributeValue( "id" );
//TODO add method requiredAttribute( "id" );
//TODO add method requiredAttributeValue( "id" );
//TODO setAttributeValue(key, value) //create attribute if necessary
//TODO setAttributeValue(attribute) //replace exisiting attribute if necessary
//TODO add XmlElement requiredFirstElement() in Adapter?
//TODO add XmlElement requiredOneElement() in AdpateR?
/**
* Represents
* Element Information Item
* except for in-scope namespaces that can be reconstructed by visiting this element parent,
* checking its namespaces, then grandparent and so on. For convenience there are
* methods to resolve namespace prefix for given namespace name.
*
* NOTE: this representaiton is optimized for streaming - iterator approach that
* allows gradual visiting of nodes is preferred over indexed access.
*
* @version $Revision: 1.25 $
* @author Aleksander Slominski
*/
public interface XmlElement extends XmlContainer, XmlContained, Cloneable
{
public static final String NO_NAMESPACE = "";
//JDK15 covariant public XmlElement clone() throws CloneNotSupportedException
/**
* Method clone
*
* @return an Object
*
* @exception CloneNotSupportedException
*
*/
public Object clone() throws CloneNotSupportedException;
//----------------------------------------------------------------------------------------------
// Element properties
/**
* XML Infoset [base URI] property
*
* @return a String
*
*/
public String getBaseUri();
/**
* XML Infoset [base URI] property
*
* @param baseUri a String
*
*/
public void setBaseUri(String baseUri);
/**
* Get top most container that is either XmlDocument or XmlElement (may be event this element!!!)
*/
public XmlContainer getRoot();
/**
* XML Infoset [parent] property.
* If current element is not child of containing parent XmlElement or XmlDocument
* then builder exception will be thrown
*/
public XmlContainer getParent();
/**
* Method setParent
*
* @param parent a XmlContainer
*
*/
public void setParent(XmlContainer parent);
/**
* Return namespace of current element
* (XML Infoset [namespace name] and [prefix] properties combined)
* null is only returned if
* element was created without namespace
* */
public XmlNamespace getNamespace();
/**
* Return namespace name (XML Infoset [namespace name]property
* or null if element has no namespace
*/
public String getNamespaceName();
/**
* Set namespace ot use for theis element.
* Note: namespace prefix is always ignored.
*/
public void setNamespace(XmlNamespace namespace);
// public String getPrefix();
// public void setPrefix(String prefix);
/**
* XML Infoset [local name] property.
*
* @return a String
*
*/
public String getName();
/**
* XML Infoset [local name] property.
*
* @param name a String
*
*/
public void setName(String name);
//----------------------------------------------------------------------------------------------
// Attributes management
//JDK15 Iterable
/** Return Iterator - null is never returned if there is no children
then iteraotr over empty collection is returned */
public Iterator attributes();
/**
* Add attribute (adds it to the XML Infoset [namespace attributes] set)
* Attribute mist
*
* @param attributeValueToAdd a XmlAttribute
*
* @return a XmlAttribute
*
*/
public XmlAttribute addAttribute(XmlAttribute attributeValueToAdd);
/**
* addAttribute
*
* @param name a String
* @param value a String
*
* @return a XmlAttribute
*
*/
public XmlAttribute addAttribute(String name, String value);
/**
* Method addAttribute
*
* @param namespace a XmlNamespace
* @param name a String
* @param value a String
*
* @return a XmlAttribute
*
*/
public XmlAttribute addAttribute(XmlNamespace namespace, String name, String value);
/**
* Method addAttribute
*
* @param type a String
* @param namespace a XmlNamespace
* @param name a String
* @param value a String
*
* @return a XmlAttribute
*
*/
public XmlAttribute addAttribute(String type, XmlNamespace namespace,
String name, String value);
/**
* Method addAttribute
*
* @param type a String
* @param namespace a XmlNamespace
* @param name a String
* @param value a String
* @param specified a boolean
*
* @return a XmlAttribute
*
*/
public XmlAttribute addAttribute(String type, XmlNamespace namespace,
String name, String value, boolean specified);
/**
* Method addAttribute
*
* @param attributeType a String
* @param attributePrefix a String
* @param attributeNamespace a String
* @param attributeName a String
* @param attributeValue a String
* @param specified a boolean
*
* @return a XmlAttribute
*
*/
public XmlAttribute addAttribute(String attributeType,
String attributePrefix,
String attributeNamespace,
String attributeName,
String attributeValue,
boolean specified);
/**
* Method ensureAttributeCapacity
*
* @param minCapacity an int
*
*/
public void ensureAttributeCapacity(int minCapacity) ;
//TODO add attributeValue(name)
//TODO add attributeValue(XmlNamespace, name)
/**
* Method getAttributeValue
*
* @param attributeNamespaceNamea String
* @param attributeName a String
*
* @return a String
*
*/
public String getAttributeValue(String attributeNamespaceName,
String attributeName);
/**
* Find attribute that matches given name or namespace
* Returns null if not found.
* Will match only attribute that have no namesapce.
*/
public XmlAttribute attribute(String attributeName);
/**
* Find attribute that matches given name or namespace
* Returns null if not found.
* NOTE: if namespace is null in this case it will match only
* attributes that have no namespace.
*
*/
public XmlAttribute attribute(XmlNamespace attributeNamespaceName,
String attributeName);
/**
* Find attribute that matches given name or namespace
* Returns null if not found.
* NOTE: if namespace is null in this case it will match only
* attributes that has no namespace.
* @deprecated Use attribute()
*/
public XmlAttribute findAttribute(String attributeNamespaceName,
String attributeName);
/**
* Method hasAttributes
*
* @return a boolean
*
*/
public boolean hasAttributes();
/**
* Method removeAttribute
*
* @param attr a XmlAttribute
*
*/
public void removeAttribute(XmlAttribute attr);
/**
* Method removeAllAttributes
*
*/
public void removeAllAttributes();
//----------------------------------------------------------------------------------------------
// Namespaces management
//JDK15 Iterable
/** Return Iterator - null is never returned if there is no children
then iteraotr over empty collection is returned */
public Iterator namespaces();
/**
* Create new namespace with prefix and namespace name (both must be not null)
* and add it to current element.
*/
public XmlNamespace declareNamespace(String prefix, String namespaceName);
/**
* Add namespace to current element (both prefix and namespace name must be not null)
*/
public XmlNamespace declareNamespace(XmlNamespace namespace);
/**
* Method ensureNamespaceDeclarationsCapacity
*
* @param minCapacity an int
*
*/
public void ensureNamespaceDeclarationsCapacity(int minCapacity);
/**
* Method hasNamespaceDeclarations
*
* @return a boolean
*
*/
public boolean hasNamespaceDeclarations();
/**
* Find namespace (will have non empty prefix) corresponding to namespace prefix
* checking first current elemen and if not found continue in parent (if element has parent)
* and so on.
*/
public XmlNamespace lookupNamespaceByPrefix(String namespacePrefix);
/**
* Find namespace (will have non empty prefix) corresponding to namespace name
* checking first current elemen and if not found continue in parent (if element has parent).
* and so on.
*/
public XmlNamespace lookupNamespaceByName(String namespaceName);
/**
* Create new namespace with null prefix (namespace name must be not null).
*/
public XmlNamespace newNamespace(String namespaceName);
/**
* Create new namespace with prefix and namespace name (both must be not null).
*/
public XmlNamespace newNamespace(String prefix, String namespaceName);
/**
* Method removeAllNamespaceDeclarations
*
*/
public void removeAllNamespaceDeclarations();
//----------------------------------------------------------------------------------------------
// Children management (element content)
//JDK15 Iterable
/** Return Iterator - null is never returned if there is no children
then iteraotr over empty collection is returned */
public Iterator children();
/**
* NOTE: =child added is _not_ checked if it XmlContainer, caller must manually fix
* parent in child by calling setParent() !!!!
*/
public void addChild(Object child);
/**
* Method addChild
*
* @param pos an int (starting from 0)
* @param child an Object
*
*/
public void addChild(int pos, Object child);
/**
* NOTE: the child element must unattached to be added
* (it is atttached if it is XmlContainer of recognized type and getParent() != null)
*/
public XmlElement addElement(XmlElement el);
/**
* Method addElement
*
* @param pos an int (starting from 0)
* @param child a XmlElement
*
* @return a XmlElement
*
*/
public XmlElement addElement(int pos, XmlElement child);
/**
* Method addElement
*
* @param name a String
*
* @return a XmlElement
*
*/
public XmlElement addElement(String name);
/**
* Method addElement
*
* @param namespace a XmlNamespace
* @param name a String
*
* @return a XmlElement
*
*/
public XmlElement addElement(XmlNamespace namespace, String name);
/**
* Method hasChildren
*
* @return a boolean
*
*/
public boolean hasChildren();
/**
* Method hasChild
*
* @param child an Object
*
* @return a boolean
*
*/
public boolean hasChild(Object child);
/**
* Method ensureChildrenCapacity
*
* @param minCapacity an int
*
*/
public void ensureChildrenCapacity(int minCapacity);
/**
* @deprecated see element()
*/
public XmlElement findElementByName(String name);
/**
* @deprecated see element()
*/
public XmlElement findElementByName(String namespaceName, String name);
/**
* @deprecated see elements()
*/
public XmlElement findElementByName(String name,
XmlElement elementToStartLooking);
/**
* @deprecated see elements()
*/
public XmlElement findElementByName(String namespaceName, String name,
XmlElement elementToStartLooking);
/**
* return element at poition (0..count-1) or IndexOutOfBoundsException if positon incorrect
*/
public XmlElement element(int position);
//int count()
//int countElement()
//XmlElement element(String name) //return first element matching, null if not found!
/**
* call element(n, name) and if null was returnedthrow XmlBuilderException
*/
public XmlElement requiredElement(XmlNamespace n, String name) throws XmlBuilderException;
/**
* find first element with name and namespace (if namespace is null it is ignored in search)
* */
public XmlElement element(XmlNamespace n, String name);
/**
* find first element with name and namespace (if namespace is null it is ignored in search)
* if no matching element is found then new element is created, appended to children, and returned
* */
public XmlElement element(XmlNamespace n, String name, boolean create);
//Iterable elements(String name);
//Iterable elements(XmlNamespace n, String name);
/** Return all elements that has namespace and name (null is never returned but empty iteraotr) */
public Iterable elements(XmlNamespace n, String name);
public void insertChild(int pos, Object childToInsert);
/**
* Create unattached element
*/
public XmlElement newElement(String name);
/**
* Method newElement
*
* @param namespace a XmlNamespace
* @param name a String
*
* @return a XmlElement
*
*/
public XmlElement newElement(XmlNamespace namespace, String name);
/**
* Method newElement
*
* @param namespaceName a String
* @param name a String
*
* @return a XmlElement
*
*/
public XmlElement newElement(String namespaceName, String name);
/**
* Removes all children - every child that was
* implementing XmlNode will have set parent to null.
*/
public void removeAllChildren();
/**
* Method removeChild
*
* @param child an Object
*
*/
public void removeChild(Object child);
/**
* Method replaceChild
*
* @param newChild an Object
* @param oldChild an Object
*
*/
public void replaceChild(Object newChild, Object oldChild);
//public void remove(int pos);
//public void set(int index, Object child);
//----------------------------------------------------------------------------------------------
// Utility methods to make manipulating Infoset easier for typical use cases
//JDK15 Iterable
/** Return Iterator - that represents all XmlElement content.
* When used exception will be thrown if non white space children are found
* (as expected no mixed content!).
*/
public Iterable requiredElementContent();
/**return children content as text - if there are any no text children throw exception */
public String requiredTextContent();
/**
* Remove all children and then add this text as only child.
*/
public void replaceChildrenWithText(String textContent);
//public Iterable elementsContent();
//public Iterable elementsContent(String name);
//public Iterable elementsContent(XmlNamespace n String name);
//String text() //children must map to text only nodes!!!
//public String requiredTextContent();
//selectNodes(String xpath)
//public XmlNamespace getNamespacePrefix(String namespaceName, boolean generate)
//public XmlNamespace findNamespace(String prefix, String namespace)
/** it may need to reconsruct whole subtree to get count ... */
//public int getChildrenCount();
//public Object getFirstChild() throws XmlPullParserException;
//public Object getNextSibling() throws XmlPullParserException;
//public Object getChildByName(String namespace, String name);
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlInfosetBuilder.java 100644 0 0 42453 10525225063 25537 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.builder;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
import org.xmlpull.v1.builder.impl.XmlInfosetBuilderImpl;
// private XmlInfosetBuilder builder = XmlInfosetBuilder.newInstance(); // (XmlPullParser)
// builder.setUseAllTokens(true) //comments, PIs, doctype
// setIgnoreComments
// setIgnoreProcessingInstructions
// builder.setNamespaceAware(true)
// builder.setBuildCompleteTree(true)
// builder.setWrapCharacters(true)
// XmlDocument doc = builder.parseUrl( url );
/**
* By default builder is using non-validating pull parser with next() method
* without namespaces to build tree consisting only of XmlDocument, XmlElemenet
* and String nodes. Additional options are available to change builder behaviour
* and to generate any deseired subset of
* XML Information Set
*
* @version $Revision: 1.8 $
* @author Aleksander Slominski
*/
public abstract class XmlInfosetBuilder
{
protected XmlPullParserFactory factory;
/**
* Create a new instance of the builder.
*/
public static XmlInfosetBuilder newInstance() throws XmlBuilderException
{
XmlInfosetBuilder impl = new XmlInfosetBuilderImpl();
try {
impl.factory = XmlPullParserFactory.newInstance(
System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
impl.factory.setNamespaceAware(true);
} catch(XmlPullParserException ex) {
throw new XmlBuilderException("could not create XmlPull factory:"+ex, ex);
}
return impl;
}
public static XmlInfosetBuilder newInstance(XmlPullParserFactory factory) throws XmlBuilderException
{
if(factory == null) throw new IllegalArgumentException();
XmlInfosetBuilder impl = new XmlInfosetBuilderImpl();
impl.factory = factory;
//try {
impl.factory.setNamespaceAware(true);
//} catch(XmlPullParserException ex) {
// throw new XmlBuilderException("could not create XmlPull factory:"+ex, ex);
//}
return impl;
}
/**
* Method get XmlPull factory that is ued by this builder.
*/
public XmlPullParserFactory getFactory() throws XmlBuilderException {return factory; }
// --- create directly\
/**
* Create a new document.
*/
public XmlDocument newDocument() throws XmlBuilderException {
return newDocument(null, null, null);
}
/**
* Create a new document with given XML prolog.
*
* @param version a String
* @param standalone a Boolean
* @param characterEncoding a String
*
* @return a XmlDocument
*
* @exception XmlBuilderException
*
*/
public abstract XmlDocument newDocument(String version,
Boolean standalone,
String characterEncoding) throws XmlBuilderException;
/**
* Create XML fragment that is not associated with any document.
*
* @param elementName name of element
*
* @return a XmlElement
*
* @exception XmlBuilderException
*
*/
public abstract XmlElement newFragment(String elementName) throws XmlBuilderException;
/**
* Create XML fragment that is not associated with any document.
*
* @param elementNamespace namespace of element
* @param elementName name of element
*
* @return a XmlElement
*
* @exception XmlBuilderException
*
*/
public abstract XmlElement newFragment(String elementNamespace, String elementName) throws XmlBuilderException;
/**
* Create XML fragment that is not associated with any document.
*
* @param elementNamespace a XmlNamespace
* @param elementName a String
*
* @return a XmlElement
*
* @exception XmlBuilderException
*
*/
public abstract XmlElement newFragment(XmlNamespace elementNamespace,
String elementName) throws XmlBuilderException;
/**
* Create a new namespace that is not associated with any XML document.
*
* @param namespaceName a String
*
* @return a XmlNamespace
*
* @exception XmlBuilderException
*
*/
public abstract XmlNamespace newNamespace(String namespaceName) throws XmlBuilderException;
/**
* Create a new namespace that is not associated with any XML document.
*
* @param prefix a String
* @param namespaceName a String
*
* @return a XmlNamespace
*
* @exception XmlBuilderException
*
*/
public abstract XmlNamespace newNamespace(String prefix, String namespaceName) throws XmlBuilderException;
// --- parsing
//public abstract XmlElement newFragment(String elementNamespace, String elementName, XmlNamespace[] context);
//public abstract XmlElement parse(XmlPullParser sourceForNode,boolean addAllNamespaces);
/**
* Parse document - parser must be in START_DOCUMENT state.
*/
public abstract XmlDocument parse(XmlPullParser sourceForDocument) throws XmlBuilderException;
/**
* Will convert current parser state into event rerpresenting XML infoset item:
* START_Document: XmlDocument without root element
* START_TAG: XmlElement without children
* TEXT: String or XmlCHaracters depending on builder mode
* additiona states to corresponding XML infoset items (when implemented!)
*
*/
public abstract Object parseItem(XmlPullParser pp) throws XmlBuilderException;
/**
* Parser must be on START_TAG and this method will convert START_TAG content into
* XmlELement. Parser location is not chnaged.
*/
public abstract XmlElement parseStartTag(XmlPullParser pp) throws XmlBuilderException;
/**
* Parse input stream to create XML document.
*
* @param is an InputStream
*
* @return a XmlDocument
*
* @exception XmlBuilderException
*
*/
public XmlDocument parseInputStream(InputStream is) throws XmlBuilderException
{
XmlPullParser pp = null;
try {
pp = factory.newPullParser();
pp.setInput(is, null);
//set options ...
} catch (XmlPullParserException e) {
throw new XmlBuilderException("could not start parsing input stream", e);
}
return parse(pp);
}
/**
* Parse input stream to create XML document using specified encoding.
*
* @param is an InputStream
* @param encoding a String
*
* @return a XmlDocument
*
* @exception XmlBuilderException
*
*/
public XmlDocument parseInputStream(InputStream is, String encoding) throws XmlBuilderException
{
XmlPullParser pp = null;
try {
pp = factory.newPullParser();
pp.setInput(is, encoding);
//set options ...
} catch (XmlPullParserException e) {
throw new XmlBuilderException("could not start parsing input stream (encoding="+encoding+")", e);
}
return parse(pp);
}
/**
* Parse reader to create XML document.
*
* @param reader a Reader
*
* @return a XmlDocument
*
* @exception XmlBuilderException
*
*/
public XmlDocument parseReader(Reader reader) throws XmlBuilderException
{
XmlPullParser pp = null;
try {
pp = factory.newPullParser();
pp.setInput(reader);
//set options ...
} catch (XmlPullParserException e) {
throw new XmlBuilderException("could not start parsing input from reader", e);
}
return parse(pp);
}
/**
* Parse input from URL location to create XML document.
*
* @param locationUrl a String
*
* @return a XmlDocument
*
* @exception XmlBuilderException
*
*/
public abstract XmlDocument parseLocation(String locationUrl) throws XmlBuilderException;
/**
* Parse fragment - parser must be on START_TAG. After parsing is on corresponding END_TAG.
*/
public abstract XmlElement parseFragment(XmlPullParser sourceForXml) throws XmlBuilderException;
/**
* Parse input stream to create XML fragment.
*
* @param is an InputStream
*
* @return a XmlElement
*
* @exception XmlBuilderException
*
*/
public XmlElement parseFragmentFromInputStream(InputStream is) throws XmlBuilderException
{
XmlPullParser pp = null;
try {
pp = factory.newPullParser();
pp.setInput(is, null);
//set options ...
try {
pp.nextTag();
} catch (IOException e) {
throw new XmlBuilderException(
"IO error when starting to parse input stream", e);
}
} catch (XmlPullParserException e) {
throw new XmlBuilderException("could not start parsing input stream", e);
}
return parseFragment(pp);
}
/**
* Parse input stream to create XML fragment using specified encoding.
*
* @param is an InputStream
* @param encoding a String
*
* @return a XmlElement
*
* @exception XmlBuilderException
*
*/
public XmlElement parseFragementFromInputStream(InputStream is, String encoding) throws XmlBuilderException
{
XmlPullParser pp = null;
try {
pp = factory.newPullParser();
pp.setInput(is, encoding);
//set options ...
try {
pp.nextTag();
} catch (IOException e) {
throw new XmlBuilderException(
"IO error when starting to parse input stream (encoding="+encoding+")", e);
}
} catch (XmlPullParserException e) {
throw new XmlBuilderException("could not start parsing input stream (encoding="+encoding+")", e);
}
return parseFragment(pp);
}
/**
* Parse reader to create XML fragment.
*
* @param reader a Reader
*
* @return a XmlElement
*
* @exception XmlBuilderException
*
*/
public XmlElement parseFragmentFromReader(Reader reader) throws XmlBuilderException
{
XmlPullParser pp = null;
try {
pp = factory.newPullParser();
pp.setInput(reader);
//set options ...
try {
pp.nextTag();
} catch (IOException e) {
throw new XmlBuilderException(
"IO error when starting to parse from reader", e);
}
} catch (XmlPullParserException e) {
throw new XmlBuilderException("could not start parsing input from reader", e);
}
return parseFragment(pp);
}
/**
* Move parser from START_TAG to the corresponding END_TAG which means
* that XML sub tree is skipped.
*
* @param pp a XmlPullParser
*
* @exception XmlBuilderException
*
*/
public void skipSubTree(XmlPullParser pp) throws XmlBuilderException
{
try {
pp.require(XmlPullParser.START_TAG, null, null);
int level = 1;
while(level > 0) {
int eventType = pp.next();
if(eventType == XmlPullParser.END_TAG) {
--level;
} else if(eventType == XmlPullParser.START_TAG) {
++level;
}
}
} catch (XmlPullParserException e) {
throw new XmlBuilderException("could not skip subtree", e);
} catch (IOException e) {
throw new XmlBuilderException("IO error when skipping subtree", e);
}
}
// --- serialization
/**
* Write XML start tag with information provided in XML element.
*
* @param el a XmlElement
* @param ser a XmlSerializer
*
* @exception XmlBuilderException
*
*/
public abstract void serializeStartTag(XmlElement el, XmlSerializer ser)
throws XmlBuilderException;
/**
* Write XML end tag with information provided in XML element.
*
* @param el a XmlElement
* @param ser a XmlSerializer
*
* @exception XmlBuilderException
*
*/
public abstract void serializeEndTag(XmlElement el, XmlSerializer ser)
throws XmlBuilderException;
/**
* Serialize XML infoset item including serializing of children.
* If item is Collection all items in collection are serialized by
* recursively calling this function.
* This method assumes that item is either interface defined in XB1 API, class String,
* or that item implements XmlSerializable otherwise IllegalArgumentException
* is thrown.
*/
public abstract void serialize(Object item, XmlSerializer serializer) throws XmlBuilderException;
//throws XmlPullParserException, IOException, IllegalArgumentException;
/**
* Serialize XML infoset item without serializing any of children.
* This method assumes that item is either interface defined in XB1 API, class String,
* or item that implements XmlSerializable otherwise IllegalArgumentException
* is thrown.
*/
public abstract void serializeItem(Object item, XmlSerializer serializer) throws XmlBuilderException;
/**
* Serialize item using default UTF8 encoding.
*
* @see serializeItem
*/
public void serializeToOutputStream(Object item, //XmlContainer node,
OutputStream os)
throws XmlBuilderException
//throws XmlPullParserException, IOException, IllegalArgumentException
{
serializeToOutputStream(item, os, "UTF8");
}
/**
* Serialize item to given output stream using given character encoding.
*
* @param item an Object
* @param os an OutputStream
* @param encoding a String
*
* @exception XmlBuilderException
*
* @see serializeItem
*
*/
public void serializeToOutputStream(Object item, //XmlContainer node,
OutputStream os,
String encoding)
throws XmlBuilderException
//throws XmlPullParserException, IOException, IllegalArgumentException
{
XmlSerializer ser = null;
try {
ser = factory.newSerializer();
ser.setOutput(os, encoding);
} catch (Exception e) {
throw new XmlBuilderException("could not serialize node to output stream"
+" (encoding="+encoding+")", e);
}
serialize(item, ser);
try {
ser.flush();
} catch (IOException e) {
throw new XmlBuilderException("could not flush output", e);
}
}
/**
* Serialize item to given writer.
*
* @param item an Object
* @param writer a Writer
*
* @exception XmlBuilderException
*
*/
public void serializeToWriter(Object item, //XmlContainer node,
Writer writer)
//throws XmlPullParserException, IOException, IllegalArgumentException
throws XmlBuilderException
{
XmlSerializer ser = null;
try {
ser = factory.newSerializer();
ser.setOutput(writer);
} catch (Exception e) {
throw new XmlBuilderException("could not serialize node to writer", e);
}
serialize(item, ser);
try {
ser.flush();
} catch (IOException e) {
throw new XmlBuilderException("could not flush output", e);
}
}
/**
* Convert item into String representing XML content.
*
* @param item an Object
*
* @return a String
*
* @exception XmlBuilderException
*
*/
public String serializeToString(Object item) //XmlContainer node)
//throws XmlPullParserException, IOException, IllegalArgumentException
throws XmlBuilderException
{
StringWriter sw = new StringWriter();
serializeToWriter(item, sw);
return sw.toString();
}
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlNamespace.java 100644 0 0 1510 10525225063 24462 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
/**
* Represents
* Namespace Information Item
* .
*
* @version $Revision: 1.2 $
* @author Aleksander Slominski
*/
public interface XmlNamespace
{
/**
* Prefix can be null.
* In this case it will be looked up from XML tree
* and used if available
* otherwise it will be automatically created only for serializaiton.
* TODO: If prefix is empty string it will be used to indicate default namespace.
*/
public String getPrefix();
/**
* Namespace name.
* Never null.
* Only allowed to be empty string if prefix is also empty string
* (used to undeclare default namespace)
*/
public String getNamespaceName();
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlNotation.java 100644 0 0 2507 10525225063 24370 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
/**
* Represents
* Notation Information Item .
* There is a notation information item for each notation declared in the DTD.
*
* @version $Revision: 1.3 $
* @author Aleksander Slominski
*/
public interface XmlNotation //extends XmlContainer
{
/**
* The name of the notation.
*/
public String getName();
/**
* The system identifier of the notation,
* as it appears in the declaration of the notation,
* without any additional URI escaping applied by the processor.
* If no system identifier was specified, this property has no value.
*/
public String getSystemIdentifier();
/**
* The public identifier of the notation, normalized as described in
* 4.2.2 External Entities [XML] .
* If the notation has no public identifier, this property has no value.
*/
public String getPublicIdentifier();
//TOOD how to implement this ...
/**
* The base URI relative to which the system identifier should be resolved
* (i.e. the base URI of the resource within which the notation declaration occurs).
*/
public String getDeclarationBaseUri();
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlProcessingInstruction.java 100644 0 0 4104 10525225063 27146 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
/**
* Represents
* Processing Instruction Information Item
* .
* There is a processing instruction information item
* for each processing instruction in the document.
* The XML declaration and text declarations for external parsed entities
* are not considered processing instructions.
*
* @version $Revision: 1.3 $
* @author Aleksander Slominski
*/
public interface XmlProcessingInstruction //extends XmlContainer
{
/**
* A string representing the target part of the processing instruction (an XML name).
*/
public String getTarget();
/**
* A string representing the content of the processing instruction,
* excluding the target and any white space immediately following it.
* If there is no such content, the value of this property will be an empty string.
*/
public String getContent();
//TODO: not clear how this should be implemented ...
/**
* The base URI of the PI. Note that if an infoset is serialized as an XML document,
* it will not be possible to preserve the base URI
* of any PI that originally appeared at the top level of an external entity,
* since there is no syntax for PIs corresponding to the xml:base attribute on elements.
*/
public String getBaseUri();
//TODO: not clear how this should be implemented ...
/**
* The notation information item named by the target.
* If there is no declaration for a notation with that name,
* this property has no value. If no declaration has been read,
* but the [all declarations processed] property of the document information item is false
* (so there may be an unread declaration), then the value of this property is unknown.
*/
public XmlNotation getNotation();
/**
* The document, element, or document type definition information item
* which contains this information item in its [children] property.
*/
public XmlContainer getParent();
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlSerializable.java 100644 0 0 671 10525225063 25163 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
import java.io.IOException;
import org.xmlpull.v1.XmlSerializer;
/**
* This interface is used during serialization by XmlInfosetBuilder
* for children that are not in XML infoset.
*
* @version $Revision: 1.4 $
* @author Aleksander Slominski
*/
public interface XmlSerializable
{
public void serialize(XmlSerializer ser) throws IOException;
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlUnexpandedEntityReference.java 100644 0 0 1050 10525225063 27674 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
/**
* Represents
* Unexpanded Entity Reference
* Information Item
* .
*
* @version $Revision: 1.3 $
* @author Aleksander Slominski
*/
public interface XmlUnexpandedEntityReference //extends XmlContainer
{
public String getName();
public String getSystemIdentifier();
public String getPublicIdentifier();
public String getDeclarationBaseUri();
public XmlElement getParent();
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/XmlUnparsedEntity.java 100644 0 0 1105 10525225063 25544 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder;
/**
* Represents
* Unparsed Entity
* Information Item
* .
*
* @version $Revision: 1.3 $
* @author Aleksander Slominski
*/
public interface XmlUnparsedEntity //extends XmlContainer
{
public String getName();
public String getSystemIdentifier();
public String getPublicIdentifier();
public String getDeclarationBaseUri();
public String getNotationName();
public XmlNotation getNotation();
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/adapter/XmlAttributeAdapter.java 100644 0 0 2656 10525225063 27466 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder.adapter;
//import java.util.IdentityHashMap;
import org.xmlpull.v1.builder.XmlAttribute;
import org.xmlpull.v1.builder.XmlNamespace;
import org.xmlpull.v1.builder.XmlElement;
/**
* Wraps XML attribute - allows overriding and other nice things.
*/
public class XmlAttributeAdapter implements XmlAttribute
{
private XmlAttribute target;
//JDK15 covariant public XmlElementAdapter clone() throws CloneNotSupportedException;
public Object clone() throws CloneNotSupportedException {
XmlAttributeAdapter ela = (XmlAttributeAdapter) super.clone();
ela.target = (XmlAttribute) target.clone();
return ela;
}
public XmlAttributeAdapter(XmlAttribute target) {
this.target = target;
}
public XmlElement getOwner() {
return target.getOwner();
}
public String getNamespaceName() {
return target.getNamespaceName();
}
public XmlNamespace getNamespace() {
return target.getNamespace();
}
public String getName() {
return target.getName();
}
public String getValue() {
return target.getValue();
}
public String getType() {
return target.getType();
}
public boolean isSpecified() {
return target.isSpecified();
}
// public void serialize(XmlSerializer ser) throws IOException {
// // TODO
// }
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/adapter/XmlDocumentAdapter.java 100644 0 0 11337 10525225063 27315 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder.adapter;
import org.xmlpull.v1.builder.Iterable;
import org.xmlpull.v1.builder.XmlContainer;
import org.xmlpull.v1.builder.XmlDocument;
import org.xmlpull.v1.builder.XmlElement;
import org.xmlpull.v1.builder.XmlNamespace;
import org.xmlpull.v1.builder.XmlNotation;
import org.xmlpull.v1.builder.XmlComment;
import org.xmlpull.v1.builder.XmlProcessingInstruction;
import org.xmlpull.v1.builder.XmlDoctype;
/**
*/
public class XmlDocumentAdapter implements XmlDocument
{
private XmlDocument target;
//JDK15 covariant public XmlElementAdapter clone() throws CloneNotSupportedException;
public Object clone() throws CloneNotSupportedException {
XmlDocumentAdapter ela = (XmlDocumentAdapter) super.clone();
ela.target = (XmlDocument) target.clone();
return ela;
}
public XmlDocumentAdapter(XmlDocument target) {
this.target = target;
// new "wrapping" parent replaces old parent for children
fixImportedChildParent(target.getDocumentElement());
//target.setParent(null);
//IdentityHashMap id = nul;
}
private void fixImportedChildParent(Object child) {
if(child instanceof XmlElement) {
XmlElement childEl = (XmlElement) child;
XmlContainer childElParent = childEl.getParent();
if(childElParent == target) {
childEl.setParent(this);
}
}
}
public Iterable children() {
return target.children();
}
public XmlElement getDocumentElement() {
return target.getDocumentElement();
}
public XmlElement requiredElement(XmlNamespace n, String name) {
return target.requiredElement(n, name);
}
public XmlElement element(XmlNamespace n, String name) {
return target.element(n, name);
}
public XmlElement element(XmlNamespace n, String name, boolean create) {
return target.element(n, name, create);
}
public Iterable notations() {
return target.notations();
}
public Iterable unparsedEntities() {
return target.unparsedEntities();
}
public String getBaseUri() {
return target.getBaseUri();
}
public String getCharacterEncodingScheme() {
return target.getCharacterEncodingScheme();
}
public void setCharacterEncodingScheme(String characterEncoding) {
target.setCharacterEncodingScheme(characterEncoding);
}
public Boolean isStandalone() {
return target.isStandalone();
}
public String getVersion() {
return target.getVersion();
}
public boolean isAllDeclarationsProcessed() {
return target.isAllDeclarationsProcessed();
}
public void setDocumentElement(XmlElement rootElement) {
target.setDocumentElement(rootElement);
}
public void addChild(Object child) {
target.addChild(child);
}
public void insertChild(int pos, Object child) {
target.insertChild(pos, child);
}
public void removeAllChildren() {
target.removeAllChildren();
}
public XmlComment newComment(String content) {
return target.newComment(content);
}
public XmlComment addComment(String content) {
return target.addComment(content);
}
public XmlDoctype newDoctype(String systemIdentifier, String publicIdentifier) {
return target.newDoctype(systemIdentifier, publicIdentifier);
}
public XmlDoctype addDoctype(String systemIdentifier, String publicIdentifier) {
return target.addDoctype(systemIdentifier, publicIdentifier);
}
public XmlElement addDocumentElement(String name) {
return target.addDocumentElement(name);
}
public XmlElement addDocumentElement(XmlNamespace namespace, String name) {
return target.addDocumentElement(namespace, name);
}
public XmlProcessingInstruction newProcessingInstruction(String target, String content) {
return this.target.newProcessingInstruction(target, content);
}
public XmlProcessingInstruction addProcessingInstruction(String target, String content) {
return this.target.addProcessingInstruction(target, content);
}
public void removeAllUnparsedEntities() {
target.removeAllUnparsedEntities();
}
public XmlNotation addNotation(String name, String systemIdentifier,
String publicIdentifier, String declarationBaseUri) {
return target.addNotation(name, systemIdentifier, publicIdentifier, declarationBaseUri);
}
public void removeAllNotations() {
target.removeAllNotations();
}
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/adapter/XmlElementAdapter.java 100644 0 0 34546 10525225063 27137 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder.adapter;
//import java.util.IdentityHashMap;
import java.util.Iterator;
import org.xmlpull.v1.builder.Iterable;
import org.xmlpull.v1.builder.XmlAttribute;
import org.xmlpull.v1.builder.XmlBuilderException;
import org.xmlpull.v1.builder.XmlContainer;
import org.xmlpull.v1.builder.XmlDocument;
import org.xmlpull.v1.builder.XmlElement;
import org.xmlpull.v1.builder.XmlNamespace;
/**
*/
public class XmlElementAdapter implements XmlElement
{
private XmlElementAdapter topAdapter;
private XmlElement target;
private XmlContainer parent;
public XmlElementAdapter(XmlElement target) {
setTarget(target);
}
private void setTarget(XmlElement target) {
this.target = target;
if(target.getParent() != null) {
//
//throw new XmlBuilderException("element to wrap must have no parent to be wrapped");
//XmlContainer parent = target.getParent();
parent = target.getParent();
if(parent instanceof XmlDocument) {
XmlDocument doc = (XmlDocument) parent;
doc.setDocumentElement(this);
} if(parent instanceof XmlElement) {
XmlElement parentEl = (XmlElement) parent;
parentEl.replaceChild(this, target);
}
}
// new "wrapping" parent replaces old parent for children
Iterator iter = target.children();
while (iter.hasNext())
{
Object child = iter.next();
fixImportedChildParent(child);
}
//target.setParent(null);
//IdentityHashMap id = nul;
}
//JDK15 covariant public XmlElementAdapter clone() throws CloneNotSupportedException;
public Object clone() throws CloneNotSupportedException {
XmlElementAdapter ela = (XmlElementAdapter) super.clone();
ela.parent = null;
ela.target = (XmlElement) target.clone();
return ela;
}
public XmlElement getTarget() { return target; }
public XmlElementAdapter getTopAdapter() {
return topAdapter != null ? topAdapter : this;
}
public void setTopAdapter(XmlElementAdapter adapter) {
this.topAdapter = adapter;
if(target instanceof XmlElementAdapter) {
((XmlElementAdapter)target).setTopAdapter(adapter);
}
}
//JDK15 T castOrWrap() ?!
public static XmlElementAdapter castOrWrap(XmlElement el, Class adapterClass) {
if(el == null) {
throw new IllegalArgumentException("null element can not be wrapped");
}
if(XmlElementAdapter.class.isAssignableFrom(adapterClass) == false) {
throw new IllegalArgumentException("class for cast/wrap must extend "+XmlElementAdapter.class);
}
if(el instanceof XmlElementAdapter) {
XmlElementAdapter currentAdap = (XmlElementAdapter) el;
Class currentAdapClass = currentAdap.getClass();
if(adapterClass.isAssignableFrom(currentAdapClass)) {
return currentAdap;
}
// visit chain
XmlElementAdapter topAdapter = currentAdap = currentAdap.getTopAdapter();
while(currentAdap.topAdapter != null) {
currentAdapClass = currentAdap.getClass();
if(currentAdapClass.isAssignableFrom(adapterClass)) {
return currentAdap;
}
if(currentAdap.target instanceof XmlElementAdapter) {
currentAdap = (XmlElementAdapter) currentAdap.target;
} else {
break;
}
}
try {
// do wrapping
currentAdap.topAdapter = (XmlElementAdapter)
adapterClass.getConstructor(new Class[]{XmlElement.class})
.newInstance(new Object[]{topAdapter});
currentAdap.topAdapter.setTopAdapter(currentAdap.topAdapter);
return currentAdap.topAdapter;
} catch (Exception e) {
throw new XmlBuilderException("could not create wrapper of "+adapterClass, e);
}
} else {
// just do simple wrapping ...
try {
XmlElementAdapter t = (XmlElementAdapter)
adapterClass.getConstructor(new Class[]{XmlElement.class})
.newInstance(new Object[]{el});
return t;
} catch (Exception e) {
throw new XmlBuilderException("could not wrap element "+el, e);
}
}
}
private void fixImportedChildParent(Object child) {
if(child instanceof XmlElement) {
XmlElement childEl = (XmlElement) child;
XmlContainer childElParent = childEl.getParent();
if(childElParent == target) {
childEl.setParent(this);
}
}
}
private XmlElement fixElementParent(XmlElement el) {
el.setParent(this);
return el;
}
public XmlContainer getRoot() {
XmlContainer root = target.getRoot();
if(root == target) {
root = this;
}
return root;
}
public XmlContainer getParent() {
return parent; //target.getParent();
}
public void setParent(XmlContainer parent) {
this.parent = parent;
//target.setParent(parent);
}
public XmlNamespace newNamespace(String prefix, String namespaceName) {
return target.newNamespace(prefix, namespaceName);
}
public XmlAttribute attribute(String attributeName) {
return target.attribute(attributeName);
}
public XmlAttribute attribute(XmlNamespace attributeNamespaceName,
String attributeName)
{
return target.attribute(attributeNamespaceName, attributeName);
}
public XmlAttribute findAttribute(String attributeNamespaceName, String attributeName) {
return target.findAttribute(attributeNamespaceName, attributeName);
}
public Iterator attributes() {
return target.attributes() ;
}
public void removeAllChildren() {
target.removeAllChildren();
}
public XmlAttribute addAttribute(String attributeType,
String attributePrefix,
String attributeNamespace,
String attributeName,
String attributeValue,
boolean specified)
{
return target.addAttribute(attributeType,
attributePrefix,
attributeNamespace,
attributeName,
attributeValue,
specified);
}
public String getAttributeValue(String attributeNamespaceName,
String attributeName)
{
return target.getAttributeValue(attributeNamespaceName, attributeName);
}
public XmlAttribute addAttribute(XmlNamespace namespace, String name, String value) {
return target.addAttribute(namespace, name, value);
}
public String getNamespaceName() {
return target.getNamespaceName();
}
public void ensureChildrenCapacity(int minCapacity) {
target.ensureChildrenCapacity(minCapacity);
}
public Iterator namespaces() {
return target.namespaces();
}
public void removeAllAttributes() {
target.removeAllAttributes();
}
public XmlNamespace getNamespace() {
return target.getNamespace();
}
public String getBaseUri() {
return target.getBaseUri();
}
public void removeAttribute(XmlAttribute attr) {
target.removeAttribute(attr);
}
public XmlNamespace declareNamespace(String prefix, String namespaceName) {
return target.declareNamespace(prefix, namespaceName);
}
public void removeAllNamespaceDeclarations() {
target.removeAllNamespaceDeclarations();
}
public boolean hasAttributes() {
return target.hasAttributes();
}
public XmlAttribute addAttribute(String type, XmlNamespace namespace, String name, String value, boolean specified) {
return target.addAttribute(type, namespace, name, value, specified);
}
public XmlNamespace declareNamespace(XmlNamespace namespace) {
return target.declareNamespace(namespace);
}
public XmlAttribute addAttribute(String name, String value) {
return target.addAttribute(name, value);
}
public boolean hasNamespaceDeclarations() {
return target.hasNamespaceDeclarations();
}
public XmlNamespace lookupNamespaceByName(String namespaceName) {
XmlNamespace ns = target.lookupNamespaceByName(namespaceName);
if(ns == null) { // needed as parent in target may not be set correctly ...
XmlContainer p = getParent();
if(p instanceof XmlElement) {
XmlElement e = (XmlElement) p;
return e.lookupNamespaceByName(namespaceName);
}
}
return ns;
}
public XmlNamespace lookupNamespaceByPrefix(String namespacePrefix) {
XmlNamespace ns = target.lookupNamespaceByPrefix(namespacePrefix);
if(ns == null) { // needed as parent in target may not be set correctly ...
XmlContainer p = getParent();
if(p instanceof XmlElement) {
XmlElement e = (XmlElement) p;
return e.lookupNamespaceByPrefix(namespacePrefix);
}
}
return ns;
}
public XmlNamespace newNamespace(String namespaceName) {
return target.newNamespace(namespaceName);
}
public void setBaseUri(String baseUri) {
target.setBaseUri(baseUri);
}
public void setNamespace(XmlNamespace namespace) {
target.setNamespace(namespace);
}
public void ensureNamespaceDeclarationsCapacity(int minCapacity) {
target.ensureNamespaceDeclarationsCapacity(minCapacity);
}
// public String getPrefix() {
// return target.getPrefix();
// }
//
// public void setPrefix(String prefix) {
// target.setPrefix(prefix);
// }
public String getName() {
return target.getName();
}
public void setName(String name) {
target.setName(name);
}
public XmlAttribute addAttribute(String type, XmlNamespace namespace, String name, String value) {
return target.addAttribute(type, namespace, name, value);
}
public void ensureAttributeCapacity(int minCapacity) {
target.ensureAttributeCapacity(minCapacity);
}
public XmlAttribute addAttribute(XmlAttribute attributeValueToAdd) {
return target.addAttribute(attributeValueToAdd);
}
// --- children
public XmlElement element(int position) {
return target.element(position);
}
public XmlElement requiredElement(XmlNamespace n, String name) {
return target.requiredElement(n, name);
}
public XmlElement element(XmlNamespace n, String name) {
return target.element(n, name);
}
public XmlElement element(XmlNamespace n, String name, boolean create) {
return target.element(n, name, create);
}
public Iterable elements(XmlNamespace n, String name) {
return target.elements(n, name);
}
public XmlElement findElementByName(String name, XmlElement elementToStartLooking) {
return target.findElementByName(name, elementToStartLooking);
}
public XmlElement newElement(XmlNamespace namespace, String name) {
return target.newElement(namespace, name);
}
public XmlElement addElement(XmlElement child)
{
return fixElementParent( target.addElement(child) );
}
public XmlElement addElement(int pos, XmlElement child) {
return fixElementParent( target.addElement(pos, child) );
}
public XmlElement addElement(String name) {
return fixElementParent( target.addElement(name) );
}
public XmlElement findElementByName(String namespaceName, String name) {
return target.findElementByName(namespaceName, name);
}
public void addChild(Object child) {
target.addChild(child);
fixImportedChildParent(child);
}
public void insertChild(int pos, Object childToInsert) {
target.insertChild(pos, childToInsert);
fixImportedChildParent(childToInsert);
}
public XmlElement findElementByName(String name) {
return target.findElementByName(name);
}
public XmlElement findElementByName(String namespaceName, String name, XmlElement elementToStartLooking) {
return target.findElementByName(namespaceName, name, elementToStartLooking);
}
public void removeChild(Object child) {
target.removeChild(child);
}
public Iterator children() {
return target.children();
}
public Iterable requiredElementContent() {
return target.requiredElementContent();
}
public String requiredTextContent() {
return target.requiredTextContent();
}
public boolean hasChild(Object child) {
return target.hasChild(child);
}
public XmlElement newElement(String namespaceName, String name) {
return target.newElement(namespaceName, name);
}
public XmlElement addElement(XmlNamespace namespace, String name) {
return fixElementParent( target.addElement(namespace, name) );
}
public boolean hasChildren() {
return target.hasChildren();
}
public void addChild(int pos, Object child) {
target.addChild(pos, child);
fixImportedChildParent(child);
}
public void replaceChild(Object newChild, Object oldChild) {
target.replaceChild(newChild, oldChild);
fixImportedChildParent(newChild);
}
public XmlElement newElement(String name) {
return target.newElement(name);
}
public void replaceChildrenWithText(String textContent) {
target.replaceChildrenWithText(textContent);
}
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/impl/XmlAttributeImpl.java 100644 0 0 6367 10525225063 26333 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder.impl;
import org.xmlpull.v1.builder.XmlAttribute;
import org.xmlpull.v1.builder.XmlElement;
import org.xmlpull.v1.builder.XmlNamespace;
/**
* Simple implementation.
*
* @author Aleksander Slominski
*/
public class XmlAttributeImpl implements XmlAttribute
{
private XmlElement owner_;
private String prefix_;
private XmlNamespace namespace_;
private String name_;
private String value_;
private String type_ = "CDATA";
private boolean default_;
public Object clone() throws CloneNotSupportedException{
XmlAttributeImpl cloned = (XmlAttributeImpl) super.clone();
cloned.owner_ = null;
// now do deep clone
cloned.prefix_ = prefix_;
cloned.namespace_ = namespace_;
cloned.name_ = name_;
cloned.value_ = value_;
cloned.default_ = default_;
return cloned;
}
XmlAttributeImpl(XmlElement owner, String name, String value) {
this.owner_ = owner;
this.name_ = name;
if(value == null) throw new IllegalArgumentException("attribute value can not be null");
this.value_ = value;
}
XmlAttributeImpl(XmlElement owner, XmlNamespace namespace,
String name, String value) {
this(owner, name, value);
this.namespace_ = namespace;
}
XmlAttributeImpl(XmlElement owner, String type, XmlNamespace namespace,
String name, String value) {
this(owner, namespace, name, value);
this.type_ = type;
}
XmlAttributeImpl(XmlElement owner,
String type,
XmlNamespace namespace,
String name,
String value,
boolean specified)
{
this(owner, namespace, name, value);
if(type == null) {
throw new IllegalArgumentException("attribute type can not be null");
}
//TODO: better checking for allowed attribute types
this.type_ = type;
this.default_ = !specified;
}
public XmlElement getOwner() {
return owner_;
}
//public String getPrefix()
//{
// return prefix_;
//}
public XmlNamespace getNamespace()
{
return namespace_;
}
public String getNamespaceName()
{
return namespace_ != null ? namespace_.getNamespaceName() : null;
}
public String getName()
{
return name_;
}
public String getValue()
{
return value_;
}
public String getType()
{
return type_;
}
public boolean isSpecified()
{
return !default_;
}
public boolean equals(Object other) {
if(other == this) return true;
if(other == null) return false;
if(!(other instanceof XmlAttribute)) return false;
XmlAttribute otherAttr = (XmlAttribute) other;
return getNamespaceName().equals(otherAttr.getNamespaceName())
&& getName().equals(otherAttr.getName())
&& getValue().equals(otherAttr.getValue());
}
public String toString() {
return "name=" + name_ + " value=" + value_;
}
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/impl/XmlCommentImpl.java 100644 0 0 1324 10525225063 25756 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder.impl;
import org.xmlpull.v1.builder.XmlComment;
import org.xmlpull.v1.builder.XmlContainer;
/**
* Simple implementation.
*
* @author Aleksander Slominski
*/
public class XmlCommentImpl implements XmlComment
{
private XmlContainer owner_;
private String content_;
XmlCommentImpl(XmlContainer owner, String content) {
this.owner_ = owner;
this.content_ = content;
if(content == null) throw new IllegalArgumentException("comment content can not be null");
}
public String getContent() {
return content_;
}
public XmlContainer getParent() {
return owner_;
}
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/impl/XmlDocumentImpl.java 100644 0 0 23705 10525225063 26161 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.builder.impl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.xmlpull.v1.builder.Iterable;
import org.xmlpull.v1.builder.XmlBuilderException;
import org.xmlpull.v1.builder.XmlComment;
import org.xmlpull.v1.builder.XmlDoctype;
import org.xmlpull.v1.builder.XmlDocument;
import org.xmlpull.v1.builder.XmlElement;
import org.xmlpull.v1.builder.XmlNamespace;
import org.xmlpull.v1.builder.XmlNotation;
import org.xmlpull.v1.builder.XmlProcessingInstruction;
public class XmlDocumentImpl implements XmlDocument
{
private List children = new ArrayList();
private XmlElement root;
private String version;
private Boolean standalone;
private String characterEncoding;
public Object clone() throws CloneNotSupportedException{
XmlDocumentImpl cloned = (XmlDocumentImpl) super.clone();
// now do deep clone
cloned.root = null;
cloned.children = cloneList(cloned, children);
int pos = cloned.findDocumentElement();
if(pos >= 0) {
cloned.root = (XmlElement) cloned.children.get(pos);
cloned.root.setParent(cloned);
}
return cloned;
}
private List cloneList(XmlDocumentImpl cloned, List list) throws CloneNotSupportedException {
if(list == null) {
return null;
}
List newList = new ArrayList(list.size());
//JDK15 for(Object member: list) {
for (int i = 0; i < list.size(); i++)
{
Object member = list.get(i);
Object newMember; // = null;
if(member instanceof XmlElement) {
XmlElement el = (XmlElement) member;
newMember = el.clone();
} else if(member instanceof java.lang.Cloneable) {
//use reflection to call clone() -- this is getting ugly!!!!
// more background on this in http://www.artima.com/intv/issues3.html "The clone Dilemma"
try {
newMember = member.getClass().getMethod("clone", null).invoke(member, null);
} catch (Exception e) {
throw new CloneNotSupportedException("failed to call clone() on "+member+e);
}
} else {
throw new CloneNotSupportedException("could not clone "+member+" of "
+(member != null ? member.getClass().toString() : ""));
}
newList.add(newMember);
}
return newList;
}
public XmlDocumentImpl(String version, Boolean standalone, String characterEncoding) {
this.version = version;
this.standalone = standalone;
this.characterEncoding = characterEncoding;
}
/**
*/
public String getVersion() {
return version;
}
/**
*
*/
public Boolean isStandalone() {
return standalone;
}
/**
*
*/
public String getCharacterEncodingScheme() {
return characterEncoding;
}
public void setCharacterEncodingScheme(String characterEncoding)
{
this.characterEncoding = characterEncoding;
}
/**
*/
public XmlProcessingInstruction newProcessingInstruction(String target, String content)
{
// TODO
throw new XmlBuilderException("not implemented");
}
/**
*/
public XmlProcessingInstruction addProcessingInstruction(String target, String content) {
// TODO
throw new XmlBuilderException("not implemented");
}
/**
* An ordered list of child information items, in document order.
* The list contains exactly one element information item.
* The list also contains one processing instruction information item
* for each processing instruction outside the document element,
* and one comment information item for each comment outside the document element.
* Processing instructions and comments within the DTD are excluded.
* If there is a document type declaration,
* the list also contains a document type declaration information item.
*/
public Iterable children() {
//throw new XmlBuilderException("not implemented");
return new Iterable() {
public Iterator iterator() {
return children.iterator();
}
};
}
/**
*/
public void removeAllUnparsedEntities() {
// TODO
throw new XmlBuilderException("not implemented");
}
/**
*/
public void setDocumentElement(XmlElement rootElement) {
// replace with existing root element
int pos = findDocumentElement();
if(pos >= 0) {
children.set(pos, rootElement);
} else {
children.add(rootElement);
}
this.root = rootElement;
rootElement.setParent(this);
//TOOD: nice assertion that htere is only one XmlElement in children ...
}
private int findDocumentElement() {
for (int i = 0; i < children.size(); i++)
{
Object element = children.get(i);
if(element instanceof XmlElement) {
return i;
}
}
return -1;
}
public XmlElement requiredElement(XmlNamespace n, String name) {
XmlElement el = element(n, name);
if(el == null) { //TODO:CTX
throw new XmlBuilderException("document does not contain element with name "+name
+" in namespace "+n.getNamespaceName());
}
return el;
}
public XmlElement element(XmlNamespace n, String name) {
return element(n, name, false);
}
public XmlElement element(XmlNamespace namespace, String name, boolean create) {
XmlElement e = getDocumentElement();
if(e == null) {
return null;
}
String eNamespaceName = e.getNamespace() != null ? e.getNamespace().getNamespaceName() : null;
if (namespace != null) {
if ((name.equals(e.getName()))
&& (eNamespaceName != null && eNamespaceName.equals(namespace.getNamespaceName())))
{
return e;
}
} else {
if ((name.equals(e.getName()))
&& (eNamespaceName == null))
{
return e;
}
}
if(create) {
return addDocumentElement(namespace, name);
} else {
return null;
}
}
/**
*/
public void insertChild(int pos, Object child) {
// TODO
throw new XmlBuilderException("not implemented");
}
/**
*/
public XmlComment addComment(String content) {
// TODO
//throw new XmlBuilderException("not implemented");
XmlComment comment = new XmlCommentImpl(this, content);
children.add(comment);
return comment;
}
/**
*
*/
public XmlDoctype newDoctype(String systemIdentifier, String publicIdentifier) {
// TODO
throw new XmlBuilderException("not implemented");
}
/**
* An unordered set of unparsed entity information items,
* one for each unparsed entity declared in the DTD.
*/
public Iterable unparsedEntities() {
// TODO
throw new XmlBuilderException("not implemented");
}
/**
*
*/
public void removeAllChildren() {
// TODO
throw new XmlBuilderException("not implemented");
}
/**
*
*/
public XmlComment newComment(String content) {
//throw new XmlBuilderException("not implemented");
return new XmlCommentImpl(null, content);
}
/**
* Method removeAllNotations
*
*/
public void removeAllNotations() {
// TODO
throw new XmlBuilderException("not implemented");
}
/**
* Method addDoctype
*
*/
public XmlDoctype addDoctype(String systemIdentifier, String publicIdentifier) {
// TODO
throw new XmlBuilderException("not implemented");
}
/**
*
*/
public void addChild(Object child) {
// TODO
throw new XmlBuilderException("not implemented");
}
/**
* Method addNotation
*
*/
public XmlNotation addNotation(String name, String systemIdentifier, String publicIdentifier, String declarationBaseUri) {
// TODO
throw new XmlBuilderException("not implemented");
}
// public XmlElement newDocumentElement(String name) {
// // TODO
// return null;
// }
/**
*
*/
public String getBaseUri() {
// TODO
throw new XmlBuilderException("not implemented");
}
/**
* An unordered set of notation information items,
* one for each notation declared in the DTD.
*/
public Iterable notations() {
// TODO
throw new XmlBuilderException("not implemented");
}
/**
*
*/
public XmlElement addDocumentElement(String name) {
return addDocumentElement(null, name);
}
public XmlElement addDocumentElement(XmlNamespace namespace, String name)
{
XmlElement el = new XmlElementImpl(namespace, name);
if(getDocumentElement() != null) {
throw new XmlBuilderException("document already has root element");
}
setDocumentElement(el);
return el;
}
/**
*
*/
public boolean isAllDeclarationsProcessed() {
// TODO
throw new XmlBuilderException("not implemented");
}
/**
*
*/
public XmlElement getDocumentElement() {
// TODO
return root;
}
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/impl/XmlElementImpl.java 100644 0 0 76533 10525225063 26003 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.builder.impl;
import org.xmlpull.v1.builder.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.xmlpull.v1.builder.Iterable;
//import org.xmlpull.v1.builder.SimpleIterator;
/**
* This is implementation if XML Infoset Element Information Item.
*
* @version $Revision: 1.41 $
* @author Aleksander Slominski
*/
public class XmlElementImpl implements XmlElement
{
private XmlContainer parent;
private XmlNamespace namespace;
//private String prefix;
private String name;
private List attrs;
private List nsList;
//NOTE: optimize for one child: Object oneChild; or create ElementWithChild????
private List children;
//JDK15 covariant public XmlElement clone() throws CloneNotSupportedException
public Object clone() throws CloneNotSupportedException
{
XmlElementImpl cloned = (XmlElementImpl) super.clone();
cloned.parent = null;
// now do deep clone
cloned.attrs = cloneList(cloned, attrs);
cloned.nsList = cloneList(cloned, nsList); ///TODO should duplicate ALL in-scope namespaces?
cloned.children = cloneList(cloned, children);
//fix parent -- if needs fixing ...
if(cloned.children != null) {
for (int i = 0; i < cloned.children.size(); i++)
{
Object member = cloned.children.get(i);
// if(member instanceof XmlElement) {
// XmlElement el = (XmlElement) member;
// if(el.getParent() == this) {
// el.setParent(null);
// el.setParent(cloned);
// }
// }
if(member instanceof XmlContained) {
XmlContained contained = (XmlContained ) member;
if(contained.getParent() == this) {
contained.setParent(null);
contained.setParent(cloned);
}
}
}
}
return cloned;
}
private List cloneList(XmlElementImpl cloned, List list) throws CloneNotSupportedException {
if(list == null) {
return null;
}
List newList = new ArrayList(list.size());
//JDK15 for(Object member: list) {
for (int i = 0; i < list.size(); i++)
{
Object member = list.get(i);
Object newMember; // = null;
if((member instanceof XmlNamespace) || (member instanceof String)) {
// immutable and has no owner - no need to clone
newMember = member;
} else if(member instanceof XmlElement) {
// XmlElement el = (XmlElement) member;
// newMember = el.clone();
XmlElement el = (XmlElement) member;
newMember = el.clone();
} else if(member instanceof XmlAttribute) {
XmlAttribute attr = (XmlAttribute) member;
newMember = new XmlAttributeImpl(cloned,
attr.getType(),
attr.getNamespace(),
attr.getName(),
attr.getValue(),
attr.isSpecified());
} else if(member instanceof java.lang.Cloneable) {
//use reflection to call clone() -- this is getting ugly!!!!
// more background on this in http://www.artima.com/intv/issues3.html "The clone Dilemma"
try {
newMember = member.getClass().getMethod("clone", null).invoke(member, null);
} catch (Exception e) {
throw new CloneNotSupportedException("failed to call clone() on "+member+e);
}
} else {
throw new CloneNotSupportedException();
}
newList.add(newMember);
}
return newList;
}
/**package**/ XmlElementImpl(String name) {
this.name = name;
}
/**package**/ XmlElementImpl(XmlNamespace namespace, String name) {
this.namespace = namespace;
this.name = name;
}
/**package**/ XmlElementImpl(String namespaceName, String name) {
if(namespaceName != null) {
this.namespace = new XmlNamespaceImpl(null, namespaceName);
}
this.name = name;
}
public XmlContainer getRoot() {
XmlContainer root = this;
while(true) {
if(! ( root instanceof XmlElement )) {
break;
}
XmlElement el = (XmlElement) root;
if(el.getParent() != null) {
root= el.getParent();
} else {
break;
}
}
return root;
}
//----- generic methods
public XmlContainer getParent() {
return parent;
}
public void setParent(XmlContainer parent)
{
if(parent != null) {
// check that parent has me as child
// if(parent instanceof XmlElement) {
// Iterator iter = ((XmlElement)parent).children();
// boolean found = false;
// while (iter.hasNext())
// {
// Object element = iter.next();
// if(element == this) {
// found = true;
// break;
// }
// }
// if(!found) {
// throw new XmlBuilderException(
// "this element must be child of parent to set its parent");
// }
// } else
if(parent instanceof XmlDocument) {
XmlDocument doc = (XmlDocument) parent;
if(doc.getDocumentElement() != this) {
throw new XmlBuilderException(
"this element must be root document element to have document set as parent"
+" but already different element is set as root document element");
}
}
}
this.parent = parent;
}
public XmlNamespace getNamespace() {
return namespace;
}
public String getNamespaceName()
{
return namespace != null ? namespace.getNamespaceName() : null;
}
public void setNamespace(XmlNamespace namespace) {
this.namespace = namespace;
}
// public String getPrefix() {
// return prefix;
// }
//
// public void setPrefix(String prefix) {
// this.prefix = prefix;
// }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String toString()
{
return "name[" + name + "]"
+ (namespace != null ? " namespace[" + namespace.getNamespaceName() + "]" : "");
}
public String getBaseUri() {
// TODO
throw new XmlBuilderException("not implemented");
}
public void setBaseUri(String baseUri) {
// TODO
throw new XmlBuilderException("not implemented");
}
//Attributes
public Iterator attributes() {
if(attrs == null) {
return EMPTY_ITERATOR;
}
return attrs.iterator();
}
public XmlAttribute addAttribute(XmlAttribute attributeValueToAdd) {
if(attrs == null) ensureAttributeCapacity(5);
//TODO: check that there is no attribute duplication (including namespaces?)
attrs.add(attributeValueToAdd);
return attributeValueToAdd;
}
public XmlAttribute addAttribute(XmlNamespace namespace, String name, String value) {
return addAttribute("CDATA", namespace, name, value, false);
}
public XmlAttribute addAttribute(String name, String value) {
return addAttribute("CDATA", null, name, value, false);
}
public XmlAttribute addAttribute(String attributeType, XmlNamespace namespace, String name, String value) {
return addAttribute(attributeType, namespace, name, value, false);
}
public XmlAttribute addAttribute(String attributeType, XmlNamespace namespace, String name,
String value, boolean specified)
{
XmlAttribute a = new XmlAttributeImpl(this, attributeType, namespace, name, value, specified);
return addAttribute(a);
}
public XmlAttribute addAttribute(String attributeType,
String attributePrefix,
String attributeNamespace,
String attributeName,
String attributeValue,
boolean specified)
{
XmlNamespace n = newNamespace(attributePrefix, attributeNamespace);
return addAttribute(attributeType, n, attributeName, attributeValue, specified);
}
public void ensureAttributeCapacity(int minCapacity) {
if(attrs == null) {
attrs = new ArrayList(minCapacity);
} else {
((ArrayList)attrs).ensureCapacity(minCapacity);
}
}
public String getAttributeValue(String attributeNamespaceName,
String attributeName)
{
XmlAttribute xat = findAttribute(attributeNamespaceName, attributeName);
if(xat != null) {
return xat.getValue();
}
return null;
}
public boolean hasAttributes() {
return attrs != null && attrs.size() > 0;
}
public XmlAttribute attribute(String attributeName) {
return attribute(null, attributeName);
}
public XmlAttribute attribute(XmlNamespace attributeNamespace,
String attributeName)
{
return findAttribute(
attributeNamespace!= null ? attributeNamespace.getNamespaceName() : null,
attributeName);
}
//todo: verify me
//if you enforce that namespace "" and null are equivalent this could be
//rewritten
/**
* @deprecated
*/
public XmlAttribute findAttribute(String attributeNamespace, String attributeName) {
if(attributeName == null) {
throw new IllegalArgumentException("attribute name ca not ber null");
}
//addtional condition ---> test if there are some attrs
if (attrs == null) {
return null;
}
int length = attrs.size();
for (int i = 0; i < length; i++)
{
XmlAttribute a = (XmlAttribute) attrs.get(i);
String aName = a.getName();
if(aName == attributeName // fast if strings are itnerned
|| attributeName.equals(aName))
{
if(attributeNamespace != null) {
String aNamespace = a.getNamespaceName();
if (attributeNamespace.equals(aNamespace)) {
return a;
} else if ((attributeNamespace == "") && (aNamespace == null)) {
return a;
}
// XmlNamespace aNamespace = a.getNamespace();
// if(aNamespace != null) {
// String aNamespaceName = aNamespace.getNamespaceName();
// if(aNamespaceName == attributeName
// || aNamespace.equals(aNamespaceName))
// {
// return a;
// }
// }
} else {
if (a.getNamespace() == null)
{
return a;
} else {
if (a.getNamespace().getNamespaceName() == "") {
return a;
}
}
}
}
}
return null;
}
public void removeAllAttributes() {
attrs = null;
}
public void removeAttribute(XmlAttribute attr) {
if(attrs == null) {
throw new XmlBuilderException("this element has no attributes to remove");
}
for (int i = 0; i < attrs.size(); i++)
{
if (attrs.get(i).equals(attr)) {
attrs.remove(i);
break;
}
}
}
//------------ Namespaces
public XmlNamespace declareNamespace(String prefix, String namespaceName) {
if(prefix == null) {
throw new XmlBuilderException("namespace added to element must have not null prefix");
}
XmlNamespace n = newNamespace(prefix, namespaceName);
return declareNamespace(n);
}
public XmlNamespace declareNamespace(XmlNamespace n) {
if(n.getPrefix() == null) {
throw new XmlBuilderException("namespace added to element must have not null prefix");
}
if(nsList == null) ensureNamespaceDeclarationsCapacity(5);
//TODO check for duplicates
nsList.add(n);
return n;
}
public boolean hasNamespaceDeclarations() {
return nsList != null && nsList.size() >0;
}
public XmlNamespace lookupNamespaceByPrefix(String namespacePrefix) {
if(namespacePrefix == null) {
throw new IllegalArgumentException("namespace prefix can not be null");
}
if(hasNamespaceDeclarations()) {
int length = nsList.size();
for (int i = 0; i < length; i++)
{
XmlNamespace n = (XmlNamespace) nsList.get(i);
if(namespacePrefix.equals(n.getPrefix()) ){
return n;
}
}
}
if(parent != null && parent instanceof XmlElement) {
return ((XmlElement)parent).lookupNamespaceByPrefix(namespacePrefix);
} else {
return null;
}
}
public XmlNamespace lookupNamespaceByName(String namespaceName) {
if(namespaceName == null) {
throw new IllegalArgumentException("namespace name can not ber null");
}
if(hasNamespaceDeclarations()) {
int length = nsList.size();
for (int i = 0; i < length; i++)
{
XmlNamespace n = (XmlNamespace) nsList.get(i);
if(namespaceName.equals(n.getNamespaceName()) ){
return n;
}
}
}
if(parent != null && parent instanceof XmlElement) {
return ((XmlElement)parent).lookupNamespaceByName(namespaceName);
} else {
return null;
}
}
public Iterator namespaces() {
if(nsList == null) {
return EMPTY_ITERATOR;
}
return nsList.iterator();
}
public XmlNamespace newNamespace(String namespaceName)
{
return newNamespace(null, namespaceName);
}
public XmlNamespace newNamespace(String prefix, String namespaceName) {
return new XmlNamespaceImpl(prefix, namespaceName);
}
public void ensureNamespaceDeclarationsCapacity(int minCapacity) {
// if(attrs == null) {
if(nsList == null) {
nsList = new ArrayList(minCapacity);
} else {
((ArrayList)nsList).ensureCapacity(minCapacity);
}
}
public void removeAllNamespaceDeclarations() {
nsList = null;
}
//---------------- Elements
public void addChild(Object child) {
if (child == null) throw new NullPointerException();
if(children == null) ensureChildrenCapacity(1);
//checkChildParent(child);
children.add(child);
//setChildParent(child);
}
public void addChild(int index, Object child) {
if(children == null) ensureChildrenCapacity(1);
//checkChildParent(child);
children.add(index, child);
//setChildParent(child);
}
private void checkChildParent(Object child) {
if(child instanceof XmlContainer) {
if(child instanceof XmlElement) {
XmlElement elChild = (XmlElement) child;
XmlContainer childParent = elChild.getParent();
if(childParent != null) {
if(childParent != parent) {
throw new XmlBuilderException(
"child must have no parent to be added to this node");
}
}
} else if(child instanceof XmlDocument) {
throw new XmlBuilderException("docuemet can not be stored as element child");
}
}
}
private void setChildParent(Object child) {
if(child instanceof XmlElement) {
XmlElement elChild = (XmlElement) child;
elChild.setParent(this);
}
}
public XmlElement addElement(XmlElement element)
{
checkChildParent(element);
addChild(element);
setChildParent(element);
return element;
}
public XmlElement addElement(int pos, XmlElement element) {
checkChildParent(element);
addChild(pos, element);
setChildParent(element);
return element;
}
public XmlElement addElement(XmlNamespace namespace, String name) {
XmlElement el = newElement(namespace, name);
addChild(el);
setChildParent(el);
return el;
}
public XmlElement addElement(String name) {
return addElement(null, name);
}
public Iterator children() {
if(children == null) {
return EMPTY_ITERATOR;
}
return children.iterator();
}
public Iterable requiredElementContent() {
if(children == null) {
return EMPTY_ITERABLE;
}
return new Iterable() {
public Iterator iterator() {
return new RequiredElementContentIterator(children.iterator());
}
};
}
public String requiredTextContent() {
if(children == null) {
// throw new XmlBuilderException("element {"+getNamespace().getNamespaceName()+"}"
// +getName()+" has no content");
return "";
}
if(children.size() == 0) {
return "";
} else if(children.size() == 1) {
Object child = children.get(0);
if(child instanceof String) {
return child.toString();
} else if(child instanceof XmlCharacters) {
return ((XmlCharacters)child).getText();
} else {
throw new XmlBuilderException("expected text content and not "
+(child != null ? child.getClass() : null)
+" with '"+child+"'");
}
}
Iterator i = children();
StringBuffer buf = new StringBuffer();
while(i.hasNext()) {
Object child = i.next();
if(child instanceof String) {
buf.append(child.toString());
} else if(child instanceof XmlCharacters) {
buf.append(((XmlCharacters)child).getText());
} else {
throw new XmlBuilderException("expected text content and not "+child.getClass()
+" with '"+child+"'");
}
}
return buf.toString();
}
public void ensureChildrenCapacity(int minCapacity)
{
if(children == null) {
children = new ArrayList(minCapacity);
} else {
((ArrayList)children).ensureCapacity(minCapacity);
}
}
public XmlElement element(int position) {
if(children == null) return null;
int length = children.size();
int count = 0;
if(position >= 0 && position < (length + 1)) {
int pos = 0;
while(pos < length) {
Object child = children.get(pos);
if(child instanceof XmlElement) {
++count;
if(count == position) {
return (XmlElement) child;
}
}
++pos;
}
} else { //TODO:CTX
throw new IndexOutOfBoundsException(
"position "+position+" bigger or equal to "+length+" children");
} //TODO:CTX
throw new IndexOutOfBoundsException(
"position "+position+" too big as only "+count+" element(s) available");
}
public XmlElement requiredElement(XmlNamespace n, String name) throws XmlBuilderException {
XmlElement el = element(n, name);
if(el == null) { //TODO:CTX
throw new XmlBuilderException("could not find element with name "+name
+" in namespace "+(n !=null ? n.getNamespaceName() : null));
}
return el;
}
public XmlElement element(XmlNamespace n, String name) {
return element(n, name, false);
}
public XmlElement element(XmlNamespace n, String name, boolean create) {
XmlElement e = n != null ? findElementByName(n.getNamespaceName(), name) : findElementByName(name);
if(e != null) {
return e;
}
//e =new XmlElementImpl(n, name);
if(create) {
return addElement(n, name);
} else {
return null;
}
}
public Iterable elements(final XmlNamespace n, final String name) {
return new Iterable() {
public Iterator iterator() {
return new ElementsSimpleIterator(n, name, children());
}
};
}
public XmlElement findElementByName(String name) {
if(children == null) return null;
int length = children.size();
for (int i = 0; i < length; i++)
{
Object child = children.get(i);
if(child instanceof XmlElement) {
XmlElement childEl = (XmlElement) child;
if(name.equals(childEl.getName())) {
return childEl;
}
}
}
return null;
}
public XmlElement findElementByName(String namespaceName, String name,
XmlElement elementToStartLooking) {
// TODO
throw new UnsupportedOperationException();
}
public XmlElement findElementByName(String name,
XmlElement elementToStartLooking)
{
// TODO
throw new UnsupportedOperationException();
}
public XmlElement findElementByName(String namespaceName, String name) {
if(children == null) return null;
int length = children.size();
for (int i = 0; i < length; i++)
{
Object child = children.get(i);
if(child instanceof XmlElement) {
XmlElement childEl = (XmlElement) child;
XmlNamespace namespace = childEl.getNamespace();
if (namespace != null) {
if ((name.equals(childEl.getName())) && (namespaceName.equals(namespace.getNamespaceName()))) {
return childEl;
}
} else {
if ((name.equals(childEl.getName())) && (namespaceName == null)) {
return childEl;
}
}
}
}
return null;
}
public boolean hasChild(Object child) {
if(children == null) {
return false;
}
for (int i = 0; i < children.size(); i++)
{
if(children.get(i) == child) {
return true;
}
}
return false;
}
public boolean hasChildren() {
return children != null && children.size() > 0;
}
public void insertChild(int pos, Object childToInsert) {
// children.set(pos, childToInsert);
if (children == null) ensureChildrenCapacity(1);
children.add(pos, childToInsert);
}
public XmlElement newElement(String name) {
return newElement((XmlNamespace)null, name);
}
public XmlElement newElement(String namespace, String name) {
return new XmlElementImpl(namespace, name);
}
public XmlElement newElement(XmlNamespace namespace, String name) {
return new XmlElementImpl(namespace, name);
}
public void replaceChild(Object newChild, Object oldChild) {
if(newChild == null) {
throw new IllegalArgumentException("new child to replace can not be null");
}
if(oldChild == null) {
throw new IllegalArgumentException("old child to replace can not be null");
}
if(!hasChildren()) {
throw new XmlBuilderException("no children available for replacement");
}
int pos = children.indexOf(oldChild);
if(pos == -1) {
throw new XmlBuilderException("could not find child to replace");
}
children.set(pos, newChild);
}
public void removeAllChildren() {
children = null;
}
public void removeChild(Object child) {
if(child == null) {
throw new IllegalArgumentException("child to remove can not be null");
}
if(!hasChildren()) {
throw new XmlBuilderException("no children to remove");
}
int pos = children.indexOf(child);
if(pos != -1) {
children.remove(pos);
}
// int length = children.size();
// for (int i = 0; i < length; i++)
// {
// Object o = children.get(i);
// if(o == child) {
// }
// }
}
public void replaceChildrenWithText(String textContent) {
removeAllChildren();
addChild(textContent);
}
private static final boolean isWhiteSpace(String txt)
{
for (int i = 0; i < txt.length(); i++)
{
if ( (txt.charAt(i) != ' ') &&
(txt.charAt(i) != '\n') &&
(txt.charAt(i) != '\t') &&
(txt.charAt(i) != '\r'))
{
return false;
}
}
return true;
}
private class ElementsSimpleIterator implements Iterator {
private Iterator children;
private XmlElement currentEl;
private XmlNamespace n;
private String name;
ElementsSimpleIterator(final XmlNamespace n, final String name, Iterator children) {
this.children = children;
this.n = n;
this.name = name;
findNextEl();
}
private void findNextEl() {
currentEl = null;
while(children.hasNext()) {
Object child = children.next();
if(child instanceof XmlElement) {
XmlElement el = (XmlElement) child;
if( (name == null || el.getName() == name || name.equals(el.getName()))
&& (n == null || el.getNamespace() == n || n.equals(el.getNamespace()))
)
{
currentEl = el;
break;
}
}
}
}
public boolean hasNext() {
return currentEl != null;
}
public Object next() {
if(currentEl == null) {
throw new XmlBuilderException(
"this iterator has no content and next() is not allowed");
}
XmlElement el = currentEl;
findNextEl();
return el;
}
public void remove() {
throw new XmlBuilderException(
"this element iterator does nto support remove()");
}
}
private static class RequiredElementContentIterator implements Iterator {
private Iterator children;
private XmlElement currentEl;
RequiredElementContentIterator(Iterator children) {
this.children = children;
findNextEl();
}
private void findNextEl() {
currentEl = null;
while(children.hasNext()) {
Object child = children.next();
if(child instanceof XmlElement) {
currentEl = (XmlElement) child;
break;
} else if(child instanceof String) {
String s = child.toString();
if(false == isWhiteSpace(s)) {
throw new XmlBuilderException( //TODO parent.getPositionDesc() ...
"only whitespace string children allowed for non mixed element content");
}
} else if(child instanceof XmlCharacters) {
XmlCharacters xc = (XmlCharacters) child;
if(!Boolean.TRUE.equals(xc.isWhitespaceContent())
|| false == isWhiteSpace(xc.getText()) )
{
throw new XmlBuilderException( //TODO parent.getPositionDesc() ...
"only whitespace characters children allowed for non mixed element content");
}
} else {
throw new XmlBuilderException( //TODO parent.getPositionDesc() ...
"only whitespace characters and element children allowed "+
"for non mixed element content and not "+child.getClass());
}
}
}
public boolean hasNext() {
return currentEl != null;
}
public Object next() {
if(currentEl == null) {
throw new XmlBuilderException(
"this iterator has no content and next() is not allowed");
}
XmlElement el = currentEl;
findNextEl();
return el;
}
public void remove() {
throw new XmlBuilderException(
"this iterator does nto support remove()");
}
}
private static class EmptyIterator implements Iterator {
public boolean hasNext() {
return false;
}
public Object next() {
throw new XmlBuilderException(
"this iterator has no content and next() is not allowed");
}
public void remove() {
throw new XmlBuilderException(
"this iterator has no content and remove() is not allowed");
}
}
private static final Iterator EMPTY_ITERATOR = new EmptyIterator();
private static final Iterable EMPTY_ITERABLE = new Iterable() {
public Iterator iterator() {
return EMPTY_ITERATOR;
}
};
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/impl/XmlInfosetBuilderImpl.java 100644 0 0 40177 10525225063 27323 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder.impl;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.Iterator;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
import org.xmlpull.v1.builder.XmlAttribute;
import org.xmlpull.v1.builder.XmlBuilderException;
import org.xmlpull.v1.builder.XmlComment;
import org.xmlpull.v1.builder.XmlContainer;
import org.xmlpull.v1.builder.XmlDocument;
import org.xmlpull.v1.builder.XmlElement;
import org.xmlpull.v1.builder.XmlNamespace;
import org.xmlpull.v1.builder.XmlInfosetBuilder;
import org.xmlpull.v1.builder.XmlSerializable;
import org.xmlpull.v1.builder.XmlCharacters;
//TODO: add equals() and hashcode()
//TODO: think about how to do gernali XmlSerialziable (to simplify serialzie()
//TODO: in XmlElement use String namespaceName and do not use XmlNamespace namespace (except for getNamespace()?
// NOTE: that XML infoset requires prefix informatio to be present even if not needed ....
/**
* Implementation of generic buuilder that uses XmlPull API to access
* current default XmlPullParser and XmlSerializer.
*
* @author Aleksander Slominski
*/
public class XmlInfosetBuilderImpl extends XmlInfosetBuilder
{
private final static String PROPERTY_XMLDECL_STANDALONE =
"http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone";
private final static String PROPERTY_XMLDECL_VERSION =
"http://xmlpull.org/v1/doc/properties.html#xmldecl-version";
//private boolean useNamespaces;
public XmlInfosetBuilderImpl() {}
public XmlDocument newDocument(String version, Boolean standalone, String characterEncoding)
{
return new XmlDocumentImpl(version, standalone, characterEncoding);
}
public XmlElement newFragment(String elementName)
{
return new XmlElementImpl((XmlNamespace)null, elementName);
}
public XmlElement newFragment(String elementNamespaceName, String elementName)
{
return new XmlElementImpl(elementNamespaceName, elementName);
}
public XmlElement newFragment(XmlNamespace elementNamespace, String elementName)
{
return new XmlElementImpl(elementNamespace, elementName);
}
//public abstract XmlNamespace newNamespace(String namespaceName);
//public abstract XmlNamespace newNamespace(String prefix, String namespaceName);
public XmlNamespace newNamespace(String namespaceName)
{
return new XmlNamespaceImpl(null, namespaceName);
}
public XmlNamespace newNamespace(String prefix, String namespaceName)
{
return new XmlNamespaceImpl(prefix, namespaceName);
}
public XmlDocument parse(XmlPullParser pp)
{
XmlDocument doc = parseDocumentStart(pp);
XmlElement root = parseFragment(pp);
doc.setDocumentElement(root);
//TODO parseDocumentEnd() - parse epilog with nextToken();
return doc;
}
public Object parseItem(XmlPullParser pp)
{
try {
int eventType = pp.getEventType();
if(eventType == XmlPullParser.START_TAG) {
return parseStartTag(pp);
} else if(eventType == XmlPullParser.TEXT) {
return pp.getText();
} else if(eventType == XmlPullParser.START_DOCUMENT) {
return parseDocumentStart(pp);
} else {
throw new XmlBuilderException("currently unsupported event type "
+XmlPullParser.TYPES[eventType]+pp.getPositionDescription());
}
} catch (XmlPullParserException e) {
throw new XmlBuilderException("could not parse XML item" ,e);
}
}
private XmlDocument parseDocumentStart(XmlPullParser pp)
//throws XmlPullParserException, IOException
{
//sourceForNode.next();
XmlDocument doc = null;
try {
if(pp.getEventType() != XmlPullParser.START_DOCUMENT) {
throw new XmlBuilderException("parser must be positioned on beginning of document"
+" and not "+pp.getPositionDescription());
}
// TODO use nextToken()
pp.next();
String xmlDeclVersion = (String) pp.getProperty(PROPERTY_XMLDECL_VERSION);
Boolean xmlDeclStandalone = (Boolean) pp.getProperty(PROPERTY_XMLDECL_STANDALONE);;
String characterEncoding = pp.getInputEncoding();
doc = new XmlDocumentImpl(xmlDeclVersion, xmlDeclStandalone, characterEncoding);
} catch (XmlPullParserException e) {
throw new XmlBuilderException("could not parse XML document prolog" ,e);
} catch (IOException e) {
throw new XmlBuilderException("could not read XML document prolog" ,e);
}
return doc;
}
public XmlElement parseFragment(XmlPullParser pp)
{
try {
int depth = pp.getDepth();
int eventType = pp.getEventType();
if(eventType != XmlPullParser.START_TAG) {
throw new XmlBuilderException(
"expected parser to be on start tag and not "+XmlPullParser.TYPES[ eventType ]
+pp.getPositionDescription());
}
//int level = depth + 1;
XmlElement curElem = parseStartTag(pp);
while(true) {
eventType = pp.next();
if(eventType == XmlPullParser.START_TAG) {
XmlElement child = parseStartTag(pp);
curElem.addElement(child);
curElem = child;
} else if(eventType == XmlPullParser.END_TAG) {
XmlContainer parent = curElem.getParent();
if(parent == null) {
if(pp.getDepth() != depth) {
throw new XmlBuilderException(
"unbalanced input"+pp.getPositionDescription());
}
return curElem;
}
curElem = (XmlElement) parent;
//--level;
//curElem = curElem.parent;
} else if(eventType == XmlPullParser.TEXT) {
curElem.addChild(pp.getText());
}
}
} catch (XmlPullParserException e) {
throw new XmlBuilderException("could not build tree from XML" ,e);
} catch (IOException e) {
throw new XmlBuilderException("could not read XML tree content" ,e);
}
}
public XmlElement parseStartTag(XmlPullParser pp)
{
try {
//assert pp.getEventType() == XmlPullParser.START_TAG;
if(pp.getEventType() != XmlPullParser.START_TAG) {
throw new XmlBuilderException(
"parser must be on START_TAG and not "+pp.getPositionDescription());
}
String elNsPrefix = pp.getPrefix();
XmlNamespace elementNs = new XmlNamespaceImpl(elNsPrefix, pp.getNamespace()) ;
XmlElement el = new XmlElementImpl(elementNs, pp.getName());
//add namespaces declarations (if any)
for (int i = pp.getNamespaceCount(pp.getDepth()-1);
i < pp.getNamespaceCount(pp.getDepth()); i++)
{
// TODO think about changing XmlPull to return "" in this case ... or not
String prefix = pp.getNamespacePrefix(i);
el.declareNamespace(prefix == null ? "" : prefix, pp.getNamespaceUri(i));
}
//add attributes and namespaces
for (int i = 0; i < pp.getAttributeCount(); i++)
{
el.addAttribute(pp.getAttributeType(i),
pp.getAttributePrefix(i),
pp.getAttributeNamespace(i),
pp.getAttributeName(i),
pp.getAttributeValue(i),
pp.isAttributeDefault(i) == false);
}
return el;
} catch (XmlPullParserException e) {
throw new XmlBuilderException("could not parse XML start tag" ,e);
//} catch (IOException e) {
// throw new XmlBuilderException("could not read XML start tag" ,e);
}
}
public XmlDocument parseLocation(String locationUrl)
{
// TODO: if first is "/" try opening file
URL url = null;
try {
url = new URL(locationUrl);
} catch (MalformedURLException e) {
throw new XmlBuilderException("could not parse URL "+locationUrl, e);
}
try {
return parseInputStream(url.openStream());
} catch (IOException e) {
throw new XmlBuilderException("could not open connection to URL "+locationUrl, e);
}
}
public void serialize(Object item, XmlSerializer serializer)
{
if(item instanceof Collection) {
Collection c = (Collection) item;
for(Iterator i = c.iterator() ; i.hasNext(); ) {
serialize(i.next(), serializer);
}
} else if(item instanceof XmlContainer) {
serializeContainer((XmlContainer)item, serializer);
} else {
serializeItem(item, serializer);
}
}
private void serializeContainer(XmlContainer node, XmlSerializer serializer)
{
if(node instanceof XmlSerializable) {
try {
((XmlSerializable)node).serialize(serializer);
} catch (IOException e) {
throw new XmlBuilderException("could not serialize node "+node+": "+e, e);
}
} else if(node instanceof XmlDocument) {
serializeDocument((XmlDocument)node, serializer);
} else if(node instanceof XmlElement) {
serializeFragment((XmlElement)node, serializer);
} else {
throw new IllegalArgumentException(
"could not serialzie unknown XML container "+node.getClass());
}
}
public void serializeItem(Object item, XmlSerializer ser)
{
try {
if(item instanceof XmlSerializable) {
//((XmlSerializable)item).serialize(ser);
try {
((XmlSerializable)item).serialize(ser);
} catch (IOException e) {
throw new XmlBuilderException("could not serialize item "+item+": "+e, e);
}
} else if(item instanceof String) {
ser.text(item.toString());
} else if(item instanceof XmlCharacters) {
ser.text(((XmlCharacters)item).getText());
} else if(item instanceof XmlComment) {
ser.comment(((XmlComment)item).getContent());
} else {
throw new IllegalArgumentException("could not serialize "+(item != null ? item.getClass() : item));
}
} catch (IOException e) {
throw new XmlBuilderException("serializing XML start tag failed", e);
}
}
public void serializeStartTag(XmlElement el, XmlSerializer ser) {
try {
//declare namespaces
XmlNamespace elNamespace = el.getNamespace();
String elPrefix = (elNamespace != null) ? elNamespace.getPrefix() : "";
if(elPrefix == null) {
elPrefix = "";
}
String nToDeclare = null;
if(el.hasNamespaceDeclarations()) {
Iterator iter = el.namespaces();
while (iter.hasNext())
{
XmlNamespace n = (XmlNamespace) iter.next();
String nPrefix = n.getPrefix();
if(!elPrefix.equals(nPrefix)) {
ser.setPrefix(nPrefix, n.getNamespaceName());
} else {
nToDeclare = n.getNamespaceName();
}
}
}
// make sure that preferred element prefix is declared last so it is picked up by serializer
if(nToDeclare != null) {
ser.setPrefix(elPrefix, nToDeclare);
} else {
if(elNamespace != null) {
// first check that it needs to be declared - will declaring change anything?
String namespaceName = elNamespace.getNamespaceName();
if(namespaceName == null) {
namespaceName = "";
}
String serPrefix = null;
if(namespaceName.length() > 0) {
ser.getPrefix(namespaceName, false);
}
if(serPrefix==null){
serPrefix="";
}
if(serPrefix != elPrefix && !serPrefix.equals(elPrefix)){
// the prefix was not declared on current elment but just to enforce prefix choice ...
ser.setPrefix(elPrefix, namespaceName);
}
}
}
ser.startTag(el.getNamespaceName(), el.getName());
if(el.hasAttributes()) {
Iterator iter = el.attributes();
while (iter.hasNext())
{
XmlAttribute a = (XmlAttribute) iter.next();
if(a instanceof XmlSerializable) {
((XmlSerializable) a).serialize(ser);
} else {
ser.attribute(a.getNamespaceName(), a.getName(), a.getValue());
}
}
}
} catch (IOException e) {
throw new XmlBuilderException("serializing XML start tag failed", e);
}
}
public void serializeEndTag(XmlElement el, XmlSerializer ser) {
try {
ser.endTag(el.getNamespaceName(), el.getName());
} catch (IOException e) {
throw new XmlBuilderException("serializing XML end tag failed", e);
}
}
//TODO: would iit be simple make XmlContainer serialziable and use it to serialize ....
//TODO but would it be more flexible?
private void serializeDocument(XmlDocument doc, XmlSerializer ser)
{
try {
ser.startDocument(doc.getCharacterEncodingScheme(), doc.isStandalone());
} catch (IOException e) {
throw new XmlBuilderException("serializing XML document start failed", e);
}
if(doc.getDocumentElement() != null) {
serializeFragment(doc.getDocumentElement(), ser);
} else {
throw new XmlBuilderException("could not serialize document without root element "+doc+": ");
}
try {
ser.endDocument();
} catch (IOException e) {
throw new XmlBuilderException("serializing XML document end failed", e);
}
}
private void serializeFragment(XmlElement el, XmlSerializer ser)
{
serializeStartTag(el, ser);
//try {
if(el.hasChildren()) {
Iterator iter = el.children();
while (iter.hasNext())
{
Object child = iter.next();
if(child instanceof XmlSerializable) {
//((XmlSerializable)child).serialize(ser);
try {
((XmlSerializable)child).serialize(ser);
} catch (IOException e) {
throw new XmlBuilderException("could not serialize item "+child+": "+e, e);
}
} else if(child instanceof XmlElement) {
serializeFragment((XmlElement)child, ser);
} else {
serializeItem(child, ser);
}
}
}
//} catch (IOException e) {
// throw new XmlBuilderException("serializing XML element children failed", e);
//}
serializeEndTag(el, ser);
}
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/impl/XmlNamespaceImpl.java 100644 0 0 3646 10525225063 26261 0 ustar aslom ewww 0 0 package org.xmlpull.v1.builder.impl;
import org.xmlpull.v1.builder.XmlNamespace;
import org.xmlpull.v1.builder.XmlBuilderException;
/**
* Simple implementation.
*
* @author Aleksander Slominski
*/
public class XmlNamespaceImpl implements XmlNamespace
{
//final static XmlNamespace NULL_NAMESPACE = new XmlNamespaceImpl(null, null);
private String namespaceName;
private String prefix;
XmlNamespaceImpl(String namespaceName) {
if(namespaceName == null) {
throw new XmlBuilderException("namespace name can not be null");
}
this.namespaceName = namespaceName;
}
XmlNamespaceImpl(String prefix, String namespaceName) {
this.prefix = prefix;
if(namespaceName == null) {
throw new XmlBuilderException("namespace name can not be null");
}
if(prefix != null) {
if(prefix.indexOf(':') != -1) {
throw new XmlBuilderException(
"prefix '"+prefix+"' for namespace '"+namespaceName+"' can not contain colon (:)");
}
}
this.namespaceName = namespaceName;
}
public String getPrefix()
{
return prefix;
}
public String getNamespaceName()
{
return namespaceName;
}
public boolean equals(Object other) {
if(other == this) return true;
if(other == null) return false;
if(!(other instanceof XmlNamespace)) return false;
XmlNamespace otherNamespace = (XmlNamespace) other;
return getNamespaceName().equals(otherNamespace.getNamespaceName());
}
public String toString() {
//String klazzName = getClass().getName();
//return klazzName+"{prefix='"+prefix+"',namespaceName='"+namespaceName+"'}";
return "{prefix='"+prefix+"',namespaceName='"+namespaceName+"'}";
}
}
xpp3-1.1.4c/src/java/builder/org/xmlpull/v1/builder/package.html 100644 0 0 4601 10525225063 23527 0 ustar aslom ewww 0 0
This package defines API modeled after
XML Information Set
for building incrmentally XML trees
from events streamed from pull parser
(user can start navigating tree before whole XML input was parsed!)
and has an unique ability to bypass tree building for selected sub trees
to work directly with underlying event stream.
This coupled with ability to create XML tree that can mix in any
Java Object allows to represent objects derived from XML (databinding)
in the XML tree.
Features
unique ability to achieve high performance that is common in streaming parsers
and ease of use associated with tree approaches in the same API
by provising very precise control over XML tree creation and access
to underlying streaming parser during tree creation
(API users needs to do it if and only if they do want to bypass default tree
creation and replace it with their customized object tree, work directly with XML
events or just skip unneded parts of XML that do not need to be in XML node tree).
easy to use : modeled after XML
Information Set
to build on well established abstract model to represent XML
small : only few classes and interfaces
fast : builds on the most powerful XmlPull API that makes possible to create
high perfromance parser implemntations
flexible: based on the state of the art interface-implementation approach
allowing anybody to modify and extend easily API
Overview
API is directly modeled on XML Information Set
with few minor exceptions but expands on it to provide additional functions to create
and manipulate XML Information Set (essentially providing
Synthetic Infoset ).
TODO:
when generics are supported in JDK upgrade API to use Iterator<T> instead of Enumeration ...
Aleksander Slominski
Last modified: $Id: package.html,v 1.1 2003/04/13 00:59:23 aslom Exp $
xpp3-1.1.4c/src/java/dom2_builder/org/xmlpull/v1/dom2_builder/DOM2XmlPullBuilder.java 100644 0 0 22003 10525225063 27315 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.dom2_builder;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import org.w3c.dom.DOMException;
//TOOD add parse method that will usenextToken() to reconstruct complete XML Infoset
/**
* Simplistic DOM2 builder that should be enough to do support most cases.
* Requires JAXP DOMBuilder to provide DOM2 implementation.
* NOTE:this class is stateless factory and it is safe to share between multiple threads.
*
*
* @author Aleksander Slominski
*/
public class DOM2XmlPullBuilder {
//protected XmlPullParser pp;
//protected XmlPullParserFactory factory;
public DOM2XmlPullBuilder() { //throws XmlPullParserException {
//factory = XmlPullParserFactory.newInstance();
}
//public DOM2XmlPullBuilder(XmlPullParser pp) throws XmlPullParserException {
//public DOM2XmlPullBuilder(XmlPullParserFactory factory)throws XmlPullParserException
//{
// this.factory = factory;
//}
protected Document newDoc() throws XmlPullParserException {
try {
// if you see dreaded "java.lang.NoClassDefFoundError: org/w3c/dom/ranges/DocumentRange"
// add the newest xercesImpl and apis JAR file to JRE/lib/endorsed
// for more deatils see: http://java.sun.com/j2se/1.4.2/docs/guide/standards/index.html
DocumentBuilderFactory domFactory
= DocumentBuilderFactory.newInstance();
DocumentBuilder builder = domFactory.newDocumentBuilder();
DOMImplementation impl = builder.getDOMImplementation();
return builder.newDocument();
} catch (FactoryConfigurationError ex) {
throw new XmlPullParserException(
"could not configure factory JAXP DocumentBuilderFactory: "+ex, null, ex);
} catch (ParserConfigurationException ex) {
throw new XmlPullParserException(
"could not configure parser JAXP DocumentBuilderFactory: "+ex, null, ex);
}
}
protected XmlPullParser newParser() throws XmlPullParserException {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
return factory.newPullParser();
}
public Element parse(Reader reader) throws XmlPullParserException, IOException {
Document docFactory = newDoc();
return parse(reader, docFactory);
}
public Element parse(Reader reader, Document docFactory)
throws XmlPullParserException, IOException
{
XmlPullParser pp = newParser();
pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
pp.setInput(reader);
pp.next();
return parse(pp, docFactory);
}
public Element parse(XmlPullParser pp, Document docFactory)
throws XmlPullParserException, IOException
{
Element root = parseSubTree(pp, docFactory);
return root;
}
public Element parseSubTree(XmlPullParser pp) throws XmlPullParserException, IOException {
Document doc = newDoc();
Element root = parseSubTree(pp, doc);
return root;
}
public Element parseSubTree(XmlPullParser pp, Document docFactory)
throws XmlPullParserException, IOException
{
BuildProcess process = new BuildProcess();
return process.parseSubTree(pp, docFactory);
}
static class BuildProcess {
private XmlPullParser pp;
private Document docFactory;
private boolean scanNamespaces = true;
private BuildProcess() {
}
public Element parseSubTree(XmlPullParser pp, Document docFactory)
throws XmlPullParserException, IOException
{
this.pp = pp;
this.docFactory = docFactory;
return parseSubTree();
}
private Element parseSubTree()
throws XmlPullParserException, IOException
{
pp.require( XmlPullParser.START_TAG, null, null);
String name = pp.getName();
String ns = pp.getNamespace( );
String prefix = pp.getPrefix();
String qname = prefix != null ? prefix+":"+name : name;
Element parent = docFactory.createElementNS(ns, qname);
//declare namespaces - quite painful and easy to fail process in DOM2
declareNamespaces(pp, parent);
// process attributes
for (int i = 0; i < pp.getAttributeCount(); i++)
{
String attrNs = pp.getAttributeNamespace(i);
String attrName = pp.getAttributeName(i);
String attrValue = pp.getAttributeValue(i);
if(attrNs == null || attrNs.length() == 0) {
parent.setAttribute(attrName, attrValue);
} else {
String attrPrefix = pp.getAttributePrefix(i);
String attrQname = attrPrefix != null ? attrPrefix+":"+attrName : attrName;
parent.setAttributeNS(attrNs, attrQname, attrValue);
}
}
// process children
while( pp.next() != XmlPullParser.END_TAG ) {
if (pp.getEventType() == XmlPullParser.START_TAG) {
Element el = parseSubTree(pp, docFactory);
parent.appendChild(el);
} else if (pp.getEventType() == XmlPullParser.TEXT) {
String text = pp.getText();
Text textEl = docFactory.createTextNode(text);
parent.appendChild(textEl);
} else {
throw new XmlPullParserException(
"unexpected event "+XmlPullParser.TYPES[ pp.getEventType() ], pp, null);
}
}
pp.require( XmlPullParser.END_TAG, ns, name);
return parent;
}
private void declareNamespaces(XmlPullParser pp, Element parent)
throws DOMException, XmlPullParserException
{
if(scanNamespaces) {
scanNamespaces = false;
int top = pp.getNamespaceCount(pp.getDepth()) - 1;
// this loop computes list of all in-scope prefixes
LOOP:
for (int i = top; i >= pp.getNamespaceCount(0); --i)
{
// make sure that no prefix is duplicated
String prefix = pp.getNamespacePrefix(i);
for (int j = top; j > i; --j)
{
String prefixJ = pp.getNamespacePrefix(j);
if((prefix != null && prefix.equals(prefixJ))
|| (prefix != null && prefix == prefixJ) )
{
// prefix is already declared -- skip it
continue LOOP;
}
}
declareOneNamespace(pp, i, parent);
}
} else {
for (int i = pp.getNamespaceCount(pp.getDepth()-1);
i < pp.getNamespaceCount(pp.getDepth());
++i)
{
declareOneNamespace(pp, i, parent);
}
}
}
private void declareOneNamespace(XmlPullParser pp, int i, Element parent)
throws DOMException, XmlPullParserException {
String xmlnsPrefix = pp.getNamespacePrefix(i);
String xmlnsUri = pp.getNamespaceUri(i);
String xmlnsDecl = (xmlnsPrefix != null) ? "xmlns:"+xmlnsPrefix : "xmlns";
parent.setAttributeNS("http://www.w3.org/2000/xmlns/", xmlnsDecl, xmlnsUri);
}
}
private static void assertEquals(String expected, String s) {
if((expected != null && !expected.equals(s)) || (expected == null && s == null)) {
throw new RuntimeException("expected '"+expected+"' but got '"+s+"'");
}
}
private static void assertNotNull(Object o) {
if(o == null) {
throw new RuntimeException("expected no null value");
}
}
/**
* Minimal inline test
*/
public static void main(String[] args) throws Exception {
}
}
xpp3-1.1.4c/src/java/mxp1_min/META-INF/services/org.xmlpull.v1.XmlPullParserFactory 100644 0 0 103 10525225062 26677 0 ustar aslom ewww 0 0 org.xmlpull.mxp1.MXParser,org.xmlpull.mxp1_serializer.MXSerializer
xpp3-1.1.4c/src/java/mxp1_min/org/xmlpull/mxp1/MXParser.java 100644 0 0 406210 10525225062 22666 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
/*
* Copyright (c) 2003 Extreme! Lab, Indiana University. All rights reserved.
*
* This software is open source. See the bottom of this file for the license.
*
* $Id: MXParser.java,v 1.52 2006/11/09 18:29:37 aslom Exp $
*/
package org.xmlpull.mxp1;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
//TODO best handling of interning issues
// have isAllNewStringInterned ???
//TODO handling surrogate pairs: http://www.unicode.org/unicode/faq/utf_bom.html#6
//TODO review code for use of bufAbsoluteStart when keeping pos between next()/fillBuf()
/**
* Absolutely minimal implementation of XMLPULL V1 API
*
* @author Aleksander Slominski
*/
public class MXParser
implements XmlPullParser
{
//NOTE: no interning of those strings --> by Java lang spec they MUST be already interned
protected final static String XML_URI = "http://www.w3.org/XML/1998/namespace";
protected final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
protected final static String FEATURE_XML_ROUNDTRIP=
//"http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
"http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
protected final static String FEATURE_NAMES_INTERNED =
"http://xmlpull.org/v1/doc/features.html#names-interned";
protected final static String PROPERTY_XMLDECL_VERSION =
"http://xmlpull.org/v1/doc/properties.html#xmldecl-version";
protected final static String PROPERTY_XMLDECL_STANDALONE =
"http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone";
protected final static String PROPERTY_XMLDECL_CONTENT =
"http://xmlpull.org/v1/doc/properties.html#xmldecl-content";
protected final static String PROPERTY_LOCATION =
"http://xmlpull.org/v1/doc/properties.html#location";
/**
* Implementation notice:
* the is instance variable that controls if newString() is interning.
* NOTE: newStringIntern always returns interned strings
* and newString MAY return interned String depending on this variable.
*
NOTE: by default in this minimal implementation it is false!
*/
protected boolean allStringsInterned;
protected void resetStringCache() {
//System.out.println("resetStringCache() minimum called");
}
protected String newString(char[] cbuf, int off, int len) {
return new String(cbuf, off, len);
}
protected String newStringIntern(char[] cbuf, int off, int len) {
return (new String(cbuf, off, len)).intern();
}
private static final boolean TRACE_SIZING = false;
// NOTE: features are not resettable and typically defaults to false ...
protected boolean processNamespaces;
protected boolean roundtripSupported;
// global parser state
protected String location;
protected int lineNumber;
protected int columnNumber;
protected boolean seenRoot;
protected boolean reachedEnd;
protected int eventType;
protected boolean emptyElementTag;
// element stack
protected int depth;
protected char[] elRawName[];
protected int elRawNameEnd[];
protected int elRawNameLine[];
protected String elName[];
protected String elPrefix[];
protected String elUri[];
//protected String elValue[];
protected int elNamespaceCount[];
/**
* Make sure that we have enough space to keep element stack if passed size.
* It will always create one additional slot then current depth
*/
protected void ensureElementsCapacity() {
final int elStackSize = elName != null ? elName.length : 0;
if( (depth + 1) >= elStackSize) {
// we add at least one extra slot ...
final int newSize = (depth >= 7 ? 2 * depth : 8) + 2; // = lucky 7 + 1 //25
if(TRACE_SIZING) {
System.err.println("TRACE_SIZING elStackSize "+elStackSize+" ==> "+newSize);
}
final boolean needsCopying = elStackSize > 0;
String[] arr = null;
// reuse arr local variable slot
arr = new String[newSize];
if(needsCopying) System.arraycopy(elName, 0, arr, 0, elStackSize);
elName = arr;
arr = new String[newSize];
if(needsCopying) System.arraycopy(elPrefix, 0, arr, 0, elStackSize);
elPrefix = arr;
arr = new String[newSize];
if(needsCopying) System.arraycopy(elUri, 0, arr, 0, elStackSize);
elUri = arr;
int[] iarr = new int[newSize];
if(needsCopying) {
System.arraycopy(elNamespaceCount, 0, iarr, 0, elStackSize);
} else {
// special initialization
iarr[0] = 0;
}
elNamespaceCount = iarr;
//TODO: avoid using element raw name ...
iarr = new int[newSize];
if(needsCopying) {
System.arraycopy(elRawNameEnd, 0, iarr, 0, elStackSize);
}
elRawNameEnd = iarr;
iarr = new int[newSize];
if(needsCopying) {
System.arraycopy(elRawNameLine, 0, iarr, 0, elStackSize);
}
elRawNameLine = iarr;
final char[][] carr = new char[newSize][];
if(needsCopying) {
System.arraycopy(elRawName, 0, carr, 0, elStackSize);
}
elRawName = carr;
// arr = new String[newSize];
// if(needsCopying) System.arraycopy(elLocalName, 0, arr, 0, elStackSize);
// elLocalName = arr;
// arr = new String[newSize];
// if(needsCopying) System.arraycopy(elDefaultNs, 0, arr, 0, elStackSize);
// elDefaultNs = arr;
// int[] iarr = new int[newSize];
// if(needsCopying) System.arraycopy(elNsStackPos, 0, iarr, 0, elStackSize);
// for (int i = elStackSize; i < iarr.length; i++)
// {
// iarr[i] = (i > 0) ? -1 : 0;
// }
// elNsStackPos = iarr;
//assert depth < elName.length;
}
}
// attribute stack
protected int attributeCount;
protected String attributeName[];
protected int attributeNameHash[];
//protected int attributeNameStart[];
//protected int attributeNameEnd[];
protected String attributePrefix[];
protected String attributeUri[];
protected String attributeValue[];
//protected int attributeValueStart[];
//protected int attributeValueEnd[];
/**
* Make sure that in attributes temporary array is enough space.
*/
protected void ensureAttributesCapacity(int size) {
final int attrPosSize = attributeName != null ? attributeName.length : 0;
if(size >= attrPosSize) {
final int newSize = size > 7 ? 2 * size : 8; // = lucky 7 + 1 //25
if(TRACE_SIZING) {
System.err.println("TRACE_SIZING attrPosSize "+attrPosSize+" ==> "+newSize);
}
final boolean needsCopying = attrPosSize > 0;
String[] arr = null;
arr = new String[newSize];
if(needsCopying) System.arraycopy(attributeName, 0, arr, 0, attrPosSize);
attributeName = arr;
arr = new String[newSize];
if(needsCopying) System.arraycopy(attributePrefix, 0, arr, 0, attrPosSize);
attributePrefix = arr;
arr = new String[newSize];
if(needsCopying) System.arraycopy(attributeUri, 0, arr, 0, attrPosSize);
attributeUri = arr;
arr = new String[newSize];
if(needsCopying) System.arraycopy(attributeValue, 0, arr, 0, attrPosSize);
attributeValue = arr;
if( ! allStringsInterned ) {
final int[] iarr = new int[newSize];
if(needsCopying) System.arraycopy(attributeNameHash, 0, iarr, 0, attrPosSize);
attributeNameHash = iarr;
}
arr = null;
// //assert attrUri.length > size
}
}
// namespace stack
protected int namespaceEnd;
protected String namespacePrefix[];
protected int namespacePrefixHash[];
protected String namespaceUri[];
protected void ensureNamespacesCapacity(int size) {
final int namespaceSize = namespacePrefix != null ? namespacePrefix.length : 0;
if(size >= namespaceSize) {
final int newSize = size > 7 ? 2 * size : 8; // = lucky 7 + 1 //25
if(TRACE_SIZING) {
System.err.println("TRACE_SIZING namespaceSize "+namespaceSize+" ==> "+newSize);
}
final String[] newNamespacePrefix = new String[newSize];
final String[] newNamespaceUri = new String[newSize];
if(namespacePrefix != null) {
System.arraycopy(
namespacePrefix, 0, newNamespacePrefix, 0, namespaceEnd);
System.arraycopy(
namespaceUri, 0, newNamespaceUri, 0, namespaceEnd);
}
namespacePrefix = newNamespacePrefix;
namespaceUri = newNamespaceUri;
if( ! allStringsInterned ) {
final int[] newNamespacePrefixHash = new int[newSize];
if(namespacePrefixHash != null) {
System.arraycopy(
namespacePrefixHash, 0, newNamespacePrefixHash, 0, namespaceEnd);
}
namespacePrefixHash = newNamespacePrefixHash;
}
//prefixesSize = newSize;
// //assert nsPrefixes.length > size && nsPrefixes.length == newSize
}
}
/**
* simplistic implementation of hash function that has constant
* time to compute - so it also means diminishing hash quality for long strings
* but for XML parsing it should be good enough ...
*/
protected static final int fastHash( char ch[], int off, int len ) {
if(len == 0) return 0;
//assert len >0
int hash = ch[off]; // hash at beginning
//try {
hash = (hash << 7) + ch[ off + len - 1 ]; // hash at the end
//} catch(ArrayIndexOutOfBoundsException aie) {
// aie.printStackTrace(); //should never happen ...
// throw new RuntimeException("this is violation of pre-condition");
//}
if(len > 16) hash = (hash << 7) + ch[ off + (len / 4)]; // 1/4 from beginning
if(len > 8) hash = (hash << 7) + ch[ off + (len / 2)]; // 1/2 of string size ...
// notice that hash is at most done 3 times <<7 so shifted by 21 bits 8 bit value
// so max result == 29 bits so it is quite just below 31 bits for long (2^32) ...
//assert hash >= 0;
return hash;
}
// entity replacement stack
protected int entityEnd;
protected String entityName[];
protected char[] entityNameBuf[];
protected String entityReplacement[];
protected char[] entityReplacementBuf[];
protected int entityNameHash[];
protected void ensureEntityCapacity() {
final int entitySize = entityReplacementBuf != null ? entityReplacementBuf.length : 0;
if(entityEnd >= entitySize) {
final int newSize = entityEnd > 7 ? 2 * entityEnd : 8; // = lucky 7 + 1 //25
if(TRACE_SIZING) {
System.err.println("TRACE_SIZING entitySize "+entitySize+" ==> "+newSize);
}
final String[] newEntityName = new String[newSize];
final char[] newEntityNameBuf[] = new char[newSize][];
final String[] newEntityReplacement = new String[newSize];
final char[] newEntityReplacementBuf[] = new char[newSize][];
if(entityName != null) {
System.arraycopy(entityName, 0, newEntityName, 0, entityEnd);
System.arraycopy(entityNameBuf, 0, newEntityNameBuf, 0, entityEnd);
System.arraycopy(entityReplacement, 0, newEntityReplacement, 0, entityEnd);
System.arraycopy(entityReplacementBuf, 0, newEntityReplacementBuf, 0, entityEnd);
}
entityName = newEntityName;
entityNameBuf = newEntityNameBuf;
entityReplacement = newEntityReplacement;
entityReplacementBuf = newEntityReplacementBuf;
if( ! allStringsInterned ) {
final int[] newEntityNameHash = new int[newSize];
if(entityNameHash != null) {
System.arraycopy(entityNameHash, 0, newEntityNameHash, 0, entityEnd);
}
entityNameHash = newEntityNameHash;
}
}
}
// input buffer management
protected static final int READ_CHUNK_SIZE = 8*1024; //max data chars in one read() call
protected Reader reader;
protected String inputEncoding;
protected InputStream inputStream;
protected int bufLoadFactor = 95; // 99%
//protected int bufHardLimit; // only matters when expanding
protected char buf[] = new char[
Runtime.getRuntime().freeMemory() > 1000000L ? READ_CHUNK_SIZE : 256 ];
protected int bufSoftLimit = ( bufLoadFactor * buf.length ) /100; // desirable size of buffer
protected boolean preventBufferCompaction;
protected int bufAbsoluteStart; // this is buf
protected int bufStart;
protected int bufEnd;
protected int pos;
protected int posStart;
protected int posEnd;
protected char pc[] = new char[
Runtime.getRuntime().freeMemory() > 1000000L ? READ_CHUNK_SIZE : 64 ];
protected int pcStart;
protected int pcEnd;
// parsing state
//protected boolean needsMore;
//protected boolean seenMarkup;
protected boolean usePC;
protected boolean seenStartTag;
protected boolean seenEndTag;
protected boolean pastEndTag;
protected boolean seenAmpersand;
protected boolean seenMarkup;
protected boolean seenDocdecl;
// transient variable set during each call to next/Token()
protected boolean tokenize;
protected String text;
protected String entityRefName;
protected String xmlDeclVersion;
protected Boolean xmlDeclStandalone;
protected String xmlDeclContent;
protected void reset() {
//System.out.println("reset() called");
location = null;
lineNumber = 1;
columnNumber = 0;
seenRoot = false;
reachedEnd = false;
eventType = START_DOCUMENT;
emptyElementTag = false;
depth = 0;
attributeCount = 0;
namespaceEnd = 0;
entityEnd = 0;
reader = null;
inputEncoding = null;
preventBufferCompaction = false;
bufAbsoluteStart = 0;
bufEnd = bufStart = 0;
pos = posStart = posEnd = 0;
pcEnd = pcStart = 0;
usePC = false;
seenStartTag = false;
seenEndTag = false;
pastEndTag = false;
seenAmpersand = false;
seenMarkup = false;
seenDocdecl = false;
xmlDeclVersion = null;
xmlDeclStandalone = null;
xmlDeclContent = null;
resetStringCache();
}
public MXParser() {
}
/**
* Method setFeature
*
* @param name a String
* @param state a boolean
*
* @throws XmlPullParserException
*
*/
public void setFeature(String name,
boolean state) throws XmlPullParserException
{
if(name == null) throw new IllegalArgumentException("feature name should not be null");
if(FEATURE_PROCESS_NAMESPACES.equals(name)) {
if(eventType != START_DOCUMENT) throw new XmlPullParserException(
"namespace processing feature can only be changed before parsing", this, null);
processNamespaces = state;
// } else if(FEATURE_REPORT_NAMESPACE_ATTRIBUTES.equals(name)) {
// if(type != START_DOCUMENT) throw new XmlPullParserException(
// "namespace reporting feature can only be changed before parsing", this, null);
// reportNsAttribs = state;
} else if(FEATURE_NAMES_INTERNED.equals(name)) {
if(state != false) {
throw new XmlPullParserException(
"interning names in this implementation is not supported");
}
} else if(FEATURE_PROCESS_DOCDECL.equals(name)) {
if(state != false) {
throw new XmlPullParserException(
"processing DOCDECL is not supported");
}
//} else if(REPORT_DOCDECL.equals(name)) {
// paramNotifyDoctype = state;
} else if(FEATURE_XML_ROUNDTRIP.equals(name)) {
//if(state == false) {
// throw new XmlPullParserException(
// "roundtrip feature can not be switched off");
//}
roundtripSupported = state;
} else {
throw new XmlPullParserException("unsupported feature "+name);
}
}
/** Unknown properties are always returned as false */
public boolean getFeature(String name)
{
if(name == null) throw new IllegalArgumentException("feature name should not be null");
if(FEATURE_PROCESS_NAMESPACES.equals(name)) {
return processNamespaces;
// } else if(FEATURE_REPORT_NAMESPACE_ATTRIBUTES.equals(name)) {
// return reportNsAttribs;
} else if(FEATURE_NAMES_INTERNED.equals(name)) {
return false;
} else if(FEATURE_PROCESS_DOCDECL.equals(name)) {
return false;
//} else if(REPORT_DOCDECL.equals(name)) {
// return paramNotifyDoctype;
} else if(FEATURE_XML_ROUNDTRIP.equals(name)) {
//return true;
return roundtripSupported;
}
return false;
}
public void setProperty(String name,
Object value)
throws XmlPullParserException
{
if(PROPERTY_LOCATION.equals(name)) {
location = (String) value;
} else {
throw new XmlPullParserException("unsupported property: '"+name+"'");
}
}
public Object getProperty(String name)
{
if(name == null) throw new IllegalArgumentException("property name should not be null");
if(PROPERTY_XMLDECL_VERSION.equals(name)) {
return xmlDeclVersion;
} else if(PROPERTY_XMLDECL_STANDALONE.equals(name)) {
return xmlDeclStandalone;
} else if(PROPERTY_XMLDECL_CONTENT.equals(name)) {
return xmlDeclContent;
} else if(PROPERTY_LOCATION.equals(name)) {
return location;
}
return null;
}
public void setInput(Reader in) throws XmlPullParserException
{
reset();
reader = in;
}
public void setInput(java.io.InputStream inputStream, String inputEncoding)
throws XmlPullParserException
{
if(inputStream == null) {
throw new IllegalArgumentException("input stream can not be null");
}
this.inputStream = inputStream;
Reader reader;
//if(inputEncoding != null) {
try {
if(inputEncoding != null) {
reader = new InputStreamReader(inputStream, inputEncoding);
} else {
//by default use UTF-8 (InputStreamReader(inputStream)) would use OS default ...
reader = new InputStreamReader(inputStream, "UTF-8");
}
} catch (UnsupportedEncodingException une) {
throw new XmlPullParserException(
"could not create reader for encoding "+inputEncoding+" : "+une, this, une);
}
//} else {
// reader = new InputStreamReader(inputStream);
//}
setInput(reader);
//must be here as reest() was called in setInput() and has set this.inputEncoding to null ...
this.inputEncoding = inputEncoding;
}
public String getInputEncoding() {
return inputEncoding;
}
public void defineEntityReplacementText(String entityName,
String replacementText)
throws XmlPullParserException
{
// throw new XmlPullParserException("not allowed");
//protected char[] entityReplacement[];
ensureEntityCapacity();
// this is to make sure that if interning works we will take advantage of it ...
this.entityName[entityEnd] = newString(entityName.toCharArray(), 0, entityName.length());
entityNameBuf[entityEnd] = entityName.toCharArray();
entityReplacement[entityEnd] = replacementText;
entityReplacementBuf[entityEnd] = replacementText.toCharArray();
if(!allStringsInterned) {
entityNameHash[ entityEnd ] =
fastHash(entityNameBuf[entityEnd], 0, entityNameBuf[entityEnd].length);
}
++entityEnd;
//TODO disallow < or & in entity replacement text (or ]]>???)
// TOOD keepEntityNormalizedForAttributeValue cached as well ...
}
public int getNamespaceCount(int depth)
throws XmlPullParserException
{
if(processNamespaces == false || depth == 0) {
return 0;
}
//int maxDepth = eventType == END_TAG ? this.depth + 1 : this.depth;
//if(depth < 0 || depth > maxDepth) throw new IllegalArgumentException(
if(depth < 0 || depth > this.depth) throw new IllegalArgumentException(
"allowed namespace depth 0.."+this.depth+" not "+depth);
return elNamespaceCount[ depth ];
}
public String getNamespacePrefix(int pos)
throws XmlPullParserException
{
//int end = eventType == END_TAG ? elNamespaceCount[ depth + 1 ] : namespaceEnd;
//if(pos < end) {
if(pos < namespaceEnd) {
return namespacePrefix[ pos ];
} else {
throw new XmlPullParserException(
"position "+pos+" exceeded number of available namespaces "+namespaceEnd);
}
}
public String getNamespaceUri(int pos) throws XmlPullParserException
{
//int end = eventType == END_TAG ? elNamespaceCount[ depth + 1 ] : namespaceEnd;
//if(pos < end) {
if(pos < namespaceEnd) {
return namespaceUri[ pos ];
} else {
throw new XmlPullParserException(
"position "+pos+" exceeded number of available namespaces "+namespaceEnd);
}
}
public String getNamespace( String prefix )
//throws XmlPullParserException
{
//int count = namespaceCount[ depth ];
if(prefix != null) {
for( int i = namespaceEnd -1; i >= 0; i--) {
if( prefix.equals( namespacePrefix[ i ] ) ) {
return namespaceUri[ i ];
}
}
if("xml".equals( prefix )) {
return XML_URI;
} else if("xmlns".equals( prefix )) {
return XMLNS_URI;
}
} else {
for( int i = namespaceEnd -1; i >= 0; i--) {
if( namespacePrefix[ i ] == null) { //"") { //null ) { //TODO check FIXME Alek
return namespaceUri[ i ];
}
}
}
return null;
}
public int getDepth()
{
return depth;
}
private static int findFragment(int bufMinPos, char[] b, int start, int end) {
//System.err.println("bufStart="+bufStart+" b="+printable(new String(b, start, end - start))+" start="+start+" end="+end);
if(start < bufMinPos) {
start = bufMinPos;
if(start > end) start = end;
return start;
}
if(end - start > 65) {
start = end - 10; // try to find good location
}
int i = start + 1;
while(--i > bufMinPos) {
if((end - i) > 65) break;
final char c = b[i];
if(c == '<' && (start - i) > 10) break;
}
return i;
}
/**
* Return string describing current position of parsers as
* text 'STATE [seen %s...] @line:column'.
*/
public String getPositionDescription ()
{
String fragment = null;
if(posStart <= pos) {
final int start = findFragment(0, buf, posStart, pos);
//System.err.println("start="+start);
if(start < pos) {
fragment = new String(buf, start, pos - start);
}
if(bufAbsoluteStart > 0 || start > 0) fragment = "..." + fragment;
}
// return " at line "+tokenizerPosRow
// +" and column "+(tokenizerPosCol-1)
// +(fragment != null ? " seen "+printable(fragment)+"..." : "");
return " "+TYPES[ eventType ] +
(fragment != null ? " seen "+printable(fragment)+"..." : "")
+" "+(location != null ? location : "")
+"@"+getLineNumber()+":"+getColumnNumber();
}
public int getLineNumber()
{
return lineNumber;
}
public int getColumnNumber()
{
return columnNumber;
}
public boolean isWhitespace() throws XmlPullParserException
{
if(eventType == TEXT || eventType == CDSECT) {
if(usePC) {
for (int i = pcStart; i = 0; i--) {
// if( prefix.equals( namespacePrefix[ i ] ) ) {
// return namespaceUri[ i ];
// }
// }
// } else {
// for( int i = namespaceEnd -1; i >= 0; i--) {
// if( namespacePrefix[ i ] == null ) {
// return namespaceUri[ i ];
// }
// }
//
// }
// return "";
}
public String getName()
{
if(eventType == START_TAG) {
//return elName[ depth - 1 ] ;
return elName[ depth ] ;
} else if(eventType == END_TAG) {
return elName[ depth ] ;
} else if(eventType == ENTITY_REF) {
if(entityRefName == null) {
entityRefName = newString(buf, posStart, posEnd - posStart);
}
return entityRefName;
} else {
return null;
}
}
public String getPrefix()
{
if(eventType == START_TAG) {
//return elPrefix[ depth - 1 ] ;
return elPrefix[ depth ] ;
} else if(eventType == END_TAG) {
return elPrefix[ depth ] ;
}
return null;
// if(eventType != START_TAG && eventType != END_TAG) return null;
// int maxDepth = eventType == END_TAG ? depth : depth - 1;
// return elPrefix[ maxDepth ];
}
public boolean isEmptyElementTag() throws XmlPullParserException
{
if(eventType != START_TAG) throw new XmlPullParserException(
"parser must be on START_TAG to check for empty element", this, null);
return emptyElementTag;
}
public int getAttributeCount()
{
if(eventType != START_TAG) return -1;
return attributeCount;
}
public String getAttributeNamespace(int index)
{
if(eventType != START_TAG) throw new IndexOutOfBoundsException(
"only START_TAG can have attributes");
if(processNamespaces == false) return NO_NAMESPACE;
if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException(
"attribute position must be 0.."+(attributeCount-1)+" and not "+index);
return attributeUri[ index ];
}
public String getAttributeName(int index)
{
if(eventType != START_TAG) throw new IndexOutOfBoundsException(
"only START_TAG can have attributes");
if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException(
"attribute position must be 0.."+(attributeCount-1)+" and not "+index);
return attributeName[ index ];
}
public String getAttributePrefix(int index)
{
if(eventType != START_TAG) throw new IndexOutOfBoundsException(
"only START_TAG can have attributes");
if(processNamespaces == false) return null;
if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException(
"attribute position must be 0.."+(attributeCount-1)+" and not "+index);
return attributePrefix[ index ];
}
public String getAttributeType(int index) {
if(eventType != START_TAG) throw new IndexOutOfBoundsException(
"only START_TAG can have attributes");
if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException(
"attribute position must be 0.."+(attributeCount-1)+" and not "+index);
return "CDATA";
}
public boolean isAttributeDefault(int index) {
if(eventType != START_TAG) throw new IndexOutOfBoundsException(
"only START_TAG can have attributes");
if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException(
"attribute position must be 0.."+(attributeCount-1)+" and not "+index);
return false;
}
public String getAttributeValue(int index)
{
if(eventType != START_TAG) throw new IndexOutOfBoundsException(
"only START_TAG can have attributes");
if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException(
"attribute position must be 0.."+(attributeCount-1)+" and not "+index);
return attributeValue[ index ];
}
public String getAttributeValue(String namespace,
String name)
{
if(eventType != START_TAG) throw new IndexOutOfBoundsException(
"only START_TAG can have attributes"+getPositionDescription());
if(name == null) {
throw new IllegalArgumentException("attribute name can not be null");
}
// TODO make check if namespace is interned!!! etc. for names!!!
if(processNamespaces) {
if(namespace == null) {
namespace = "";
}
for(int i = 0; i < attributeCount; ++i) {
if((namespace == attributeUri[ i ] ||
namespace.equals(attributeUri[ i ]) )
//(namespace != null && namespace.equals(attributeUri[ i ]))
// taking advantage of String.intern()
&& name.equals(attributeName[ i ]) )
{
return attributeValue[i];
}
}
} else {
if(namespace != null && namespace.length() == 0) {
namespace = null;
}
if(namespace != null) throw new IllegalArgumentException(
"when namespaces processing is disabled attribute namespace must be null");
for(int i = 0; i < attributeCount; ++i) {
if(name.equals(attributeName[i]))
{
return attributeValue[i];
}
}
}
return null;
}
public int getEventType()
throws XmlPullParserException
{
return eventType;
}
public void require(int type, String namespace, String name)
throws XmlPullParserException, IOException
{
if(processNamespaces == false && namespace != null) {
throw new XmlPullParserException(
"processing namespaces must be enabled on parser (or factory)"+
" to have possible namespaces declared on elements"
+(" (position:"+ getPositionDescription())+")");
}
if (type != getEventType()
|| (namespace != null && !namespace.equals (getNamespace()))
|| (name != null && !name.equals (getName ())) )
{
throw new XmlPullParserException (
"expected event "+TYPES[ type ]
+(name != null ? " with name '"+name+"'" : "")
+(namespace != null && name != null ? " and" : "")
+(namespace != null ? " with namespace '"+namespace+"'" : "")
+" but got"
+(type != getEventType() ? " "+TYPES[ getEventType() ] : "")
+(name != null && getName() != null && !name.equals (getName ())
? " name '"+getName()+"'" : "")
+(namespace != null && name != null
&& getName() != null && !name.equals (getName ())
&& getNamespace() != null && !namespace.equals (getNamespace())
? " and" : "")
+(namespace != null && getNamespace() != null && !namespace.equals (getNamespace())
? " namespace '"+getNamespace()+"'" : "")
+(" (position:"+ getPositionDescription())+")");
}
}
/**
* Skip sub tree that is currently parser positioned on.
* NOTE: parser must be on START_TAG and when function returns
* parser will be positioned on corresponding END_TAG
*/
public void skipSubTree()
throws XmlPullParserException, IOException
{
require(START_TAG, null, null);
int level = 1;
while(level > 0) {
int eventType = next();
if(eventType == END_TAG) {
--level;
} else if(eventType == START_TAG) {
++level;
}
}
}
// public String readText() throws XmlPullParserException, IOException
// {
// if (getEventType() != TEXT) return "";
// String result = getText();
// next();
// return result;
// }
public String nextText() throws XmlPullParserException, IOException
{
// String result = null;
// boolean onStartTag = false;
// if(eventType == START_TAG) {
// onStartTag = true;
// next();
// }
// if(eventType == TEXT) {
// result = getText();
// next();
// } else if(onStartTag && eventType == END_TAG) {
// result = "";
// } else {
// throw new XmlPullParserException(
// "parser must be on START_TAG or TEXT to read text", this, null);
// }
// if(eventType != END_TAG) {
// throw new XmlPullParserException(
// "event TEXT it must be immediately followed by END_TAG", this, null);
// }
// return result;
if(getEventType() != START_TAG) {
throw new XmlPullParserException(
"parser must be on START_TAG to read next text", this, null);
}
int eventType = next();
if(eventType == TEXT) {
final String result = getText();
eventType = next();
if(eventType != END_TAG) {
throw new XmlPullParserException(
"TEXT must be immediately followed by END_TAG and not "
+TYPES[ getEventType() ], this, null);
}
return result;
} else if(eventType == END_TAG) {
return "";
} else {
throw new XmlPullParserException(
"parser must be on START_TAG or TEXT to read text", this, null);
}
}
public int nextTag() throws XmlPullParserException, IOException
{
next();
if(eventType == TEXT && isWhitespace()) { // skip whitespace
next();
}
if (eventType != START_TAG && eventType != END_TAG) {
throw new XmlPullParserException("expected START_TAG or END_TAG not "
+TYPES[ getEventType() ], this, null);
}
return eventType;
}
public int next()
throws XmlPullParserException, IOException
{
tokenize = false;
return nextImpl();
}
public int nextToken()
throws XmlPullParserException, IOException
{
tokenize = true;
return nextImpl();
}
protected int nextImpl()
throws XmlPullParserException, IOException
{
text = null;
pcEnd = pcStart = 0;
usePC = false;
bufStart = posEnd;
if(pastEndTag) {
pastEndTag = false;
--depth;
namespaceEnd = elNamespaceCount[ depth ]; // less namespaces available
}
if(emptyElementTag) {
emptyElementTag = false;
pastEndTag = true;
return eventType = END_TAG;
}
// [1] document ::= prolog element Misc*
if(depth > 0) {
if(seenStartTag) {
seenStartTag = false;
return eventType = parseStartTag();
}
if(seenEndTag) {
seenEndTag = false;
return eventType = parseEndTag();
}
// ASSUMPTION: we are _on_ first character of content or markup!!!!
// [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*
char ch;
if(seenMarkup) { // we have read ahead ...
seenMarkup = false;
ch = '<';
} else if(seenAmpersand) {
seenAmpersand = false;
ch = '&';
} else {
ch = more();
}
posStart = pos - 1; // VERY IMPORTANT: this is correct start of event!!!
// when true there is some potential event TEXT to return - keep gathering
boolean hadCharData = false;
// when true TEXT data is not continual (like ) and requires PC merging
boolean needsMerging = false;
MAIN_LOOP:
while(true) {
// work on MARKUP
if(ch == '<') {
if(hadCharData) {
//posEnd = pos - 1;
if(tokenize) {
seenMarkup = true;
return eventType = TEXT;
}
}
ch = more();
if(ch == '/') {
if(!tokenize && hadCharData) {
seenEndTag = true;
//posEnd = pos - 2;
return eventType = TEXT;
}
return eventType = parseEndTag();
} else if(ch == '!') {
ch = more();
if(ch == '-') {
// note: if(tokenize == false) posStart/End is NOT changed!!!!
parseComment();
if(tokenize) return eventType = COMMENT;
if( !usePC && hadCharData ) {
needsMerging = true;
} else {
posStart = pos; //completely ignore comment
}
} else if(ch == '[') {
//posEnd = pos - 3;
// must remember previous posStart/End as it merges with content of CDATA
//int oldStart = posStart + bufAbsoluteStart;
//int oldEnd = posEnd + bufAbsoluteStart;
parseCDSect(hadCharData);
if(tokenize) return eventType = CDSECT;
final int cdStart = posStart;
final int cdEnd = posEnd;
final int cdLen = cdEnd - cdStart;
if(cdLen > 0) { // was there anything inside CDATA section?
hadCharData = true;
if(!usePC) {
needsMerging = true;
}
}
// posStart = oldStart;
// posEnd = oldEnd;
// if(cdLen > 0) { // was there anything inside CDATA section?
// if(hadCharData) {
// // do merging if there was anything in CDSect!!!!
// // if(!usePC) {
// // // posEnd is correct already!!!
// // if(posEnd > posStart) {
// // joinPC();
// // } else {
// // usePC = true;
// // pcStart = pcEnd = 0;
// // }
// // }
// // if(pcEnd + cdLen >= pc.length) ensurePC(pcEnd + cdLen);
// // // copy [cdStart..cdEnd) into PC
// // System.arraycopy(buf, cdStart, pc, pcEnd, cdLen);
// // pcEnd += cdLen;
// if(!usePC) {
// needsMerging = true;
// posStart = cdStart;
// posEnd = cdEnd;
// }
// } else {
// if(!usePC) {
// needsMerging = true;
// posStart = cdStart;
// posEnd = cdEnd;
// hadCharData = true;
// }
// }
// //hadCharData = true;
// } else {
// if( !usePC && hadCharData ) {
// needsMerging = true;
// }
// }
} else {
throw new XmlPullParserException(
"unexpected character in markup "+printable(ch), this, null);
}
} else if(ch == '?') {
parsePI();
if(tokenize) return eventType = PROCESSING_INSTRUCTION;
if( !usePC && hadCharData ) {
needsMerging = true;
} else {
posStart = pos; //completely ignore PI
}
} else if( isNameStartChar(ch) ) {
if(!tokenize && hadCharData) {
seenStartTag = true;
//posEnd = pos - 2;
return eventType = TEXT;
}
return eventType = parseStartTag();
} else {
throw new XmlPullParserException(
"unexpected character in markup "+printable(ch), this, null);
}
// do content compaction if it makes sense!!!!
} else if(ch == '&') {
// work on ENTITTY
//posEnd = pos - 1;
if(tokenize && hadCharData) {
seenAmpersand = true;
return eventType = TEXT;
}
final int oldStart = posStart + bufAbsoluteStart;
final int oldEnd = posEnd + bufAbsoluteStart;
final char[] resolvedEntity = parseEntityRef();
if(tokenize) return eventType = ENTITY_REF;
// check if replacement text can be resolved !!!
if(resolvedEntity == null) {
if(entityRefName == null) {
entityRefName = newString(buf, posStart, posEnd - posStart);
}
throw new XmlPullParserException(
"could not resolve entity named '"+printable(entityRefName)+"'",
this, null);
}
//int entStart = posStart;
//int entEnd = posEnd;
posStart = oldStart - bufAbsoluteStart;
posEnd = oldEnd - bufAbsoluteStart;
if(!usePC) {
if(hadCharData) {
joinPC(); // posEnd is already set correctly!!!
needsMerging = false;
} else {
usePC = true;
pcStart = pcEnd = 0;
}
}
//assert usePC == true;
// write into PC replacement text - do merge for replacement text!!!!
for (int i = 0; i < resolvedEntity.length; i++)
{
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = resolvedEntity[ i ];
}
hadCharData = true;
//assert needsMerging == false;
} else {
if(needsMerging) {
//assert usePC == false;
joinPC(); // posEnd is already set correctly!!!
//posStart = pos - 1;
needsMerging = false;
}
//no MARKUP not ENTITIES so work on character data ...
// [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
hadCharData = true;
boolean normalizedCR = false;
final boolean normalizeInput = tokenize == false || roundtripSupported == false;
// use loop locality here!!!!
boolean seenBracket = false;
boolean seenBracketBracket = false;
do {
// check that ]]> does not show in
if(ch == ']') {
if(seenBracket) {
seenBracketBracket = true;
} else {
seenBracket = true;
}
} else if(seenBracketBracket && ch == '>') {
throw new XmlPullParserException(
"characters ]]> are not allowed in content", this, null);
} else {
if(seenBracket) {
seenBracketBracket = seenBracket = false;
}
// assert seenTwoBrackets == seenBracket == false;
}
if(normalizeInput) {
// deal with normalization issues ...
if(ch == '\r') {
normalizedCR = true;
posEnd = pos -1;
// posEnd is already is set
if(!usePC) {
if(posEnd > posStart) {
joinPC();
} else {
usePC = true;
pcStart = pcEnd = 0;
}
}
//assert usePC == true;
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = '\n';
} else if(ch == '\n') {
// if(!usePC) { joinPC(); } else { if(pcEnd >= pc.length) ensurePC(); }
if(!normalizedCR && usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = '\n';
}
normalizedCR = false;
} else {
if(usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = ch;
}
normalizedCR = false;
}
}
ch = more();
} while(ch != '<' && ch != '&');
posEnd = pos - 1;
continue MAIN_LOOP; // skip ch = more() from below - we are alreayd ahead ...
}
ch = more();
} // endless while(true)
} else {
if(seenRoot) {
return parseEpilog();
} else {
return parseProlog();
}
}
}
protected int parseProlog()
throws XmlPullParserException, IOException
{
// [2] prolog: ::= XMLDecl? Misc* (doctypedecl Misc*)? and look for [39] element
char ch;
if(seenMarkup) {
ch = buf[ pos - 1 ];
} else {
ch = more();
}
if(eventType == START_DOCUMENT) {
// bootstrap parsing with getting first character input!
// deal with BOM
// detect BOM and drop it (Unicode int Order Mark)
if(ch == '\uFFFE') {
throw new XmlPullParserException(
"first character in input was UNICODE noncharacter (0xFFFE)"+
"- input requires int swapping", this, null);
}
if(ch == '\uFEFF') {
// skipping UNICODE int Order Mark (so called BOM)
ch = more();
}
}
seenMarkup = false;
boolean gotS = false;
posStart = pos - 1;
final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false;
boolean normalizedCR = false;
while(true) {
// deal with Misc
// [27] Misc ::= Comment | PI | S
// deal with docdecl --> mark it!
// else parseStartTag seen <[^/]
if(ch == '<') {
if(gotS && tokenize) {
posEnd = pos - 1;
seenMarkup = true;
return eventType = IGNORABLE_WHITESPACE;
}
ch = more();
if(ch == '?') {
// check if it is 'xml'
// deal with XMLDecl
if(parsePI()) { // make sure to skip XMLDecl
if(tokenize) {
return eventType = PROCESSING_INSTRUCTION;
}
} else {
// skip over - continue tokenizing
posStart = pos;
gotS = false;
}
} else if(ch == '!') {
ch = more();
if(ch == 'D') {
if(seenDocdecl) {
throw new XmlPullParserException(
"only one docdecl allowed in XML document", this, null);
}
seenDocdecl = true;
parseDocdecl();
if(tokenize) return eventType = DOCDECL;
} else if(ch == '-') {
parseComment();
if(tokenize) return eventType = COMMENT;
} else {
throw new XmlPullParserException(
"unexpected markup posStart) {
joinPC();
} else {
usePC = true;
pcStart = pcEnd = 0;
}
}
//assert usePC == true;
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = '\n';
} else if(ch == '\n') {
if(!normalizedCR && usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = '\n';
}
normalizedCR = false;
} else {
if(usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = ch;
}
normalizedCR = false;
}
}
} else {
throw new XmlPullParserException(
"only whitespace content allowed before start tag and not "+printable(ch),
this, null);
}
ch = more();
}
}
protected int parseEpilog()
throws XmlPullParserException, IOException
{
if(eventType == END_DOCUMENT) {
throw new XmlPullParserException("already reached end of XML input", this, null);
}
if(reachedEnd) {
return eventType = END_DOCUMENT;
}
boolean gotS = false;
final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false;
boolean normalizedCR = false;
try {
// epilog: Misc*
char ch;
if(seenMarkup) {
ch = buf[ pos - 1 ];
} else {
ch = more();
}
seenMarkup = false;
posStart = pos - 1;
if(!reachedEnd) {
while(true) {
// deal with Misc
// [27] Misc ::= Comment | PI | S
if(ch == '<') {
if(gotS && tokenize) {
posEnd = pos - 1;
seenMarkup = true;
return eventType = IGNORABLE_WHITESPACE;
}
ch = more();
if(reachedEnd) {
break;
}
if(ch == '?') {
// check if it is 'xml'
// deal with XMLDecl
parsePI();
if(tokenize) return eventType = PROCESSING_INSTRUCTION;
} else if(ch == '!') {
ch = more();
if(reachedEnd) {
break;
}
if(ch == 'D') {
parseDocdecl(); //FIXME
if(tokenize) return eventType = DOCDECL;
} else if(ch == '-') {
parseComment();
if(tokenize) return eventType = COMMENT;
} else {
throw new XmlPullParserException(
"unexpected markup posStart) {
joinPC();
} else {
usePC = true;
pcStart = pcEnd = 0;
}
}
//assert usePC == true;
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = '\n';
} else if(ch == '\n') {
if(!normalizedCR && usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = '\n';
}
normalizedCR = false;
} else {
if(usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = ch;
}
normalizedCR = false;
}
}
} else {
throw new XmlPullParserException(
"in epilog non whitespace content is not allowed but got "+printable(ch),
this, null);
}
ch = more();
if(reachedEnd) {
break;
}
}
}
// throw Exception("unexpected content in epilog
// catch EOFException return END_DOCUEMENT
//try {
} catch(EOFException ex) {
reachedEnd = true;
}
if(reachedEnd) {
if(tokenize && gotS) {
posEnd = pos; // well - this is LAST available character pos
return eventType = IGNORABLE_WHITESPACE;
}
return eventType = END_DOCUMENT;
} else {
throw new XmlPullParserException("internal error in parseEpilog");
}
}
public int parseEndTag() throws XmlPullParserException, IOException {
//ASSUMPTION ch is past ""
// [42] ETag ::= '' Name S? '>'
char ch = more();
if(!isNameStartChar(ch)) {
throw new XmlPullParserException(
"expected name start and not "+printable(ch), this, null);
}
posStart = pos - 3;
final int nameStart = pos - 1 + bufAbsoluteStart;
do {
ch = more();
} while(isNameChar(ch));
// now we go one level down -- do checks
//--depth; //FIXME
// check that end tag name is the same as start tag
//String name = new String(buf, nameStart - bufAbsoluteStart,
// (pos - 1) - (nameStart - bufAbsoluteStart));
//int last = pos - 1;
int off = nameStart - bufAbsoluteStart;
//final int len = last - off;
final int len = (pos - 1) - off;
final char[] cbuf = elRawName[depth];
if(elRawNameEnd[depth] != len) {
// construct strings for exception
final String startname = new String(cbuf, 0, elRawNameEnd[depth]);
final String endname = new String(buf, off, len);
throw new XmlPullParserException(
"end tag name "+endname+"> must match start tag name <"+startname+">"
+" from line "+elRawNameLine[depth], this, null);
}
for (int i = 0; i < len; i++)
{
if(buf[off++] != cbuf[i]) {
// construct strings for exception
final String startname = new String(cbuf, 0, len);
final String endname = new String(buf, off - i - 1, len);
throw new XmlPullParserException(
"end tag name "+endname+"> must be the same as start tag <"+startname+">"
+" from line "+elRawNameLine[depth], this, null);
}
}
while(isS(ch)) { ch = more(); } // skip additional white spaces
if(ch != '>') {
throw new XmlPullParserException(
"expected > to finish end tag not "+printable(ch)
+" from line "+elRawNameLine[depth], this, null);
}
//namespaceEnd = elNamespaceCount[ depth ]; //FIXME
posEnd = pos;
pastEndTag = true;
return eventType = END_TAG;
}
public int parseStartTag() throws XmlPullParserException, IOException {
//ASSUMPTION ch is past '
// [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
++depth; //FIXME
posStart = pos - 2;
emptyElementTag = false;
attributeCount = 0;
// retrieve name
final int nameStart = pos - 1 + bufAbsoluteStart;
int colonPos = -1;
char ch = buf[ pos - 1];
if(ch == ':' && processNamespaces) throw new XmlPullParserException(
"when namespaces processing enabled colon can not be at element name start",
this, null);
while(true) {
ch = more();
if(!isNameChar(ch)) break;
if(ch == ':' && processNamespaces) {
if(colonPos != -1) throw new XmlPullParserException(
"only one colon is allowed in name of element when namespaces are enabled",
this, null);
colonPos = pos - 1 + bufAbsoluteStart;
}
}
// retrieve name
ensureElementsCapacity();
//TODO check for efficient interning and then use elRawNameInterned!!!!
int elLen = (pos - 1) - (nameStart - bufAbsoluteStart);
if(elRawName[ depth ] == null || elRawName[ depth ].length < elLen) {
elRawName[ depth ] = new char[ 2 * elLen ];
}
System.arraycopy(buf, nameStart - bufAbsoluteStart, elRawName[ depth ], 0, elLen);
elRawNameEnd[ depth ] = elLen;
elRawNameLine[ depth ] = lineNumber;
String name = null;
// work on prefixes and namespace URI
String prefix = null;
if(processNamespaces) {
if(colonPos != -1) {
prefix = elPrefix[ depth ] = newString(buf, nameStart - bufAbsoluteStart,
colonPos - nameStart);
name = elName[ depth ] = newString(buf, colonPos + 1 - bufAbsoluteStart,
//(pos -1) - (colonPos + 1));
pos - 2 - (colonPos - bufAbsoluteStart));
} else {
prefix = elPrefix[ depth ] = null;
name = elName[ depth ] = newString(buf, nameStart - bufAbsoluteStart, elLen);
}
} else {
name = elName[ depth ] = newString(buf, nameStart - bufAbsoluteStart, elLen);
}
while(true) {
while(isS(ch)) { ch = more(); } // skip additional white spaces
if(ch == '>') {
break;
} else if(ch == '/') {
if(emptyElementTag) throw new XmlPullParserException(
"repeated / in tag declaration", this, null);
emptyElementTag = true;
ch = more();
if(ch != '>') throw new XmlPullParserException(
"expected > to end empty tag not "+printable(ch), this, null);
break;
} else if(isNameStartChar(ch)) {
ch = parseAttribute();
ch = more();
continue;
} else {
throw new XmlPullParserException(
"start tag unexpected character "+printable(ch), this, null);
}
//ch = more(); // skip space
}
// now when namespaces were declared we can resolve them
if(processNamespaces) {
String uri = getNamespace(prefix);
if(uri == null) {
if(prefix == null) { // no prefix and no uri => use default namespace
uri = NO_NAMESPACE;
} else {
throw new XmlPullParserException(
"could not determine namespace bound to element prefix "+prefix,
this, null);
}
}
elUri[ depth ] = uri;
//String uri = getNamespace(prefix);
//if(uri == null && prefix == null) { // no prefix and no uri => use default namespace
// uri = "";
//}
// resolve attribute namespaces
for (int i = 0; i < attributeCount; i++)
{
final String attrPrefix = attributePrefix[ i ];
if(attrPrefix != null) {
final String attrUri = getNamespace(attrPrefix);
if(attrUri == null) {
throw new XmlPullParserException(
"could not determine namespace bound to attribute prefix "+attrPrefix,
this, null);
}
attributeUri[ i ] = attrUri;
} else {
attributeUri[ i ] = NO_NAMESPACE;
}
}
//TODO
//[ WFC: Unique Att Spec ]
// check attribute uniqueness constraint for attributes that has namespace!!!
for (int i = 1; i < attributeCount; i++)
{
for (int j = 0; j < i; j++)
{
if( attributeUri[j] == attributeUri[i]
&& (allStringsInterned && attributeName[j].equals(attributeName[i])
|| (!allStringsInterned
&& attributeNameHash[ j ] == attributeNameHash[ i ]
&& attributeName[j].equals(attributeName[i])) )
) {
// prepare data for nice error message?
String attr1 = attributeName[j];
if(attributeUri[j] != null) attr1 = attributeUri[j]+":"+attr1;
String attr2 = attributeName[i];
if(attributeUri[i] != null) attr2 = attributeUri[i]+":"+attr2;
throw new XmlPullParserException(
"duplicated attributes "+attr1+" and "+attr2, this, null);
}
}
}
} else { // ! processNamespaces
//[ WFC: Unique Att Spec ]
// check raw attribute uniqueness constraint!!!
for (int i = 1; i < attributeCount; i++)
{
for (int j = 0; j < i; j++)
{
if((allStringsInterned && attributeName[j].equals(attributeName[i])
|| (!allStringsInterned
&& attributeNameHash[ j ] == attributeNameHash[ i ]
&& attributeName[j].equals(attributeName[i])) )
) {
// prepare data for nice error message?
final String attr1 = attributeName[j];
final String attr2 = attributeName[i];
throw new XmlPullParserException(
"duplicated attributes "+attr1+" and "+attr2, this, null);
}
}
}
}
elNamespaceCount[ depth ] = namespaceEnd;
posEnd = pos;
return eventType = START_TAG;
}
protected char parseAttribute() throws XmlPullParserException, IOException
{
// parse attribute
// [41] Attribute ::= Name Eq AttValue
// [WFC: No External Entity References]
// [WFC: No < in Attribute Values]
final int prevPosStart = posStart + bufAbsoluteStart;
final int nameStart = pos - 1 + bufAbsoluteStart;
int colonPos = -1;
char ch = buf[ pos - 1 ];
if(ch == ':' && processNamespaces) throw new XmlPullParserException(
"when namespaces processing enabled colon can not be at attribute name start",
this, null);
boolean startsWithXmlns = processNamespaces && ch == 'x';
int xmlnsPos = 0;
ch = more();
while(isNameChar(ch)) {
if(processNamespaces) {
if(startsWithXmlns && xmlnsPos < 5) {
++xmlnsPos;
if(xmlnsPos == 1) { if(ch != 'm') startsWithXmlns = false; }
else if(xmlnsPos == 2) { if(ch != 'l') startsWithXmlns = false; }
else if(xmlnsPos == 3) { if(ch != 'n') startsWithXmlns = false; }
else if(xmlnsPos == 4) { if(ch != 's') startsWithXmlns = false; }
else if(xmlnsPos == 5) {
if(ch != ':') throw new XmlPullParserException(
"after xmlns in attribute name must be colon"
+"when namespaces are enabled", this, null);
//colonPos = pos - 1 + bufAbsoluteStart;
}
}
if(ch == ':') {
if(colonPos != -1) throw new XmlPullParserException(
"only one colon is allowed in attribute name"
+" when namespaces are enabled", this, null);
colonPos = pos - 1 + bufAbsoluteStart;
}
}
ch = more();
}
ensureAttributesCapacity(attributeCount);
// --- start processing attributes
String name = null;
String prefix = null;
// work on prefixes and namespace URI
if(processNamespaces) {
if(xmlnsPos < 4) startsWithXmlns = false;
if(startsWithXmlns) {
if(colonPos != -1) {
//prefix = attributePrefix[ attributeCount ] = null;
final int nameLen = pos - 2 - (colonPos - bufAbsoluteStart);
if(nameLen == 0) {
throw new XmlPullParserException(
"namespace prefix is required after xmlns: "
+" when namespaces are enabled", this, null);
}
name = //attributeName[ attributeCount ] =
newString(buf, colonPos - bufAbsoluteStart + 1, nameLen);
//pos - 1 - (colonPos + 1 - bufAbsoluteStart)
}
} else {
if(colonPos != -1) {
int prefixLen = colonPos - nameStart;
prefix = attributePrefix[ attributeCount ] =
newString(buf, nameStart - bufAbsoluteStart,prefixLen);
//colonPos - (nameStart - bufAbsoluteStart));
int nameLen = pos - 2 - (colonPos - bufAbsoluteStart);
name = attributeName[ attributeCount ] =
newString(buf, colonPos - bufAbsoluteStart + 1, nameLen);
//pos - 1 - (colonPos + 1 - bufAbsoluteStart));
//name.substring(0, colonPos-nameStart);
} else {
prefix = attributePrefix[ attributeCount ] = null;
name = attributeName[ attributeCount ] =
newString(buf, nameStart - bufAbsoluteStart,
pos - 1 - (nameStart - bufAbsoluteStart));
}
if(!allStringsInterned) {
attributeNameHash[ attributeCount ] = name.hashCode();
}
}
} else {
// retrieve name
name = attributeName[ attributeCount ] =
newString(buf, nameStart - bufAbsoluteStart,
pos - 1 - (nameStart - bufAbsoluteStart));
////assert name != null;
if(!allStringsInterned) {
attributeNameHash[ attributeCount ] = name.hashCode();
}
}
// [25] Eq ::= S? '=' S?
while(isS(ch)) { ch = more(); } // skip additional spaces
if(ch != '=') throw new XmlPullParserException(
"expected = after attribute name", this, null);
ch = more();
while(isS(ch)) { ch = more(); } // skip additional spaces
// [10] AttValue ::= '"' ([^<&"] | Reference)* '"'
// | "'" ([^<&'] | Reference)* "'"
final char delimit = ch;
if(delimit != '"' && delimit != '\'') throw new XmlPullParserException(
"attribute value must start with quotation or apostrophe not "
+printable(delimit), this, null);
// parse until delimit or < and resolve Reference
//[67] Reference ::= EntityRef | CharRef
//int valueStart = pos + bufAbsoluteStart;
boolean normalizedCR = false;
usePC = false;
pcStart = pcEnd;
posStart = pos;
while(true) {
ch = more();
if(ch == delimit) {
break;
} if(ch == '<') {
throw new XmlPullParserException(
"markup not allowed inside attribute value - illegal < ", this, null);
} if(ch == '&') {
// extractEntityRef
posEnd = pos - 1;
if(!usePC) {
final boolean hadCharData = posEnd > posStart;
if(hadCharData) {
// posEnd is already set correctly!!!
joinPC();
} else {
usePC = true;
pcStart = pcEnd = 0;
}
}
//assert usePC == true;
final char[] resolvedEntity = parseEntityRef();
// check if replacement text can be resolved !!!
if(resolvedEntity == null) {
if(entityRefName == null) {
entityRefName = newString(buf, posStart, posEnd - posStart);
}
throw new XmlPullParserException(
"could not resolve entity named '"+printable(entityRefName)+"'",
this, null);
}
// write into PC replacement text - do merge for replacement text!!!!
for (int i = 0; i < resolvedEntity.length; i++)
{
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = resolvedEntity[ i ];
}
} else if(ch == '\t' || ch == '\n' || ch == '\r') {
// do attribute value normalization
// as described in http://www.w3.org/TR/REC-xml#AVNormalize
// TODO add test for it form spec ...
// handle EOL normalization ...
if(!usePC) {
posEnd = pos - 1;
if(posEnd > posStart) {
joinPC();
} else {
usePC = true;
pcEnd = pcStart = 0;
}
}
//assert usePC == true;
if(pcEnd >= pc.length) ensurePC(pcEnd);
if(ch != '\n' || !normalizedCR) {
pc[pcEnd++] = ' '; //'\n';
}
} else {
if(usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = ch;
}
}
normalizedCR = ch == '\r';
}
if(processNamespaces && startsWithXmlns) {
String ns = null;
if(!usePC) {
ns = newStringIntern(buf, posStart, pos - 1 - posStart);
} else {
ns = newStringIntern(pc, pcStart, pcEnd - pcStart);
}
ensureNamespacesCapacity(namespaceEnd);
int prefixHash = -1;
if(colonPos != -1) {
if(ns.length() == 0) {
throw new XmlPullParserException(
"non-default namespace can not be declared to be empty string", this, null);
}
// declare new namespace
namespacePrefix[ namespaceEnd ] = name;
if(!allStringsInterned) {
prefixHash = namespacePrefixHash[ namespaceEnd ] = name.hashCode();
}
} else {
// declare new default namespace ...
namespacePrefix[ namespaceEnd ] = null; //""; //null; //TODO check FIXME Alek
if(!allStringsInterned) {
prefixHash = namespacePrefixHash[ namespaceEnd ] = -1;
}
}
namespaceUri[ namespaceEnd ] = ns;
// detect duplicate namespace declarations!!!
final int startNs = elNamespaceCount[ depth - 1 ];
for (int i = namespaceEnd - 1; i >= startNs; --i)
{
if(((allStringsInterned || name == null) && namespacePrefix[ i ] == name)
|| (!allStringsInterned && name != null &&
namespacePrefixHash[ i ] == prefixHash
&& name.equals(namespacePrefix[ i ])
))
{
final String s = name == null ? "default" : "'"+name+"'";
throw new XmlPullParserException(
"duplicated namespace declaration for "+s+" prefix", this, null);
}
}
++namespaceEnd;
} else {
if(!usePC) {
attributeValue[ attributeCount ] =
new String(buf, posStart, pos - 1 - posStart);
} else {
attributeValue[ attributeCount ] =
new String(pc, pcStart, pcEnd - pcStart);
}
++attributeCount;
}
posStart = prevPosStart - bufAbsoluteStart;
return ch;
}
protected char[] charRefOneCharBuf = new char[1];
protected char[] parseEntityRef()
throws XmlPullParserException, IOException
{
// entity reference http://www.w3.org/TR/2000/REC-xml-20001006#NT-Reference
// [67] Reference ::= EntityRef | CharRef
// ASSUMPTION just after &
entityRefName = null;
posStart = pos;
char ch = more();
if(ch == '#') {
// parse character reference
char charRef = 0;
ch = more();
if(ch == 'x') {
//encoded in hex
while(true) {
ch = more();
if(ch >= '0' && ch <= '9') {
charRef = (char)(charRef * 16 + (ch - '0'));
} else if(ch >= 'a' && ch <= 'f') {
charRef = (char)(charRef * 16 + (ch - ('a' - 10)));
} else if(ch >= 'A' && ch <= 'F') {
charRef = (char)(charRef * 16 + (ch - ('A' - 10)));
} else if(ch == ';') {
break;
} else {
throw new XmlPullParserException(
"character reference (with hex value) may not contain "
+printable(ch), this, null);
}
}
} else {
// encoded in decimal
while(true) {
if(ch >= '0' && ch <= '9') {
charRef = (char)(charRef * 10 + (ch - '0'));
} else if(ch == ';') {
break;
} else {
throw new XmlPullParserException(
"character reference (with decimal value) may not contain "
+printable(ch), this, null);
}
ch = more();
}
}
posEnd = pos - 1;
charRefOneCharBuf[0] = charRef;
if(tokenize) {
text = newString(charRefOneCharBuf, 0, 1);
}
return charRefOneCharBuf;
} else {
// [68] EntityRef ::= '&' Name ';'
// scan name until ;
if(!isNameStartChar(ch)) {
throw new XmlPullParserException(
"entity reference names can not start with character '"
+printable(ch)+"'", this, null);
}
while(true) {
ch = more();
if(ch == ';') {
break;
}
if(!isNameChar(ch)) {
throw new XmlPullParserException(
"entity reference name can not contain character "
+printable(ch)+"'", this, null);
}
}
posEnd = pos - 1;
// determine what name maps to
final int len = posEnd - posStart;
if(len == 2 && buf[posStart] == 'l' && buf[posStart+1] == 't') {
if(tokenize) {
text = "<";
}
charRefOneCharBuf[0] = '<';
return charRefOneCharBuf;
//if(paramPC || isParserTokenizing) {
// if(pcEnd >= pc.length) ensurePC();
// pc[pcEnd++] = '<';
//}
} else if(len == 3 && buf[posStart] == 'a'
&& buf[posStart+1] == 'm' && buf[posStart+2] == 'p') {
if(tokenize) {
text = "&";
}
charRefOneCharBuf[0] = '&';
return charRefOneCharBuf;
} else if(len == 2 && buf[posStart] == 'g' && buf[posStart+1] == 't') {
if(tokenize) {
text = ">";
}
charRefOneCharBuf[0] = '>';
return charRefOneCharBuf;
} else if(len == 4 && buf[posStart] == 'a' && buf[posStart+1] == 'p'
&& buf[posStart+2] == 'o' && buf[posStart+3] == 's')
{
if(tokenize) {
text = "'";
}
charRefOneCharBuf[0] = '\'';
return charRefOneCharBuf;
} else if(len == 4 && buf[posStart] == 'q' && buf[posStart+1] == 'u'
&& buf[posStart+2] == 'o' && buf[posStart+3] == 't')
{
if(tokenize) {
text = "\"";
}
charRefOneCharBuf[0] = '"';
return charRefOneCharBuf;
} else {
final char[] result = lookuEntityReplacement(len);
if(result != null) {
return result;
}
}
if(tokenize) text = null;
return null;
}
}
protected char[] lookuEntityReplacement(int entitNameLen)
throws XmlPullParserException, IOException
{
if(!allStringsInterned) {
final int hash = fastHash(buf, posStart, posEnd - posStart);
LOOP:
for (int i = entityEnd - 1; i >= 0; --i)
{
if(hash == entityNameHash[ i ] && entitNameLen == entityNameBuf[ i ].length) {
final char[] entityBuf = entityNameBuf[ i ];
for (int j = 0; j < entitNameLen; j++)
{
if(buf[posStart + j] != entityBuf[j]) continue LOOP;
}
if(tokenize) text = entityReplacement[ i ];
return entityReplacementBuf[ i ];
}
}
} else {
entityRefName = newString(buf, posStart, posEnd - posStart);
for (int i = entityEnd - 1; i >= 0; --i)
{
// take advantage that interning for newStirng is enforced
if(entityRefName == entityName[ i ]) {
if(tokenize) text = entityReplacement[ i ];
return entityReplacementBuf[ i ];
}
}
}
return null;
}
protected void parseComment()
throws XmlPullParserException, IOException
{
// implements XML 1.0 Section 2.5 Comments
//ASSUMPTION: seen
ch = more();
if(seenDashDash && ch != '>') {
throw new XmlPullParserException(
"in comment after two dashes (--) next character must be >"
+" not "+printable(ch), this, null);
}
if(ch == '-') {
if(!seenDash) {
seenDash = true;
} else {
seenDashDash = true;
seenDash = false;
}
} else if(ch == '>') {
if(seenDashDash) {
break; // found end sequence!!!!
} else {
seenDashDash = false;
}
seenDash = false;
} else {
seenDash = false;
}
if(normalizeIgnorableWS) {
if(ch == '\r') {
normalizedCR = true;
//posEnd = pos -1;
//joinPC();
// posEnd is already set
if(!usePC) {
posEnd = pos -1;
if(posEnd > posStart) {
joinPC();
} else {
usePC = true;
pcStart = pcEnd = 0;
}
}
//assert usePC == true;
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = '\n';
} else if(ch == '\n') {
if(!normalizedCR && usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = '\n';
}
normalizedCR = false;
} else {
if(usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = ch;
}
normalizedCR = false;
}
}
}
} catch(EOFException ex) {
// detect EOF and create meaningful error ...
throw new XmlPullParserException(
"comment started on line "+curLine+" and column "+curColumn+" was not closed",
this, ex);
}
if(tokenize) {
posEnd = pos - 3;
if(usePC) {
pcEnd -= 2;
}
}
}
protected boolean parsePI()
throws XmlPullParserException, IOException
{
// implements XML 1.0 Section 2.6 Processing Instructions
// [16] PI ::= '' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
// [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
//ASSUMPTION: seen
if(tokenize) posStart = pos;
final int curLine = lineNumber;
final int curColumn = columnNumber;
int piTargetStart = pos + bufAbsoluteStart;
int piTargetEnd = -1;
final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false;
boolean normalizedCR = false;
try {
boolean seenQ = false;
char ch = more();
if(isS(ch)) {
throw new XmlPullParserException(
"processing instruction PITarget must be exactly after and not white space character",
this, null);
}
while(true) {
// scan until it hits ?>
//ch = more();
if(ch == '?') {
seenQ = true;
} else if(ch == '>') {
if(seenQ) {
break; // found end sequence!!!!
}
seenQ = false;
} else {
if(piTargetEnd == -1 && isS(ch)) {
piTargetEnd = pos - 1 + bufAbsoluteStart;
// [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
if((piTargetEnd - piTargetStart) == 3) {
if((buf[piTargetStart] == 'x' || buf[piTargetStart] == 'X')
&& (buf[piTargetStart+1] == 'm' || buf[piTargetStart+1] == 'M')
&& (buf[piTargetStart+2] == 'l' || buf[piTargetStart+2] == 'L')
)
{
if(piTargetStart > 3) { // posStart) {
joinPC();
} else {
usePC = true;
pcStart = pcEnd = 0;
}
}
//assert usePC == true;
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = '\n';
} else if(ch == '\n') {
if(!normalizedCR && usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = '\n';
}
normalizedCR = false;
} else {
if(usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = ch;
}
normalizedCR = false;
}
}
ch = more();
}
} catch(EOFException ex) {
// detect EOF and create meaningful error ...
throw new XmlPullParserException(
"processing instruction started on line "+curLine+" and column "+curColumn
+" was not closed",
this, ex);
}
if(piTargetEnd == -1) {
piTargetEnd = pos - 2 + bufAbsoluteStart;
//throw new XmlPullParserException(
// "processing instruction must have PITarget name", this, null);
}
piTargetStart -= bufAbsoluteStart;
piTargetEnd -= bufAbsoluteStart;
if(tokenize) {
posEnd = pos - 2;
if(normalizeIgnorableWS) {
--pcEnd;
}
}
return true;
}
// protected final static char[] VERSION = {'v','e','r','s','i','o','n'};
// protected final static char[] NCODING = {'n','c','o','d','i','n','g'};
// protected final static char[] TANDALONE = {'t','a','n','d','a','l','o','n','e'};
// protected final static char[] YES = {'y','e','s'};
// protected final static char[] NO = {'n','o'};
protected final static char[] VERSION = "version".toCharArray();
protected final static char[] NCODING = "ncoding".toCharArray();
protected final static char[] TANDALONE = "tandalone".toCharArray();
protected final static char[] YES = "yes".toCharArray();
protected final static char[] NO = "no".toCharArray();
protected void parseXmlDecl(char ch)
throws XmlPullParserException, IOException
{
// [23] XMLDecl ::= ''
// first make sure that relative positions will stay OK
preventBufferCompaction = true;
bufStart = 0; // necessary to keep pos unchanged during expansion!
// --- parse VersionInfo
// [24] VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"')
// parse is positioned just on first S past 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9')
&& ch != '_' && ch != '.' && ch != ':' && ch != '-')
{
throw new XmlPullParserException(
" 'z') && (ch < 'A' || ch > 'Z'))
{
throw new XmlPullParserException(
" 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9')
&& ch != '.' && ch != '_' && ch != '-')
{
throw new XmlPullParserException(
" as last part of ') {
throw new XmlPullParserException(
"expected ?> as last part of '
int bracketLevel = 0;
final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false;
boolean normalizedCR = false;
while(true) {
ch = more();
if(ch == '[') ++bracketLevel;
if(ch == ']') --bracketLevel;
if(ch == '>' && bracketLevel == 0) break;
if(normalizeIgnorableWS) {
if(ch == '\r') {
normalizedCR = true;
//posEnd = pos -1;
//joinPC();
// posEnd is alreadys set
if(!usePC) {
posEnd = pos -1;
if(posEnd > posStart) {
joinPC();
} else {
usePC = true;
pcStart = pcEnd = 0;
}
}
//assert usePC == true;
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = '\n';
} else if(ch == '\n') {
if(!normalizedCR && usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = '\n';
}
normalizedCR = false;
} else {
if(usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = ch;
}
normalizedCR = false;
}
}
}
posEnd = pos - 1;
}
protected void parseCDSect(boolean hadCharData)
throws XmlPullParserException, IOException
{
// implements XML 1.0 Section 2.7 CDATA Sections
// [18] CDSect ::= CDStart CData CDEnd
// [19] CDStart ::= '' Char*))
// [21] CDEnd ::= ']]>'
//ASSUMPTION: seen posStart) {
joinPC();
} else {
usePC = true;
pcStart = pcEnd = 0;
}
}
}
}
boolean seenBracket = false;
boolean seenBracketBracket = false;
boolean normalizedCR = false;
while(true) {
// scan until it hits "]]>"
ch = more();
if(ch == ']') {
if(!seenBracket) {
seenBracket = true;
} else {
seenBracketBracket = true;
//seenBracket = false;
}
} else if(ch == '>') {
if(seenBracket && seenBracketBracket) {
break; // found end sequence!!!!
} else {
seenBracketBracket = false;
}
seenBracket = false;
} else {
if(seenBracket) {
seenBracket = false;
}
}
if(normalizeInput) {
// deal with normalization issues ...
if(ch == '\r') {
normalizedCR = true;
posStart = cdStart - bufAbsoluteStart;
posEnd = pos - 1; // posEnd is alreadys set
if(!usePC) {
if(posEnd > posStart) {
joinPC();
} else {
usePC = true;
pcStart = pcEnd = 0;
}
}
//assert usePC == true;
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = '\n';
} else if(ch == '\n') {
if(!normalizedCR && usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = '\n';
}
normalizedCR = false;
} else {
if(usePC) {
if(pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = ch;
}
normalizedCR = false;
}
}
}
} catch(EOFException ex) {
// detect EOF and create meaningful error ...
throw new XmlPullParserException(
"CDATA section started on line "+curLine+" and column "+curColumn+" was not closed",
this, ex);
}
if(normalizeInput) {
if(usePC) {
pcEnd = pcEnd - 2;
}
}
posStart = cdStart - bufAbsoluteStart;
posEnd = pos - 3;
}
protected void fillBuf() throws IOException, XmlPullParserException {
if(reader == null) throw new XmlPullParserException(
"reader must be set before parsing is started");
// see if we are in compaction area
if(bufEnd > bufSoftLimit) {
// expand buffer it makes sense!!!!
boolean compact = bufStart > bufSoftLimit;
boolean expand = false;
if(preventBufferCompaction) {
compact = false;
expand = true;
} else if(!compact) {
//freeSpace
if(bufStart < buf.length / 2) {
// less then half buffer available forcompactin --> expand instead!!!
expand = true;
} else {
// at least half of buffer can be reclaimed --> worthwhile effort!!!
compact = true;
}
}
// if buffer almost full then compact it
if(compact) {
//TODO: look on trashing
// //assert bufStart > 0
System.arraycopy(buf, bufStart, buf, 0, bufEnd - bufStart);
if(TRACE_SIZING) System.out.println(
"TRACE_SIZING fillBuf() compacting "+bufStart
+" bufEnd="+bufEnd
+" pos="+pos+" posStart="+posStart+" posEnd="+posEnd
+" buf first 100 chars:"+new String(buf, bufStart,
bufEnd - bufStart < 100 ? bufEnd - bufStart : 100 ));
} else if(expand) {
final int newSize = 2 * buf.length;
final char newBuf[] = new char[ newSize ];
if(TRACE_SIZING) System.out.println("TRACE_SIZING fillBuf() "+buf.length+" => "+newSize);
System.arraycopy(buf, bufStart, newBuf, 0, bufEnd - bufStart);
buf = newBuf;
if(bufLoadFactor > 0) {
//bufSoftLimit = ( bufLoadFactor * buf.length ) /100;
bufSoftLimit = (int) (( ((long) bufLoadFactor) * buf.length ) /100);
}
} else {
throw new XmlPullParserException("internal error in fillBuffer()");
}
bufEnd -= bufStart;
pos -= bufStart;
posStart -= bufStart;
posEnd -= bufStart;
bufAbsoluteStart += bufStart;
bufStart = 0;
if(TRACE_SIZING) System.out.println(
"TRACE_SIZING fillBuf() after bufEnd="+bufEnd
+" pos="+pos+" posStart="+posStart+" posEnd="+posEnd
+" buf first 100 chars:"+new String(buf, 0, bufEnd < 100 ? bufEnd : 100));
}
// at least one character must be read or error
final int len = buf.length - bufEnd > READ_CHUNK_SIZE ? READ_CHUNK_SIZE : buf.length - bufEnd;
final int ret = reader.read(buf, bufEnd, len);
if(ret > 0) {
bufEnd += ret;
if(TRACE_SIZING) System.out.println(
"TRACE_SIZING fillBuf() after filling in buffer"
+" buf first 100 chars:"+new String(buf, 0, bufEnd < 100 ? bufEnd : 100));
return;
}
if(ret == -1) {
if(bufAbsoluteStart == 0 && pos == 0) {
throw new EOFException("input contained no data");
} else {
if(seenRoot && depth == 0) { // inside parsing epilog!!!
reachedEnd = true;
return;
} else {
StringBuffer expectedTagStack = new StringBuffer();
if(depth > 0) {
//final char[] cbuf = elRawName[depth];
//final String startname = new String(cbuf, 0, elRawNameEnd[depth]);
expectedTagStack.append(" - expected end tag");
if(depth > 1) {
expectedTagStack.append("s"); //more than one end tag
}
expectedTagStack.append(" ");
for (int i = depth; i > 0; i--)
{
String tagName = new String(elRawName[i], 0, elRawNameEnd[i]);
expectedTagStack.append("").append(tagName).append('>');
}
expectedTagStack.append(" to close");
for (int i = depth; i > 0; i--)
{
if(i != depth) {
expectedTagStack.append(" and"); //more than one end tag
}
String tagName = new String(elRawName[i], 0, elRawNameEnd[i]);
expectedTagStack.append(" start tag <"+tagName+">");
expectedTagStack.append(" from line "+elRawNameLine[i]);
}
expectedTagStack.append(", parser stopped on");
}
throw new EOFException("no more data available"
+expectedTagStack.toString()+getPositionDescription());
}
}
} else {
throw new IOException("error reading input, returned "+ret);
}
}
protected char more() throws IOException, XmlPullParserException {
if(pos >= bufEnd) {
fillBuf();
// this return value should be ignonored as it is used in epilog parsing ...
if(reachedEnd) return (char)-1;
}
final char ch = buf[pos++];
//line/columnNumber
if(ch == '\n') { ++lineNumber; columnNumber = 1; }
else { ++columnNumber; }
//System.out.print(ch);
return ch;
}
// /**
// * This function returns position of parser in XML input stream
// * (how many characters were processed.
// * NOTE: this logical position and not byte offset as encodings
// * such as UTF8 may use more than one byte to encode one character.
// */
// public int getCurrentInputPosition() {
// return pos + bufAbsoluteStart;
// }
protected void ensurePC(int end) {
//assert end >= pc.length;
final int newSize = end > READ_CHUNK_SIZE ? 2 * end : 2 * READ_CHUNK_SIZE;
final char[] newPC = new char[ newSize ];
if(TRACE_SIZING) System.out.println("TRACE_SIZING ensurePC() "+pc.length+" ==> "+newSize+" end="+end);
System.arraycopy(pc, 0, newPC, 0, pcEnd);
pc = newPC;
//assert end < pc.length;
}
protected void joinPC() {
//assert usePC == false;
//assert posEnd > posStart;
final int len = posEnd - posStart;
final int newEnd = pcEnd + len + 1;
if(newEnd >= pc.length) ensurePC(newEnd); // add 1 for extra space for one char
//assert newEnd < pc.length;
System.arraycopy(buf, posStart, pc, pcEnd, len);
pcEnd += len;
usePC = true;
}
protected char requireInput(char ch, char[] input)
throws XmlPullParserException, IOException
{
for (int i = 0; i < input.length; i++)
{
if(ch != input[i]) {
throw new XmlPullParserException(
"expected "+printable(input[i])+" in "+new String(input)
+" and not "+printable(ch), this, null);
}
ch = more();
}
return ch;
}
protected char requireNextS()
throws XmlPullParserException, IOException
{
final char ch = more();
if(!isS(ch)) {
throw new XmlPullParserException(
"white space is required and not "+printable(ch), this, null);
}
return skipS(ch);
}
protected char skipS(char ch)
throws XmlPullParserException, IOException
{
while(isS(ch)) { ch = more(); } // skip additional spaces
return ch;
}
// nameStart / name lookup tables based on XML 1.1 http://www.w3.org/TR/2001/WD-xml11-20011213/
protected static final int LOOKUP_MAX = 0x400;
protected static final char LOOKUP_MAX_CHAR = (char)LOOKUP_MAX;
// protected static int lookupNameStartChar[] = new int[ LOOKUP_MAX_CHAR / 32 ];
// protected static int lookupNameChar[] = new int[ LOOKUP_MAX_CHAR / 32 ];
protected static boolean lookupNameStartChar[] = new boolean[ LOOKUP_MAX ];
protected static boolean lookupNameChar[] = new boolean[ LOOKUP_MAX ];
private static final void setName(char ch)
//{ lookupNameChar[ (int)ch / 32 ] |= (1 << (ch % 32)); }
{ lookupNameChar[ ch ] = true; }
private static final void setNameStart(char ch)
//{ lookupNameStartChar[ (int)ch / 32 ] |= (1 << (ch % 32)); setName(ch); }
{ lookupNameStartChar[ ch ] = true; setName(ch); }
static {
setNameStart(':');
for (char ch = 'A'; ch <= 'Z'; ++ch) setNameStart(ch);
setNameStart('_');
for (char ch = 'a'; ch <= 'z'; ++ch) setNameStart(ch);
for (char ch = '\u00c0'; ch <= '\u02FF'; ++ch) setNameStart(ch);
for (char ch = '\u0370'; ch <= '\u037d'; ++ch) setNameStart(ch);
for (char ch = '\u037f'; ch < '\u0400'; ++ch) setNameStart(ch);
setName('-');
setName('.');
for (char ch = '0'; ch <= '9'; ++ch) setName(ch);
setName('\u00b7');
for (char ch = '\u0300'; ch <= '\u036f'; ++ch) setName(ch);
}
//private final static boolean isNameStartChar(char ch) {
protected boolean isNameStartChar(char ch) {
return (ch < LOOKUP_MAX_CHAR && lookupNameStartChar[ ch ])
|| (ch >= LOOKUP_MAX_CHAR && ch <= '\u2027')
|| (ch >= '\u202A' && ch <= '\u218F')
|| (ch >= '\u2800' && ch <= '\uFFEF')
;
// if(ch < LOOKUP_MAX_CHAR) return lookupNameStartChar[ ch ];
// else return ch <= '\u2027'
// || (ch >= '\u202A' && ch <= '\u218F')
// || (ch >= '\u2800' && ch <= '\uFFEF')
// ;
//return false;
// return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == ':'
// || (ch >= '0' && ch <= '9');
// if(ch < LOOKUP_MAX_CHAR) return (lookupNameStartChar[ (int)ch / 32 ] & (1 << (ch % 32))) != 0;
// if(ch <= '\u2027') return true;
// //[#x202A-#x218F]
// if(ch < '\u202A') return false;
// if(ch <= '\u218F') return true;
// // added pairts [#x2800-#xD7FF] | [#xE000-#xFDCF] | [#xFDE0-#xFFEF] | [#x10000-#x10FFFF]
// if(ch < '\u2800') return false;
// if(ch <= '\uFFEF') return true;
// return false;
// else return (supportXml11 && ( (ch < '\u2027') || (ch > '\u2029' && ch < '\u2200') ...
}
//private final static boolean isNameChar(char ch) {
protected boolean isNameChar(char ch) {
//return isNameStartChar(ch);
// if(ch < LOOKUP_MAX_CHAR) return (lookupNameChar[ (int)ch / 32 ] & (1 << (ch % 32))) != 0;
return (ch < LOOKUP_MAX_CHAR && lookupNameChar[ ch ])
|| (ch >= LOOKUP_MAX_CHAR && ch <= '\u2027')
|| (ch >= '\u202A' && ch <= '\u218F')
|| (ch >= '\u2800' && ch <= '\uFFEF')
;
//return false;
// return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == ':'
// || (ch >= '0' && ch <= '9');
// if(ch < LOOKUP_MAX_CHAR) return (lookupNameStartChar[ (int)ch / 32 ] & (1 << (ch % 32))) != 0;
//else return
// else if(ch <= '\u2027') return true;
// //[#x202A-#x218F]
// else if(ch < '\u202A') return false;
// else if(ch <= '\u218F') return true;
// // added pairts [#x2800-#xD7FF] | [#xE000-#xFDCF] | [#xFDE0-#xFFEF] | [#x10000-#x10FFFF]
// else if(ch < '\u2800') return false;
// else if(ch <= '\uFFEF') return true;
//else return false;
}
protected boolean isS(char ch) {
return (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t');
// || (supportXml11 && (ch == '\u0085' || ch == '\u2028');
}
//protected boolean isChar(char ch) { return (ch < '\uD800' || ch > '\uDFFF')
// ch != '\u0000' ch < '\uFFFE'
//protected char printable(char ch) { return ch; }
protected String printable(char ch) {
if(ch == '\n') {
return "\\n";
} else if(ch == '\r') {
return "\\r";
} else if(ch == '\t') {
return "\\t";
} else if(ch == '\'') {
return "\\'";
} if(ch > 127 || ch < 32) {
return "\\u"+Integer.toHexString((int)ch);
}
return ""+ch;
}
protected String printable(String s) {
if(s == null) return null;
final int sLen = s.length();
StringBuffer buf = new StringBuffer(sLen + 10);
for(int i = 0; i < sLen; ++i) {
buf.append(printable(s.charAt(i)));
}
s = buf.toString();
return s;
}
}
/*
* Indiana University Extreme! Lab Software License, Version 1.2
*
* Copyright (C) 2003 The Trustees of Indiana University.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1) All redistributions of source code must retain the above
* copyright notice, the list of authors in the original source
* code, this list of conditions and the disclaimer listed in this
* license;
*
* 2) All redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the disclaimer
* listed in this license in the documentation and/or other
* materials provided with the distribution;
*
* 3) Any documentation included with all redistributions must include
* the following acknowledgement:
*
* "This product includes software developed by the Indiana
* University Extreme! Lab. For further information please visit
* http://www.extreme.indiana.edu/"
*
* Alternatively, this acknowledgment may appear in the software
* itself, and wherever such third-party acknowledgments normally
* appear.
*
* 4) The name "Indiana University" or "Indiana University
* Extreme! Lab" shall not be used to endorse or promote
* products derived from this software without prior written
* permission from Indiana University. For written permission,
* please contact http://www.extreme.indiana.edu/.
*
* 5) Products derived from this software may not use "Indiana
* University" name nor may "Indiana University" appear in their name,
* without prior written permission of the Indiana University.
*
* Indiana University provides no reassurances that the source code
* provided does not infringe the patent or any other intellectual
* property rights of any other entity. Indiana University disclaims any
* liability to any recipient for claims brought by any other entity
* based on infringement of intellectual property rights or otherwise.
*
* LICENSEE UNDERSTANDS THAT SOFTWARE IS PROVIDED "AS IS" FOR WHICH
* NO WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. INDIANA
* UNIVERSITY GIVES NO WARRANTIES AND MAKES NO REPRESENTATION THAT
* SOFTWARE IS FREE OF INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR
* OTHER PROPRIETARY RIGHTS. INDIANA UNIVERSITY MAKES NO WARRANTIES THAT
* SOFTWARE IS FREE FROM "BUGS", "VIRUSES", "TROJAN HORSES", "TRAP
* DOORS", "WORMS", OR OTHER HARMFUL CODE. LICENSEE ASSUMES THE ENTIRE
* RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR ASSOCIATED MATERIALS,
* AND TO THE PERFORMANCE AND VALIDITY OF INFORMATION GENERATED USING
* SOFTWARE.
*/
xpp3-1.1.4c/src/java/mxp1_min/org/xmlpull/mxp1/package.html 100644 0 0 520 10525225062 22515 0 ustar aslom ewww 0 0
Contains MXP1 parser minimal implementation that should work on J2ME and
implementation of XMLPULL V1 API .
xpp3-1.1.4c/src/java/mxp1_standard/META-INF/services/org.xmlpull.v1.XmlPullParserFactory 100644 0 0 41 10525225062 27675 0 ustar aslom ewww 0 0 org.xmlpull.mxp1.MXParserFactory
xpp3-1.1.4c/src/java/mxp1_standard/org/xmlpull/mxp1/MXParserCachingStrings.java 100644 0 0 41163 10525225062 26514 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
/*
* Copyright (c) 2002-2004 Extreme! Lab, Indiana University. All rights reserved.
*
* This software is open source. See the bottom of this file for the licence.
*
* $Id: MXParserCachingStrings.java,v 1.11 2006/10/23 13:36:27 aslom Exp $
*/
package org.xmlpull.mxp1;
import java.io.Reader;
import org.xmlpull.v1.XmlPullParserException;
/**
* Extend MXP parser to use string cache of char[] to interned String
*
NOTE: it is not non-validaint parser as there is no supporting internal DTD parsing
* no full XML 1.0 (or 1.1) character classes are supported.
*
* @author Aleksander Slominski
*/
public class MXParserCachingStrings extends MXParser implements Cloneable
{
protected final static boolean CACHE_STATISTICS = false;
protected final static boolean TRACE_SIZING = false;
protected final static int INITIAL_CAPACITY = 13;
protected int cacheStatCalls;
protected int cacheStatWalks;
protected int cacheStatResets;
protected int cacheStatRehash;
/** NOTE: implemented as integers and not flot to allow to work on J2ME. */
protected static final int CACHE_LOAD = 77; //in % ie. 77% == 77/100
protected int cacheEntriesCount;
protected int cacheEntriesThreshold;
//entries are kept in a simple linear list
protected char[][] keys;
protected String[] values;
// private boolean global;
// // as it is shared state ALL access to those varaibles must be synchronized!
// // global cache variables shadow per-instance variables for maximum performance
// // as cache is alway growing the access is optimized for really fast unsychronized lookups
// private static int globalCacheEntriesCount;
// private static int globalCacheEntriesThreshold;
// private static char[][] globalKeys;
// private static String[] globalValues;
public Object clone() throws CloneNotSupportedException
{
if(reader != null) {
if(!(reader instanceof Cloneable)) {
throw new CloneNotSupportedException("reader used in parser must implement Cloneable!");
}
}
MXParserCachingStrings cloned = (MXParserCachingStrings) super.clone();
//protected Reader reader;
if(reader != null) {
// why Cloneable has no clone() inside? good question and needs for stupid CloneableReader ...
//cloned.reader = (Reader) ((Cloneable)reader).clone(); //BING BONG doe snot work ...
//use reflection to call clone() -- this is getting ugly!!!!
// more background on this in http://www.artima.com/intv/issues3.html "The clone Dilemma"
try {
Object o = reader.getClass().getMethod("clone", null).invoke(reader, null);
cloned.reader = (Reader) o;
} catch (Exception e) {
//throw new CloneNotSupportedException("failed to call clone() on reader "+reader+e);
CloneNotSupportedException ee =
new CloneNotSupportedException("failed to call clone() on reader "+reader+":"+e);
ee.initCause(e);
throw ee;
}
}
// NOTE: "A clone of a multidimensional array is shallow, which is to say that
// "it creates only a single new array. Subarrays are shared, ..."
// http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html#64347
// protected char[][] keys;
if(keys != null) {
//TODO REVISIT: it seems cloneCCArr() is not needed
cloned.keys = (char[][]) keys.clone();
}
// protected String[] values;
if(values != null) {
cloned.values = (String[]) values.clone();
}
//---- base class
// protected char[] elRawName[];
if(elRawName != null) {
cloned.elRawName = cloneCCArr(elRawName);
}
// protected int elRawNameEnd[];
if(elRawNameEnd != null) {
cloned.elRawNameEnd = (int[]) elRawNameEnd.clone();
}
// protected int elRawNameLine[];
if(elRawNameLine != null) {
cloned.elRawNameLine = (int[]) elRawNameLine.clone();
}
// protected String elName[];
if(elName != null) {
cloned.elName = (String[]) elName.clone();
}
// protected String elPrefix[];
if(elPrefix != null) {
cloned.elPrefix = (String[]) elPrefix.clone();
}
// protected String elUri[];
if(elUri != null) {
cloned.elUri = (String[]) elUri.clone();
}
// protected int elNamespaceCount[];
if(elNamespaceCount != null) {
cloned.elNamespaceCount = (int[]) elNamespaceCount.clone();
}
// protected String attributeName[];
if(attributeName != null) {
cloned.attributeName = (String[]) attributeName.clone();
}
// protected int attributeNameHash[];
if(attributeNameHash != null) {
cloned.attributeNameHash = (int[]) attributeNameHash.clone();
}
// protected String attributePrefix[];
if(attributePrefix != null) {
cloned.attributePrefix = (String[]) attributePrefix.clone();
}
// protected String attributeUri[];
if(attributeUri != null) {
cloned.attributeUri = (String[]) attributeUri.clone();
}
// protected String attributeValue[];
if(attributeValue != null) {
cloned.attributeValue = (String[]) attributeValue.clone();
}
// protected String namespacePrefix[];
if(namespacePrefix != null) {
cloned.namespacePrefix = (String[]) namespacePrefix.clone();
}
// protected int namespacePrefixHash[];
if(namespacePrefixHash != null) {
cloned.namespacePrefixHash = (int[]) namespacePrefixHash.clone();
}
// protected String namespaceUri[];
if(namespaceUri != null) {
cloned.namespaceUri = (String[]) namespaceUri.clone();
}
// protected String entityName[];
if(entityName != null) {
cloned.entityName = (String[]) entityName.clone();
}
// protected char[] entityNameBuf[];
if(entityNameBuf != null) {
cloned.entityNameBuf = cloneCCArr(entityNameBuf);
}
// protected int entityNameHash[];
if(entityNameHash != null) {
cloned.entityNameHash = (int[]) entityNameHash.clone();
}
// protected char[] entityReplacementBuf[];
if(entityReplacementBuf != null) {
cloned.entityReplacementBuf = cloneCCArr(entityReplacementBuf);
}
// protected String entityReplacement[];
if(entityReplacement != null) {
cloned.entityReplacement = (String[]) entityReplacement.clone();
}
// protected char buf[];
if(buf != null) {
cloned.buf = (char[]) buf.clone();
}
// protected char pc[];
if(pc != null) {
cloned.pc = (char[]) pc.clone();
}
// protected char[] charRefOneCharBuf;
if(charRefOneCharBuf != null) {
cloned.charRefOneCharBuf = (char[]) charRefOneCharBuf.clone();
}
return cloned;
}
private char[][] cloneCCArr(char[][] ccarr) {
char[][] cca = (char[][]) ccarr.clone();
for (int i = 0; i < cca.length; i++)
{
if(cca[i] != null) {
cca[i] = (char[]) cca[i].clone();
}
}
return cca;
}
public MXParserCachingStrings() {
super();
allStringsInterned = true;
initStringCache();
}
/**
* This allows to change name iterning property in this enhanced impl.
*/
public void setFeature(String name,
boolean state) throws XmlPullParserException
{
if(FEATURE_NAMES_INTERNED.equals(name)) {
if(eventType != START_DOCUMENT) throw new XmlPullParserException(
"interning names feature can only be changed before parsing", this, null);
allStringsInterned = state;
if(state == false) {
if(keys != null) resetStringCache();
}
} else {
super.setFeature(name, state);
}
}
public boolean getFeature(String name)
{
if(FEATURE_NAMES_INTERNED.equals(name)) {
return allStringsInterned;
} else {
return super.getFeature(name);
}
}
/**
* Hook to GC finalization to print statistics about pool cache impl. perf.
*/
public void finalize() {
if(CACHE_STATISTICS) {
if( cacheStatCalls > 0) {
System.out.println("statistics: average walk:"+cacheStatWalks+"/"+cacheStatCalls+
" ("+((double)cacheStatWalks)/cacheStatCalls+")"+
" resets="+cacheStatResets+" rehash="+cacheStatRehash);
} else {
System.out.println("statistics: cache was not used");
}
}
}
/**
* If feature name interning is enabled then this funtion
* MUST return interned string.
*/
protected String newString(char[] cbuf, int off, int len) {
if(allStringsInterned) {
return newStringIntern(cbuf, off, len);
} else {
return super.newString(cbuf, off, len);
}
}
/**
* This is efficient implementation of pool that returns
* interned String based on char[] input.
*/
protected String newStringIntern(char[] cbuf, int off, int len) {
//return (new String(cbuf, off, len)).intern();
if(CACHE_STATISTICS) ++cacheStatCalls;
if (cacheEntriesCount >= cacheEntriesThreshold) {
rehash();
}
int offset = fastHash(cbuf, off, len) % keys.length;
char[] k = null;
while( (k = keys[offset]) != null
&& !keysAreEqual(k, 0, k.length,
cbuf, off, len))
{
offset = (offset + 1) % keys.length;
if(CACHE_STATISTICS) ++cacheStatWalks;
}
if (k != null) {
return values[offset];
} else {
k = new char[len];
System.arraycopy(cbuf, off, k, 0, len);
final String v = new String(k).intern();
keys[offset] = k;
values[offset] = v;
++cacheEntriesCount;
return v;
}
}
protected void initStringCache() {
if(keys == null) {
//int initialCapacity = 13;
if(INITIAL_CAPACITY < 0) {
throw new IllegalArgumentException("Illegal initial capacity: " + INITIAL_CAPACITY);
}
if(CACHE_LOAD < 0 || CACHE_LOAD > 99) {
throw new IllegalArgumentException("Illegal load factor: " + CACHE_LOAD);
}
cacheEntriesThreshold = (int)((INITIAL_CAPACITY * CACHE_LOAD)/100);
if(cacheEntriesThreshold >= INITIAL_CAPACITY) throw new RuntimeException(
"internal error: threshold must be less than capacity: "+INITIAL_CAPACITY);
keys = new char[INITIAL_CAPACITY][];
values = new String[INITIAL_CAPACITY];
cacheEntriesCount = 0;
}
}
protected void resetStringCache() {
//System.out.println("reset string cache()");
if(CACHE_STATISTICS) ++cacheStatResets;
initStringCache();
}
private void rehash() {
if(CACHE_STATISTICS) ++cacheStatRehash;
final int newSize = 2 * keys.length + 1;
cacheEntriesThreshold = (int)((newSize * CACHE_LOAD)/100);
if(cacheEntriesThreshold >= newSize) throw new RuntimeException(
"internal error: threshold must be less than capacity: "+newSize);
if(TRACE_SIZING) System.err.println("resized "+keys.length+" => "+newSize);
final char[][] newKeys = new char[newSize][];
final String[] newValues = new String[newSize];
for(int i = 0; i < keys.length; i++) {
final char[] k = keys[i];
keys[i] = null;
final String v = values[i];
values[i] = null;
if(k != null) {
int newOffset = fastHash(k, 0, k.length) % newSize;
char[] newk = null;
while((newk = newKeys[newOffset]) != null) {
if(keysAreEqual(newk, 0, newk.length,
k, 0, k.length)) {
throw new RuntimeException("internal cache error: duplicated keys: "+
new String(newk)+" and "+new String(k));
}
newOffset = (newOffset + 1) % newSize;
}
newKeys[newOffset] = k;
newValues[newOffset] = v;
}
}
keys = newKeys;
values = newValues;
}
private static final boolean keysAreEqual (char[] a, int astart, int alength,
char[] b, int bstart, int blength) {
if(alength != blength) {
return false;
} else {
for(int i = 0; i < alength; i++) {
if(a[astart + i] != b[bstart + i]) {
return false;
}
}
return true;
}
}
}
/*
* Indiana University Extreme! Lab Software License, Version 1.2
*
* Copyright (c) 2002-2004 The Trustees of Indiana University.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1) All redistributions of source code must retain the above
* copyright notice, the list of authors in the original source
* code, this list of conditions and the disclaimer listed in this
* license;
*
* 2) All redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the disclaimer
* listed in this license in the documentation and/or other
* materials provided with the distribution;
*
* 3) Any documentation included with all redistributions must include
* the following acknowledgement:
*
* "This product includes software developed by the Indiana
* University Extreme! Lab. For further information please visit
* http://www.extreme.indiana.edu/"
*
* Alternatively, this acknowledgment may appear in the software
* itself, and wherever such third-party acknowledgments normally
* appear.
*
* 4) The name "Indiana University" or "Indiana University
* Extreme! Lab" shall not be used to endorse or promote
* products derived from this software without prior written
* permission from Indiana University. For written permission,
* please contact http://www.extreme.indiana.edu/.
*
* 5) Products derived from this software may not use "Indiana
* University" name nor may "Indiana University" appear in their name,
* without prior written permission of the Indiana University.
*
* Indiana University provides no reassurances that the source code
* provided does not infringe the patent or any other intellectual
* property rights of any other entity. Indiana University disclaims any
* liability to any recipient for claims brought by any other entity
* based on infringement of intellectual property rights or otherwise.
*
* LICENSEE UNDERSTANDS THAT SOFTWARE IS PROVIDED "AS IS" FOR WHICH
* NO WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. INDIANA
* UNIVERSITY GIVES NO WARRANTIES AND MAKES NO REPRESENTATION THAT
* SOFTWARE IS FREE OF INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR
* OTHER PROPRIETARY RIGHTS. INDIANA UNIVERSITY MAKES NO WARRANTIES THAT
* SOFTWARE IS FREE FROM "BUGS", "VIRUSES", "TROJAN HORSES", "TRAP
* DOORS", "WORMS", OR OTHER HARMFUL CODE. LICENSEE ASSUMES THE ENTIRE
* RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR ASSOCIATED MATERIALS,
* AND TO THE PERFORMANCE AND VALIDITY OF INFORMATION GENERATED USING
* SOFTWARE.
*/
xpp3-1.1.4c/src/java/mxp1_standard/org/xmlpull/mxp1/MXParserFactory.java 100644 0 0 10604 10525225062 25211 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
/*
* Copyright (c) 2002-2004 Extreme! Lab, Indiana University. All rights reserved.
*
* This software is open source. See the bottom of this file for the licence.
*
* $Id: MXParserFactory.java,v 1.6 2004/03/02 09:14:41 aslom Exp $
*/
package org.xmlpull.mxp1;
import java.util.Enumeration;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
import org.xmlpull.mxp1_serializer.MXSerializer;
/**
* Simple facotry to speed up creation process.
*
* @author Aleksander Slominski
*/
public class MXParserFactory
extends XmlPullParserFactory
{
protected static boolean stringCachedParserAvailable = true;
public XmlPullParser newPullParser() throws XmlPullParserException {
XmlPullParser pp = null;
if(stringCachedParserAvailable) {
try {
pp = new MXParserCachingStrings();
} catch(Exception ex) {
stringCachedParserAvailable = false;
}
}
if(pp == null) {
pp = new MXParser();
}
for (Enumeration e = features.keys (); e.hasMoreElements ();) {
final String key = (String) e.nextElement();
final Boolean value = (Boolean) features.get(key);
if(value != null && value.booleanValue()) {
pp.setFeature(key, true);
}
}
return pp;
}
public XmlSerializer newSerializer() throws XmlPullParserException {
return new MXSerializer();
}
}
/*
* Indiana University Extreme! Lab Software License, Version 1.2
*
* Copyright (c) 2002-2004 The Trustees of Indiana University.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1) All redistributions of source code must retain the above
* copyright notice, the list of authors in the original source
* code, this list of conditions and the disclaimer listed in this
* license;
*
* 2) All redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the disclaimer
* listed in this license in the documentation and/or other
* materials provided with the distribution;
*
* 3) Any documentation included with all redistributions must include
* the following acknowledgement:
*
* "This product includes software developed by the Indiana
* University Extreme! Lab. For further information please visit
* http://www.extreme.indiana.edu/"
*
* Alternatively, this acknowledgment may appear in the software
* itself, and wherever such third-party acknowledgments normally
* appear.
*
* 4) The name "Indiana University" or "Indiana University
* Extreme! Lab" shall not be used to endorse or promote
* products derived from this software without prior written
* permission from Indiana University. For written permission,
* please contact http://www.extreme.indiana.edu/.
*
* 5) Products derived from this software may not use "Indiana
* University" name nor may "Indiana University" appear in their name,
* without prior written permission of the Indiana University.
*
* Indiana University provides no reassurances that the source code
* provided does not infringe the patent or any other intellectual
* property rights of any other entity. Indiana University disclaims any
* liability to any recipient for claims brought by any other entity
* based on infringement of intellectual property rights or otherwise.
*
* LICENSEE UNDERSTANDS THAT SOFTWARE IS PROVIDED "AS IS" FOR WHICH
* NO WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. INDIANA
* UNIVERSITY GIVES NO WARRANTIES AND MAKES NO REPRESENTATION THAT
* SOFTWARE IS FREE OF INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR
* OTHER PROPRIETARY RIGHTS. INDIANA UNIVERSITY MAKES NO WARRANTIES THAT
* SOFTWARE IS FREE FROM "BUGS", "VIRUSES", "TROJAN HORSES", "TRAP
* DOORS", "WORMS", OR OTHER HARMFUL CODE. LICENSEE ASSUMES THE ENTIRE
* RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR ASSOCIATED MATERIALS,
* AND TO THE PERFORMANCE AND VALIDITY OF INFORMATION GENERATED USING
* SOFTWARE.
*/
xpp3-1.1.4c/src/java/mxp1_standard/org/xmlpull/mxp1/MXParserNonValidating.java 100644 0 0 33703 10525225062 26344 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
/*
* Copyright (c) 2002-2004 Extreme! Lab, Indiana University. All rights reserved.
*
* This software is open source. See the bottom of this file for the licence.
*
* $Id: MXParserNonValidating.java,v 1.6 2004/03/02 09:14:41 aslom Exp $
*/
package org.xmlpull.mxp1;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParserException;
/**
* Extend MXP parser to be full non validating XML 1.0 parser
* (added internal DTD parsing and support for full XML 1.0 (or 1.1) character classes).
*
* @author Aleksander Slominski
*/
public class MXParserNonValidating extends MXParserCachingStrings
{
private boolean processDocDecl;
public MXParserNonValidating() {
super();
}
/**
* This allows to change processing DOCDECL (controls if parser is non-validating).
*/
public void setFeature(String name,
boolean state) throws XmlPullParserException
{
if(FEATURE_PROCESS_DOCDECL.equals(name)) {
if(eventType != START_DOCUMENT) throw new XmlPullParserException(
"process DOCDECL feature can only be changed before parsing", this, null);
processDocDecl = state;
if(state == false) {
//
}
} else {
super.setFeature(name, state);
}
}
public boolean getFeature(String name)
{
if(FEATURE_PROCESS_DOCDECL.equals(name)) {
return processDocDecl;
} else {
return super.getFeature(name);
}
}
// will need to overwrite more() and processEntityRef ...
protected char more() throws IOException, XmlPullParserException {
return super.more();
}
protected char[] lookuEntityReplacement(int entitNameLen)
throws XmlPullParserException, IOException
{
if(!allStringsInterned) {
final int hash = fastHash(buf, posStart, posEnd - posStart);
LOOP:
for (int i = entityEnd - 1; i >= 0; --i)
{
if(hash == entityNameHash[ i ] && entitNameLen == entityNameBuf[ i ].length) {
final char[] entityBuf = entityNameBuf[ i ];
for (int j = 0; j < entitNameLen; j++)
{
if(buf[posStart + j] != entityBuf[j]) continue LOOP;
}
if(tokenize) text = entityReplacement[ i ];
return entityReplacementBuf[ i ];
}
}
} else {
entityRefName = newString(buf, posStart, posEnd - posStart);
for (int i = entityEnd - 1; i >= 0; --i)
{
// take advantage that interning for newStirng is enforced
if(entityRefName == entityName[ i ]) {
if(tokenize) text = entityReplacement[ i ];
return entityReplacementBuf[ i ];
}
}
}
return null;
}
protected void parseDocdecl()
throws XmlPullParserException, IOException
{
//make sure that tokenize flag is disabled temporarily!!!!
final boolean oldTokenize = tokenize;
try {
//ASSUMPTION: seen '
ch = requireNextS();
int nameStart = pos;
ch = readName(ch);
int nameEnd = pos;
ch = skipS(ch);
// [75] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral
if(ch == 'S' || ch == 'P') {
ch = processExternalId(ch);
ch = skipS(ch);
}
if(ch == '[') {
processInternalSubset();
}
ch = skipS(ch);
if(ch != '>') {
throw new XmlPullParserException(
"expected > to finish <[DOCTYPE but got "+printable(ch), this, null);
}
posEnd = pos - 1;
} finally {
tokenize = oldTokenize;
}
}
protected char processExternalId(char ch)
throws XmlPullParserException, IOException
{
// [75] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral
// [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
// [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
// [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
//TODO
return ch;
}
protected void processInternalSubset()
throws XmlPullParserException, IOException
{
// [28] ... (markupdecl | DeclSep)* ']' // [WFC: External Subset]
// [28a] DeclSep ::= PEReference | S // [WFC: PE Between Declarations]
// [69] PEReference ::= '%' Name ';' //[WFC: No Recursion] [WFC: In DTD]
while(true) {
char ch = more(); // firs ttime called it will skip initial "["
if(ch == ']') break;
if(ch == '%') {
processPEReference();
} else if(isS(ch)) {
ch = skipS(ch);
} else {
processMarkupDecl(ch);
}
}
}
protected void processPEReference()
throws XmlPullParserException, IOException
{
//TODO
}
protected void processMarkupDecl(char ch)
throws XmlPullParserException, IOException
{
// [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | NotationDecl | PI | Comment
// [WFC: PEs in Internal Subset]
//BIG SWITCH statement
if(ch != '<') {
throw new XmlPullParserException("expected < for markupdecl in DTD not "+printable(ch),
this, null);
}
ch = more();
if(ch == '?') {
parsePI();
} else if(ch == '!') {
ch = more();
if(ch == '-') {
// note: if(tokenize == false) posStart/End is NOT changed!!!!
parseComment();
} else {
ch = more();
if(ch == 'A') {
processAttlistDecl(ch); //A-TTLIST
} else if(ch == 'E') {
ch = more();
if(ch == 'L') {
processElementDecl(ch); //EL-EMENT
} else if(ch == 'N') {
processEntityDecl(ch); // EN-TITY
} else {
throw new XmlPullParserException(
"expected ELEMENT or ENTITY after '
//???? [VC: Unique Element Type Declaration]
// [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
// [47] children ::= (choice | seq) ('?' | '*' | '+')?
// [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')?
// [49] choice ::= '(' S? cp ( S? '|' S? cp )+ S? ')'
// [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
// [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*'
// | '(' S? '#PCDATA' S? ')'
//assert ch == 'L'
ch = requireNextS();
readName(ch);
ch = requireNextS();
// readContentSpec(ch);
}
protected void processAttlistDecl(char ch)
throws XmlPullParserException, IOException
{
// [52] AttlistDecl ::= ''
// [53] AttDef ::= S Name S AttType S DefaultDecl
// [54] AttType ::= StringType | TokenizedType | EnumeratedType
// [55] StringType ::= 'CDATA'
// [56] TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' | 'ENTITIES' | 'NMTOKEN'
// | 'NMTOKENS'
// [57] EnumeratedType ::= NotationType | Enumeration
// [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'
// [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'
// [60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' | (('#FIXED' S)? AttValue)
// [WFC: No < in Attribute Values]
//assert ch == 'A'
}
protected void processEntityDecl(char ch)
throws XmlPullParserException, IOException
{
// [70] EntityDecl ::= GEDecl | PEDecl
// [71] GEDecl ::= ''
// [72] PEDecl ::= ''
// [73] EntityDef ::= EntityValue | (ExternalID NDataDecl?)
// [74] PEDef ::= EntityValue | ExternalID
// [75] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral
//[9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"'
// | "'" ([^%&'] | PEReference | Reference)* "'"
//assert ch == 'N'
}
protected void processNotationDecl(char ch)
throws XmlPullParserException, IOException
{
// [82] NotationDecl ::= ''
// [83] PublicID ::= 'PUBLIC' S PubidLiteral
//assert ch == 'N'
}
protected char readName(char ch)
throws XmlPullParserException, IOException
{
if(isNameStartChar(ch)) {
throw new XmlPullParserException(
"XML name must start with name start character not "+printable(ch), this, null);
}
while(isNameChar(ch)) {
ch = more();
}
return ch;
}
}
/*
* Indiana University Extreme! Lab Software License, Version 1.2
*
* Copyright (c) 2002-2004 The Trustees of Indiana University.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1) All redistributions of source code must retain the above
* copyright notice, the list of authors in the original source
* code, this list of conditions and the disclaimer listed in this
* license;
*
* 2) All redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the disclaimer
* listed in this license in the documentation and/or other
* materials provided with the distribution;
*
* 3) Any documentation included with all redistributions must include
* the following acknowledgement:
*
* "This product includes software developed by the Indiana
* University Extreme! Lab. For further information please visit
* http://www.extreme.indiana.edu/"
*
* Alternatively, this acknowledgment may appear in the software
* itself, and wherever such third-party acknowledgments normally
* appear.
*
* 4) The name "Indiana University" or "Indiana University
* Extreme! Lab" shall not be used to endorse or promote
* products derived from this software without prior written
* permission from Indiana University. For written permission,
* please contact http://www.extreme.indiana.edu/.
*
* 5) Products derived from this software may not use "Indiana
* University" name nor may "Indiana University" appear in their name,
* without prior written permission of the Indiana University.
*
* Indiana University provides no reassurances that the source code
* provided does not infringe the patent or any other intellectual
* property rights of any other entity. Indiana University disclaims any
* liability to any recipient for claims brought by any other entity
* based on infringement of intellectual property rights or otherwise.
*
* LICENSEE UNDERSTANDS THAT SOFTWARE IS PROVIDED "AS IS" FOR WHICH
* NO WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. INDIANA
* UNIVERSITY GIVES NO WARRANTIES AND MAKES NO REPRESENTATION THAT
* SOFTWARE IS FREE OF INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR
* OTHER PROPRIETARY RIGHTS. INDIANA UNIVERSITY MAKES NO WARRANTIES THAT
* SOFTWARE IS FREE FROM "BUGS", "VIRUSES", "TROJAN HORSES", "TRAP
* DOORS", "WORMS", OR OTHER HARMFUL CODE. LICENSEE ASSUMES THE ENTIRE
* RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR ASSOCIATED MATERIALS,
* AND TO THE PERFORMANCE AND VALIDITY OF INFORMATION GENERATED USING
* SOFTWARE.
*/
xpp3-1.1.4c/src/java/mxp1_standard/org/xmlpull/mxp1/package.html 100644 0 0 424 10525225062 23535 0 ustar aslom ewww 0 0
Contains XPP3 implementation of XMLPULL V1 API .
xpp3-1.1.4c/src/java/parser_pool/org/xmlpull/v1/parser_pool/XmlPullParserPool.java 100644 0 0 4677 10525225063 27330 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.parser_pool;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
// add aging so parser used more than X times is not resused ...
/**
* Very simple utility to make pooling of XmlPull parsers easy.
*
* @author Aleksander Slominski
*/
public class XmlPullParserPool {
protected List pool = new ArrayList();
protected XmlPullParserFactory factory;
public XmlPullParserPool() throws XmlPullParserException {
this(XmlPullParserFactory.newInstance());
}
public XmlPullParserPool(XmlPullParserFactory factory) {
if(factory == null) throw new IllegalArgumentException();
this.factory = factory;
}
protected XmlPullParser newParser() throws XmlPullParserException {
return factory.newPullParser();
}
public XmlPullParser getPullParserFromPool()
throws XmlPullParserException
{
XmlPullParser pp = null;
if(pool.size() > 0) {
synchronized(pool) {
if(pool.size() > 0) {
pp = (XmlPullParser) pool.remove(pool.size() - 1);
}
}
}
if(pp == null) {
pp = newParser();
//System.err.println("new parser instance created pp="+pp);
}
return pp;
}
public void returnPullParserToPool(XmlPullParser pp) {
if(pp == null) throw new IllegalArgumentException();
synchronized(pool) {
pool.add(pp);
}
}
// simple inline test
public static void main(String[] args) throws Exception
{
//XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
//XmlPullParserPool pool = new XmlPullParserPool(factory);
XmlPullParserPool pool = new XmlPullParserPool();
XmlPullParser p1 = pool.getPullParserFromPool();
pool.returnPullParserToPool(p1);
XmlPullParser p2 = pool.getPullParserFromPool();
//assert p1 == p2;
if(p1 != p2) throw new RuntimeException();
pool.returnPullParserToPool(p2);
System.out.println(pool.getClass()+" OK");
}
}
xpp3-1.1.4c/src/java/samples/BestDeal.java 100644 0 0 11250 10525225062 17367 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
import org.xmlpull.v1.*;
import java.io.*;
import java.text.MessageFormat;
/**
* Rewritten http://www-106.ibm.com/developerworks/xml/library/x-saxapi/listing4.html
* to make easy to comapre how to "natutal is to manage state with SAX and with XMLPULL API.
* For details see: http://www-106.ibm.com/developerworks/xml/library/x-saxapi/
*/
public class BestDeal {
protected static final String MESSAGE =
"The best deal is proposed by {0}. "
+ "A(n) {1} delivered in {2,number,integer} days for "
+ "{3,number,currency}";
protected static final String NAMESPACE_URI =
"http://www.psol.com/xbe2/listing8.3";
/**
* properties we are collecting: best price, delivery time,
* product and vendor names
*/
public double price = Double.MAX_VALUE;
public int delivery = Integer.MAX_VALUE;
public String product = null;
public String vendor = null;
/**
* target delivery value (refuse elements above this target)
*/
protected int targetDelivery;
/**
* creates an "empty" BestDeal with the given target for delivery
* @param td the target for delivery
*/
public BestDeal(int td) {
targetDelivery = td;
}
/**
* updates the best deal from the given list in the format
*/
public void update(XmlPullParser parser)
throws IOException, XmlPullParserException {
parser.require(XmlPullParser.START_DOCUMENT, null, null);
parser.nextTag();
parser.require(XmlPullParser.START_TAG, NAMESPACE_URI, "price-list");
parser.nextTag();
parser.require(XmlPullParser.START_TAG, NAMESPACE_URI, "name");
product = parser.nextText();
parser.require(XmlPullParser.END_TAG, NAMESPACE_URI, "name");
while (parser.nextTag() == XmlPullParser.START_TAG) {
checkVendor(parser);
}
parser.require(XmlPullParser.END_TAG, NAMESPACE_URI, "price-list");
parser.next();
parser.require(XmlPullParser.END_DOCUMENT, null, null);
}
/** subroutine handling a single vendor */
public void checkVendor(XmlPullParser parser)
throws IOException, XmlPullParserException {
parser.require(XmlPullParser.START_TAG, NAMESPACE_URI, "vendor");
String currentVendor = null;
while (parser.nextTag() == XmlPullParser.START_TAG) {
parser.require(XmlPullParser.START_TAG, NAMESPACE_URI, null);
String name = parser.getName();
if (name.equals("name")) {
currentVendor = parser.nextText();
} else if (name.equals("price-quote")) {
int currentDelivery =
Integer.parseInt(parser.getAttributeValue("", "delivery"));
double currentPrice = Double.parseDouble(parser.nextText());
if (currentDelivery < targetDelivery && currentPrice < price) {
vendor = currentVendor;
price = currentPrice;
delivery = currentDelivery;
}
} else {
System.out.println("trying to skip unknwon element: "+ name);
String content = parser.nextText();
System.out.println("skipped element content:" + content);
}
parser.require(XmlPullParser.END_TAG, NAMESPACE_URI, name);
}
parser.require(XmlPullParser.END_TAG, NAMESPACE_URI, "vendor");
}
/**
* main() method
* decodes command-line parameters and invoke the parser
* @param args command-line argument
* @throw Exception catch-all for underlying exceptions
*/
public static void main(String[] args)
throws IOException, XmlPullParserException {
if (args.length < 2) {
System.out.println("BestDeal ");
return;
}
BestDeal bestDeal = new BestDeal(Integer.parseInt(args[1]));
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
InputStream is = new FileInputStream(args[0]);
parser.setInput(is, null);
bestDeal.update(parser);
is.close();
Object[] objects =
new Object[] {
bestDeal.vendor,
bestDeal.product,
new Integer(bestDeal.delivery),
new Double(bestDeal.price)};
System.out.println(MessageFormat.format(MESSAGE, objects));
}
}
xpp3-1.1.4c/src/java/samples/LICENSE.txt 100644 0 0 562 10525225062 16630 0 ustar aslom ewww 0 0 XMLPULL API IS FREE
-------------------
All of the XMLPULL API source code, compiled code, and documentation
contained in this distribution *except* for tests (see separate LICENSE_TESTS.txt)
are in the Public Domain.
XMLPULL API comes with NO WARRANTY or guarantee of fitness for any purpose.
Initial authors:
Stefan Haustein
Aleksander Slominski
2001-12-12
xpp3-1.1.4c/src/java/samples/MyXmlPullApp.java 100644 0 0 11150 10525225062 20247 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
/**
* An example of an application that uses XMLPULL V1 API.
*
* @author Aleksander Slominski
*/
public class MyXmlPullApp
{
public final static String SAMPLE_XML =
"\n"+
"\n"+
"\n"+
"Roses are Red \n"+
"Roses are red, \n"+
"Violets are blue; \n"+
"Sugar is sweet, \n"+
"And I love you. \n"+
" ";
public static void main (String args[])
throws XmlPullParserException, IOException
{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
//factory.setNamespaceAware(true);
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
XmlPullParser xpp = factory.newPullParser();
System.out.println("parser implementation class is "+xpp.getClass());
MyXmlPullApp app = new MyXmlPullApp();
if(args.length == 0) {
System.out.println("Parsing simple sample XML");//:\n"+ SAMPLE_XML);
xpp.setInput( new StringReader( SAMPLE_XML ) );
app.processDocument(xpp);
} else {
for (int i = 0; i < args.length; i++) {
System.out.println("Parsing file: "+args[i]);
xpp.setInput ( new FileReader ( args [i] ) );
//xpp.setInput ( new InputStreamReader( new FileInputStream ( args [i] ) ) );
//xpp.setInput ( new FileInputStream ( args [i] ), "UTF8" );
app.processDocument(xpp);
}
}
}
public void processDocument(XmlPullParser xpp)
throws XmlPullParserException, IOException
{
int eventType = xpp.getEventType();
do {
if(eventType == XmlPullParser.START_DOCUMENT) {
System.out.println("Start document");
} else if(eventType == XmlPullParser.END_DOCUMENT) {
System.out.println("End document");
} else if(eventType == XmlPullParser.START_TAG) {
processStartElement(xpp);
} else if(eventType == XmlPullParser.END_TAG) {
processEndElement(xpp);
} else if(eventType == XmlPullParser.TEXT) {
processText(xpp);
}
eventType = xpp.next();
} while (eventType != XmlPullParser.END_DOCUMENT);
}
public void processStartElement (XmlPullParser xpp)
{
String name = xpp.getName();
String uri = xpp.getNamespace();
if ("".equals (uri)) {
System.out.println("Start element: " + name);
} else {
System.out.println("Start element: {" + uri + "}" + name);
}
}
public void processEndElement (XmlPullParser xpp)
{
String name = xpp.getName();
String uri = xpp.getNamespace();
if ("".equals (uri))
System.out.println("End element: " + name);
else
System.out.println("End element: {" + uri + "}" + name);
}
int holderForStartAndLength[] = new int[2];
public void processText (XmlPullParser xpp) throws XmlPullParserException
{
char ch[] = xpp.getTextCharacters(holderForStartAndLength);
int start = holderForStartAndLength[0];
int length = holderForStartAndLength[1];
System.out.print("Characters: \"");
for (int i = start; i < start + length; i++) {
switch (ch[i]) {
case '\\':
System.out.print("\\\\");
break;
case '"':
System.out.print("\\\"");
break;
case '\n':
System.out.print("\\n");
break;
case '\r':
System.out.print("\\r");
break;
case '\t':
System.out.print("\\t");
break;
default:
System.out.print(ch[i]);
break;
}
}
System.out.print("\"\n");
}
}
xpp3-1.1.4c/src/java/samples/MyXmlWriteApp.java 100644 0 0 7276 10525225062 20423 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
import java.io.IOException;
import java.io.PrintWriter;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
/**
* An example of an application that uses XmlPull v1 API to write XML.
*
* @author Aleksander Slominski
*/
public class MyXmlWriteApp {
private final static String NAMESPACE = "http://www.megginson.com/ns/exp/poetry";
public static void main (String args[])
throws XmlPullParserException, IOException {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
XmlSerializer serializer = factory.newSerializer();
System.out.println("serializer implementation class is "+serializer.getClass());
boolean addNewLine = false;
int argPos = 0;
while(argPos < args.length)
{
String arg = args[argPos];
if("-n".equals(arg) ) {
addNewLine = true;
} else if("-i".equals(arg)) {
// set indentation to number of spaces passed as argument
String s = args[++argPos];
int indentSize = Integer.parseInt(s);
StringBuffer buf = new StringBuffer(indentSize);
for (int i = 0; i < indentSize; i++)
{
buf.append(' ');
}
String indent = buf.toString();
// this is optional propery
serializer.setProperty(
"http://xmlpull.org/v1/doc/properties.html#serializer-indentation", indent);
}
++argPos;
}
// set output
serializer.setOutput(new PrintWriter( System.out ));
// first write XML declaration
serializer.startDocument(null, null);
// add some empty lines before first start tag
serializer.ignorableWhitespace("\n\n");
// if prefix is not set serializer will generate automatically prefix
// we overwrite this mechanism and manually namespace to be default (empty prefix)
serializer.setPrefix("", NAMESPACE);
serializer.startTag(NAMESPACE, "poem");
if(addNewLine) serializer.text("\n");
serializer.startTag(NAMESPACE, "title");
serializer.text("Roses are Red");
serializer.endTag(NAMESPACE, "title");
if(addNewLine) serializer.text("\n");
serializer.startTag(NAMESPACE, "l")
.text("Roses are red,")
.endTag(NAMESPACE, "l");
if(addNewLine) serializer.text("\n");
//multiple operations can be also combined to get shorter syntax
serializer.startTag(NAMESPACE, "l").text("Violets are blue;").endTag(NAMESPACE, "l");
if(addNewLine) serializer.text("\n");
// or writing can be delegate to specialized functions
writeLine(serializer, "Sugar is sweet,", addNewLine);
writeLine(serializer, "And I love you.,", addNewLine);
serializer.endTag(NAMESPACE, "poem");
// this will ensure that output is flushed and prevent from writing to serializer
serializer.endDocument();
}
private static void writeLine(XmlSerializer serializer, String line, boolean addNewLine)
throws IOException {
serializer.startTag(NAMESPACE, "l");
serializer.text(line);
serializer.endTag(NAMESPACE, "l");
if(addNewLine) serializer.text("\n");
}
}
xpp3-1.1.4c/src/java/samples/README.txt 100644 0 0 63 10525225062 16457 0 ustar aslom ewww 0 0 place for samples demonstrating use of XMLPULL API
xpp3-1.1.4c/src/java/samples/RSSReader.java 100644 0 0 11467 10525225062 17510 0 ustar aslom ewww 0 0 // modified by Aleksander Slominski
// based on http://www.xml.com/pub/a/2002/05/22/parsing.html?page=2
import java.io.*;
import java.net.*;
import org.xmlpull.v1.*;
public class RSSReader {
public static void main(String [] args)
{
// create an instance of RSSReader
RSSReader rssreader = new RSSReader();
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
String url = args[0];
InputStreamReader stream = new InputStreamReader(
new URL(url).openStream());
parser.setInput(stream);
XmlSerializer writer = factory.newSerializer();
writer.setOutput(new OutputStreamWriter(System.out));
rssreader.convertRSSToHtml(parser, writer);
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
public void convertRSSToHtml(XmlPullParser parser, XmlSerializer writer)
throws IOException, XmlPullParserException
{
//
if (parser.nextTag() == XmlPullParser.START_TAG
&& parser.getName().equals("rss"))
{
writer.startTag(null,"html");
if (parser.nextTag() == XmlPullParser.START_TAG
&& parser.getName().equals("channel"))
{
convertChannelToHtml(parser, writer);
parser.require(XmlPullParser.END_TAG, null, "channel");
} else {
new RuntimeException("expectd channel start tag not "+parser.getPositionDescription());
}
parser.nextTag();
parser.require(XmlPullParser.END_TAG, null, "rss");
writer.endTag(null, "html");
writer.flush();
} else {
throw new RuntimeException("expectd an RSS document at" + parser.getPositionDescription());
}
}
public void convertChannelToHtml(XmlPullParser parser, XmlSerializer writer)
throws IOException, XmlPullParserException
{
//
boolean seenBody = false; //assumption that title is before items ...
while (parser.nextTag() != XmlPullParser.END_TAG) { // this guranteed by well formednes of XML && parser.getName().equals("channel"))) {
// if (parser.getEventType() == XmlPullParser.START_TAG) { //guranteed by nextTag
//
if(parser.getName().equals("title") && !seenBody) {
writer.startTag(null,"head");
writer.startTag(null,"title").text(parser.nextText()).endTag(null,"title");
writer.endTag(null,"head");
} else if(parser.getName().equals("item")) {
if(!seenBody) {
writer.startTag(null, "body");
seenBody = true;
}
convertItemToHtml(parser, writer);
} else {
// skip any element content including sub elements...
int level = 1;
while (level > 0) {
switch(parser.next()) {
case XmlPullParser.START_TAG: ++level; break;
case XmlPullParser.END_TAG: --level; break;
}
}
}
}
if(seenBody) writer.endTag(null, "body");
}
public void convertItemToHtml(XmlPullParser parser, XmlSerializer writer)
throws IOException, XmlPullParserException
{
writer.startTag(null, "p");
//
String title = null, link = null, description = null;
while (parser.nextTag() != XmlPullParser.END_TAG) {
if (parser.getName().equals("title")) {
title = parser.nextText();
} else if (parser.getName().equals("link")) {
link = parser.nextText();
} else if (parser.getName().equals("description")) {
description = parser.nextText();
}
}
//HashMap attributes = new HashMap(1);
//if(link != null) attributes.put("href", link);
//writer.beginElement("a",attributes);
writer.startTag(null, "a");
writer.attribute(null, "href", link);
if(title != null) {
writer.text(title);
} else {
writer.text(link);
}
writer.endTag(null,"a");
//writer.writeEmptyElement("br");
writer.startTag(null, "br").endTag(null, "br");
if(description != null) writer.text(description);
writer.endTag(null, "p"); // end the "p" element
}
}
xpp3-1.1.4c/src/java/samples/Roundtrip.java 100644 0 0 14505 10525225062 17700 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
//package org.xmlpull.v1.samples;
import java.io.*;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
/**
* This sample demonstrates how to roundtrip XML document
* (roundtrip is not exact but infoset level)
*/
public class Roundtrip {
private final static String PROPERTY_XMLDECL_STANDALONE =
"http://xmlpull.org/v1/doc/features.html#xmldecl-standalone";
private final static String PROPERTY_SERIALIZER_INDENTATION =
"http://xmlpull.org/v1/doc/properties.html#serializer-indentation";
private XmlPullParser parser;
private XmlSerializer serializer;
private Roundtrip (XmlPullParser parser, XmlSerializer serializer) {
this.parser = parser;
this.serializer = serializer;
}
private void writeStartTag () throws XmlPullParserException, IOException {
//check for case when feature xml roundtrip is supported
//if (parser.getFeature (FEATURE_XML_ROUNDTRIP)) {
if (!parser.getFeature (XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES)) {
for (int i = parser.getNamespaceCount (parser.getDepth ()-1);
i <= parser.getNamespaceCount (parser.getDepth ())-1; i++) {
serializer.setPrefix
(parser.getNamespacePrefix (i),
parser.getNamespaceUri (i));
}
}
serializer.startTag(parser.getNamespace (), parser.getName ());
for (int i = 0; i < parser.getAttributeCount (); i++) {
serializer.attribute
(parser.getAttributeNamespace (i),
parser.getAttributeName (i),
parser.getAttributeValue (i));
}
//serializer.closeStartTag();
}
private void writeToken (int eventType) throws XmlPullParserException, IOException {
switch (eventType) {
case XmlPullParser.START_DOCUMENT:
//use Boolean.TRUE to make it standalone
Boolean standalone = (Boolean) parser.getProperty(PROPERTY_XMLDECL_STANDALONE);
serializer.startDocument(parser.getInputEncoding(), standalone);
break;
case XmlPullParser.END_DOCUMENT:
serializer.endDocument();
break;
case XmlPullParser.START_TAG:
writeStartTag ();
break;
case XmlPullParser.END_TAG:
serializer.endTag(parser.getNamespace (), parser.getName ());
break;
case XmlPullParser.IGNORABLE_WHITESPACE:
//comment it to remove ignorable whtespaces from XML infoset
String s = parser.getText ();
serializer.ignorableWhitespace (s);
break;
case XmlPullParser.TEXT:
serializer.text (parser.getText ());
break;
case XmlPullParser.ENTITY_REF:
serializer.entityRef (parser.getName ());
break;
case XmlPullParser.CDSECT:
serializer.cdsect( parser.getText () );
break;
case XmlPullParser.PROCESSING_INSTRUCTION:
serializer.processingInstruction( parser.getText ());
break;
case XmlPullParser.COMMENT:
serializer.comment (parser.getText ());
break;
case XmlPullParser.DOCDECL:
serializer.docdecl (parser.getText ());
break;
}
}
private void roundTrip() throws XmlPullParserException, IOException {
parser.nextToken(); // read first token
writeToken (XmlPullParser.START_DOCUMENT); // write optional XMLDecl if present
while (parser.getEventType () != XmlPullParser.END_DOCUMENT) {
writeToken ( parser.getEventType () );
parser.nextToken ();
}
writeToken (XmlPullParser.END_DOCUMENT);
}
private static void roundTrip(Reader reader, Writer writer, String indent)
throws XmlPullParserException, IOException
{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser pp = factory.newPullParser();
pp.setInput(reader);
XmlSerializer serializer = factory.newSerializer();
serializer.setOutput( writer );
if(indent != null) {
serializer.setProperty(PROPERTY_SERIALIZER_INDENTATION, indent);
}
(new Roundtrip(pp, serializer)).roundTrip();
}
// public static void main(String[] args) throws Exception {
// String XML = "fdf ";
// Reader r = new StringReader(XML);
// Writer w = new StringWriter();
// roundTrip(r, w, " ");
// System.out.println("indented XML="+w);
// }
private static void roundTrip(XmlPullParserFactory factory, String loc)
throws XmlPullParserException, IOException
{
roundTrip(factory, loc, null);
}
private static void roundTrip(XmlPullParserFactory factory, String loc, String indent)
throws XmlPullParserException, IOException
{
XmlPullParser pp = factory.newPullParser();
pp.setInput(new java.net.URL(loc).openStream(), null);
XmlSerializer serializer = factory.newSerializer();
serializer.setOutput( System.out, null);
if(indent != null) {
serializer.setProperty(PROPERTY_SERIALIZER_INDENTATION, indent);
}
(new Roundtrip(pp, serializer)).roundTrip();
}
public static void main(String[] args) throws Exception {
//for (int i = 0; i < args.length; i++)
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
for (int i = 0; i < 1; i++)
{
roundTrip(factory, args[i], " ");
}
}
}
xpp3-1.1.4c/src/java/samples/SimpleXmlPullApp.java 100644 0 0 3477 10525225062 21110 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
import java.io.IOException;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
/**
* Very simple application that demonstrates basics of XMLPULL V1 API.
*
* @author Aleksander Slominski
*/
public class SimpleXmlPullApp
{
public static void main (String args[])
throws XmlPullParserException, IOException
{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
//factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
XmlPullParser xpp = factory.newPullParser();
System.out.println("parser implementation class is "+xpp.getClass());
xpp.setInput ( new StringReader ( "Hello World! " ) );
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
System.out.println("Start document");
} else if(eventType == XmlPullParser.END_DOCUMENT) {
System.out.println("End document");
} else if(eventType == XmlPullParser.START_TAG) {
System.out.println("Start tag "+xpp.getName());
} else if(eventType == XmlPullParser.END_TAG) {
System.out.println("End tag "+xpp.getName());
} else if(eventType == XmlPullParser.TEXT) {
System.out.println("Text "+xpp.getText());
}
eventType = xpp.next();
}
}
}
xpp3-1.1.4c/src/java/samples/XMLRPCDecoder.java 100644 0 0 77136 10525225062 20216 0 ustar aslom ewww 0 0 //
// ===========================================================================
//
// Title: XMLRPCDecoder.java
// Description: [Description]
// Author: Raphael Szwarc
// http://guests.evectors.it/zoe/
// Creation Date: Sun Nov 24 2002
// Legal: Copyright (c) 2002-2004 Raphael Szwarc. All Rights Reserved.
//
// For license information please see XPP3's LICENSE.txt file
// Also available at http://www.xmlpull.org/
//
// ---------------------------------------------------------------------------
//
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParser;
import java.io.Reader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.OutputStream;
import java.io.BufferedOutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
public abstract class XMLRPCDecoder extends Object
{
// ===========================================================================
// Constant(s)
// ---------------------------------------------------------------------------
private static final Class[] Classes =
{
FaultDecoder.class,
MethodDecoder.class,
ParametersDecoder.class,
ArrayDecoder.class,
StructureDecoder.class,
ValueDecoder.class,
IntegerDecoder.class,
BooleanDecoder.class,
StringDecoder.class,
DoubleDecoder.class,
DateDecoder.class,
Base64Decoder.class
};
// ===========================================================================
// Class variable(s)
// ---------------------------------------------------------------------------
private final static Map _decoders = new HashMap();
// ===========================================================================
// Instance variable(s)
// ---------------------------------------------------------------------------
// ===========================================================================
// Constructor method(s)
// ---------------------------------------------------------------------------
protected XMLRPCDecoder()
{
super();
}
// ===========================================================================
// Class initialization method(s)
// ---------------------------------------------------------------------------
static
{
Class[] someClasses = XMLRPCDecoder.Classes;
int count = someClasses.length;
for ( int index = 0; index < count; index++ )
{
Class aClass = someClasses[ index ];
try
{
XMLRPCDecoder aDecoder = (XMLRPCDecoder) aClass.newInstance();
aDecoder.register( _decoders );
}
catch (Exception anException)
{
throw new RuntimeException( "XMLRPCDecoder.decoders: " + anException );
}
}
}
// ===========================================================================
// Class method(s)
// ---------------------------------------------------------------------------
private static Map decoders()
{
return _decoders;
}
public static Object decode(Reader aReader) throws Exception
{
if ( aReader != null )
{
Map someDecoders = XMLRPCDecoder.decoders();
XmlPullParserFactory aFactory = XmlPullParserFactory.newInstance();
XmlPullParser aParser = aFactory.newPullParser();
aParser.setInput( aReader );
return XMLRPCDecoder.decode( aParser );
}
throw new IllegalArgumentException( "XMLRPCDecoder.decode: null reader." );
}
private static XMLRPCDecoder decoderWithName(String aName)
{
if ( aName != null )
{
return (XMLRPCDecoder) XMLRPCDecoder.decoders().get( aName.toUpperCase() );
}
throw new IllegalArgumentException( "XMLRPCDecoder.decoderWithName: null name." );
}
private static Object decode(XmlPullParser aParser) throws Exception
{
if ( aParser != null )
{
int anEventType = aParser.getEventType();
while ( anEventType != XmlPullParser.END_DOCUMENT )
{
if ( anEventType == XmlPullParser.START_TAG )
{
String aName = aParser.getName();
XMLRPCDecoder aDecoder = XMLRPCDecoder.decoderWithName( aName );
if ( aDecoder != null )
{
return aDecoder.decodeWithParser( aParser );
}
else
{
anEventType = aParser.next();
}
}
else
{
anEventType = aParser.next();
}
}
return null;
}
throw new IllegalArgumentException( "XMLRPCDecoder.decode: null reader." );
}
// ===========================================================================
// Instance method(s)
// ---------------------------------------------------------------------------
protected abstract String[] names();
protected void register(Map aMap)
{
if ( aMap != null )
{
String[] someNames = this.names();
if ( someNames != null )
{
int count = someNames.length;
for ( int index = 0; index < count; index++ )
{
String aName = someNames[ index ];
aMap.put( aName.toUpperCase(), this );
}
return;
}
throw new IllegalStateException( "XMLRPCDecoder.register: null names." );
}
throw new IllegalArgumentException( "XMLRPCDecoder.register: null map." );
}
protected abstract Object decodeWithParser(XmlPullParser aParser) throws Exception;
// ===========================================================================
// FaultDecoder method(s)
// ---------------------------------------------------------------------------
private static final class FaultDecoder extends XMLRPCDecoder
{
private static final String Name = "fault";
private static final String[] Names = { FaultDecoder.Name };
private static final String FaultStringKey = "faultString";
private static final String FaultCodeKey = "faultCode";
protected FaultDecoder()
{
super();
}
protected String[] names()
{
return FaultDecoder.Names;
}
protected Object decodeWithParser(XmlPullParser aParser) throws Exception
{
if ( aParser != null )
{
aParser.require( XmlPullParser.START_TAG, null, FaultDecoder.Name );
aParser.nextTag();
Map aMap = (Map) XMLRPCDecoder.decode( aParser );
Object aValue = null;
if ( aMap != null )
{
String aDescription = (String) aMap.get( FaultDecoder.FaultStringKey );
Number aCode = (Number) aMap.get( FaultDecoder.FaultCodeKey );
aValue = new RuntimeException( aDescription + "(" + aCode + ")" );
}
aParser.require( XmlPullParser.END_TAG, null, FaultDecoder.Name );
aParser.nextTag();
return aValue;
}
throw new IllegalArgumentException( "XMLRPCDecoder.FaultDecoder.decodeWithParser: null parser." );
}
}
// ===========================================================================
// MethodDecoder method(s)
// ---------------------------------------------------------------------------
private static final class MethodDecoder extends XMLRPCDecoder
{
private static final String Name = "methodCall";
private static final String[] Names = { MethodDecoder.Name };
protected MethodDecoder()
{
super();
}
protected String[] names()
{
return MethodDecoder.Names;
}
protected Object decodeWithParser(XmlPullParser aParser) throws Exception
{
if ( aParser != null )
{
aParser.require( XmlPullParser.START_TAG, null, MethodDecoder.Name );
aParser.nextTag();
String aMethodName = aParser.nextText();
Collection someArguments = (Collection) XMLRPCDecoder.decode( aParser );
Map aValue = new HashMap();
aValue.put( "methodName", aMethodName );
aValue.put( "parameters", someArguments );
if ( aParser.getEventType() != XmlPullParser.END_DOCUMENT )
{
aParser.require( XmlPullParser.END_TAG, null, MethodDecoder.Name );
aParser.next();
}
return aValue;
}
throw new IllegalArgumentException( "XMLRPCDecoder.MethodDecoder.decodeWithParser: null parser." );
}
}
// ===========================================================================
// ParametersDecoder method(s)
// ---------------------------------------------------------------------------
private static final class ParametersDecoder extends XMLRPCDecoder
{
private static final String Name = "params";
private static final String ParamName = "param";
private static final String[] Names = { ParametersDecoder.Name };
protected ParametersDecoder()
{
super();
}
protected String[] names()
{
return ParametersDecoder.Names;
}
protected Object decodeWithParser(XmlPullParser aParser) throws Exception
{
if ( aParser != null )
{
Collection aCollection = new ArrayList();
aParser.require( XmlPullParser.START_TAG, null, ParametersDecoder.Name );
aParser.nextTag();
while ( ( aParser.getEventType() != XmlPullParser.END_DOCUMENT ) && ( aParser.getEventType() == XmlPullParser.START_TAG ) )
{
aParser.require( XmlPullParser.START_TAG, null, ParametersDecoder.ParamName );
aParser.nextTag();
aCollection.add( XMLRPCDecoder.decode( aParser ) );
aParser.require( XmlPullParser.END_TAG, null, ParametersDecoder.ParamName );
aParser.nextTag();
}
aParser.require( XmlPullParser.END_TAG, null, ParametersDecoder.Name );
aParser.nextTag();
if ( aCollection.isEmpty() == true )
{
aCollection = null;
}
return aCollection;
}
throw new IllegalArgumentException( "XMLRPCDecoder.ParametersDecoder.decodeWithParser: null parser." );
}
}
// ===========================================================================
// ArrayDecoder method(s)
// ---------------------------------------------------------------------------
private static final class ArrayDecoder extends XMLRPCDecoder
{
private static final String Name = "array";
private static final String DataName = "data";
private static final String[] Names = { ArrayDecoder.Name };
protected ArrayDecoder()
{
super();
}
protected String[] names()
{
return ArrayDecoder.Names;
}
protected Object decodeWithParser(XmlPullParser aParser) throws Exception
{
if ( aParser != null )
{
Collection aCollection = new ArrayList();
aParser.require( XmlPullParser.START_TAG, null, ArrayDecoder.Name );
aParser.nextTag();
aParser.require( XmlPullParser.START_TAG, null, ArrayDecoder.DataName );
aParser.nextTag();
while ( ( aParser.getEventType() != XmlPullParser.END_DOCUMENT ) && ( aParser.getEventType() == XmlPullParser.START_TAG ) )
{
Object aValue = XMLRPCDecoder.decode( aParser );
aCollection.add( aValue );
}
if ( aCollection.isEmpty() == true )
{
aCollection = null;
}
aParser.require( XmlPullParser.END_TAG, null, ArrayDecoder.DataName );
aParser.nextTag();
aParser.require( XmlPullParser.END_TAG, null, ArrayDecoder.Name );
aParser.nextTag();
return aCollection;
}
throw new IllegalArgumentException( "XMLRPCDecoder.ArrayDecoder.decodeWithParser: null parser." );
}
}
// ===========================================================================
// StructureDecoder method(s)
// ---------------------------------------------------------------------------
private static final class StructureDecoder extends XMLRPCDecoder
{
private static final String Name = "struct";
private static final String MemberName = "member";
private static final String NameName = "name";
private static final String[] Names = { StructureDecoder.Name };
protected StructureDecoder()
{
super();
}
protected String[] names()
{
return StructureDecoder.Names;
}
protected Object decodeWithParser(XmlPullParser aParser) throws Exception
{
if ( aParser != null )
{
Map aMap = new HashMap();
aParser.require( XmlPullParser.START_TAG, null, StructureDecoder.Name );
aParser.nextTag();
while ( ( aParser.getEventType() != XmlPullParser.END_DOCUMENT ) && ( aParser.getEventType() == XmlPullParser.START_TAG ) )
{
Object aKey = null;
Object aValue = null;
aParser.require( XmlPullParser.START_TAG, null, StructureDecoder.MemberName );
aParser.nextTag();
aParser.require( XmlPullParser.START_TAG, null, StructureDecoder.NameName );
aKey = aParser.nextText();
aParser.require( XmlPullParser.END_TAG, null, StructureDecoder.NameName );
aValue = XMLRPCDecoder.decode( aParser );
aParser.require( XmlPullParser.END_TAG, null, StructureDecoder.MemberName );
aParser.nextTag();
if ( ( aKey != null ) && ( aValue != null ) )
{
aMap.put( aKey, aValue );
}
}
aParser.require( XmlPullParser.END_TAG, null, StructureDecoder.Name );
aParser.nextTag();
if ( aMap.isEmpty() == true )
{
aMap = null;
}
return aMap;
}
throw new IllegalArgumentException( "XMLRPCDecoder.StructureDecoder.decodeWithParser: null parser." );
}
}
// ===========================================================================
// ArrayDecoder method(s)
// ---------------------------------------------------------------------------
private static final class ValueDecoder extends XMLRPCDecoder
{
private static final String Name = "value";
private static final String[] Names = { ValueDecoder.Name };
protected ValueDecoder()
{
super();
}
protected String[] names()
{
return ValueDecoder.Names;
}
protected Object decodeWithParser(XmlPullParser aParser) throws Exception
{
if ( aParser != null )
{
Object aValue = null;
aParser.require( XmlPullParser.START_TAG, null, ValueDecoder.Name );
aParser.next();
if ( aParser.getEventType() == XmlPullParser.END_TAG )
{
aValue = "";
}
else
//if ( aParser.getEventType() == aParser.TEXT)
//{
// aValue = aParser.getText();
// aParser.next();
//}
//else
{
aValue = XMLRPCDecoder.decode( aParser );
}
aParser.require( XmlPullParser.END_TAG, null, ValueDecoder.Name );
aParser.nextTag();
return aValue;
}
throw new IllegalArgumentException( "XMLRPCDecoder.ValueDecoder.decodeWithParser: null parser." );
}
}
// ===========================================================================
// IntegerDecoder method(s)
// ---------------------------------------------------------------------------
private static final class IntegerDecoder extends XMLRPCDecoder
{
private static final String IntName = "int";
private static final String I4Name = "i4";
private static final String[] Names = { IntegerDecoder.IntName, IntegerDecoder.I4Name };
protected IntegerDecoder()
{
super();
}
protected String[] names()
{
return IntegerDecoder.Names;
}
protected Object decodeWithParser(XmlPullParser aParser) throws Exception
{
if ( aParser != null )
{
String aName = aParser.getName();
aParser.require( XmlPullParser.START_TAG, null, aName );
String aString = aParser.nextText();
Object aValue = null;
if ( aString != null )
{
try
{
aValue = new Integer( aString );
}
catch(Exception anException)
{
System.err.println( anException );
}
}
aParser.require( XmlPullParser.END_TAG, null, aName );
aParser.nextTag();
return aValue;
}
throw new IllegalArgumentException( "XMLRPCDecoder.IntegerDecoder.decodeWithParser: null parser." );
}
}
// ===========================================================================
// BooleanDecoder method(s)
// ---------------------------------------------------------------------------
private static final class BooleanDecoder extends XMLRPCDecoder
{
private static final String Name = "boolean";
private static final String[] Names = { BooleanDecoder.Name };
private static final String False = "0";
protected BooleanDecoder()
{
super();
}
protected String[] names()
{
return BooleanDecoder.Names;
}
protected Object decodeWithParser(XmlPullParser aParser) throws Exception
{
if ( aParser != null )
{
aParser.require( XmlPullParser.START_TAG, null, BooleanDecoder.Name );
String aString = aParser.nextText();
Object aValue = Boolean.TRUE;
if ( BooleanDecoder.False.equals( aString ) == true )
{
aValue = Boolean.FALSE;
}
aParser.require( XmlPullParser.END_TAG, null, BooleanDecoder.Name );
aParser.next();
return aValue;
}
throw new IllegalArgumentException( "XMLRPCDecoder.BooleanDecoder.decodeWithParser: null parser." );
}
}
// ===========================================================================
// DoubleDecoder method(s)
// ---------------------------------------------------------------------------
private static final class DoubleDecoder extends XMLRPCDecoder
{
private static final String Name = "double";
private static final String[] Names = { DoubleDecoder.Name };
protected DoubleDecoder()
{
super();
}
protected String[] names()
{
return DoubleDecoder.Names;
}
protected Object decodeWithParser(XmlPullParser aParser) throws Exception
{
if ( aParser != null )
{
aParser.require( XmlPullParser.START_TAG, null, DoubleDecoder.Name );
String aString = aParser.nextText();
Object aValue = null;
if ( aString != null )
{
try
{
aValue = new Double( aString );
}
catch(Exception anException)
{
System.err.println( anException );
}
}
aParser.require( XmlPullParser.END_TAG, null, DoubleDecoder.Name );
aParser.nextTag();
return aValue;
}
throw new IllegalArgumentException( "XMLRPCDecoder.DoubleDecoder.decodeWithParser: null parser." );
}
}
// ===========================================================================
// StringDecoder method(s)
// ---------------------------------------------------------------------------
private static final class StringDecoder extends XMLRPCDecoder
{
private static final String Name = "string";
private static final String[] Names = { StringDecoder.Name };
protected StringDecoder()
{
super();
}
protected String[] names()
{
return StringDecoder.Names;
}
protected Object decodeWithParser(XmlPullParser aParser) throws Exception
{
if ( aParser != null )
{
aParser.require( XmlPullParser.START_TAG, null, StringDecoder.Name );
String aValue = aParser.nextText();
aParser.require( XmlPullParser.END_TAG, null, StringDecoder.Name );
aParser.next();
if ( ( aValue != null ) && ( aValue.length() == 0 ) )
{
aValue = null;
}
return aValue;
}
throw new IllegalArgumentException( "XMLRPCDecoder.StringDecoder.decodeWithParser: null parser." );
}
}
// ===========================================================================
// DateDecoder method(s)
// ---------------------------------------------------------------------------
private static final class DateDecoder extends XMLRPCDecoder
{
private static final String Name = "dateTime.iso8601";
private static final String[] Names = { DateDecoder.Name };
private static final String Format = "yyyyMMdd'T'HH:mm:ss";
protected DateDecoder()
{
super();
}
protected String[] names()
{
return DateDecoder.Names;
}
protected Object decodeWithParser(XmlPullParser aParser) throws Exception
{
if ( aParser != null )
{
aParser.require( XmlPullParser.START_TAG, null, DateDecoder.Name );
String aString = aParser.nextText();
Date aValue = null;
if ( aString != null )
{
try
{
DateFormat aFormat = new SimpleDateFormat( DateDecoder.Format );
aValue = aFormat.parse( aString );
}
catch(Exception anException)
{
System.err.println( anException );
}
}
aParser.require( XmlPullParser.END_TAG, null, DateDecoder.Name );
aParser.nextTag();
return aValue;
}
throw new IllegalArgumentException( "XMLRPCDecoder.DateDecoder.decodeWithParser: null parser." );
}
}
// ===========================================================================
// Base64Decoder method(s)
// ---------------------------------------------------------------------------
private static final class Base64Decoder extends XMLRPCDecoder
{
private static final String Name = "base64";
private static final String[] Names = { Base64Decoder.Name };
protected Base64Decoder()
{
super();
}
protected String[] names()
{
return Base64Decoder.Names;
}
protected Object decodeWithParser(XmlPullParser aParser) throws Exception
{
if ( aParser != null )
{
aParser.require( XmlPullParser.START_TAG, null, Base64Decoder.Name );
String aString = aParser.nextText();
Object aValue = null;
if ( aString != null )
{
try
{
aValue = Base64.decode( aString.getBytes() );
}
catch(Exception anException)
{
System.err.println( aValue );
}
}
aParser.require( XmlPullParser.END_TAG, null, Base64Decoder.Name );
aParser.nextTag();
return aValue;
}
throw new IllegalArgumentException( "XMLRPCDecoder.Base64Decoder.decodeWithParser: null parser." );
}
}
// ===========================================================================
// Base64 method(s)
// ---------------------------------------------------------------------------
public static final class Base64 extends Object
{
/**
* Returns an array of bytes which were encoded in the passed
* character array.
*
* @param data the array of base64-encoded characters
* @return decoded data array
*/
static public byte[] decode( byte[] data )
{
int len = ( ( data.length + 3 ) / 4 ) * 3;
if ( data.length > 0 && data[ data.length - 1 ] == '=' )
{
--len;
}
if ( data.length > 1 && data[ data.length - 2 ] == '=' )
{
--len;
}
byte[] out = new byte[ len ];
int shift = 0; // # of excess bits stored in accum
int accum = 0; // excess bits
int index = 0;
for ( int ix = 0; ix < data.length; ix++ )
{
int value = codes[ data[ ix ] & 0xFF ]; // ignore high byte of char
if ( value >= 0 )
{
// skip over non-code
accum <<= 6; // bits shift up by 6 each time thru
shift += 6; // loop, with new bits being put in
accum |= value; // at the bottom.
if ( shift >= 8 )
{
// whenever there are 8 or more shifted in,
shift -= 8; // write them out (from the top, leaving any
// excess at the bottom for next iteration.
out[ index++ ] = ( byte )( ( accum >> shift ) & 0xff );
}
}
}
if ( index != out.length )
{
throw new RuntimeException(
"Error decoding BASE64 element: Miscalculated data length." );
}
return out;
}
/** Code characters for values 0..63 */
static private char[] alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".toCharArray();
/** Lookup table for converting base64 characters to value in range 0..63 */
static private byte[] codes = new byte[256];
/** Initialize look-up table */
static
{
for ( int i = 0; i < 256; i++ )
{
codes[ i ] = -1;
}
for ( int i = 'A'; i <= 'Z'; i++ )
{
codes[ i ] = ( byte )( i - 'A' );
}
for ( int i = 'a'; i <= 'z'; i++ )
{
codes[ i ] = ( byte )( 26 + i - 'a' );
}
for ( int i = '0'; i <= '9'; i++ )
{
codes[ i ] = ( byte )( 52 + i - '0' );
}
codes[ '+' ] = 62;
codes[ '/' ] = 63;
}
}
// ===========================================================================
// Main method(s)
// ---------------------------------------------------------------------------
public static void main (String args[])
{
args= new String[] {"http://www.oreillynet.com/meerkat/xml-rpc/server.php"};
if ( args.length == 1 )
{
System.out.println( "Decoding \"" + args[ 0 ] + "\"" );
try
{
URL anURL = new URL( args[ 0 ] );
byte[] aRequest = "system.listMethods ".getBytes();
URLConnection aConnection = anURL.openConnection();
aConnection.setDoInput( true );
aConnection.setDoOutput( true );
aConnection.setUseCaches( false );
aConnection.setAllowUserInteraction( false );
aConnection.setRequestProperty( "Content-Type", "text/xml" );
aConnection.setRequestProperty( "Content-Length", Integer.toString( aRequest.length ) );
OutputStream anOutputStream = new BufferedOutputStream( aConnection.getOutputStream() );
anOutputStream.write( aRequest );
anOutputStream.flush();
InputStream anInputStream = new BufferedInputStream( aConnection.getInputStream() );
Reader aReader = new InputStreamReader( anInputStream );
Object anObject = XMLRPCDecoder.decode( aReader );
System.out.println( "anObject: " + anObject.getClass() );
System.out.println( "anObject: " + anObject );
}
catch(Exception anException)
{
System.err.println( anException );
}
return;
}
System.out.println( "XMLRPCDecoder maps an XML-RPC document into its Java equivalent." );
System.out.println( "This example will send a canned 'system.listMethods' to the target url." );
System.out.println( "Usage: " );
System.out.println( "Example: \"http://www.oreillynet.com/meerkat/xml-rpc/server.php\"" );
}
}
xpp3-1.1.4c/src/java/samples/XmlCompare.java 100644 0 0 14051 10525225062 17755 0 ustar aslom ewww 0 0 import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
public class XmlCompare {
protected static final String FEATURE_XML_ROUNDTRIP =
"http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
public static void main (String args[])
throws XmlPullParserException, IOException
{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
XmlPullParser pp = factory.newPullParser();
try {
pp.setFeature(FEATURE_XML_ROUNDTRIP, false);
} catch(XmlPullParserException ex) {
throw new RuntimeException("could nto disable roundtrip feature: "+ex);
}
System.out.println("parser implementation class is "+pp.getClass());
//pp.setInput(new StringReader(SAMPLE_XML));
final String FILE = "fcked_up2.xml";
pp.setInput(new FileReader(FILE));
//final String NS_URI = "http://whappdev1/bscwebservices/";
String text = getNextElementText(pp);
//System.out.println("getNextElementText="+text);
//Writer w = new FileWriter("c:/Forge/homepage/xmlpull/f3.xml");
//w.write(text);
//w.close();
// now just parse input
//pp.nextTag();
//System.out.println("current tag namespace="+pp.getNamespace()+" name="+pp.getName());
//pp.require(XmlPullParser.START_TAG, NS_URI, "string");
//System.out.println("text='"+pp.nextText()+"'");
// note nextText() moved parser to END_TAG
//System.out.println("current tag namespace="+pp.getNamespace()+" name="+pp.getName());
//pp.require(XmlPullParser.END_TAG, NS_URI, "string");
compareXmlTwoFiles(new FileReader(FILE),
new StringReader(text));
}
/**
* Returns the next Element in the stream (including all sub elements) as a String
* @param parser
* @return
* @throws org.xmlpull.v1.XmlPullParserException
* @throws java.io.IOException
*/
public static String getNextElementText(XmlPullParser parser) throws XmlPullParserException, IOException {
if(parser.getFeature(FEATURE_XML_ROUNDTRIP) == false) {
throw new RuntimeException("roundtrip feature must be enabled to get tag content");
}
int level = 1;
StringBuffer buf = new StringBuffer();
parser.nextTag();
buf.append(parser.getText());
//int [] holderForStartAndLength = new int[2];
while (level > 0) {
int event = parser.next();
String text = parser.getText();
if (event == XmlPullParser.START_TAG) {
buf.append(text);
if(parser.isEmptyElementTag()) {
parser.next(); //skip empty tag
} else {
level++;
}
} else if (event == XmlPullParser.END_TAG) {
// We need to handle tags... ;) returns both START_TAG= and END_TAG=
//if (!tmp.endsWith("/>")) buf.append(tmp);
buf.append(text);
level--;
//} else if (!parser.isWhitespace()) {
} else if (text.length() > 0) {
StringBuffer escapedText = new StringBuffer(text.length());
for (int i = 0; i < text.length(); i++)
{
char ch = text.charAt(i);
if(ch == '<') {
escapedText.append("<");
} else if(ch == '&') {
escapedText.append("&");
} else if(ch == '"') {
escapedText.append(""");
} else if(ch == '\'') {
escapedText.append("'");
} else {
escapedText.append(ch);
}
}
buf.append(escapedText);
}
}
return buf.toString();
}
static void compareXmlTwoFiles(Reader rr, Reader rq) throws XmlPullParserException, IOException {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
//System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
"org.xmlpull.mxp1.MXParserFactory", null);
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
XmlPullParser r = factory.newPullParser();
r.setInput(rr);
XmlPullParser q = factory.newPullParser();
q.setInput(rq);
while(true) {
r.next();
q.next();
if(r.getEventType() != q.getEventType()) {
throw new RuntimeException("inconsistent events");
}
if(r.getEventType() == XmlPullParser.END_DOCUMENT) {
break;
}
if(r.getEventType() == XmlPullParser.START_TAG || r.getEventType() == XmlPullParser.END_TAG ) {
String rName = r.getName();
String qName = q.getName();
if(!rName.equals(qName)) {
throw new RuntimeException("element names mismatch");
}
if(r.getEventType() == XmlPullParser.START_TAG) {
}
} else if(r.getEventType() == XmlPullParser.TEXT) {
String rText = r.getText();
String qText = q.getText();
if(!rText.equals(qText)) {
throw new RuntimeException("text content mismatch '"+rText+"' and '"+qText+"'");
}
} else {
throw new RuntimeException("unknown event type "+r.getEventType()
+r.getPositionDescription());
}
System.err.print(".");
}
System.err.println("\nOK");
}
}
xpp3-1.1.4c/src/java/samples/XmlPullCount.java 100644 0 0 11670 10525225062 20320 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.FileInputStream;
/**
* Simple example that counts XML elements, characters and attributes.
*
* @author Aleksander Slominski
*/
public class XmlPullCount
{
public final static String SAMPLE_XML =
"\n"+
"\n"+
"\n"+
"Roses are Red \n"+
"Roses are red, \n"+
"Violets are blue; \n"+
"Sugar is sweet, \n"+
"And I love you. \n"+
" ";
int countChars;
int countAttribs;
int countSTags;
boolean verbose;
public static void main (String args[])
throws XmlPullParserException, IOException
{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
factory.setNamespaceAware(false);
System.err.println("using factory "+factory.getClass());
XmlPullParser xpp = factory.newPullParser();
System.err.println("using parser "+xpp.getClass());
XmlPullCount app = new XmlPullCount();
app.verbose = true;
for(int c = 0; c < 2; ++c) {
System.err.println("run#"+c);
app.resetCounters();
if(args.length == 0) {
System.err.println("Parsing simple sample XML length="+SAMPLE_XML.length());
xpp.setInput( new StringReader( SAMPLE_XML ) );
app.countXml(xpp);
} else {
//r (int i = 0; i < args.length; i++) {
File f = new File(args[0]);
System.err.println("Parsing file: "+args[0]+" length="+f.length());
//xpp.setInput ( new FileReader ( args [0] ) );
xpp.setInput ( new FileInputStream ( args [0] ), "UTF8" );
app.countXml(xpp);
//
}
app.printReport();
}
System.err.println("finished");
}
public void resetCounters() {
countChars = countSTags = countAttribs = 0;
}
public void printReport() {
System.err.println("characters="+countChars
+" elements="+countSTags
+" attributes="+countAttribs);
}
public void countXml(XmlPullParser xpp) throws XmlPullParserException, IOException {
int holderForStartAndLength[] = new int[2];
xpp.require(XmlPullParser.START_DOCUMENT, null, null);
int eventType = xpp.next();
xpp.require(XmlPullParser.START_TAG, null, null);
while (eventType != XmlPullParser.END_DOCUMENT) {
//System.err.println("pos="+xpp.getPositionDescription());
if(eventType == XmlPullParser.START_TAG) {
++countSTags;
countAttribs += xpp.getAttributeCount();
if(verbose) {
System.err.println("START_TAG "+xpp.getName());
}
} else if(eventType == XmlPullParser.TEXT) {
//char ch[] = xpp.getTextCharacters(holderForStartAndLength);
xpp.getTextCharacters(holderForStartAndLength);
//int start = holderForStartAndLength[0];
int length = holderForStartAndLength[1];
countChars += length;
if(verbose) {
System.err.println("TEXT '"+printable(xpp.getText())+"'");
}
} else if(eventType == XmlPullParser.END_TAG) {
if(verbose) {
System.err.println("END_TAG "+xpp.getName());
}
}
eventType = xpp.next();
}
}
protected String printable(char ch) {
if(ch == '\n') {
return "\\n";
} else if(ch == '\r') {
return "\\r";
} else if(ch == '\t') {
return "\\t";
} if(ch > 127 || ch < 32) {
StringBuffer buf = new StringBuffer("\\u");
String hex = Integer.toHexString((int)ch);
for (int i = 0; i < 4-hex.length(); i++)
{
buf.append('0');
}
buf.append(hex);
return buf.toString();
}
return ""+ch;
}
protected String printable(String s) {
if(s == null) return null;
StringBuffer buf = new StringBuffer();
for(int i = 0; i < s.length(); ++i) {
buf.append(printable(s.charAt(i)));
}
s = buf.toString();
return s;
}
}
xpp3-1.1.4c/src/java/samples/eventlist/EventList.java 100644 0 0 2321 10525225062 21615 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package eventlist;
import java.io.*;
import org.xmlpull.v1.*;
public class EventList {
public static void main (String [] args) throws IOException, XmlPullParserException{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
Reader reader = (args.length > 0) ?
new FileReader (args [0]) :
(Reader) new StringReader("Hello World! ");
XmlPullParser xpp = factory.newPullParser();
xpp.setInput (reader);
int eventType;
while ((eventType = xpp.next()) != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_TAG) {
System.out.println("START_TAG "+xpp.getName());
} else if(eventType == XmlPullParser.END_TAG) {
System.out.println("END_TAG "+xpp.getName());
} else if(eventType == XmlPullParser.TEXT) {
System.out.println("TEXT "+xpp.getText());
}
}
}
}
xpp3-1.1.4c/src/java/samples/pricelist.xml 100644 0 0 1532 10525225062 17543 0 ustar aslom ewww 0 0
XML Training
Playfield Training
999.00
899.00
XMLi
2999.00
1499.00
699.00
WriteIT
799.00
899.00
Emailaholic
1999.00
xpp3-1.1.4c/src/java/samples/rss.xml 100644 0 0 2442 10525225062 16355 0 ustar aslom ewww 0 0
mars
http://www.example.com/mars
Developer news from the MARS community
en-us
Copyright 2999-3001, MARS team.
editor@example.com
webmaster@example.com
mars
http://www.example.com/images/mynetscape3188.gif
http://www.example.com
88
31
News, opinions, tips and issues concerning MARS development
-
MARS 1.0 Released
http://www.example.com/read?item=3322323
The latest verion of MARS survival toolkit release.
-
Rapid growth of MARS confirmed
http://www.example.com/read?item=334300909
Independent office EARTH confirmed that MARS is growing.
Another in series of astrounding NONSENSE news!
xpp3-1.1.4c/src/java/sax2_driver/README.txt 100644 0 0 74 10525225062 17245 0 ustar aslom ewww 0 0 SAX2 driver that uses XmlPull API to implement XMLReader.
xpp3-1.1.4c/src/java/sax2_driver/org/xmlpull/v1/sax2/Driver.java 100644 0 0 44327 10525225063 23426 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.sax2;
import java.io.InputStream;
import java.io.IOException;
import java.io.Reader;
// not J2ME classes -- remove if you want to run in MIDP devices
import java.net.URL;
import java.net.MalformedURLException;
// not J2ME classes
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import org.xml.sax.Attributes;
import org.xml.sax.DTDHandler;
import org.xml.sax.ContentHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
/**
* SAX2 Driver that pulls events from XmlPullParser
* and comverts them into SAX2 callbacks.
*
* @author Aleksander Slominski
*/
public class Driver implements Locator, XMLReader, Attributes
{
protected static final String DECLARATION_HANDLER_PROPERTY =
"http://xml.org/sax/properties/declaration-handler";
protected static final String LEXICAL_HANDLER_PROPERTY =
"http://xml.org/sax/properties/lexical-handler";
protected static final String NAMESPACES_FEATURE =
"http://xml.org/sax/features/namespaces";
protected static final String NAMESPACE_PREFIXES_FEATURE =
"http://xml.org/sax/features/namespace-prefixes";
protected static final String VALIDATION_FEATURE =
"http://xml.org/sax/features/validation";
protected static final String APACHE_SCHEMA_VALIDATION_FEATURE =
"http://apache.org/xml/features/validation/schema";
protected static final String APACHE_DYNAMIC_VALIDATION_FEATURE =
"http://apache.org/xml/features/validation/dynamic";
protected ContentHandler contentHandler = new DefaultHandler();
protected ErrorHandler errorHandler = new DefaultHandler();;
protected String systemId;
protected XmlPullParser pp;
//private final static boolean DEBUG = false;
/**
*/
public Driver() throws XmlPullParserException {
final XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
pp = factory.newPullParser();
}
public Driver(XmlPullParser pp) throws XmlPullParserException {
this.pp = pp;
}
// -- Attributes interface
public int getLength() { return pp.getAttributeCount(); }
public String getURI(int index) { return pp.getAttributeNamespace(index); }
public String getLocalName(int index) { return pp.getAttributeName(index); }
public String getQName(int index) {
final String prefix = pp.getAttributePrefix(index);
if(prefix != null) {
return prefix+':'+pp.getAttributeName(index);
} else {
return pp.getAttributeName(index);
}
}
public String getType(int index) { return pp.getAttributeType(index); }
public String getValue(int index) { return pp.getAttributeValue(index); }
public int getIndex(String uri, String localName) {
for (int i = 0; i < pp.getAttributeCount(); i++)
{
if(pp.getAttributeNamespace(i).equals(uri)
&& pp.getAttributeName(i).equals(localName))
{
return i;
}
}
return -1;
}
public int getIndex(String qName) {
for (int i = 0; i < pp.getAttributeCount(); i++)
{
if(pp.getAttributeName(i).equals(qName))
{
return i;
}
}
return -1;
}
public String getType(String uri, String localName) {
for (int i = 0; i < pp.getAttributeCount(); i++)
{
if(pp.getAttributeNamespace(i).equals(uri)
&& pp.getAttributeName(i).equals(localName))
{
return pp.getAttributeType(i);
}
}
return null;
}
public String getType(String qName) {
for (int i = 0; i < pp.getAttributeCount(); i++)
{
if(pp.getAttributeName(i).equals(qName))
{
return pp.getAttributeType(i);
}
}
return null;
}
public String getValue(String uri, String localName) {
return pp.getAttributeValue(uri, localName);
}
public String getValue(String qName) {
return pp.getAttributeValue(null, qName);
}
// -- Locator interface
public String getPublicId() { return null; }
public String getSystemId() { return systemId; }
public int getLineNumber() { return pp.getLineNumber(); }
public int getColumnNumber() { return pp.getColumnNumber(); }
// --- XMLReader interface
public boolean getFeature(String name)
throws SAXNotRecognizedException, SAXNotSupportedException
{
if(NAMESPACES_FEATURE.equals(name)) {
return pp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES);
} else if(NAMESPACE_PREFIXES_FEATURE.equals(name)) {
return pp.getFeature(XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES);
} else if(VALIDATION_FEATURE.equals(name)) {
return pp.getFeature(XmlPullParser.FEATURE_VALIDATION);
// } else if(APACHE_SCHEMA_VALIDATION_FEATURE.equals(name)) {
// return false; //TODO
// } else if(APACHE_DYNAMIC_VALIDATION_FEATURE.equals(name)) {
// return false; //TODO
} else {
return pp.getFeature(name);
//throw new SAXNotRecognizedException("unrecognized feature "+name);
}
}
public void setFeature (String name, boolean value)
throws SAXNotRecognizedException, SAXNotSupportedException
{
try {
if(NAMESPACES_FEATURE.equals(name)) {
pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, value);
} else if(NAMESPACE_PREFIXES_FEATURE.equals(name)) {
if(pp.getFeature(XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES) != value) {
pp.setFeature(XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES, value);
}
} else if(VALIDATION_FEATURE.equals(name)) {
pp.setFeature(XmlPullParser.FEATURE_VALIDATION, value);
// } else if(APACHE_SCHEMA_VALIDATION_FEATURE.equals(name)) {
// // can ignore as validation must be false ...
// // if(true == value) {
// // throw new SAXNotSupportedException("schema validation is not supported");
// // }
// } else if(APACHE_DYNAMIC_VALIDATION_FEATURE.equals(name)) {
// if(true == value) {
// throw new SAXNotSupportedException("dynamic validation is not supported");
// }
} else {
pp.setFeature(name, value);
//throw new SAXNotRecognizedException("unrecognized feature "+name);
}
} catch(XmlPullParserException ex) {
throw new SAXNotSupportedException("problem with setting feature "+name+": "+ex);
}
}
public Object getProperty (String name)
throws SAXNotRecognizedException, SAXNotSupportedException
{
if(DECLARATION_HANDLER_PROPERTY.equals(name)) {
return null;
} else if(LEXICAL_HANDLER_PROPERTY.equals(name)) {
return null;
} else {
return pp.getProperty(name);
//throw new SAXNotRecognizedException("not recognized get property "+name);
}
}
public void setProperty (String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException
{
//
if(DECLARATION_HANDLER_PROPERTY.equals(name)) {
throw new SAXNotSupportedException("not supported setting property "+name);//+" to "+value);
} else if(LEXICAL_HANDLER_PROPERTY.equals(name)) {
throw new SAXNotSupportedException("not supported setting property "+name);//+" to "+value);
} else {
try {
pp.setProperty(name, value);
} catch(XmlPullParserException ex) {
throw new SAXNotSupportedException("not supported set property "+name+": "+ ex);
}
//throw new SAXNotRecognizedException("not recognized set property "+name);
}
}
public void setEntityResolver (EntityResolver resolver) {}
public EntityResolver getEntityResolver () { return null; }
public void setDTDHandler (DTDHandler handler) {}
public DTDHandler getDTDHandler () { return null; }
public void setContentHandler (ContentHandler handler)
{
this.contentHandler = handler;
}
public ContentHandler getContentHandler() { return contentHandler; }
public void setErrorHandler(ErrorHandler handler) {
this.errorHandler = handler;
}
public ErrorHandler getErrorHandler() { return errorHandler; }
public void parse(InputSource source) throws SAXException, IOException
{
systemId = source.getSystemId();
contentHandler.setDocumentLocator(this);
final Reader reader = source.getCharacterStream();
try {
if (reader == null) {
InputStream stream = source.getByteStream();
final String encoding = source.getEncoding();
if (stream == null) {
systemId = source.getSystemId();
if(systemId == null) {
SAXParseException saxException = new SAXParseException(
"null source systemId" , this);
errorHandler.fatalError(saxException);
return;
}
// NOTE: replace with Connection to run in J2ME environment
try {
final URL url = new URL(systemId);
stream = url.openStream();
} catch (MalformedURLException nue) {
try {
stream = new FileInputStream(systemId);
} catch (FileNotFoundException fnfe) {
final SAXParseException saxException = new SAXParseException(
"could not open file with systemId "+systemId, this, fnfe);
errorHandler.fatalError(saxException);
return;
}
}
}
pp.setInput(stream, encoding);
} else {
pp.setInput(reader);
}
} catch (XmlPullParserException ex) {
final SAXParseException saxException = new SAXParseException(
"parsing initialization error: "+ex, this, ex);
//if(DEBUG) ex.printStackTrace();
errorHandler.fatalError(saxException);
return;
}
// start parsing - move to first start tag
try {
contentHandler.startDocument();
// get first event
pp.next();
// it should be start tag...
if(pp.getEventType() != XmlPullParser.START_TAG) {
final SAXParseException saxException = new SAXParseException(
"expected start tag not"+pp.getPositionDescription(), this);
//throw saxException;
errorHandler.fatalError(saxException);
return;
}
} catch (XmlPullParserException ex) {
final SAXParseException saxException = new SAXParseException(
"parsing initialization error: "+ex, this, ex);
//ex.printStackTrace();
errorHandler.fatalError(saxException);
return;
}
// now real parsing can start!
parseSubTree(pp);
// and finished ...
contentHandler.endDocument();
}
public void parse(String systemId) throws SAXException, IOException {
parse(new InputSource(systemId));
}
public void parseSubTree(XmlPullParser pp) throws SAXException, IOException {
this.pp = pp;
final boolean namespaceAware = pp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES);
try {
if(pp.getEventType() != XmlPullParser.START_TAG) {
throw new SAXException(
"start tag must be read before skiping subtree"+pp.getPositionDescription());
}
final int[] holderForStartAndLength = new int[2];
final StringBuffer rawName = new StringBuffer(16);
String prefix = null;
String name = null;
int level = pp.getDepth() - 1;
int type = XmlPullParser.START_TAG;
LOOP:
do {
switch(type) {
case XmlPullParser.START_TAG:
if(namespaceAware) {
final int depth = pp.getDepth() - 1;
final int countPrev =
(level > depth) ? pp.getNamespaceCount(depth) : 0;
//int countPrev = pp.getNamespaceCount(pp.getDepth() - 1);
final int count = pp.getNamespaceCount(depth + 1);
for (int i = countPrev; i < count; i++)
{
contentHandler.startPrefixMapping(
pp.getNamespacePrefix(i),
pp.getNamespaceUri(i)
);
}
name = pp.getName();
prefix = pp.getPrefix();
if(prefix != null) {
rawName.setLength(0);
rawName.append(prefix);
rawName.append(':');
rawName.append(name);
}
startElement(pp.getNamespace(),
name,
prefix != null ? rawName.toString() : name );
} else {
startElement(pp.getNamespace(),
pp.getName(),
pp.getName());
}
//++level;
break;
case XmlPullParser.TEXT:
final char[] chars = pp.getTextCharacters(holderForStartAndLength);
contentHandler.characters(chars,
holderForStartAndLength[0], //start
holderForStartAndLength[1] //len
);
break;
case XmlPullParser.END_TAG:
//--level;
if(namespaceAware) {
name = pp.getName();
prefix = pp.getPrefix();
if(prefix != null) {
rawName.setLength(0);
rawName.append(prefix);
rawName.append(':');
rawName.append(name);
}
contentHandler.endElement(pp.getNamespace(),
name,
prefix != null ? rawName.toString() : name
);
// when entering show prefixes for all levels!!!!
final int depth = pp.getDepth();
final int countPrev =
(level > depth) ? pp.getNamespaceCount(pp.getDepth()) : 0;
int count = pp.getNamespaceCount(pp.getDepth() - 1);
// undeclare them in reverse order
for (int i = count - 1; i >= countPrev; i--)
{
contentHandler.endPrefixMapping(
pp.getNamespacePrefix(i)
);
}
} else {
contentHandler.endElement(pp.getNamespace(),
pp.getName(),
pp.getName()
);
}
break;
case XmlPullParser.END_DOCUMENT:
break LOOP;
}
type = pp.next();
} while(pp.getDepth() > level);
} catch (XmlPullParserException ex) {
final SAXParseException saxException = new SAXParseException("parsing error: "+ex, this, ex);
ex.printStackTrace();
errorHandler.fatalError(saxException);
}
}
/**
* Calls {@link ContentHandler.startElement(String, String, String, Attributes) startElement}
* on the ContentHandler
with this
driver object as the
* {@link Attributes} implementation. In default implementation
* {@link Attributes} object is valid only during this method call and may not
* be stored. Sub-classes can overwrite this method to cache attributes.
*/
protected void startElement(String namespace, String localName, String qName) throws SAXException {
contentHandler.startElement(namespace, localName, qName, this);
}
}
xpp3-1.1.4c/src/java/serializer_impl/org/xmlpull/mxp1_serializer/MXSerializer.java 100644 0 0 126242 10525225062 27442 0 ustar aslom ewww 0 0 package org.xmlpull.mxp1_serializer;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import org.xmlpull.v1.XmlSerializer;
/**
* Implementation of XmlSerializer interface from XmlPull V1 API.
* This implementation is optimzied for performance and low memory footprint.
*
* Implemented features:
* FEATURE_NAMES_INTERNED - when enabled all returned names
* (namespaces, prefixes) will be interned and it is required that
* all names passed as arguments MUST be interned
* FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE
*
* Implemented properties:
* PROPERTY_SERIALIZER_INDENTATION
* PROPERTY_SERIALIZER_LINE_SEPARATOR
*
*
*/
public class MXSerializer implements XmlSerializer {
protected final static String XML_URI = "http://www.w3.org/XML/1998/namespace";
protected final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
private static final boolean TRACE_SIZING = false;
private static final boolean TRACE_ESCAPING = false;
protected final String FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE =
"http://xmlpull.org/v1/doc/features.html#serializer-attvalue-use-apostrophe";
protected final String FEATURE_NAMES_INTERNED =
"http://xmlpull.org/v1/doc/features.html#names-interned";
protected final String PROPERTY_SERIALIZER_INDENTATION =
"http://xmlpull.org/v1/doc/properties.html#serializer-indentation";
protected final String PROPERTY_SERIALIZER_LINE_SEPARATOR =
"http://xmlpull.org/v1/doc/properties.html#serializer-line-separator";
protected final static String PROPERTY_LOCATION =
"http://xmlpull.org/v1/doc/properties.html#location";
// properties/features
protected boolean namesInterned;
protected boolean attributeUseApostrophe;
protected String indentationString = null; //" ";
protected String lineSeparator = "\n";
protected String location;
protected Writer out;
protected int autoDeclaredPrefixes;
protected int depth = 0;
// element stack
protected String elNamespace[] = new String[ 2 ];
protected String elName[] = new String[ elNamespace.length ];
protected String elPrefix[] = new String[ elNamespace.length ];
protected int elNamespaceCount[] = new int[ elNamespace.length ];
//namespace stack
protected int namespaceEnd = 0;
protected String namespacePrefix[] = new String[ 8 ];
protected String namespaceUri[] = new String[ namespacePrefix.length ];
protected boolean finished;
protected boolean pastRoot;
protected boolean setPrefixCalled;
protected boolean startTagIncomplete;
protected boolean doIndent;
protected boolean seenTag;
protected boolean seenBracket;
protected boolean seenBracketBracket;
// buffer output if neede to write escaped String see text(String)
private static final int BUF_LEN = Runtime.getRuntime().freeMemory() > 1000000L ? 8*1024 : 256;
protected char buf[] = new char[ BUF_LEN ];
protected static final String precomputedPrefixes[];
static {
precomputedPrefixes = new String[32]; //arbitrary number ...
for (int i = 0; i < precomputedPrefixes.length; i++)
{
precomputedPrefixes[i] = ("n"+i).intern();
}
}
private boolean checkNamesInterned = false;
private void checkInterning(String name) {
if(namesInterned && name != name.intern()) {
throw new IllegalArgumentException(
"all names passed as arguments must be interned"
+"when NAMES INTERNED feature is enabled");
}
}
protected void reset() {
location = null;
out = null;
autoDeclaredPrefixes = 0;
depth = 0;
// nullify references on all levels to allow it to be GCed
for (int i = 0; i < elNamespaceCount.length; i++)
{
elName[ i ] = null;
elPrefix[ i ] = null;
elNamespace[ i ] = null;
elNamespaceCount[ i ] = 2;
}
namespaceEnd = 0;
//NOTE: no need to intern() as all literal strings and string-valued constant expressions
//are interned. String literals are defined in 3.10.5 of the Java Language Specification
// just checking ...
//assert "xmlns" == "xmlns".intern();
//assert XMLNS_URI == XMLNS_URI.intern();
//TODO: how to prevent from reporting this namespace?
// this is special namespace declared for consistensy with XML infoset
namespacePrefix[ namespaceEnd ] = "xmlns";
namespaceUri[ namespaceEnd ] = XMLNS_URI;
++namespaceEnd;
namespacePrefix[ namespaceEnd ] = "xml";
namespaceUri[ namespaceEnd ] = XML_URI;
++namespaceEnd;
finished = false;
pastRoot = false;
setPrefixCalled = false;
startTagIncomplete = false;
//doIntent is not changed
seenTag = false;
seenBracket = false;
seenBracketBracket = false;
}
protected void ensureElementsCapacity() {
final int elStackSize = elName.length;
//assert (depth + 1) >= elName.length;
// we add at least one extra slot ...
final int newSize = (depth >= 7 ? 2 * depth : 8) + 2; // = lucky 7 + 1 //25
if(TRACE_SIZING) {
System.err.println(
getClass().getName()+" elStackSize "+elStackSize+" ==> "+newSize);
}
final boolean needsCopying = elStackSize > 0;
String[] arr = null;
// reuse arr local variable slot
arr = new String[newSize];
if(needsCopying) System.arraycopy(elName, 0, arr, 0, elStackSize);
elName = arr;
arr = new String[newSize];
if(needsCopying) System.arraycopy(elPrefix, 0, arr, 0, elStackSize);
elPrefix = arr;
arr = new String[newSize];
if(needsCopying) System.arraycopy(elNamespace, 0, arr, 0, elStackSize);
elNamespace = arr;
final int[] iarr = new int[newSize];
if(needsCopying) {
System.arraycopy(elNamespaceCount, 0, iarr, 0, elStackSize);
} else {
// special initialization
iarr[0] = 0;
}
elNamespaceCount = iarr;
}
protected void ensureNamespacesCapacity() { //int size) {
//int namespaceSize = namespacePrefix != null ? namespacePrefix.length : 0;
//assert (namespaceEnd >= namespacePrefix.length);
//if(size >= namespaceSize) {
//int newSize = size > 7 ? 2 * size : 8; // = lucky 7 + 1 //25
final int newSize = namespaceEnd > 7 ? 2 * namespaceEnd : 8;
if(TRACE_SIZING) {
System.err.println(
getClass().getName()+" namespaceSize "+namespacePrefix.length+" ==> "+newSize);
}
final String[] newNamespacePrefix = new String[newSize];
final String[] newNamespaceUri = new String[newSize];
if(namespacePrefix != null) {
System.arraycopy(
namespacePrefix, 0, newNamespacePrefix, 0, namespaceEnd);
System.arraycopy(
namespaceUri, 0, newNamespaceUri, 0, namespaceEnd);
}
namespacePrefix = newNamespacePrefix;
namespaceUri = newNamespaceUri;
// TODO use hashes for quick namespace->prefix lookups
// if( ! allStringsInterned ) {
// int[] newNamespacePrefixHash = new int[newSize];
// if(namespacePrefixHash != null) {
// System.arraycopy(
// namespacePrefixHash, 0, newNamespacePrefixHash, 0, namespaceEnd);
// }
// namespacePrefixHash = newNamespacePrefixHash;
// }
//prefixesSize = newSize;
// ////assert nsPrefixes.length > size && nsPrefixes.length == newSize
//}
}
public void setFeature(String name,
boolean state) throws IllegalArgumentException, IllegalStateException
{
if(name == null) {
throw new IllegalArgumentException("feature name can not be null");
}
if(FEATURE_NAMES_INTERNED.equals(name)) {
namesInterned = state;
} else if(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE.equals(name)) {
attributeUseApostrophe = state;
} else {
throw new IllegalStateException("unsupported feature "+name);
}
}
public boolean getFeature(String name) throws IllegalArgumentException
{
if(name == null) {
throw new IllegalArgumentException("feature name can not be null");
}
if(FEATURE_NAMES_INTERNED.equals(name)) {
return namesInterned;
} else if(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE.equals(name)) {
return attributeUseApostrophe;
} else {
return false;
}
}
// precomputed variables to simplify writing indentation
protected int offsetNewLine;
protected int indentationJump;
protected char[] indentationBuf;
protected int maxIndentLevel;
protected boolean writeLineSepartor; //should end-of-line be written
protected boolean writeIndentation; // is indentation used?
/**
* For maximum efficiency when writing indents the required output is pre-computed
* This is internal function that recomputes buffer after user requested chnages.
*/
protected void rebuildIndentationBuf() {
if(doIndent == false) return;
final int maxIndent = 65; //hardcoded maximum indentation size in characters
int bufSize = 0;
offsetNewLine = 0;
if(writeLineSepartor) {
offsetNewLine = lineSeparator.length();
bufSize += offsetNewLine;
}
maxIndentLevel = 0;
if(writeIndentation) {
indentationJump = indentationString.length();
maxIndentLevel = maxIndent / indentationJump;
bufSize += maxIndentLevel * indentationJump;
}
if(indentationBuf == null || indentationBuf.length < bufSize) {
indentationBuf = new char[bufSize + 8];
}
int bufPos = 0;
if(writeLineSepartor) {
for (int i = 0; i < lineSeparator.length(); i++)
{
indentationBuf[ bufPos++ ] = lineSeparator.charAt(i);
}
}
if(writeIndentation) {
for (int i = 0; i < maxIndentLevel; i++)
{
for (int j = 0; j < indentationString.length(); j++)
{
indentationBuf[ bufPos++ ] = indentationString.charAt(j);
}
}
}
}
// if(doIndent) writeIndent();
protected void writeIndent() throws IOException {
final int start = writeLineSepartor ? 0 : offsetNewLine;
final int level = (depth > maxIndentLevel) ? maxIndentLevel : depth;
out.write( indentationBuf, start, ( (level - 1) * indentationJump) + offsetNewLine);
}
public void setProperty(String name,
Object value) throws IllegalArgumentException, IllegalStateException
{
if(name == null) {
throw new IllegalArgumentException("property name can not be null");
}
if(PROPERTY_SERIALIZER_INDENTATION.equals(name)) {
indentationString = (String)value;
} else if(PROPERTY_SERIALIZER_LINE_SEPARATOR.equals(name)) {
lineSeparator = (String)value;
} else if(PROPERTY_LOCATION.equals(name)) {
location = (String) value;
} else {
throw new IllegalStateException("unsupported property "+name);
}
writeLineSepartor = lineSeparator != null && lineSeparator.length() > 0;
writeIndentation = indentationString != null && indentationString.length() > 0;
// optimize - do not write when nothing to write ...
doIndent = indentationString != null && (writeLineSepartor || writeIndentation);
//NOTE: when indentationString == null there is no indentation
// (even though writeLineSeparator may be true ...)
rebuildIndentationBuf();
seenTag = false; // for consistency
}
public Object getProperty(String name) throws IllegalArgumentException
{
if(name == null) {
throw new IllegalArgumentException("property name can not be null");
}
if(PROPERTY_SERIALIZER_INDENTATION.equals(name)) {
return indentationString;
} else if(PROPERTY_SERIALIZER_LINE_SEPARATOR.equals(name)) {
return lineSeparator;
} else if(PROPERTY_LOCATION.equals(name)) {
return location;
} else {
return null;
}
}
private String getLocation() {
return location != null ? " @"+location : "";
}
// this is special method that can be accessed directly to retrieve Writer serializer is using
public Writer getWriter()
{
return out;
}
public void setOutput(Writer writer)
{
reset();
out = writer;
}
public void setOutput(OutputStream os, String encoding) throws IOException
{
if(os == null) throw new IllegalArgumentException("output stream can not be null");
reset();
if(encoding != null) {
out = new OutputStreamWriter(os, encoding);
} else {
out = new OutputStreamWriter(os);
}
}
public void startDocument (String encoding, Boolean standalone) throws IOException
{
char apos = attributeUseApostrophe ? '\'' : '"';
if(attributeUseApostrophe) {
out.write("");
}
public void endDocument() throws IOException
{
// close all unclosed tag;
while(depth > 0) {
endTag(elNamespace[ depth ], elName[ depth ]);
}
//assert depth == 0;
//assert startTagIncomplete == false;
finished = pastRoot = startTagIncomplete = true;
out.flush();
}
public void setPrefix(String prefix, String namespace) throws IOException
{
if(startTagIncomplete) closeStartTag();
//assert prefix != null;
//assert namespace != null;
if (prefix == null) {
prefix = "";
}
if(!namesInterned) {
prefix = prefix.intern(); //will throw NPE if prefix==null
} else if(checkNamesInterned) {
checkInterning(prefix);
} else if(prefix == null) {
throw new IllegalArgumentException("prefix must be not null"+getLocation());
}
//check that prefix is not duplicated ...
for (int i = elNamespaceCount[ depth ]; i < namespaceEnd; i++)
{
if(prefix == namespacePrefix[ i ]) {
throw new IllegalStateException("duplicated prefix "+printable(prefix)+getLocation());
}
}
if(!namesInterned) {
namespace = namespace.intern();
} else if(checkNamesInterned) {
checkInterning(namespace);
} else if(namespace == null) {
throw new IllegalArgumentException("namespace must be not null"+getLocation());
}
if(namespaceEnd >= namespacePrefix.length) {
ensureNamespacesCapacity();
}
namespacePrefix[ namespaceEnd ] = prefix;
namespaceUri[ namespaceEnd ] = namespace;
++namespaceEnd;
setPrefixCalled = true;
}
protected String lookupOrDeclarePrefix( String namespace ) {
return getPrefix(namespace, true);
}
public String getPrefix(String namespace, boolean generatePrefix)
{
return getPrefix(namespace, generatePrefix, false);
}
protected String getPrefix(String namespace, boolean generatePrefix, boolean nonEmpty)
{
//assert namespace != null;
if(!namesInterned) {
// when String is interned we can do much faster namespace stack lookups ...
namespace = namespace.intern();
} else if(checkNamesInterned) {
checkInterning(namespace);
//assert namespace != namespace.intern();
}
if(namespace == null) {
throw new IllegalArgumentException("namespace must be not null"+getLocation());
} else if(namespace.length() == 0) {
throw new IllegalArgumentException("default namespace cannot have prefix"+getLocation());
}
// first check if namespace is already in scope
for (int i = namespaceEnd - 1; i >= 0 ; --i)
{
if(namespace == namespaceUri[ i ]) {
final String prefix = namespacePrefix[ i ];
if(nonEmpty && prefix.length() == 0) continue;
// now check that prefix is still in scope
for (int p = namespaceEnd - 1; p > i ; --p)
{
if(prefix == namespacePrefix[ p ])
continue; // too bad - prefix is redeclared with different namespace
}
return prefix;
}
}
// so not found it ...
if(!generatePrefix) {
return null;
}
return generatePrefix(namespace);
}
private String generatePrefix(String namespace) {
//assert namespace == namespace.intern();
while(true) {
++autoDeclaredPrefixes;
//fast lookup uses table that was pre-initialized in static{} ....
final String prefix = autoDeclaredPrefixes < precomputedPrefixes.length
? precomputedPrefixes[autoDeclaredPrefixes] : ("n"+autoDeclaredPrefixes).intern();
// make sure this prefix is not declared in any scope (avoid hiding in-scope prefixes)!
for (int i = namespaceEnd - 1; i >= 0 ; --i)
{
if(prefix == namespacePrefix[ i ]) {
continue; // prefix is already declared - generate new and try again
}
}
// declare prefix
if(namespaceEnd >= namespacePrefix.length) {
ensureNamespacesCapacity();
}
namespacePrefix[ namespaceEnd ] = prefix;
namespaceUri[ namespaceEnd ] = namespace;
++namespaceEnd;
return prefix;
}
}
public int getDepth()
{
return depth;
}
public String getNamespace ()
{
return elNamespace[depth];
}
public String getName()
{
return elName[depth];
}
public XmlSerializer startTag (String namespace, String name) throws IOException
{
if(startTagIncomplete) {
closeStartTag();
}
seenBracket = seenBracketBracket = false;
++depth;
if(doIndent && depth > 0 && seenTag) {
writeIndent();
}
seenTag = true;
setPrefixCalled = false;
startTagIncomplete = true;
if( (depth + 1) >= elName.length) {
ensureElementsCapacity();
}
////assert namespace != null;
if(checkNamesInterned && namesInterned) checkInterning(namespace);
elNamespace[ depth ] = (namesInterned || namespace == null) ? namespace : namespace.intern();
//assert name != null;
//elName[ depth ] = name;
if(checkNamesInterned && namesInterned) checkInterning(name);
elName[ depth ] = (namesInterned || name == null) ? name : name.intern();
if(out == null) {
throw new IllegalStateException("setOutput() must called set before serialization can start");
}
out.write('<');
if(namespace != null) {
if(namespace.length() > 0) {
//ALEK: in future make this algo a feature on serializer
String prefix = null;
if(depth > 0 && (namespaceEnd - elNamespaceCount[depth-1]) == 1) {
// if only one prefix was declared un-declare it if the prefix is already declared on parent el with the same URI
String uri = namespaceUri[namespaceEnd-1];
if(uri == namespace || uri.equals(namespace)) {
String elPfx = namespacePrefix[namespaceEnd-1];
// 2 == to skip predefined namesapces (xml and xmlns ...)
for(int pos = elNamespaceCount[depth-1] - 1; pos >= 2; --pos ) {
String pf = namespacePrefix[pos];
if(pf == elPfx || pf.equals(elPfx)) {
String n = namespaceUri[pos];
if(n == uri || n.equals(uri)) {
--namespaceEnd; //un-declare namespace: this is kludge!
prefix = elPfx;
}
break;
}
}
}
}
if(prefix == null) {
prefix = lookupOrDeclarePrefix( namespace );
}
//assert prefix != null;
// make sure that default ("") namespace to not print ":"
if(prefix.length() > 0) {
elPrefix[ depth ] = prefix;
out.write(prefix);
out.write(':');
} else {
elPrefix[ depth ] = "";
}
} else {
// make sure that default namespace can be declared
for (int i = namespaceEnd - 1; i >= 0 ; --i) {
if(namespacePrefix[ i ] == "") {
final String uri = namespaceUri[ i ];
if(uri == null) {
// declare default namespace
setPrefix("", "");
} else if(uri.length() > 0) {
throw new IllegalStateException(
"start tag can not be written in empty default namespace "+
"as default namespace is currently bound to '"+uri+"'"+getLocation());
}
break;
}
}
elPrefix[ depth ] = "";
}
} else {
elPrefix[ depth ] = "";
}
out.write(name);
return this;
}
public XmlSerializer attribute (String namespace, String name,
String value) throws IOException
{
if(!startTagIncomplete) {
throw new IllegalArgumentException("startTag() must be called before attribute()"+getLocation());
}
//assert setPrefixCalled == false;
out.write(' ');
////assert namespace != null;
if(namespace != null && namespace.length() > 0) {
//namespace = namespace.intern();
if(!namesInterned) {
namespace = namespace.intern();
} else if(checkNamesInterned) {
checkInterning(namespace);
}
String prefix = getPrefix( namespace, false, true );
//assert( prefix != null);
//if(prefix.length() == 0) {
if(prefix == null) {
// needs to declare prefix to hold default namespace
//NOTE: attributes such as a='b' are in NO namespace
prefix = generatePrefix(namespace);
}
out.write(prefix);
out.write(':');
// if(prefix.length() > 0) {
// out.write(prefix);
// out.write(':');
// }
}
//assert name != null;
out.write(name);
out.write('=');
//assert value != null;
out.write( attributeUseApostrophe ? '\'' : '"');
writeAttributeValue(value, out);
out.write( attributeUseApostrophe ? '\'' : '"');
return this;
}
protected void closeStartTag() throws IOException {
if(finished) {
throw new IllegalArgumentException("trying to write past already finished output"+getLocation());
}
if(seenBracket) {
seenBracket = seenBracketBracket = false;
}
if( startTagIncomplete || setPrefixCalled ) {
if(setPrefixCalled) {
throw new IllegalArgumentException(
"startTag() must be called immediately after setPrefix()"+getLocation());
}
if(!startTagIncomplete) {
throw new IllegalArgumentException("trying to close start tag that is not opened"+getLocation());
}
// write all namespace delcarations!
writeNamespaceDeclarations();
out.write('>');
elNamespaceCount[ depth ] = namespaceEnd;
startTagIncomplete = false;
}
}
private void writeNamespaceDeclarations() throws IOException
{
//int start = elNamespaceCount[ depth - 1 ];
for (int i = elNamespaceCount[ depth - 1 ]; i < namespaceEnd; i++)
{
if(doIndent && namespaceUri[ i ].length() > 40) {
writeIndent();
out.write(" ");
}
if(namespacePrefix[ i ] != "") {
out.write(" xmlns:");
out.write(namespacePrefix[ i ]);
out.write('=');
} else {
out.write(" xmlns=");
}
out.write( attributeUseApostrophe ? '\'' : '"');
//NOTE: escaping of namespace value the same way as attributes!!!!
writeAttributeValue(namespaceUri[ i ], out);
out.write( attributeUseApostrophe ? '\'' : '"');
}
}
public XmlSerializer endTag(String namespace, String name) throws IOException
{
// check that level is valid
////assert namespace != null;
//if(namespace != null) {
// namespace = namespace.intern();
//}
seenBracket = seenBracketBracket = false;
if(namespace != null) {
if(!namesInterned) {
namespace = namespace.intern();
} else if(checkNamesInterned) {
checkInterning(namespace);
}
}
if(namespace != elNamespace[ depth ])
{
throw new IllegalArgumentException(
"expected namespace "+printable(elNamespace[ depth ])
+" and not "+printable(namespace)+getLocation());
}
if(name == null) {
throw new IllegalArgumentException("end tag name can not be null"+getLocation());
}
if(checkNamesInterned && namesInterned) {
checkInterning(name);
}
String startTagName = elName[ depth ];
if((!namesInterned && !name.equals(startTagName))
|| (namesInterned && name != startTagName ))
{
throw new IllegalArgumentException(
"expected element name "+printable(elName[ depth ])+" and not "+printable(name)+getLocation());
}
if(startTagIncomplete) {
writeNamespaceDeclarations();
out.write(" />"); //space is added to make it easier to work in XHTML!!!
--depth;
} else {
//assert startTagIncomplete == false;
if(doIndent && seenTag) { writeIndent(); }
out.write("");
String startTagPrefix = elPrefix[ depth ];
if(startTagPrefix.length() > 0) {
out.write(startTagPrefix);
out.write(':');
}
// if(namespace != null && namespace.length() > 0) {
// //TODO prefix should be alredy known from matching start tag ...
// final String prefix = lookupOrDeclarePrefix( namespace );
// //assert( prefix != null);
// if(prefix.length() > 0) {
// out.write(prefix);
// out.write(':');
// }
// }
out.write(name);
out.write('>');
--depth;
}
namespaceEnd = elNamespaceCount[ depth ];
startTagIncomplete = false;
seenTag = true;
return this;
}
public XmlSerializer text (String text) throws IOException
{
//assert text != null;
if(startTagIncomplete || setPrefixCalled) closeStartTag();
if(doIndent && seenTag) seenTag = false;
writeElementContent(text, out);
return this;
}
public XmlSerializer text (char [] buf, int start, int len) throws IOException
{
if(startTagIncomplete || setPrefixCalled) closeStartTag();
if(doIndent && seenTag) seenTag = false;
writeElementContent(buf, start, len, out);
return this;
}
public void cdsect (String text) throws IOException
{
if(startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag();
if(doIndent && seenTag) seenTag = false;
out.write("");
}
public void entityRef (String text) throws IOException
{
if(startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag();
if(doIndent && seenTag) seenTag = false;
out.write('&');
out.write(text); //escape?
out.write(';');
}
public void processingInstruction (String text) throws IOException
{
if(startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag();
if(doIndent && seenTag) seenTag = false;
out.write("");
out.write(text); //escape?
out.write("?>");
}
public void comment (String text) throws IOException
{
if(startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag();
if(doIndent && seenTag) seenTag = false;
out.write("");
}
public void docdecl (String text) throws IOException
{
if(startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag();
if(doIndent && seenTag) seenTag = false;
out.write("");
}
public void ignorableWhitespace (String text) throws IOException
{
if(startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag();
if(doIndent && seenTag) seenTag = false;
if(text.length() == 0) {
throw new IllegalArgumentException(
"empty string is not allowed for ignorable whitespace"+getLocation());
}
out.write(text); //no escape?
}
public void flush () throws IOException
{
if(!finished && startTagIncomplete) closeStartTag();
out.flush();
}
// --- utility methods
protected void writeAttributeValue(String value, Writer out) throws IOException
{
//.[apostrophe and <, & escaped],
final char quot = attributeUseApostrophe ? '\'' : '"';
final String quotEntity = attributeUseApostrophe ? "'" : """;
int pos = 0;
for (int i = 0; i < value.length(); i++)
{
char ch = value.charAt(i);
if(ch == '&') {
if(i > pos) out.write(value.substring(pos, i));
out.write("&");
pos = i + 1;
} if(ch == '<') {
if(i > pos) out.write(value.substring(pos, i));
out.write("<");
pos = i + 1;
}else if(ch == quot) {
if(i > pos) out.write(value.substring(pos, i));
out.write(quotEntity);
pos = i + 1;
} else if(ch < 32) {
//in XML 1.0 only legal character are #x9 | #xA | #xD
// and they must be escaped otherwise in attribute value they are normalized to spaces
if(ch == 13 || ch == 10 || ch == 9) {
if(i > pos) out.write(value.substring(pos, i));
out.write("");
out.write(Integer.toString(ch));
out.write(';');
pos = i + 1;
} else {
if(TRACE_ESCAPING) System.err.println(getClass().getName()+" DEBUG ATTR value.len="+value.length()+" "+printable(value));
throw new IllegalStateException(
//"character "+Integer.toString(ch)+" is not allowed in output"+getLocation());
"character "+printable(ch)+" ("+Integer.toString(ch)+") is not allowed in output"+getLocation()
+" (attr value="+printable(value)+")");
// in XML 1.1 legal are [#x1-#xD7FF]
// if(ch > 0) {
// if(i > pos) out.write(text.substring(pos, i));
// out.write("");
// out.write(Integer.toString(ch));
// out.write(';');
// pos = i + 1;
// } else {
// throw new IllegalStateException(
// "character zero is not allowed in XML 1.1 output"+getLocation());
// }
}
}
}
if(pos > 0) {
out.write(value.substring(pos));
} else {
out.write(value); // this is shortcut to the most common case
}
}
protected void writeElementContent(String text, Writer out) throws IOException
{
// esccape '<', '&', ']]>', <32 if necessary
int pos = 0;
for (int i = 0; i < text.length(); i++)
{
//TODO: check if doing char[] text.getChars() would be faster than getCharAt(i) ...
char ch = text.charAt(i);
if(ch == ']') {
if(seenBracket) {
seenBracketBracket = true;
} else {
seenBracket = true;
}
} else {
if(ch == '&') {
if(i > pos) out.write(text.substring(pos, i));
out.write("&");
pos = i + 1;
} else if(ch == '<') {
if(i > pos) out.write(text.substring(pos, i));
out.write("<");
pos = i + 1;
} else if(seenBracketBracket && ch == '>') {
if(i > pos) out.write(text.substring(pos, i));
out.write(">");
pos = i + 1;
} else if(ch < 32) {
//in XML 1.0 only legal character are #x9 | #xA | #xD
if( ch == 9 || ch == 10 || ch == 13) {
// pass through
// } else if(ch == 13) { //escape
// if(i > pos) out.write(text.substring(pos, i));
// out.write("");
// out.write(Integer.toString(ch));
// out.write(';');
// pos = i + 1;
} else {
if(TRACE_ESCAPING) System.err.println(getClass().getName()+" DEBUG TEXT value.len="+text.length()+" "+printable(text));
throw new IllegalStateException(
"character "+Integer.toString(ch)+" is not allowed in output"+getLocation()
+" (text value="+printable(text)+")");
// in XML 1.1 legal are [#x1-#xD7FF]
// if(ch > 0) {
// if(i > pos) out.write(text.substring(pos, i));
// out.write("");
// out.write(Integer.toString(ch));
// out.write(';');
// pos = i + 1;
// } else {
// throw new IllegalStateException(
// "character zero is not allowed in XML 1.1 output"+getLocation());
// }
}
}
if(seenBracket) {
seenBracketBracket = seenBracket = false;
}
}
}
if(pos > 0) {
out.write(text.substring(pos));
} else {
out.write(text); // this is shortcut to the most common case
}
}
protected void writeElementContent(char[] buf, int off, int len, Writer out) throws IOException
{
// esccape '<', '&', ']]>'
final int end = off + len;
int pos = off;
for (int i = off; i < end; i++)
{
final char ch = buf[i];
if(ch == ']') {
if(seenBracket) {
seenBracketBracket = true;
} else {
seenBracket = true;
}
} else {
if(ch == '&') {
if(i > pos) {
out.write(buf, pos, i - pos);
}
out.write("&");
pos = i + 1;
} else if(ch == '<') {
if(i > pos) {
out.write(buf, pos, i - pos);
}
out.write("<");
pos = i + 1;
} else if(seenBracketBracket && ch == '>') {
if(i > pos) {
out.write(buf, pos, i - pos);
}
out.write(">");
pos = i + 1;
} else if(ch < 32) {
//in XML 1.0 only legal character are #x9 | #xA | #xD
if( ch == 9 || ch == 10 || ch == 13) {
// pass through
// } else if(ch == 13 ) { //if(ch == '\r') {
// if(i > pos) {
// out.write(buf, pos, i - pos);
// }
// out.write("");
// out.write(Integer.toString(ch));
// out.write(';');
// pos = i + 1;
} else {
if(TRACE_ESCAPING) System.err.println(
getClass().getName()+" DEBUG TEXT value.len="
+len+" "+printable(new String(buf,off,len)));
throw new IllegalStateException(
"character "+printable(ch)+" ("+Integer.toString(ch)+") is not allowed in output"+getLocation());
// in XML 1.1 legal are [#x1-#xD7FF]
// if(ch > 0) {
// if(i > pos) out.write(text.substring(pos, i));
// out.write("");
// out.write(Integer.toString(ch));
// out.write(';');
// pos = i + 1;
// } else {
// throw new IllegalStateException(
// "character zero is not allowed in XML 1.1 output"+getLocation());
// }
}
}
if(seenBracket) {
seenBracketBracket = seenBracket = false;
}
// assert seenBracketBracket == seenBracket == false;
}
}
if(end > pos) {
out.write(buf, pos, end - pos);
}
}
/** simple utility method -- good for debugging */
protected static final String printable(String s) {
if(s == null) return "null";
StringBuffer retval = new StringBuffer(s.length() + 16);
retval.append("'");
char ch;
for (int i = 0; i < s.length(); i++) {
addPrintable(retval, s.charAt(i));
}
retval.append("'");
return retval.toString();
}
protected static final String printable(char ch) {
StringBuffer retval = new StringBuffer();
addPrintable(retval, ch);
return retval.toString();
}
private static void addPrintable(StringBuffer retval, char ch)
{
switch (ch)
{
case '\b':
retval.append("\\b");
break;
case '\t':
retval.append("\\t");
break;
case '\n':
retval.append("\\n");
break;
case '\f':
retval.append("\\f");
break;
case '\r':
retval.append("\\r");
break;
case '\"':
retval.append("\\\"");
break;
case '\'':
retval.append("\\\'");
break;
case '\\':
retval.append("\\\\");
break;
default:
if (ch < 0x20 || ch > 0x7e) {
final String ss = "0000" + Integer.toString(ch, 16);
retval.append("\\u" + ss.substring(ss.length() - 4, ss.length()));
} else {
retval.append(ch);
}
}
}
}
xpp3-1.1.4c/src/java/tests/AllXmlPullApiTests.java 100644 0 0 1007 10525225064 21066 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
import org.xmlpull.v1.tests.PackageTests;
/**
* Just call XML Pull API package tests driver.
*
* @author Aleksander Slominski
*/
public class AllXmlPullApiTests {
public static void main (String[] args) {
PackageTests.main(args);
}
}
xpp3-1.1.4c/src/java/tests/LICENSE_TESTS.txt 100644 0 0 61204 10525225064 17352 0 ustar aslom ewww 0 0 XMLPULL API TESTS LICENSE
--------------------------------------
XMLPULL V1 API TESTS
Copyright (C) 2002 Aleksander Slominski
XMLPULL V1 API TESTS are free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
XMLPULL V1 API TESTS are 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(see below and at http://www.gnu.org/copyleft/lesser.html).
NOTE: XMLPULL V1 API TESTS are released under the Lesser GPL (LGPL) license,
granting you permission to use them in commercial and non-commercial applications for
free. Unlike regular GPL, LGPL does not force you to license your own software under GPL.
-------------------------------------------------------------------------------
GNU Lesser Public License
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your freedom to share and
change it. By contrast, the GNU General Public Licenses are intended to guarantee your
freedom to share and change free software--to make sure the software is free for all its
users.
This license, the Lesser General Public License, applies to some specially designated
software packages--typically libraries--of the Free Software Foundation and other authors
who decide to use it. You can use it too, but we suggest you first think carefully about
whether this license or the ordinary General Public License is the better strategy to use in
any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use, not price. Our
General Public Licenses are designed to make sure that you have the freedom to
distribute copies of free software (and charge for this service if you wish); that you receive
source code or can get it if you want it; that you can change the software and use pieces
of it in new free programs; and that you are informed that you can do these things.
To protect your rights, we need to make restrictions that forbid distributors to deny you
these rights or to ask you to surrender these rights. These restrictions translate to certain
responsibilities for you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis or for a fee, you must
give the recipients all the rights that we gave you. You must make sure that they, too,
receive or can get the source code. If you link other code with the library, you must
provide complete object files to the recipients, so that they can relink them with the library
after making changes to the library and recompiling it. And you must show them these
terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the library, and (2) we
offer you this license, which gives you legal permission to copy, distribute and/or modify
the library.
To protect each distributor, we want to make it very clear that there is no warranty for the
free library. Also, if the library is modified by someone else and passed on, the recipients
should know that what they have is not the original version, so that the original author's
reputation will not be affected by problems that might be introduced by others.
Finally, software patents pose a constant threat to the existence of any free program. We
wish to make sure that a company cannot effectively restrict the users of a free program
by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent
license obtained for a version of the library must be consistent with the full freedom of use
specified in this license.
Most GNU software, including some libraries, is covered by the ordinary GNU General
Public License. This license, the GNU Lesser General Public License, applies to certain
designated libraries, and is quite different from the ordinary General Public License. We
use this license for certain libraries in order to permit linking those libraries into non-free
programs.
When a program is linked with a library, whether statically or using a shared library, the
combination of the two is legally speaking a combined work, a derivative of the original
library. The ordinary General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General Public License permits
more lax criteria for linking other code with the library.
We call this license the "Lesser" General Public License because it does Less to protect
the user's freedom than the ordinary General Public License. It also provides other free
software developers Less of an advantage over competing non-free programs. These
disadvantages are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain special
circumstances.
For example, on rare occasions, there may be a special need to encourage the widest
possible use of a certain library, so that it becomes a de-facto standard. To achieve this,
non-free programs must be allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this case, there is little to
gain by limiting the free library to free software only, so we use the Lesser General Public
License.
In other cases, permission to use a particular library in non-free programs enables a
greater number of people to use a large body of free software. For example, permission
to use the GNU C Library in non-free programs enables many more people to use the
whole GNU operating system, as well as its variant, the GNU/Linux operating system.
Although the Lesser General Public License is Less protective of the users' freedom, it
does ensure that the user of a program that is linked with the Library has the freedom
and the wherewithal to run that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and modification follow. Pay
close attention to the difference between a "work based on the library" and a "work that
uses the library". The former contains code derived from the library, whereas the latter
must be combined with the library in order to run.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND
MODIFICATION
0. This License Agreement applies to any software library or other program which
contains a notice placed by the copyright holder or other authorized party saying it may
be distributed under the terms of this Lesser General Public License (also called "this
License"). Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data prepared so as to be
conveniently linked with application programs (which use some of those functions and
data) to form executables.
The "Library", below, refers to any such software library or work which has been
distributed under these terms. A "work based on the Library" means either the Library or
any derivative work under copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated straightforwardly into
another language. (Hereinafter, translation is included without limitation in the term
"modification".)
"Source code" for a work means the preferred form of the work for making modifications
to it. For a library, complete source code means all the source code for all modules it
contains, plus any associated interface definition files, plus the scripts used to control
compilation and installation of the library.
Activities other than copying, distribution and modification are not covered by this
License; they are outside its scope. The act of running a program using the Library is not
restricted, and output from such a program is covered only if its contents constitute a
work based on the Library (independent of the use of the Library in a tool for writing it).
Whether that is true depends on what the Library does and what the program that uses
the Library does.
1. You may copy and distribute verbatim copies of the Library's complete source code as
you receive it, in any medium, provided that you conspicuously and appropriately publish
on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all
the notices that refer to this License and to the absence of any warranty; and distribute a
copy of this License along with the Library.
You may charge a fee for the physical act of transferring a copy, and you may at your
option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Library or any portion of it, thus forming a
work based on the Library, and copy and distribute such modifications or work under the
terms of Section 1 above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices stating that
you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no charge to all
third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a table of data to
be supplied by an application program that uses the facility, other than as an
argument passed when the facility is invoked, then you must make a good
faith effort to ensure that, in the event an application does not supply such
function or table, the facility still operates, and performs whatever part of its
purpose remains meaningful.
(For example, a function in a library to compute square roots has a purpose
that is entirely well-defined independent of the application. Therefore,
Subsection 2d requires that any application-supplied function or table used
by this function must be optional: if the application does not supply it, the
square root function must still compute square roots.)
These requirements apply to the modified work as a whole. If identifiable
sections of that work are not derived from the Library, and can be
reasonably considered independent and separate works in themselves, then
this License, and its terms, do not apply to those sections when you
distribute them as separate works. But when you distribute the same sections
as part of a whole which is a work based on the Library, the distribution of
the whole must be on the terms of this License, whose permissions for other
licensees extend to the entire whole, and thus to each and every part
regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to
work written entirely by you; rather, the intent is to exercise the right to
control the distribution of derivative or collective works based on the Library.
In addition, mere aggregation of another work not based on the Library with
the Library (or with a work based on the Library) on a volume of a storage or
distribution medium does not bring the other work under the scope of this
License.
3. You may opt to apply the terms of the ordinary GNU General Public License instead of
this License to a given copy of the Library. To do this, you must alter all the notices that
refer to this License, so that they refer to the ordinary GNU General Public License,
version 2, instead of to this License. (If a newer version than version 2 of the ordinary
GNU General Public License has appeared, then you can specify that version instead if
you wish.) Do not make any other change in these notices.
Once this change is made in a given copy, it is irreversible for that copy, so the ordinary
GNU General Public License applies to all subsequent copies and derivative works made
from that copy.
This option is useful when you wish to copy part of the code of the Library into a program
that is not a library.
4. You may copy and distribute the Library (or a portion or derivative of it, under Section
2) in object code or executable form under the terms of Sections 1 and 2 above provided
that you accompany it with the complete corresponding machine-readable source code,
which must be distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange.
If distribution of object code is made by offering access to copy from a designated place,
then offering equivalent access to copy the source code from the same place satisfies the
requirement to distribute the source code, even though third parties are not compelled to
copy the source along with the object code.
5. A program that contains no derivative of any portion of the Library, but is designed to
work with the Library by being compiled or linked with it, is called a "work that uses the
Library". Such a work, in isolation, is not a derivative work of the Library, and therefore
falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library creates an executable that
is a derivative of the Library (because it contains portions of the Library), rather than a
"work that uses the library". The executable is therefore covered by this License. Section
6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file that is part of the
Library, the object code for the work may be a derivative work of the Library even though
the source code is not. Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The threshold for this to be true
is not precisely defined by law.
If such an object file uses only numerical parameters, data structure layouts and
accessors, and small macros and small inline functions (ten lines or less in length), then
the use of the object file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the Library will still fall
under Section 6.)
Otherwise, if the work is a derivative of the Library, you may distribute the object code for
the work under the terms of Section 6. Any executables containing that work also fall
under Section 6, whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or link a "work that uses
the Library" with the Library to produce a work containing portions of the Library, and
distribute that work under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse engineering for
debugging such modifications.
You must give prominent notice with each copy of the work that the Library is used in it
and that the Library and its use are covered by this License. You must supply a copy of
this License. If the work during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference directing the user to
the copy of this License. Also, you must do one of these things:
a) Accompany the work with the complete corresponding machine-readable
source code for the Library including whatever changes were used in the
work (which must be distributed under Sections 1 and 2 above); and, if the
work is an executable linked with the Library, with the complete
machine-readable "work that uses the Library", as object code and/or source
code, so that the user can modify the Library and then relink to produce a
modified executable containing the modified Library. (It is understood that the
user who changes the contents of definitions files in the Library will not
necessarily be able to recompile the application to use the modified
definitions.)
b) Use a suitable shared library mechanism for linking with the Library. A
suitable mechanism is one that (1) uses at run time a copy of the library
already present on the user's computer system, rather than copying library
functions into the executable, and (2) will operate properly with a modified
version of the library, if the user installs one, as long as the modified version
is interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at least three years, to
give the same user the materials specified in Subsection 6a, above, for a
charge no more than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy from a
designated place, offer equivalent access to copy the above specified
materials from the same place.
e) Verify that the user has already received a copy of these materials or that
you have already sent this user a copy.
For an executable, the required form of the "work that uses the Library" must include any
data and utility programs needed for reproducing the executable from it. However, as a
special exception, the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major components (compiler,
kernel, and so on) of the operating system on which the executable runs, unless that
component itself accompanies the executable.
It may happen that this requirement contradicts the license restrictions of other
proprietary libraries that do not normally accompany the operating system. Such a
contradiction means you cannot use both them and the Library together in an executable
that you distribute.
7. You may place library facilities that are a work based on the Library side-by-side in a
single library together with other library facilities not covered by this License, and
distribute such a combined library, provided that the separate distribution of the work
based on the Library and of the other library facilities is otherwise permitted, and provided
that you do these two things:
a) Accompany the combined library with a copy of the same work based on
the Library, uncombined with any other library facilities. This must be
distributed under the terms of the Sections above.
b) Give prominent notice with the combined library of the fact that part of it is
a work based on the Library, and explaining where to find the accompanying
uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute the Library except as
expressly provided under this License. Any attempt otherwise to copy, modify, sublicense,
link with, or distribute the Library is void, and will automatically terminate your rights under
this License. However, parties who have received copies, or rights, from you under this
License will not have their licenses terminated so long as such parties remain in full
compliance.
9. You are not required to accept this License, since you have not signed it. However,
nothing else grants you permission to modify or distribute the Library or its derivative
works. These actions are prohibited by law if you do not accept this License. Therefore,
by modifying or distributing the Library (or any work based on the Library), you indicate
your acceptance of this License to do so, and all its terms and conditions for copying,
distributing or modifying the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the Library), the
recipient automatically receives a license from the original licensor to copy, distribute, link
with or modify the Library subject to these terms and conditions. You may not impose any
further restrictions on the recipients' exercise of the rights granted herein. You are not
responsible for enforcing compliance by third parties with this License.
11. If, as a consequence of a court judgment or allegation of patent infringement or for
any other reason (not limited to patent issues), conditions are imposed on you (whether
by court order, agreement or otherwise) that contradict the conditions of this License,
they do not excuse you from the conditions of this License. If you cannot distribute so as
to satisfy simultaneously your obligations under this License and any other pertinent
obligations, then as a consequence you may not distribute the Library at all. For example,
if a patent license would not permit royalty-free redistribution of the Library by all those
who receive copies directly or indirectly through you, then the only way you could satisfy
both it and this License would be to refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any particular
circumstance, the balance of the section is intended to apply, and the section as a whole
is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or other property
right claims or to contest validity of any such claims; this section has the sole purpose of
protecting the integrity of the free software distribution system which is implemented by
public license practices. Many people have made generous contributions to the wide
range of software distributed through that system in reliance on consistent application of
that system; it is up to the author/donor to decide if he or she is willing to distribute
software through any other system and a licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed to be a consequence
of the rest of this License.
12. If the distribution and/or use of the Library is restricted in certain countries either by
patents or by copyrighted interfaces, the original copyright holder who places the Library
under this License may add an explicit geographical distribution limitation excluding those
countries, so that distribution is permitted only in or among countries not thus excluded. In
such case, this License incorporates the limitation as if written in the body of this License.
13. The Free Software Foundation may publish revised and/or new versions of the Lesser
General Public License from time to time. Such new versions will be similar in spirit to the
present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library specifies a version
number of this License which applies to it and "any later version", you have the option of
following the terms and conditions either of that version or of any later version published
by the Free Software Foundation. If the Library does not specify a license version
number, you may choose any version ever published by the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free programs whose
distribution conditions are incompatible with these, write to the author to ask for
permission. For software which is copyrighted by the Free Software Foundation, write to
the Free Software Foundation; we sometimes make exceptions for this. Our decision will
be guided by the two goals of preserving the free status of all derivatives of our free
software and of promoting the sharing and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS
WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
xpp3-1.1.4c/src/java/tests/README.txt 100644 0 0 156 10525225064 16202 0 ustar aslom ewww 0 0 This is copy of src/java/tests directory from xmlpull-api-v1 CVS
for more details see: http://www.xmlpull.org
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/PackageTests.java 100644 0 0 16762 10525225064 23753 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import junit.framework.Test;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import junit.textui.ResultPrinter;
import junit.textui.TestRunner;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
// -server -Dorg.xmlpull.v1.XmlPullParserFactory=org.xmlpull.v1.xni2xmlpull1.X2ParserFactory
// -Dorg.xmlpull.v1.XmlPullParserFactory=org.xmlpull.v1.xni2xmlpull1.X2ParserFactory
// -Dorg.xmlpull.v1.XmlPullParserFactory=org.xmlpull.mxp1.MXParserFactory
// -Dorg.xmlpull.v1.tests=org.xmlpull.mxp1.MXParser,org.xmlpull.mxp1_serializer.MXSerializer
/**
* TODO: add tests for mixed next() with nextToken()
*
* @author Aleksander Slominski
*/
public class PackageTests extends TestRunner {
private static boolean runAll;
public static boolean runnigAllTests() { return runAll; }
//public static void setRunnigAllTests(boolean enable) { runAll = enable; }
public PackageTests() {
super();
}
public static Test suite() {
TestSuite suite = new TestSuite("XmlPull V1 API TESTS");
suite.addTestSuite(TestFactory.class);
suite.addTestSuite(TestSimple.class);
suite.addTestSuite(TestSimpleWithNs.class);
suite.addTestSuite(TestSerialize.class);
suite.addTestSuite(TestSerializeWithNs.class);
suite.addTestSuite(TestSimpleToken.class);
suite.addTestSuite(TestAttributes.class);
suite.addTestSuite(TestEolNormalization.class);
suite.addTestSuite(TestEntityReplacement.class);
suite.addTestSuite(TestCdsect.class);
suite.addTestSuite(TestEvent.class);
suite.addTestSuite(TestToken.class);
suite.addTestSuite(TestMisc.class);
suite.addTestSuite(TestSetInput.class);
suite.addTestSuite(TestSimpleProcessDocdecl.class);
suite.addTestSuite(TestSimpleValidation.class);
suite.addTestSuite(TestProcessDocdecl.class);
// finally run tests based on XML input files
suite.addTestSuite(TestBootstrapXmlTests.class);
suite.addTestSuite(TestXmlSimple.class);
suite.addTestSuite(TestXmlTypical.class);
suite.addTestSuite(TestXmlCdsect.class);
return suite;
}
public synchronized void tick() {
//if(resultPrinter != null) {
// resultPrinter.startTest(null);
//} else {
System.err.print(".");
//}
}
// public synchronized void startTest(Test test) {
// writer()
// System.err.print(".");
// //if (fColumn++ >= 40) {
// // writer().println();
// // fColumn= 0;
// //}
// }
private static StringBuffer notes = new StringBuffer();
public static void addNote(String note) {
if(PackageTests.runnigAllTests() == false) {
System.out.print(note);
System.out.flush();
}
notes.append(note);
}
public void runPackageTests(String testFactoryName) {
//writer()
System.err.println("Executing XmlPull API tests"
+(testFactoryName != null ? " for '"+testFactoryName+"'" : ""));
notes.setLength(0);
XmlPullParserFactory f = null;
try {
f = UtilTestCase.factoryNewInstance();
addNote("* factory "+f.getClass()+"\n");//+" created from property "
//+System.getProperty(XmlPullParserFactory.PROPERTY_NAME)+"\n");
} catch (Exception ex) {
System.err.println(
"ERROR: tests aborted - could not create instance of XmlPullParserFactory:");
ex.printStackTrace();
System.exit(1);
}
XmlPullParser parser = null;
try {
parser=f.newPullParser();
} catch (Exception ex) {
System.err.println(
"ERROR: tests aborted - could not create instance of XmlPullParser from factory "
+f.getClass());
ex.printStackTrace();
System.exit(2);
}
XmlSerializer serializer = null;
try {
serializer=f.newSerializer();
} catch (Exception ex) {
System.err.println(
"ERROR: tests aborted - could not create instance of XmlSerializer from factory "
+f.getClass());
ex.printStackTrace();
System.exit(3);
}
String name = getClass().getName();
name = name.substring(name.lastIndexOf('.')+1);
System.out.println(name+" uses factory="+f.getClass().getName()
+" parser="+parser.getClass().getName()
+" serializer="+serializer.getClass().getName()
);
// now run all tests ...
//junit.textui.TestRunner.run(suite());
TestRunner aTestRunner= new TestRunner();
try {
TestResult r = doRun(suite(), false);
if (!r.wasSuccessful())
System.exit(-1);
//System.exit(0);
} catch(Exception e) {
System.err.println(e.getMessage());
System.exit(-2);
}
if(notes.length() > 0) {
//writer().
System.err.println("Test results "
+(testFactoryName != null ? "for '"+testFactoryName+"'" : "")
+"\n"+notes+"\n");
}
}
public void printFinalReport() {
//writer()
System.err.println("\nAll tests were passed.");
}
public static void main (String[] args) {
final PackageTests driver = new PackageTests();
final ResultPrinter resultPrinter = new ResultPrinter(System.err);
driver.setPrinter(resultPrinter);
final String listOfTests = System.getProperty("org.xmlpull.v1.tests");
final String FACTORY_PROPERTY = XmlPullParserFactory.PROPERTY_NAME;
final String DEFAULT_FACTORY_PROPERTY = System.getProperty(FACTORY_PROPERTY);
runAll = true;
if(listOfTests != null) {
int pos = 0;
while (pos < listOfTests.length()) {
int cut = listOfTests.indexOf(':', pos);
if (cut == -1) cut = listOfTests.length();
String testFactoryName = listOfTests.substring(pos, cut);
if("DEFAULT".equals(testFactoryName)) {
if(DEFAULT_FACTORY_PROPERTY != null) {
System.setProperty(FACTORY_PROPERTY, DEFAULT_FACTORY_PROPERTY);
} else {
// overcoming limitation of System.setProperty not allowing
// null or empty values (who knows how to unset property ?!)
System.setProperty(FACTORY_PROPERTY, "DEFAULT");
}
} else {
System.setProperty(FACTORY_PROPERTY, testFactoryName);
}
driver.runPackageTests(testFactoryName);
pos = cut + 1;
}
driver.printFinalReport();
} else {
driver.runPackageTests(null);
}
System.exit(0);
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestAttributes.java 100644 0 0 22636 10525225064 24360 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
//import junit.framework.Test;
import junit.framework.TestSuite;
import java.io.StringReader;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* Test attribute uniqueness is ensured.
*
* @author Aleksander Slominski
*/
public class TestAttributes extends UtilTestCase {
private XmlPullParserFactory factory;
public TestAttributes(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
assertEquals(false, factory.getFeature(XmlPullParser.FEATURE_VALIDATION));
}
protected void tearDown() {
}
public void testAttribs() throws IOException, XmlPullParserException
{
final String XML_ATTRS =
""+
"my-event "+
" "+
" ";
XmlPullParser pp = factory.newPullParser();
pp.setInput(new StringReader(XML_ATTRS));
assertEquals(XmlPullParser.START_TAG, pp.next());
assertEquals("event", pp.getName());
assertEquals(XmlPullParser.START_TAG, pp.next());
assertEquals("type", pp.getName());
assertEquals(XmlPullParser.TEXT, pp.next());
assertEquals("my-event", pp.getText());
assertEquals(pp.next(), XmlPullParser.END_TAG);
assertEquals("type", pp.getName());
assertEquals(XmlPullParser.START_TAG, pp.next());
assertEquals("handback", pp.getName());
//assertEquals(XmlPullParser.CONTENT, pp.next());
//assertEquals("", pp.readContent());
String xsiNull = pp.getAttributeValue(
"http://www.w3.org/1999/XMLSchema/instance", "null");
assertEquals("1", xsiNull);
String xsiType = pp.getAttributeValue(
"http://www.w3.org/1999/XMLSchema/instance", "type");
assertEquals("ns2:string", xsiType);
String typeName = getQNameLocal(xsiType);
assertEquals("string", typeName);
String typeNS = getQNameUri(pp, xsiType);
assertEquals("http://www.w3.org/1999/XMLSchema", typeNS);
assertEquals(pp.next(), XmlPullParser.END_TAG);
assertEquals("handback", pp.getName());
assertEquals(pp.next(), XmlPullParser.END_TAG);
assertEquals("event", pp.getName());
assertEquals(pp.next(), XmlPullParser.END_DOCUMENT);
}
private String getQNameLocal(String qname) {
if(qname == null) return null;
int pos = qname.indexOf(':');
return qname.substring(pos + 1);
}
private String getQNameUri(XmlPullParser pp, String qname) throws XmlPullParserException {
if(qname == null) return null;
int pos = qname.indexOf(':');
if(pos == -1) throw new XmlPullParserException(
"qname des not have prefix");
String prefix = qname.substring(0, pos);
return pp.getNamespace(prefix);
}
public void testAttribUniq() throws IOException, XmlPullParserException
{
final String attribsOk =
" \n"+
"";
final String duplicateAttribs =
" \n"+
"";
final String duplicateNsAttribs =
" \n"+
"";
final String duplicateXmlns =
" \n"+
"";
final String duplicateAttribXmlnsDefault =
" \n"+
"";
XmlPullParser pp = factory.newPullParser();
parseOneElement(pp, attribsOk, false);
assertEquals("a", pp.getAttributeValue(null, "a"));
assertEquals("b", pp.getAttributeValue(null, "b"));
assertEquals("c", pp.getAttributeValue(null, "m:a"));
assertEquals("d", pp.getAttributeValue(null, "n:b"));
assertEquals("e", pp.getAttributeValue(null, "n:x"));
parseOneElement(pp, attribsOk, true);
assertEquals("a", pp.getAttributeValue("","a"));
assertEquals("b", pp.getAttributeValue("","b"));
assertEquals(null, pp.getAttributeValue("", "m:a"));
assertEquals(null, pp.getAttributeValue("", "n:b"));
assertEquals(null, pp.getAttributeValue("", "n:x"));
assertEquals("c", pp.getAttributeValue("Some-Namespace-URI", "a"));
assertEquals("d", pp.getAttributeValue("Some-Namespace-URI", "b"));
assertEquals("e", pp.getAttributeValue("Some-Namespace-URI", "x"));
parseOneElement(pp, duplicateNsAttribs, false);
parseOneElement(pp, duplicateAttribXmlnsDefault, false);
parseOneElement(pp, duplicateAttribXmlnsDefault, true);
Exception ex;
ex = null;
try {
parseOneElement(pp, duplicateAttribs, false);
} catch(XmlPullParserException rex) {
ex = rex;
}
assertNotNull(ex);
ex = null;
try {
parseOneElement(pp, duplicateAttribs, true);
} catch(XmlPullParserException rex) {
ex = rex;
}
assertNotNull(ex);
ex = null;
try {
parseOneElement(pp, duplicateXmlns, false);
} catch(XmlPullParserException rex) {
ex = rex;
}
assertNotNull(ex);
ex = null;
try {
parseOneElement(pp, duplicateXmlns, true);
} catch(XmlPullParserException rex) {
ex = rex;
}
assertNotNull(ex);
ex = null;
try {
parseOneElement(pp, duplicateNsAttribs, true);
} catch(XmlPullParserException rex) {
ex = rex;
}
assertNotNull(ex);
final String declaringDefaultEmptyNs =
" ";
// allowed when namespaces disabled
parseOneElement(pp, declaringDefaultEmptyNs, false);
// allowed to redeclare defaut anemspace to empty string, see:
// http://www.w3.org/TR/1999/REC-xml-names-19990114/#ns-decl
parseOneElement(pp, declaringDefaultEmptyNs, true);
final String declaringPrefixedEmptyNs =
" ";
// allowed when namespaces disabled
parseOneElement(pp, declaringPrefixedEmptyNs, false);
// otherwise it is error to declare '' for non-default NS as described in
// http://www.w3.org/TR/1999/REC-xml-names-19990114/#ns-decl
ex = null;
try {
parseOneElement(pp, declaringPrefixedEmptyNs, true);
} catch(XmlPullParserException rex) {
ex = rex;
}
assertNotNull(ex);
}
private void parseOneElement(
final XmlPullParser pp,
final String buf,
final boolean supportNamespaces)
throws IOException, XmlPullParserException
{
//pp.setInput(buf.toCharArray());
pp.setInput(new StringReader(buf));
//pp.setNamespaceAware(supportNamespaces);
pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, supportNamespaces);
//pp.setAllowedMixedContent(false);
pp.next();
//pp.readStartTag(stag);
if(supportNamespaces) {
assertEquals("test", pp.getName());
} else {
assertEquals("m:test", pp.getName());
}
}
public void testAttribValueNormalization() throws IOException, XmlPullParserException
{
final String XML_ATTRS =
" ";
XmlPullParser pp = factory.newPullParser();
pp.setInput(new StringReader(XML_ATTRS));
assertEquals(XmlPullParser.START_TAG, pp.next());
assertEquals("javadoc", pp.getName());
assertEquals("${packages}", pp.getAttributeValue(0));
assertEquals("${packages}", pp.getAttributeValue("", "packagenames"));
assertEquals(
"",
pp.getAttributeValue("", "bottom")
);
//System.out.println(pp.getAttributeValue("", "bottom"));
}
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestAttributes.class));
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestBootstrapXmlTests.java 100644 0 0 16024 10525225064 25705 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
//import junit.framework.Test;
//import junit.framework.TestCase;
import junit.framework.TestSuite;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* Make minimal checks that tests described in XML can be processed.
*
* @author Aleksander Slominski
*/
public class TestBootstrapXmlTests extends UtilTestCase {
private XmlPullParserFactory factory;
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestBootstrapXmlTests.class));
}
public TestBootstrapXmlTests(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
}
protected void tearDown() {
}
final String TEST_NS = "http://xmlpull.org/v1/tests/2002-08.xsd";
final String MINI_TEST_XML =
"\n"+
" \r"+
" "+
"<foo/> "+
" \n"+
" \n"+
" "+
" "+
" "+
" \n \n"
;
public void testMini() throws Exception {
XmlPullParser pp = factory.newPullParser();
pp.setInput( new StringReader( MINI_TEST_XML ) );
pp.next();
pp.require( XmlPullParser.START_TAG, TEST_NS, "tests");
pp.next();
pp.require( XmlPullParser.TEXT, null, null);
String text = pp.getText();
assertEquals("\n ", text);
pp.next();
pp.require( XmlPullParser.START_TAG, TEST_NS, "test-parser");
// check name
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "create-parser");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "create-parser");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "input-inline");
text = "";
if(pp.next() == XmlPullParser.TEXT) {
text = pp.getText();
pp.next();
}
assertEquals(" ", text);
pp.require( XmlPullParser.END_TAG, TEST_NS, "input-inline");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "next");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "next");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "expect");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "expect");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "next");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "next");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "expect");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "expect");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "next");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "next");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "expect");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "expect");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "test-parser");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "tests");
pp.next();
pp.require( XmlPullParser.END_DOCUMENT, null, null);
}
final String TYPICAL_TEST_XML =
"\n"+
" \r"+
" "+
"<foo att="t" att2='a' >&</foo>"+
//"<foo/> "+
" \r\n"+
" http://xmlpull.org/v1/doc/features.html#process-namespaces \r\n"+
" \n"+
" \n"+
" "+
" "+
" "+
" \n \n"
;
public void testTypical() throws Exception {
XmlPullParser pp = factory.newPullParser();
pp.setInput( new StringReader( TYPICAL_TEST_XML ) );
pp.next();
pp.require( XmlPullParser.START_TAG, TEST_NS, "tests");
pp.next();
pp.require( XmlPullParser.TEXT, null, null);
String text = pp.getText();
assertEquals("\n ", text);
pp.next();
pp.require( XmlPullParser.START_TAG, TEST_NS, "test-parser");
// check name
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "create-parser");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "create-parser");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "input-inline");
text = "";
if(pp.next() == XmlPullParser.TEXT) {
text = pp.getText();
pp.next();
}
assertEquals(" bar&baz & ", text);
pp.require( XmlPullParser.END_TAG, TEST_NS, "input-inline");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "set-feature");
text = pp.nextText();
assertEquals("http://xmlpull.org/v1/doc/features.html#process-namespaces", text);
pp.require( XmlPullParser.END_TAG, TEST_NS, "set-feature");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "expect");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "expect");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "next");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "next");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "expect");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "expect");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "next-text");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "next-text");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "next");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "next");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, TEST_NS, "expect");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "expect");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "test-parser");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, TEST_NS, "tests");
pp.next();
pp.require( XmlPullParser.END_DOCUMENT, null, null);
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestCdsect.java 100644 0 0 15541 10525225064 23434 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
//import junit.framework.Test;
import junit.framework.TestSuite;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* Simple test for CDATA parsing.
*
* @author Aleksander Slominski
*/
public class TestCdsect extends UtilTestCase {
private XmlPullParserFactory factory;
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestCdsect.class));
}
public TestCdsect(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
}
protected void tearDown() {
}
public void testCdsect() throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
final String XML =
"o ";
xpp.setInput(new StringReader(XML));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "t", null, false/*empty*/, 0);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, " foo ", false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "t", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
}
public void testCdsectWithEol() throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
final String XML =
" \no\n ";
xpp.setInput(new StringReader(XML));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "t", null, false/*empty*/, 0);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, " \nfoo \n\n\n", false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "t", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
}
public void testCdsectWithComment() throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
final String XML =
" \n]]>\r ";
xpp.setInput(new StringReader(XML));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "t", null, false/*empty*/, 0);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, " \nfoo\n", false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "t", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
}
public void testCdsectSoleContent() throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
final String XML =
"]]> ";
xpp.setInput(new StringReader(XML));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "t", null, false/*empty*/, 0);
xpp.next();
//System.err.println(getClass()+" text="+printable(xpp.getText()));
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, "foo", false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "t", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
}
public void testBigCdsect() throws Exception {
testBigCdsect(1);
testBigCdsect(10);
testBigCdsect(15);
testBigCdsect(16);
testBigCdsect(100);
testBigCdsect(127);
testBigCdsect(128);
testBigCdsect(1023);
testBigCdsect(1024);
testBigCdsect(1025);
testBigCdsect(16*1024-1);
testBigCdsect(16*1024);
testBigCdsect(16*1024+1);
}
public void testBigCdsect(int size) throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
// inspired by http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=238
char[] oneToTen = "0123456789".toCharArray();
StringBuffer cdataContent = new StringBuffer(size+16);
for (int i = 0; i < size; i++) {
char c = oneToTen[i % 10];
cdataContent.append(c);
}
StringBuffer XML = new StringBuffer(size+16);
XML.append(" ");
xpp.setInput(new StringReader(XML.toString()));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, false/*empty*/, 0);
xpp.next();
//System.err.println(getClass()+" text="+printable(xpp.getText()+" expected="+cdataContent.toString()));
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, cdataContent.toString(), false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "foo", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestEntityReplacement.java 100644 0 0 13624 10525225064 25663 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
//import junit.framework.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import junit.framework.TestSuite;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
/**
* Test if entity replacement works ok.
* This test is designe to work bboth for validating and non validating parsers!
*
* @author Aleksander Slominski
*/
public class TestEntityReplacement extends UtilTestCase {
private XmlPullParserFactory factory;
public TestEntityReplacement(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
//assertEquals(false, factory.getFeature(XmlPullParser.FEATURE_VALIDATION));
}
protected void tearDown() {
}
public void testEntityReplacement() throws IOException, XmlPullParserException
{
// taken from http://www.w3.org/TR/REC-xml#sec-entexpand
final String XML_ENTITY_EXPANSION =
"\n"+
"\n"+
"\n"+
"' >\n"+
"%xx;\n"+
"]>"+
"This sample shows a &tricky; method. ";
XmlPullParser pp = factory.newPullParser();
// default parser must work!!!!
pp.setInput(new StringReader( XML_ENTITY_EXPANSION ) );
if(pp.getFeature( XmlPullParser.FEATURE_PROCESS_DOCDECL ) == false) {
pp.defineEntityReplacementText("tricky", "error-prone");
}
testEntityReplacement(pp);
// now we try for no FEATURE_PROCESS_DOCDECL
pp.setInput(new StringReader( XML_ENTITY_EXPANSION ) );
try {
pp.setFeature( XmlPullParser.FEATURE_PROCESS_DOCDECL, false );
} catch( Exception ex ){
}
if( pp.getFeature( XmlPullParser.FEATURE_PROCESS_DOCDECL ) == false ) {
pp.defineEntityReplacementText("tricky", "error-prone");
testEntityReplacement(pp);
}
// try to use FEATURE_PROCESS_DOCDECL if supported
pp.setInput(new StringReader( XML_ENTITY_EXPANSION ) );
try {
pp.setFeature( XmlPullParser.FEATURE_PROCESS_DOCDECL, true );
//PackageTests.addNote("* feature "+pp.FEATURE_PROCESS_DOCDECL+" is supported\n");
} catch( Exception ex ){
}
if( pp.getFeature( XmlPullParser.FEATURE_PROCESS_DOCDECL ) ) {
testEntityReplacement(pp);
}
// try to use FEATURE_VALIDATION if supported
pp.setInput(new StringReader( XML_ENTITY_EXPANSION ) );
try {
pp.setFeature( XmlPullParser.FEATURE_VALIDATION, true );
//PackageTests.addNote("* feature "+pp.FEATURE_VALIDATION+" is supported\n");
} catch( Exception ex ){
}
if( pp.getFeature( XmlPullParser.FEATURE_VALIDATION ) ) {
testEntityReplacement(pp);
}
}
public void testEntityReplacement(XmlPullParser pp) throws IOException, XmlPullParserException
{
pp.next();
checkParserStateNs(pp, 1, XmlPullParser.START_TAG,
null, 0, "", "test", null, false, 0);
pp.next();
checkParserStateNs(pp, 1, XmlPullParser.TEXT, null, 0, null, null,
"This sample shows a error-prone method.", false, -1);
pp.next();
checkParserStateNs(pp, 1, XmlPullParser.END_TAG,
null, 0, "", "test", null, false, -1);
pp.nextToken();
checkParserStateNs(pp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
}
/**
* Additional tests to confirm that
* Bug 192
* Escaped characters disappear in certain cases
* is not present in XmlPull implementations.
*/
public void testLastEntity(String xml, String expectedText) throws Exception {
InputStream stream = new ByteArrayInputStream(xml.getBytes());
XmlPullParser pp = factory.newPullParser();
// default parser must work!!!!
pp.setInput(stream, "UTF-8" );
pp.nextTag();
assertEquals(XmlPullParser.START_TAG, pp.getEventType());
//assertEquals("UTF-8", pp.getCharacterEncodingScheme());
//assertEquals("1.0", startdoc.getVersion());
String c = pp.nextText();
assertEquals(expectedText, c);
assertEquals(XmlPullParser.END_TAG, pp.getEventType());
}
public void testLastEntity() throws Exception {
testLastEntity(
"<text> ",
""
);
testLastEntity(
"<text> ",
" "
);
}
public void testDefineEntityBeforeSetInput() throws IOException, XmlPullParserException
{
XmlPullParser pp = factory.newPullParser();
pp.defineEntityReplacementText("foo", "bar");
pp.setInput(new StringReader( " " ) );
}
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestEntityReplacement.class));
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestEolNormalization.java 100644 0 0 12772 10525225064 25520 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import junit.framework.TestSuite;
import java.io.StringReader;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* Test end-of-line normalization
*
* @author Aleksander Slominski
*/
public class TestEolNormalization extends UtilTestCase {
private XmlPullParserFactory factory;
public TestEolNormalization(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
//factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
factory.setNamespaceAware(true);
assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
assertEquals(false, factory.getFeature(XmlPullParser.FEATURE_VALIDATION));
}
protected void tearDown() {
}
public void testNormalizeLine()
throws IOException, XmlPullParserException
{
XmlPullParser pp = factory.newPullParser();
//-----------------------
// ---- simple tests for end of line normalization
final String simpleR = "-\n-\r-\r\n-\n\r-";
// element content EOL normalizaton
final String tagSimpleR = ""+simpleR+" ";
final String expectedSimpleN = "-\n-\n-\n-\n\n-";
parseOneElement(pp, tagSimpleR, true);
assertEquals(XmlPullParser.TEXT, pp.next());
assertEquals(printable(expectedSimpleN), printable(pp.getText()));
// attribute content normalization
final String attrSimpleR = "";
final String normalizedSimpleN = "- - - - -";
parseOneElement(pp, attrSimpleR, true);
String attrVal = pp.getAttributeValue("","a");
//TODO Xerces2
assertEquals(printable(normalizedSimpleN), printable(attrVal));
//-----------------------
// --- more complex example with more line engins together
final String firstR =
"\r \r\n \n\r \n\n \r\n\r \r\r \r\n\n \n\r\r\n\r"+
"";
// element content
final String tagR =
""+
firstR+
" \r\n";
final String expectedN =
"\n \n \n\n \n\n \n\n \n\n \n\n \n\n\n\n";
parseOneElement(pp, tagR, true);
assertEquals(XmlPullParser.TEXT, pp.next());
assertEquals(printable(expectedN), printable(pp.getText()));
// attribute value
final String attrR =
" ";
final String normalizedN =
" ";
parseOneElement(pp, attrR, true);
attrVal = pp.getAttributeValue("","fifi");
//System.err.println("attrNormalized.len="+normalizedN.length());
//System.err.println("attrVal.len="+attrVal.length());
//TODO Xerces2
assertEquals(printable(normalizedN), printable(attrVal));
//-----------------------
// --- even more complex
final String manyLineBreaks =
"fifi\r&\r&\r\n foo &\r bar \n\r\n""+
firstR;
final String manyTag =
""+
manyLineBreaks+
" \r\n";
final String manyExpected =
"fifi\n&\n&\n foo &\n bar \n\n\""+
expectedN;
//"\r \r\n \n\r \n\n \r\n\r \r\r \r\n\n \n\r\r\n\r";
parseOneElement(pp, manyTag, true);
assertEquals(XmlPullParser.TEXT, pp.next());
assertEquals(printable(manyExpected), printable(pp.getText()));
assertEquals(manyExpected, pp.getText());
assertEquals(pp.next(), XmlPullParser.END_TAG);
assertEquals("test", pp.getName());
// having \r\n as last characters is the hardest case
//assertEquals(XmlPullParser.CONTENT, pp.next());
//assertEquals("\n", pp.readContent());
assertEquals(pp.next(), XmlPullParser.END_DOCUMENT);
final String manyAttr =
" ";
final String manyNormalized =
"fifi & & foo & bar \""+
normalizedN;
parseOneElement(pp, manyAttr, true);
attrVal = pp.getAttributeValue("","fifi");
//TODO Xerces2
assertEquals(printable(manyNormalized), printable(attrVal));
}
private void parseOneElement(
final XmlPullParser pp,
final String buf,
final boolean supportNamespaces)
throws IOException, XmlPullParserException
{
//pp.setInput(buf.toCharArray());
pp.setInput(new StringReader(buf));
//pp.setNamespaceAware(supportNamespaces);
pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, supportNamespaces);
//pp.setAllowedMixedContent(false);
pp.next();
//pp.readStartTag(stag);
if(supportNamespaces) {
assertEquals("test", pp.getName());
} else {
assertEquals("m:test", pp.getName());
}
}
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestEolNormalization.class));
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestEvent.java 100644 0 0 14157 10525225064 23312 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
//import junit.framework.Test;
//import junit.framework.TestCase;
import junit.framework.TestSuite;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* More complete test to verify paring.
*
* @author Aleksander Slominski
*/
public class TestEvent extends UtilTestCase {
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestEvent.class));
}
public TestEvent(String name) {
super(name);
}
protected XmlPullParserFactory newFactory() throws XmlPullParserException {
XmlPullParserFactory factory = factoryNewInstance();
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
assertEquals(false, factory.getFeature(XmlPullParser.FEATURE_VALIDATION));
return factory;
}
protected void tearDown() {
}
public void testEvent() throws Exception {
XmlPullParserFactory factory = newFactory();
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader(TEST_XML));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "root", null, false, 0);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, "\n", false, -1);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.START_TAG, null, 0, "", "foo", null, false, 0);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.TEXT, null, 0, null, null, "bar", false, -1);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.END_TAG, null, 0, "", "foo", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, "\n", false, -1);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.START_TAG,
null, 1, "http://www.xmlpull.org/temp", "hugo", null, false, 0);
checkNamespace(xpp, 0, null, "http://www.xmlpull.org/temp", true);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.TEXT, null, 1, null, null, " \n\n \n ", false, -1);
xpp.next();
checkParserStateNs(xpp, 3, XmlPullParser.START_TAG,
null, 1, "http://www.xmlpull.org/temp", "hugochild", null, false, 0);
xpp.next();
checkParserStateNs(xpp, 3, XmlPullParser.TEXT, null, 1, null, null,
"This is in a new namespace", false, -1);
xpp.next();
checkParserStateNs(xpp, 3, XmlPullParser.END_TAG,
null, 1, "http://www.xmlpull.org/temp", "hugochild", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.END_TAG,
null, 1, "http://www.xmlpull.org/temp", "hugo", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, "\t\n", false, -1);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.START_TAG, null, 0, "", "bar", null, true, 1);
checkAttribNs(xpp, 0, null, "", "testattr", "123abc");
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.END_TAG, null, 0, "", "bar", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "root", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
}
public void testMultiNs() throws Exception {
XmlPullParserFactory factory = newFactory();
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader(" "));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, false, 0);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.START_TAG, null, 1, "", "bar", null, true, 0);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.END_TAG, null, 1, "", "bar", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.START_TAG, null, 1, "", "char", null, false, 0);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.END_TAG, null, 1, "", "char", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "foo", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.setInput(new StringReader(" "));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, false, 0);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.START_TAG, null, 1, "", "bar", null, false, 0);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.END_TAG, null, 1, "", "bar", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.START_TAG, null, 1, "", "char", null, false, 0);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.END_TAG, null, 1, "", "char", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "foo", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestFactory.java 100644 0 0 4212 10525225064 23607 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import junit.framework.TestSuite;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
/**
* Simple test ot verify pull parser factory
*
* @author Aleksander Slominski
*/
public class TestFactory extends UtilTestCase {
public TestFactory(String name) {
super(name);
}
public void testFactory() throws Exception {
XmlPullParserFactory factory = factoryNewInstance();
//System.out.println("factory = "+factory);
XmlPullParser xpp = factory.newPullParser();
PackageTests.addNote("* default parser "+xpp.getClass()+"\n");
assertEquals(false, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
//factory.setNamespaceAware(false);
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
//assertEquals(false, factory.isNamespaceAware());
assertEquals(false, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
xpp = factory.newPullParser();
assertEquals(false, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
//factory.setNamespaceAware(true);
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
//assertEquals(true, factory.isNamespaceAware());
assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
PackageTests.addNote("* namespace enabled parser "+xpp.getClass()+"\n");
}
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestFactory.class));
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestMisc.java 100644 0 0 57164 10525225064 23131 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import junit.framework.TestSuite;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* Tests checking miscellaneous features.
*
* @author Aleksander Slominski
*/
public class TestMisc extends UtilTestCase {
private XmlPullParserFactory factory;
public TestMisc(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
}
protected void tearDown() {
}
public void testCharactersLegacy() throws Exception {
// [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
// SGML "legacy" in XML 1.0 as described in http://www.w3.org/TR/REC-xml#syntax
// that XML parsers are required to throw error if they encounter ']]>'
final String INPUT_XML = " d] ]] > ]> fd \n]]> \n ";
XmlPullParser pp = factory.newPullParser();
pp.setInput( new StringReader( INPUT_XML ) );
pp.nextTag();
pp.require( XmlPullParser.START_TAG, null, "t");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, null, "test1");
assertEquals( "d] ]] > ]> fd", pp.nextText() );
pp.require( XmlPullParser.END_TAG, null, "test1");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, null, "test2");
try {
pp.nextText();
fail("if TEXT contains ]]> parser must fail");
} catch(XmlPullParserException ex) {}
}
public void testNextTag() throws Exception {
final String INPUT_XML = " foo \n \n ";
XmlPullParser pp = factory.newPullParser();
pp.setInput( new StringReader( INPUT_XML ) );
pp.nextTag();
pp.require( XmlPullParser.START_TAG, null, "t");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, null, "test1");
assertEquals( "foo", pp.nextText() );
pp.require( XmlPullParser.END_TAG, null, "test1");
pp.nextTag();
pp.require( XmlPullParser.START_TAG, null, "test2");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, null, "test2");
pp.nextTag();
pp.require( XmlPullParser.END_TAG, null, "t");
pp.next();
pp.require( XmlPullParser.END_DOCUMENT, null, null);
}
// public void testReadText() throws Exception {
// final String INPUT_XML = "foo ";
// XmlPullParser pp = factory.newPullParser();
// pp.setInput( new StringReader( INPUT_XML ) );
// assertEquals( "", pp.readText() );
// pp.next();
// assertEquals( "", pp.readText() );
// pp.next();
// assertEquals( "foo", pp.readText() );
// assertEquals( pp.TYPES[ XmlPullParser.END_TAG ], pp.TYPES[ pp.getEventType() ]);
// }
public void testNextText() throws Exception {
final String INPUT_XML =
"foo bar ";
XmlPullParser pp = factory.newPullParser();
pp.setInput( new StringReader( INPUT_XML ) );
pp.next();
pp.require( XmlPullParser.START_TAG, null, "t");
pp.next();
pp.require( XmlPullParser.START_TAG, null, "test1");
assertEquals( "foo", pp.nextText() );
pp.require( XmlPullParser.END_TAG, null, "test1");
pp.next();
pp.require( XmlPullParser.START_TAG, null, "test2");
assertEquals( "", pp.nextText() );
pp.require( XmlPullParser.END_TAG, null, "test2");
pp.next();
pp.require( XmlPullParser.START_TAG, null, "test3");
assertEquals( "", pp.nextText() );
pp.require( XmlPullParser.END_TAG, null, "test3");
pp.next();
pp.require( XmlPullParser.START_TAG, null, "test4");
//pp.next();
//pp.require( XmlPullParser.TEXT, null, null);
assertEquals( "bar", pp.nextText() );
pp.require( XmlPullParser.END_TAG, null, "test4");
pp.next();
pp.require( XmlPullParser.END_TAG, null, "t");
pp.next();
pp.require( XmlPullParser.END_DOCUMENT, null, null);
// now check for error conditions
pp.setInput( new StringReader( INPUT_XML ) );
pp.next();
pp.require( XmlPullParser.START_TAG, null, "t");
pp.next();
pp.require( XmlPullParser.START_TAG, null, "test1");
pp.next();
pp.require( XmlPullParser.TEXT, null, null);
try {
pp.nextText();
fail("if current tag is TEXT no next text content can be returned!");
} catch(XmlPullParserException ex) {}
pp.setInput( new StringReader( INPUT_XML ) );
pp.next();
pp.require( XmlPullParser.START_TAG, null, "t");
try {
pp.nextText();
fail("if next tag is START_TAG no text content can be returned!");
} catch(XmlPullParserException ex) {}
pp.setInput( new StringReader( INPUT_XML ) );
pp.next();
pp.require( XmlPullParser.START_TAG, null, "t");
pp.next();
pp.require( XmlPullParser.START_TAG, null, "test1");
pp.next();
pp.next();
pp.require( XmlPullParser.END_TAG, null, "test1");
try {
pp.nextText();
fail("if current tag is END_TAG no text content can be returned!");
} catch(XmlPullParserException ex) {}
}
public void testRequire() throws Exception {
//public void require (int type, String namespace, String name)
final String INPUT_XML = "foo \t ";
XmlPullParser pp = factory.newPullParser();
pp.setInput( new StringReader( INPUT_XML ) );
pp.require( XmlPullParser.START_DOCUMENT, null, null);
pp.next();
pp.require( XmlPullParser.START_TAG, null, "test");
pp.require( XmlPullParser.START_TAG, "", null);
pp.require( XmlPullParser.START_TAG, "", "test");
pp.next();
pp.require( XmlPullParser.START_TAG, "", "t");
pp.next();
pp.require( XmlPullParser.TEXT, null, null);
pp.next();
pp.require( XmlPullParser.END_TAG, "", "t");
pp.next();
pp.require( XmlPullParser.START_TAG, "URI", "s");
pp.next();
pp.require( XmlPullParser.TEXT, null, null);
assertEquals("\t", pp.getText());
pp.next();
pp.require( XmlPullParser.END_TAG, "URI", "s");
pp.next();
pp.require( XmlPullParser.END_TAG, "", "test");
pp.next();
pp.require( XmlPullParser.END_DOCUMENT, null, null);
//now check that require will NOT skip white space
pp = factory.newPullParser();
pp.setInput( new StringReader( "\t " ) );
pp.require( XmlPullParser.START_DOCUMENT, null, null);
pp.next();
pp.require( XmlPullParser.START_TAG, "URI", "s");
pp.next();
try {
pp.require( XmlPullParser.END_TAG, "URI", "s");
fail("require() MUST NOT skip white spaces");
} catch(XmlPullParserException ex){}
}
public void testXmlDecl() throws Exception {
XmlPullParser pp = factory.newPullParser();
pp.setInput( new StringReader( " " ) );
pp.require( XmlPullParser.START_DOCUMENT, null, null);
pp.next();
pp.require( XmlPullParser.START_TAG, null, "foo");
pp.next();
pp.require( XmlPullParser.END_TAG, null, "foo");
pp.next();
pp.require( XmlPullParser.END_DOCUMENT, null, null);
pp.setInput( new StringReader(
" " ));
pp.require( XmlPullParser.START_DOCUMENT, null, null);
pp.next();
pp.require( XmlPullParser.START_TAG, null, "foo");
pp.setInput( new StringReader(
" " ));
pp.require( XmlPullParser.START_DOCUMENT, null, null);
assertNull(pp.getProperty(PROPERTY_XMLDECL_VERSION));
assertNull(pp.getProperty(PROPERTY_XMLDECL_STANDALONE));
assertNull(pp.getProperty(PROPERTY_XMLDECL_CONTENT));
pp.next();
pp.require( XmlPullParser.START_TAG, null, "foo");
String xmlDeclVersion = (String) pp.getProperty(PROPERTY_XMLDECL_VERSION);
if(xmlDeclVersion != null) {
assertEquals("XMLDecl version","1.0", xmlDeclVersion);
PackageTests.addNote("* optional property "+PROPERTY_XMLDECL_VERSION+" is supported\n");
}
Boolean xmlDeclStandalone = (Boolean) pp.getProperty(PROPERTY_XMLDECL_STANDALONE);
if(xmlDeclStandalone != null) {
assertTrue("XMLDecl standalone",xmlDeclStandalone.booleanValue());
PackageTests.addNote("* optional property "+PROPERTY_XMLDECL_STANDALONE+" is supported\n");
}
String xmlDeclContent = (String) pp.getProperty(PROPERTY_XMLDECL_CONTENT);
if(xmlDeclContent != null) {
String expected = " version=\"1.0\" \t encoding='UTF-8' \nstandalone='yes' ";
assertEquals("XMLDecl content", printable(expected), printable(xmlDeclContent));
PackageTests.addNote("* optional property "+PROPERTY_XMLDECL_CONTENT+" is supported\n");
}
// XML decl without required verion
pp.setInput( new StringReader( " " ) );
pp.require( XmlPullParser.START_DOCUMENT, null, null);
// check that proerties are reset
assertNull(pp.getProperty(PROPERTY_XMLDECL_VERSION));
assertNull(pp.getProperty(PROPERTY_XMLDECL_STANDALONE));
assertNull(pp.getProperty(PROPERTY_XMLDECL_CONTENT));
try {
pp.next();
fail("expected exception for invalid XML declaration without version");
} catch(XmlPullParserException ex){}
pp.setInput( new StringReader(
"\n " ));
pp.require( XmlPullParser.START_DOCUMENT, null, null);
try {
pp.next();
fail("expected exception for invalid XML declaration with standalone at wrong position");
} catch(XmlPullParserException ex){}
pp.setInput( new StringReader(
""
+" " ));
pp.require( XmlPullParser.START_DOCUMENT, null, null);
// make sure that XMLDecl is not reported
pp.nextToken();
pp.require( XmlPullParser.COMMENT, null, null);
pp.nextToken();
pp.require( XmlPullParser.START_TAG, null, "foo");
pp.next();
pp.require( XmlPullParser.END_TAG, null, "foo");
pp.next();
pp.require( XmlPullParser.END_DOCUMENT, null, null);
}
public void testComments() throws Exception {
XmlPullParser pp = factory.newPullParser();
pp.setInput( new StringReader( " " ) );
pp.require( XmlPullParser.START_DOCUMENT, null, null);
pp.next();
pp.require( XmlPullParser.START_TAG, null, "foo");
try {
pp.next();
fail("expected eception for invalid comment ending with --->");
} catch(XmlPullParserException ex){}
testContentMerging(pp, " ", null);
testContentMerging(pp, "\n\n ", "\n\n");
testContentMerging(pp, "\n ", "\n");
testContentMerging(pp, "alek\n ", "alek\n");
testContentMerging(pp, "al\nek\n ", "al\nek\n");
}
public void testContentMerging(final XmlPullParser pp, final String xml, final String expected)
throws Exception {
pp.setInput( new StringReader( xml ) );
pp.next();
pp.require( XmlPullParser.START_TAG, null, "foo");
if(expected != null) {
pp.next();
pp.require( XmlPullParser.TEXT, null, null);
assertEquals(printable(expected), printable(pp.getText()));
assertEquals(expected, pp.getText());
}
pp.next();
pp.require( XmlPullParser.END_TAG, null, "foo");
}
public void testComments2() throws Exception {
testComments2(" \r\n \n ", " \n \n ");
testComments2(" \r\n \r\n ", " \n \n ");
testComments2(" \r\n \r\n", " \n \n");
testComments2(" \r\n \r\n\r\n", " \n \n\n");
testComments2("\r\n\n \n ", "\n\n \n ");
testComments2("\r \n ", "\n \n ");
testComments2("\n \r", "\n \n");
testComments2("\r\n ","\n ");
testComments2("\r\n ? ","\n ? ");
testComments2("\n \n \n ");
testComments2("\n\n \n ");
testComments2(" \n \n ");
testComments2("\n \n ");
testComments2("\n \n");
testComments2("\n ");
testComments2("- - ");
testComments2("/b>");
testComments2("?? ?/b>");
testComments2("?? ?/b ?>");
}
public void testComments2(String value) throws Exception {
testComments2(value, value);
}
public void testComments2(String value, String expected) throws Exception {
XmlPullParser pp = factory.newPullParser();
final String XML = "\n\n ";
testContentMerging(pp, XML, "\n\n");
pp.setInput( new StringReader( XML ) );
pp.require( XmlPullParser.START_DOCUMENT, null, null);
pp.next();
pp.require( XmlPullParser.START_TAG, null, "foo");
pp.nextToken();
pp.require( XmlPullParser.TEXT, null, null);
assertEquals("\n", pp.getText());
pp.nextToken();
pp.require( XmlPullParser.COMMENT, null, null);
//System.err.println(getClass()+" expected="+printable(expected)+" text="+printable(pp.getText()));
assertEquals(printable(expected), printable(pp.getText()));
assertEquals(expected, pp.getText());
pp.nextToken();
pp.require( XmlPullParser.TEXT, null, null);
assertEquals("\n", pp.getText());
pp.nextToken();
pp.require( XmlPullParser.END_TAG, null, "foo");
}
public void testPI() throws Exception {
XmlPullParser pp = factory.newPullParser();
//System.out.println(getClass()+"-pp="+pp);
pp.setInput( new StringReader( " " ) );
pp.require( XmlPullParser.START_DOCUMENT, null, null);
pp.next();
pp.require( XmlPullParser.START_TAG, null, "foo");
pp.next();
pp.require( XmlPullParser.END_TAG, null, "foo");
pp.setInput( new StringReader( " " ) );
pp.require( XmlPullParser.START_DOCUMENT, null, null);
pp.next();
pp.require( XmlPullParser.START_TAG, null, "foo");
try {
pp.next();
fail("expected exception for invalid PI starting with xml");
} catch(XmlPullParserException ex){}
pp.setInput( new StringReader( " " ) );
pp.require( XmlPullParser.START_DOCUMENT, null, null);
pp.next();
pp.require( XmlPullParser.START_TAG, null, "foo");
pp.nextToken();
pp.require( XmlPullParser.PROCESSING_INSTRUCTION, null, null);
assertEquals("PI", "pi test", pp.getText());
pp.next();
pp.require( XmlPullParser.END_TAG, null, "foo");
testContentMerging(pp, " ", null);
testContentMerging(pp, "\n\n ", "\n\n");
testContentMerging(pp, "\n ", "\n");
try {
testContentMerging(pp, " this is PI ?>\n ", "\n");
fail("expected parser to fail as there is space in PI between and target");
} catch(org.xmlpull.v1.XmlPullParserException e) {
}
}
public void testPi2() throws Exception {
testPi2("\r\n \n ", "\n \n ");
testPi2("\r\n \r\n ", "\n \n ");
testPi2("\r\n \r\n", "\n \n");
testPi2("\r\n \r\n\r\n", "\n \n\n");
testPi2("\r\n\n \n ", "\n\n \n ");
testPi2("\r \n ", "\n \n ");
testPi2("\n \r", "\n \n");
testPi2("\r\n ","\n ");
testPi2("\n \n \n ");
testPi2("\n\n \n ");
testPi2(" \n \n ");
testPi2("\n \n ");
testPi2("\n \n");
testPi2("\n ");
testPi2("- - ");
testPi2("/b>");
testPi2("cx- ");
testPi2("|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
//import junit.framework.Test;
//import junit.framework.TestCase;
import junit.framework.TestSuite;
//import java.io.ByteArrayInputStream;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* Test FEATURE_PROCESS_DOCDECL (when supported)
*
* @author Aleksander Slominski
*/
public class TestProcessDocdecl extends UtilTestCase {
private XmlPullParserFactory factory;
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestProcessDocdecl.class));
}
public TestProcessDocdecl(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
//assertEquals(false, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
//assertEquals(false, factory.getFeature(XmlPullParser.FEATURE_VALIDATION));
assertEquals(false, factory.isNamespaceAware());
assertEquals(false, factory.isValidating());
//System.out.println("factory="+factory);
}
private XmlPullParser newParser(boolean useNamespaces, boolean useValidation)
throws XmlPullParserException
{
XmlPullParser xpp = factory.newPullParser();
xpp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, useNamespaces);
assertEquals(useNamespaces, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
try {
xpp.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
} catch(XmlPullParserException ex) {
return null;
}
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL));
try {
xpp.setFeature(XmlPullParser.FEATURE_VALIDATION, useValidation);
} catch(XmlPullParserException ex) {
return null;
}
assertEquals(useValidation, xpp.getFeature(XmlPullParser.FEATURE_VALIDATION));
return xpp;
}
protected void tearDown() {
}
public void testSimpleEntity() throws Exception {
testSimpleEntity(false, false);
testSimpleEntity(true, false);
testSimpleEntity(false, true);
testSimpleEntity(true, true);
}
public void testAttributeNormalization() throws Exception {
//TODO check that Xerces NON-validating normalization of NMTOKEN attributes
//http://www.w3.org/TR/REC-xml#AVNormalize
}
public void testSimpleEntity(boolean useNamespaces, boolean useValidation) throws Exception {
XmlPullParser xpp = newParser(useNamespaces, useValidation);
if(xpp == null) return;
//http://www.w3.org/TR/REC-xml#intern-replacement
final String XML_SIMPLE_ENT_PROLOG =
"\n"+
"\n"+
//"\n"+
"\n"+
// "\n"+
// "\n"+
// "\n"+
"\n"+
"\n"+
"]>\n";
final String XML_SIMPLE_ENT = XML_SIMPLE_ENT_PROLOG+
"Publication: &book; \n";
// final String PUB_ENTITY_INTERNAL_REPLACEMENT =
// "La Peste: Albert Camus,\n"+
// " 1947 ditions Gallimard. &rights;";
final String PUB_ENTITY_INTERNAL_REPLACEMENT =
"La Peste: Albert Camus,\n"+
"&pub;. &rights;";
final String PUB_ENTITY_REPLACEMENT =
"La Peste: Albert Camus,\n"+
" 1947 ditions Gallimard. All rights reserved";
//next
xpp.setInput(new StringReader( XML_SIMPLE_ENT ));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "test", null, false/*empty*/, 0);
xpp.next();
String expectedContent = "Publication: "+PUB_ENTITY_REPLACEMENT+" ";
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, expectedContent, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "test", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
//nextToken
}
public void testEntityWithMarkup() throws Exception {
testEntityWithMarkup(false, false);
testEntityWithMarkup(true, false);
testEntityWithMarkup(true, true);
testEntityWithMarkup(false, true);
}
public void testEntityWithMarkup(boolean useNamespaces, boolean useValidation)
throws Exception
{
XmlPullParser xpp = newParser(useNamespaces, useValidation);
if(xpp == null) return;
//http://www.w3.org/TR/REC-xml#sec-entexpand
// derived from
final String XML_REPLACE_ENT =
"\n"+
"\n"+
"\n"+
"An ampersand (&) may be escaped\n"+
"numerically (&#38;) or with a general entity\n"+
"(&).
\" >\n"+
"]>\n"+
"&example; ";
final String EXAMPLE_ENTITY_INTERNAL_REPLACEMENT =
"An ampersand (&) may be escaped\n"+
"numerically (&) or with a general entity\n"+
"(&).
\n";
final String EXAMPLE_ENTITY_TEXT_EVENT =
"An ampersand (&) may be escaped\n"+
"numerically (&) or with a general entity\n"+
"(&).";
//next
xpp.setInput(new StringReader( XML_REPLACE_ENT ));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "test", null, false/*empty*/, 0);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.START_TAG, null, 0, "", "p", null, false/*empty*/, 0);
xpp.next();
String expectedContent = EXAMPLE_ENTITY_TEXT_EVENT;
checkParserStateNs(xpp, 2, XmlPullParser.TEXT, null, 0, null, null, expectedContent, false, -1);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.END_TAG, null, 0, "", "p", null, false/*empty*/, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, " ", false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "test", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
}
public void testTricky() throws Exception {
testTricky(false, false);
testTricky(true, false);
testTricky(true, true);
testTricky(false, true);
}
public void testTricky(boolean useNamespaces, boolean useValidation)
throws Exception
{
XmlPullParser xpp = newParser(useNamespaces, useValidation);
if(xpp == null) return;
// derived from
final String XML_TRICKY =
"\n"+
"\n"+
"\n"+
"' >\n"+
"%xx;\n"+
"]>\n"+
"This sample shows a &tricky; method. \n";
final String EXPECTED_XML_TRICKY =
"This sample shows a error-prone method.";
//next
xpp.setInput(new StringReader( XML_TRICKY ));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "test", null, false/*empty*/, 0);
xpp.next();
String expectedContent = EXPECTED_XML_TRICKY;
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, expectedContent, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "test", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
//TODO nextToken()
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestSerialize.java 100644 0 0 24554 10525225064 24162 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import junit.framework.TestSuite;
import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
/**
* Simple test to verify serializer (with no namespaces)
*
* @author Aleksander Slominski
*/
public class TestSerialize extends UtilTestCase {
private XmlPullParserFactory factory;
private XmlPullParser xpp;
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestSerialize.class));
}
public TestSerialize(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
xpp = factory.newPullParser();
assertEquals(false, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
}
protected void tearDown() {
}
public void testSimpleWriter() throws Exception {
XmlSerializer ser = factory.newSerializer();
PackageTests.addNote("* default serializer "+ser.getClass()+"\n");
//assert there is error if trying to write
//assert there is error if trying to write
try {
ser.startTag(null, "foo");
fail("exception was expected of serializer if no input was set on parser");
} catch(Exception ex) {}
ser.setOutput(null);
//assert there is error if trying to write
try {
ser.startTag(null, "foo");
fail("exception was expected of serializer if no input was set on parser");
} catch(Exception ex) {}
StringWriter sw = new StringWriter();
ser.setOutput(sw);
try {
ser.setOutput(null, null);
fail("exception was expected of setOutput() if output stream is null");
} catch(IllegalArgumentException ex) {}
//check get property
ser.setOutput(sw);
//assertEquals(null, ser.getOutputEncoding());
ser.startDocument("ISO-8859-1", Boolean.TRUE);
ser.startTag(null, "foo");
ser.endTag(null, "foo");
ser.endDocument();
// now validate that can be deserialzied
//xpp.setInput(new StringReader(" "));
String serialized = sw.toString();
xpp.setInput(new StringReader(serialized));
assertEquals(null, xpp.getInputEncoding());
checkParserState(xpp, 0, XmlPullParser.START_DOCUMENT, null, null, false, -1);
xpp.next();
checkParserState(xpp, 1, XmlPullParser.START_TAG, "foo", null, xpp.isEmptyElementTag() /*empty*/, 0);
xpp.next();
checkParserState(xpp, 1, XmlPullParser.END_TAG, "foo", null, false, -1);
xpp.next();
checkParserState(xpp, 0, XmlPullParser.END_DOCUMENT, null, null, false, -1);
}
public void testSimpleStream() throws Exception {
XmlSerializer ser = factory.newSerializer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ser.setOutput(baos, "UTF-8");
ser.startDocument("UTF-8", null);
ser.startTag("", "foo");
ser.text("test");
ser.endTag("", "foo");
ser.endDocument();
//check taking input form input stream
//byte[] binput = "test ".getBytes("UTF8");
byte[] binput = baos.toByteArray();
xpp.setInput(new ByteArrayInputStream( binput ), "UTF-8" );
assertEquals("UTF-8", xpp.getInputEncoding());
//xpp.setInput(new StringReader( " " ) );
checkParserState(xpp, 0, XmlPullParser.START_DOCUMENT, null, null, false, -1);
xpp.next();
checkParserState(xpp, 1, XmlPullParser.START_TAG, "foo", null, false /*empty*/, 0);
xpp.next();
checkParserState(xpp, 1, XmlPullParser.TEXT, null, "test", false, -1);
assertEquals(false, xpp.isWhitespace());
xpp.next();
checkParserState(xpp, 1, XmlPullParser.END_TAG, "foo", null, false, -1);
xpp.next();
checkParserState(xpp, 0, XmlPullParser.END_DOCUMENT, null, null, false, -1);
}
public void testSimpleSerWithAttribute() throws Exception {
XmlSerializer ser = factory.newSerializer();
// one step further - it has an attribute and content ...
StringWriter sw = new StringWriter();
assertEquals(0, ser.getDepth());
ser.setOutput(sw);
assertEquals(0, ser.getDepth());
ser.startDocument(null, null);
assertEquals(0, ser.getDepth());
assertEquals(null, ser.getNamespace());
assertEquals(null, ser.getName());
ser.startTag(null, "foo");
assertEquals(1, ser.getDepth());
assertEquals(null, ser.getNamespace());
assertEquals("foo", ser.getName());
ser.attribute(null, "attrName", "attrVal");
assertEquals(1, ser.getDepth());
assertEquals(null, ser.getNamespace());
assertEquals("foo", ser.getName());
ser.text("bar");
assertEquals(1, ser.getDepth());
assertEquals(null, ser.getNamespace());
assertEquals("foo", ser.getName());
ser.startTag("", "p:t");
assertEquals(2, ser.getDepth());
assertEquals("", ser.getNamespace());
assertEquals("p:t", ser.getName());
ser.text("\n\t ");
ser.endTag("", "p:t");
assertEquals(1, ser.getDepth());
assertEquals(null, ser.getNamespace());
assertEquals("foo", ser.getName());
ser.endTag(null, "foo");
assertEquals(0, ser.getDepth());
assertEquals(null, ser.getNamespace());
assertEquals(null, ser.getName());
ser.endDocument();
assertEquals(0, ser.getDepth());
assertEquals(null, ser.getNamespace());
assertEquals(null, ser.getName());
//xpp.setInput(new StringReader("bar\r\n\t "));
String serialized = sw.toString();
xpp.setInput(new StringReader(serialized));
checkParserState(xpp, 0, XmlPullParser.START_DOCUMENT, null, null, false, -1);
xpp.next();
checkParserState(xpp, 1, XmlPullParser.START_TAG, "foo", null, false, 1);
checkAttrib(xpp, 0, "attrName", "attrVal");
xpp.next();
checkParserState(xpp, 1, XmlPullParser.TEXT, null, "bar", false, -1);
assertEquals(false, xpp.isWhitespace());
xpp.next();
checkParserState(xpp, 2, XmlPullParser.START_TAG, "p:t", null, false, 0);
xpp.next();
checkParserState(xpp, 2, XmlPullParser.TEXT, null, "\n\t ", false, -1);
assertTrue(xpp.isWhitespace());
xpp.next();
checkParserState(xpp, 2, XmlPullParser.END_TAG, "p:t", null, false, -1);
xpp.next();
checkParserState(xpp, 1, XmlPullParser.END_TAG, "foo", null, false, -1);
xpp.next();
checkParserState(xpp, 0, XmlPullParser.END_DOCUMENT, null, null, false, -1);
}
public void testEscaping() throws Exception {
XmlSerializer ser = factory.newSerializer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ser.setOutput(baos, "UTF-8");
ser.startDocument("UTF-8", null);
ser.startTag("", "foo");
String s = "test\u0008\t\r\n";
try {
ser.attribute(null, "att", s);
fail("expected to fail for control character (<32)");
} catch(IllegalArgumentException e) {
} catch(IllegalStateException e){
}
ser = factory.newSerializer();
baos = new ByteArrayOutputStream();
ser.setOutput(baos, "UTF-8");
ser.startDocument("UTF-8", null);
ser.startTag("", "foo");
try {
ser.text(s);
} catch(IllegalArgumentException e) {
} catch(IllegalStateException e){
}
ser = factory.newSerializer();
baos = new ByteArrayOutputStream();
ser.setOutput(baos, "UTF-8");
ser.startDocument("UTF-8", null);
ser.startTag("", "foo");
s = "test\u0009\t\r\n";
String expectedS = "test\u0009\t\n";
ser.attribute(null, "att", s);
ser.text(s);
ser.endTag("", "foo");
ser.endDocument();
//check taking input form input stream
//byte[] binput = "test ".getBytes("UTF8");
byte[] binput = baos.toByteArray();
//System.out.println(getClass()+" binput="+printable(new String(binput)));
xpp.setInput(new ByteArrayInputStream( binput ), "UTF-8" );
assertEquals("UTF-8", xpp.getInputEncoding());
//xpp.setInput(new StringReader( " " ) );
checkParserState(xpp, 0, XmlPullParser.START_DOCUMENT, null, null, false, -1);
xpp.next();
checkParserState(xpp, 1, XmlPullParser.START_TAG, "foo", null, false /*empty*/, 1);
assertEquals(printable(s), printable(xpp.getAttributeValue(null, "att")));
xpp.next();
checkParserState(xpp, 1, XmlPullParser.TEXT, null, expectedS, false, -1);
assertEquals(false, xpp.isWhitespace());
xpp.next();
checkParserState(xpp, 1, XmlPullParser.END_TAG, "foo", null, false, -1);
xpp.next();
checkParserState(xpp, 0, XmlPullParser.END_DOCUMENT, null, null, false, -1);
baos = new ByteArrayOutputStream();
ser.setOutput(baos, "UTF-8");
ser.startDocument("UTF-8", null);
ser.startTag("", "foo");
s = "test\u0000\t\r\n";
try {
ser.attribute(null, "att", s);
fail("expected to fail as zero chartacter is illegal both in XML 1.0 and 1.1");
} catch(Exception e) {}
try {
ser.text(s);
fail("expected to fail as zero chartacter is illegal both in XML 1.0 and 1.1");
} catch(Exception e) {}
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestSerializeWithNs.java 100644 0 0 137414 10525225064 25337 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import junit.framework.TestSuite;
import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
/**
* Simple test to verify serializer (with namespaces)
*
* @author Aleksander Slominski
*/
public class TestSerializeWithNs extends UtilTestCase {
private XmlPullParserFactory factory;
private XmlPullParser xpp;
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestSerializeWithNs.class));
}
public TestSerializeWithNs(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
factory.setNamespaceAware(true);
// now validate that can be deserialzied
xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
}
protected void tearDown() {
}
private void checkSimpleWriterResult(String textContent) throws Exception {
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, xpp.isEmptyElementTag() /*empty*/, 0);
if(textContent != null) {
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, textContent, false, -1);
}
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "foo", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
}
public void testSimpleWriter() throws Exception {
XmlSerializer ser = factory.newSerializer();
//assert there is error if trying to write
//assert there is error if trying to write
try {
ser.startTag("", "foo");
fail("exception was expected of serializer if no input was set");
} catch(Exception ex) {}
ser.setOutput(null);
//assert there is error if trying to write
try {
ser.startTag("", "foo");
fail("exception was expected of serializer if no input was set");
} catch(Exception ex) {}
StringWriter sw = new StringWriter();
ser.setOutput(sw);
try {
ser.setOutput(null, null);
fail("exception was expected of setOutput() if output stream is null");
} catch(IllegalArgumentException ex) {}
//check get property
ser.setOutput(sw);
//assertEquals(null, ser.getOutputEncoding());
ser.startDocument("ISO-8859-1", Boolean.TRUE);
ser.startTag("", "foo");
//TODO: check that startTag(null, ...) is allowed
ser.endTag("", "foo");
ser.endDocument();
//xpp.setInput(new StringReader(" "));
String serialized = sw.toString();
xpp.setInput(new StringReader(serialized));
assertEquals(null, xpp.getInputEncoding());
checkSimpleWriterResult(null);
}
public void testSimpleOutputStream() throws Exception {
XmlSerializer ser = factory.newSerializer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ser.setOutput(baos, "UTF-8");
ser.startDocument("UTF-8", null);
ser.startTag("", "foo");
final String text = "\"test<&>&";
ser.text(text);
ser.endTag("", "foo");
ser.endDocument();
//check taking input form input stream
//byte[] binput = "test ".getBytes("UTF8");
byte[] binput = baos.toByteArray();
xpp.setInput(new ByteArrayInputStream( binput ), "UTF-8" );
assertEquals("UTF-8", xpp.getInputEncoding());
//xpp.setInput(new StringReader( " " ) );
checkSimpleWriterResult(text);
}
public void testNamespaceGeneration() throws Exception {
XmlSerializer ser = factory.newSerializer();
//System.out.println(getClass()+" ser="+ser);
StringWriter sw = new StringWriter();
ser.setOutput(sw);
//assertEquals(null, ser.getOutputEncoding());
ser.startDocument("ISO-8859-1", Boolean.TRUE);
ser.setPrefix("boo", "http://example.com/boo");
ser.startTag("", "foo");
ser.attribute("http://example.com/boo", "attr", "val");
String booPrefix = ser.getPrefix("http://example.com/boo", false);
assertEquals("boo", booPrefix);
//check that new prefix may be generated after startTag and used as attribbute value
String newPrefix = ser.getPrefix("http://example.com/bar", true);
ser.attribute("http://example.com/bar", "attr", "val");
ser.startTag("http://example.com/bar", "foo");
ser.endTag("http://example.com/bar", "foo");
String checkPrefix = ser.getPrefix("http://example.com/bar", false);
assertEquals(newPrefix, checkPrefix);
ser.endTag("", "foo");
checkPrefix = ser.getPrefix("http://example.com/bar", false);
assertEquals(null, checkPrefix);
ser.endDocument();
//xpp.setInput(new StringReader(" "));
String serialized = sw.toString();
//System.out.println(getClass()+" serialized="+serialized);
//xpp.setInput(new StringReader(serialized));
}
public void testMisc() throws Exception {
XmlSerializer ser = factory.newSerializer();
StringWriter sw = new StringWriter();
ser.setOutput(sw);
assertEquals(0, ser.getDepth());
assertEquals(null, ser.getNamespace());
assertEquals(null, ser.getName());
// all comments etc
ser.startDocument(null, Boolean.TRUE);
assertEquals(0, ser.getDepth());
assertEquals(null, ser.getNamespace());
assertEquals(null, ser.getName());
final String docdecl = " foo [\n"+
"\n"+
"\n"
+"]";
ser.docdecl(docdecl);
ser.processingInstruction("pi test");
final String iws = "\n\t";
ser.ignorableWhitespace(iws);
assertEquals(0, ser.getDepth());
assertEquals(null, ser.getNamespace());
assertEquals(null, ser.getName());
ser.startTag(null, "foo");
assertEquals(1, ser.getDepth());
assertEquals(null, ser.getNamespace());
assertEquals("foo", ser.getName());
//check escaping & < > " '
final String attrVal = "attrVal&<>\"''&";
//final String attrVal = "attrVal&;";
ser.attribute(null, "attrName", attrVal);
assertEquals(1, ser.getDepth());
assertEquals(null, ser.getNamespace());
assertEquals("foo", ser.getName());
ser.entityRef("amp");
final String cdsect = "hello\"test";
ser.cdsect(cdsect);
ser.setPrefix("ns1", "usri2");
assertEquals(1, ser.getDepth());
assertEquals(null, ser.getNamespace());
assertEquals("foo", ser.getName());
ser.startTag("uri1", "bar");
assertEquals(2, ser.getDepth());
assertEquals("uri1", ser.getNamespace());
assertEquals("bar", ser.getName());
final String text = "test\n\ntest";
char[] buf = text.toCharArray();
ser.text(buf, 0, buf.length);
final String comment = "comment B- ";
ser.comment(comment);
assertEquals(2, ser.getDepth());
assertEquals("uri1", ser.getNamespace());
assertEquals("bar", ser.getName());
assertEquals(2, ser.getDepth());
assertEquals("uri1", ser.getNamespace());
assertEquals("bar", ser.getName());
ser.endDocument(); // should close unclosed foo and bar start tag
assertEquals(0, ser.getDepth());
assertEquals(null, ser.getNamespace());
assertEquals(null, ser.getName());
// -- now check that we get back what we serialized ...
String serialized = sw.toString();
//System.out.println(getClass()+" serialized="+serialized);
xpp.setInput(new StringReader(serialized));
xpp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 0, XmlPullParser.DOCDECL, null, 0, null, null, false, -1);
String gotDocdecl = xpp.getText();
if(gotDocdecl != null) {
assertEquals(printable(docdecl), printable(gotDocdecl));
}
xpp.nextToken();
checkParserStateNs(xpp, 0, XmlPullParser.PROCESSING_INSTRUCTION, null, 0, null, null, "pi test", false, -1);
xpp.nextToken();
if(xpp.getEventType() == XmlPullParser.IGNORABLE_WHITESPACE) {
String expectedIws = gatherTokenText(xpp, XmlPullParser.IGNORABLE_WHITESPACE, true);
assertEquals(printable(iws), printable(expectedIws));
}
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, false, 1);
checkAttribNs(xpp, 0, null, "", "attrName", attrVal);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.ENTITY_REF, null, 0, null, "amp", "&", false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.CDSECT, null, 0, null, null, cdsect, false, -1);
assertEquals(false, xpp.isWhitespace());
xpp.nextToken();
checkParserStateNs(xpp, 2, XmlPullParser.START_TAG, 2, "uri1", "bar", false, 0);
String gotText = nextTokenGathered(xpp, XmlPullParser.TEXT, false);
//System.out.println(getClass()+" text="+printable(text)+" got="+printable(gotText));
assertEquals(printable(text), printable(gotText));
//xpp.nextToken();
checkParserStateNs(xpp, 2, XmlPullParser.COMMENT, null, 2, null, null, comment, false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 2, XmlPullParser.END_TAG, 2, "uri1", "bar", false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, 0, "", "foo", false, -1);
}
private static final String ENV = "http://www.w3.org/2002/06/soap-envelope";
private static final String ALERTCONTROL = "http://example.org/alertcontrol";
private static final String ALERT = "http://example.org/alert";
private static final String EXPIRES = "2001-06-22T14:00:00-05:00";
private static final String MSG = "Pick up Mary at school at 2pm";
private static final String ROLE = "http://www.w3.org/2002/06/soap-envelope/role/ultimateReceiver";
// based on example from SOAP 1.2 spec http://www.w3.org/TR/soap12-part1/
private static final String SOAP12 =
""+
""+
""+
"1 "+
""+EXPIRES+" "+
" "+
" "+
""+
""+
""+MSG+" "+
" "+
" "+
" ";
private String generateSoapEnvelope(String envPrefix,
String alertcontrolPrefix,
String alertPrefix) throws Exception
{
return generateSoapEnvelope(envPrefix, alertcontrolPrefix, alertPrefix,
null, null, null);
}
private final String PROPERTY_SERIALIZER_INDENTATION =
"http://xmlpull.org/v1/doc/properties.html#serializer-indentation";
private final String PROPERTY_SERIALIZER_LINE_SEPARATOR =
"http://xmlpull.org/v1/doc/properties.html#serializer-line-separator";
private final String FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE =
"http://xmlpull.org/v1/doc/features.html#serializer-attvalue-use-apostrophe";
private boolean serializerIndentationSupported;
private boolean serializerLineSeparatorSupported;
private boolean serializerUseApostropheSupported;
/**
* Test optional support pretty printing
*/
public void testUseApostrophe() throws Exception {
XmlSerializer ser = factory.newSerializer();
try {
ser.setFeature(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE, true);
} catch(Exception ex) {
// ignore test if optional property not supported
return;
}
PackageTests.addNote("* optional feature "+FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE+" is supported\n");
boolean useApost = ser.getFeature(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE);
assertEquals(true, useApost);
checkAttributeQuot(true, ser);
ser.setFeature(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE, false);
useApost = ser.getFeature(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE);
assertEquals(false, useApost);
checkAttributeQuot(false, ser);
useApost = ser.getFeature(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE);
assertEquals(false, useApost);
ser.setFeature(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE, true);
useApost = ser.getFeature(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE);
assertEquals(true, useApost);
checkAttributeQuot(true, ser);
checkAttributeQuotMix(ser);
}
/**
* Check that attribute was quoted correctly
*/
private void checkAttributeQuot(boolean useApostrophe, XmlSerializer ser) throws Exception {
StringWriter sw = new StringWriter();
ser.setOutput(sw);
ser.startTag("", "test");
ser.attribute(null, "att", "value");
ser.endTag("", "test");
ser.endDocument();
String s = sw.toString();
if(useApostrophe) {
assertTrue("use apostrophe for attribute value", s.indexOf("'value'") !=-1);
} else {
assertTrue("use quotation for attribute value", s.indexOf("\"value\"") !=-1);
}
// some validaiton of serialized XML
XmlPullParser pp = factory.newPullParser();
pp.setInput(new StringReader(s));
pp.nextTag();
pp.require(XmlPullParser.START_TAG, null, "test");
assertEquals("value", pp.getAttributeValue(XmlPullParser.NO_NAMESPACE, "att"));
pp.nextTag();
pp.require(XmlPullParser.END_TAG, null, "test");
}
/**
* Check that attribute quotations can be changed _during_ serialization
*/
private void checkAttributeQuotMix(XmlSerializer ser) throws Exception {
StringWriter sw = new StringWriter();
ser.setOutput(sw);
ser.startTag("", "test");
ser.attribute(null, "att", "value");
ser.setFeature(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE, true);
ser.attribute(null, "attA", "valueA");
ser.setFeature(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE, false);
ser.attribute(null, "attQ", "valueQ");
ser.endTag("", "test");
ser.endDocument();
String s = sw.toString();
assertTrue("use apostrophe for attribute value", s.indexOf("'valueA'") !=-1);
assertTrue("use apostrophe for attribute value", s.indexOf("\"valueQ\"") !=-1);
// some validaiton of serialized XML
XmlPullParser pp = factory.newPullParser();
pp.setInput(new StringReader(s));
pp.nextTag();
pp.require(XmlPullParser.START_TAG, null, "test");
assertEquals("value", pp.getAttributeValue(XmlPullParser.NO_NAMESPACE, "att"));
assertEquals("valueA", pp.getAttributeValue(XmlPullParser.NO_NAMESPACE, "attA"));
assertEquals("valueQ", pp.getAttributeValue(XmlPullParser.NO_NAMESPACE, "attQ"));
pp.nextTag();
pp.require(XmlPullParser.END_TAG, null, "test");
}
public void testIndentation() throws Exception {
XmlSerializer ser = factory.newSerializer();
try {
ser.setProperty(PROPERTY_SERIALIZER_INDENTATION, " ");
} catch(Exception ex) {
// ignore test if optional property not supported
return;
}
PackageTests.addNote("* optional property "+PROPERTY_SERIALIZER_INDENTATION+" is supported\n");
StringWriter sw = new StringWriter();
ser.setOutput(sw);
ser.startTag("", "S1");
ser.startTag("", "S2");
ser.text("T");
ser.endTag("", "S2");
ser.startTag("", "M2");
ser.startTag("", "M3");
ser.endTag("", "M3");
ser.endTag("", "M2");
ser.endTag("", "S1");
ser.endDocument();
String xml = sw.toString();
//System.out.println(getClass()+" xml="+xml);
checkFormatting(" ", 0, "\n", "= 0);
// check that indent string is used at level
for (int i = 0; i < level; i++)
{
for (int j = indent.length() - 1; j >= 0 ; j--)
{
--pos;
if(pos < 0) {
fail("not enough indent for "+printable(s)+" in "+printable(xml));
}
char indentCh = indent.charAt(j);
char ch = xml.charAt(pos);
assertEquals(
"expected indentation character '"+printable(indent)+"'"
+" pos="+pos+" s='"+printable(s)
+"' xml="+printable(xml),
printable(indentCh), printable(ch));
}
}
// check that indent is of exact size and line ending is as expected
if(pos > 0) {
--pos;
char ch = xml.charAt(pos);
if(lineSeparator != null) {
for (int i = lineSeparator.length() - 1; i >=0 ; i--)
{
char lineSepCh = lineSeparator.charAt(i);
assertEquals(
"expected end of line at pos="+pos+" s='"+printable(s)
+"' xml="+printable(xml),
printable(lineSepCh), printable(ch));
--pos;
ch = xml.charAt(pos);
}
} else {
char indentCh = indent.charAt(indent.length() - 1);
assertTrue(
"expected character that is different from '"+printable(indent)+"'"
+" used for indentation "
+"pos="+pos+" s="+printable(s)+" xml="+printable(xml),
indentCh != ch);
}
}
}
public void testLineSeparator() throws Exception {
XmlSerializer ser = factory.newSerializer();
try {
ser.setProperty(PROPERTY_SERIALIZER_LINE_SEPARATOR, "\n");
} catch(Exception ex) {
// ignore test if optional property not supported
return;
}
PackageTests.addNote("* optional property "+PROPERTY_SERIALIZER_LINE_SEPARATOR+" is supported\n");
}
/** generate SOAP 1.2 envelope
try to use indentation
and check automtic namespace prefix declaration
and auto-generation of prefixes
*/
private String generateSoapEnvelope(String envPrefix,
String alertcontrolPrefix,
String alertPrefix,
Boolean attvalueUseApostrophe,
String indentation,
String lineSeparator
)
throws Exception
{
XmlSerializer ser = factory.newSerializer();
StringWriter sw = new StringWriter();
ser.setOutput(sw);
if(attvalueUseApostrophe !=null) {
try {
ser.setFeature(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE,
attvalueUseApostrophe.booleanValue());
serializerUseApostropheSupported = true;
} catch(Exception ex) {
// ignore if optional feature not supported
}
}
if(indentation !=null) {
try {
ser.setProperty(PROPERTY_SERIALIZER_INDENTATION, indentation);
serializerIndentationSupported = true;
} catch(Exception ex) {
// ignore if optional property not supported
}
}
if(lineSeparator !=null) {
try {
ser.setProperty(PROPERTY_SERIALIZER_LINE_SEPARATOR, lineSeparator);
serializerLineSeparatorSupported = true;
} catch(Exception ex) {
// ignore if optional property not supported
}
}
// all comments etc
ser.startDocument(null, Boolean.TRUE);
if(envPrefix != null) ser.setPrefix(envPrefix, ENV);
ser.startTag(ENV, "Envelope");
ser.startTag(ENV, "Header");
if(alertcontrolPrefix != null) ser.setPrefix(alertcontrolPrefix, ALERTCONTROL);
ser.startTag(ALERTCONTROL, "alertcontrol");
ser.attribute(ENV, "mustUnderstand", "true");
ser.attribute(ENV, "role", ROLE);
ser.startTag(ALERTCONTROL, "priority");
ser.text("1");
ser.endTag(ALERTCONTROL, "priority");
ser.startTag(ALERTCONTROL, "expires");
ser.text(EXPIRES);
ser.endTag(ALERTCONTROL, "expires");
ser.endTag(ALERTCONTROL, "alertcontrol");
ser.endTag(ENV, "Header");
ser.startTag(ENV, "Body");
if(alertPrefix != null) ser.setPrefix(alertPrefix, ALERT);
ser.startTag(ALERT, "alert");
ser.startTag(ALERT, "msg");
ser.text(MSG);
ser.endTag(ALERT, "msg");
ser.endTag(ALERT, "alert");
ser.endTag(ENV, "Body");
ser.endTag(ENV, "Envelope");
ser.endDocument();
String s = sw.toString();
return s;
}
public void testSetPrefix(String prefix) throws Exception {
XmlSerializer ser = factory.newSerializer();
StringWriter sw = new StringWriter();
ser.setOutput(sw);
final String NS = "http://example.com/test";
ser.setPrefix(prefix, NS);
ser.startTag(NS, "foo");
ser.endDocument();
String serialized = sw.toString();
//System.out.println(getClass()+" sw="+sw);
xpp.setInput(new StringReader(serialized));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
String expectedPrefix = (prefix != null && prefix.length() == 0) ? null : prefix;
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, expectedPrefix, 1, NS, "foo", null, xpp.isEmptyElementTag() /*empty*/, 0);
}
public void testSetPrefix() throws Exception {
testSetPrefix("ns");
testSetPrefix("");
testSetPrefix(null);
}
/**
* Testing for case described in http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=241
*/
public void testAttrPrefix(String prefix, boolean extraPrefix) throws Exception {
XmlSerializer ser = factory.newSerializer();
//System.err.println(getClass()+" ser="+ser.getClass());
StringWriter sw = new StringWriter();
ser.setOutput(sw);
final String NS = "http://example.com/test";
ser.setPrefix(prefix, NS);
if(extraPrefix) ser.setPrefix("p1", NS);
ser.startTag(NS, "foo");
ser.attribute(NS, "attr", "aar");
ser.endDocument();
String serialized = sw.toString();
xpp.setInput(new StringReader(serialized));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
String expectedPrefix = (prefix != null && prefix.length() == 0) ? null : prefix;
if(extraPrefix) expectedPrefix = "p1";
int nsCount = 1;
if(extraPrefix) ++nsCount;
if(expectedPrefix == null) ++nsCount;
//System.err.println(getClass()+" nsCount="+nsCount+" extraPrefix="+extraPrefix+" expectedPrefix="+expectedPrefix+" sw="+sw);
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, expectedPrefix, nsCount, NS, "foo", null, xpp.isEmptyElementTag() /*empty*/, 1);
checkAttribNs(xpp, 0, NS, "attr", "aar");
}
public void testAttrPrefix() throws Exception {
testAttrPrefix("ns", false);
testAttrPrefix("", false);
testAttrPrefix(null, false);
testAttrPrefix("ns", true);
testAttrPrefix("", true);
testAttrPrefix(null, true);
}
/** setPrefix check that prefix is not duplicated ... */
public void testSetPrefixAdv() throws Exception {
//TODO check redeclaring defult namespace
checkTestSetPrefixSoap(SOAP12);
checkTestSetPrefixSoap(generateSoapEnvelope("env", "n", "m"));
checkTestSetPrefixSoap(generateSoapEnvelope(null, null, "m"));
checkTestSetPrefixSoap(generateSoapEnvelope("env", null, "m"));
checkTestSetPrefixSoap(generateSoapEnvelope("env", "", ""));
String generated = generateSoapEnvelope("", "n", "m");
//System.err.println(getClass()+" generated="+generated);
// 1 is for one extra namespace must be added to declare xmlns namespace
// for attrbute mustUnderstan in SOAP-ENV namespace
checkTestSetPrefixSoap(generated, 1,false);
checkTestSetPrefixSoap(generateSoapEnvelope("", null, "m"),1,false);
//check optional pretty printing
checkTestSetPrefixSoap(generateSoapEnvelope("env", "n", "m", Boolean.FALSE, null, null));
checkTestSetPrefixSoap(generateSoapEnvelope("env", "n", "m", Boolean.TRUE, null, null));
checkTestSetPrefixSoap(generateSoapEnvelope("env", "n", "m", null, " ", null), true);
checkTestSetPrefixSoap(generateSoapEnvelope("env", "n", "m", null, "\t", null), true);
checkTestSetPrefixSoap(generateSoapEnvelope("env", "n", "m", null, " ", null), true);
String s = generateSoapEnvelope("env", "n", "m", Boolean.TRUE, " ", "\n");
//System.out.println(getClass()+" envelope="+generateSoapEnvelope("", "n", "m"));
checkTestSetPrefixSoap(s, true);
}
/** check that ti is possible to select which prefix should be used for namespace
* For more details check http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=169
*/
public void testSetPrefixPreferences() throws Exception {
testSetPrefixPreferences("", null);
testSetPrefixPreferences("saml", "saml");
// check case when prefix in Infoset is invalid -- prefix preoprty is optional after all
// http://www.w3.org/TR/xml-infoset/#infoitem.element
testSetPrefixPreferences("sample", "saml");
testSetPrefixPreferences("", null);
testSetPrefixPreferences("saml", "saml");
}
private void testSetPrefixPreferences(String preferredPrefix, String expectedPrefix) throws Exception {
XmlSerializer ser = factory.newSerializer();
StringWriter sw = new StringWriter();
ser.setOutput(sw);
//
// Book-Signing Event
//
//
//
//
//
// check namespaces generation with explicit prefixes
// byte[] binput = (""+
// ""+
// ""+
// " "+
// " ").getBytes("US-ASCII");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ser.setOutput(baos, "UTF8");
ser.startDocument(null, null);
ser.setPrefix("", "namesp");
ser.setPrefix("ns1", "namesp1");
ser.setPrefix("ns2", "namesp2");
ser.startTag("namesp", "foo");
ser.setPrefix("ns1", "x1");
ser.setPrefix("ns3", "namesp3");
ser.setPrefix("", "namesp1");
ser.startTag("x1", "bar");
ser.startTag("namesp2", "gugu");
ser.attribute("", "a1", "v1");
ser.attribute("namesp2", "a2", "v2" );
ser.attribute("http://www.w3.org/XML/1998/namespace", "lang", "en");
ser.attribute("x1", "a3", "v3");
ser.endTag("namesp2", "gugu");
ser.setPrefix("ns1", "y1");
ser.startTag("namesp1", "baz");
ser.endTag("namesp1", "baz");
ser.endTag("x1", "bar");
ser.endTag("namesp", "foo");
ser.endDocument();
byte[] binput = baos.toByteArray();
//System.out.println(getClass().getName()+"serialized="+new String(binput, "US-ASCII"));
xpp.setInput(new ByteArrayInputStream( binput ), "US-ASCII" );
assertEquals("US-ASCII", xpp.getInputEncoding());
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 3, "namesp", "foo", null, false, 0);
assertEquals(0, xpp.getNamespaceCount(0));
assertEquals(3, xpp.getNamespaceCount(1));
checkNamespace(xpp, 0, null, "namesp", true);
checkNamespace(xpp, 1, "ns1", "namesp1", true);
checkNamespace(xpp, 2, "ns2", "namesp2", true);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.START_TAG, "ns1", 6, "x1", "bar", null, false, 0);
assertEquals(0, xpp.getNamespaceCount(0));
assertEquals(3, xpp.getNamespaceCount(1));
assertEquals(6, xpp.getNamespaceCount(2));
checkNamespace(xpp, 3, "ns1", "x1", true);
checkNamespace(xpp, 4, "ns3", "namesp3", true);
checkNamespace(xpp, 5, null, "namesp1", true);
xpp.next();
checkParserStateNs(xpp, 3, XmlPullParser.START_TAG, "ns2", 6, "namesp2", "gugu", null, true, 4);
assertEquals(6, xpp.getNamespaceCount(2));
assertEquals(6, xpp.getNamespaceCount(3));
assertEquals("x1", xpp.getNamespace("ns1"));
assertEquals("namesp2", xpp.getNamespace("ns2"));
assertEquals("namesp3", xpp.getNamespace("ns3"));
checkAttribNs(xpp, 0, null, "", "a1", "v1");
checkAttribNs(xpp, 1, "ns2", "namesp2", "a2", "v2");
checkAttribNs(xpp, 2, "xml", "http://www.w3.org/XML/1998/namespace", "lang", "en");
checkAttribNs(xpp, 3, "ns1", "x1", "a3", "v3");
xpp.next();
checkParserStateNs(xpp, 3, XmlPullParser.END_TAG, "ns2", 6, "namesp2", "gugu", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 3, XmlPullParser.START_TAG, null, 7, "namesp1", "baz", null, xpp.isEmptyElementTag(), 0);
assertEquals(0, xpp.getNamespaceCount(0));
assertEquals(3, xpp.getNamespaceCount(1));
assertEquals(6, xpp.getNamespaceCount(2));
assertEquals(7, xpp.getNamespaceCount(3));
checkNamespace(xpp, 6, "ns1", "y1", true);
assertEquals("y1", xpp.getNamespace("ns1"));
assertEquals("namesp2", xpp.getNamespace("ns2"));
assertEquals("namesp3", xpp.getNamespace("ns3"));
xpp.next();
checkParserStateNs(xpp, 3, XmlPullParser.END_TAG, null, 7, "namesp1", "baz", null, false, -1);
assertEquals("y1", xpp.getNamespace("ns1"));
assertEquals("namesp2", xpp.getNamespace("ns2"));
assertEquals("namesp3", xpp.getNamespace("ns3"));
// check that declared namespaces can be accessed for current end tag
assertEquals(3, xpp.getDepth());
assertEquals(6, xpp.getNamespaceCount(2));
assertEquals(7, xpp.getNamespaceCount(3));
// chekc that namespace is accessible by direct addresssing
assertEquals(null, xpp.getNamespacePrefix(0));
assertEquals("namesp", xpp.getNamespaceUri(0));
assertEquals("ns1", xpp.getNamespacePrefix(1));
assertEquals("namesp1", xpp.getNamespaceUri(1));
assertEquals("ns1", xpp.getNamespacePrefix(3));
assertEquals("x1", xpp.getNamespaceUri(3));
assertEquals("ns1", xpp.getNamespacePrefix(6));
assertEquals("y1", xpp.getNamespaceUri(6));
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.END_TAG, "ns1", 6, "x1", "bar", null, false, -1);
// check that namespace is undelcared
assertEquals("x1", xpp.getNamespace("ns1"));
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 3, "namesp", "foo", null, false, -1);
assertEquals("namesp1", xpp.getNamespace("ns1"));
assertEquals("namesp2", xpp.getNamespace("ns2"));
assertEquals(null, xpp.getNamespace("ns3"));
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
assertEquals(null, xpp.getNamespace("ns1"));
assertEquals(null, xpp.getNamespace("ns2"));
assertEquals(null, xpp.getNamespace("ns3"));
}
private void assertXmlEquals(String expectedXml, String actualXml)
throws Exception
{
XmlPullParser expect = factory.newPullParser();
expect.setInput(new StringReader(expectedXml));
XmlPullParser actual = factory.newPullParser();
actual.setInput(new StringReader(actualXml));
while(true) {
expect.next();
actual.next();
assertXml("inconsistent event type", expect, actual,
XmlPullParser.TYPES[ expect.getEventType() ],
XmlPullParser.TYPES[ actual.getEventType() ]
);
if(expect.getEventType() == XmlPullParser.END_DOCUMENT) {
break;
}
if(expect.getEventType() == XmlPullParser.START_TAG
|| expect.getEventType() == XmlPullParser.END_TAG )
{
assertXml("tag names", expect, actual,
expect.getName(), actual.getName());
assertXml("tag namespaces", expect, actual,
expect.getNamespace(), actual.getNamespace());
if(expect.getEventType() == XmlPullParser.START_TAG) {
// check consisteny of attributes -- allow them to be in any order
int expectAttrCount = expect.getAttributeCount();
assertXml("attributes count", expect, actual,
""+expectAttrCount, ""+actual.getAttributeCount());
for (int i = 0; i < expectAttrCount; i++)
{
String expectAttrNamespace = expect.getAttributeNamespace(i);
String expectAttrName = expect.getAttributeName(i);
String expectAttrType = expect.getAttributeType(i);
String expectAttrValue = expect.getAttributeValue(i);
boolean expectAttrDefault = expect.isAttributeDefault(i);
// find this attribute actual position
int actualPos = -1;
for (int j = 0; j < expectAttrCount; j++)
{
if(expectAttrNamespace.equals(actual.getAttributeNamespace(j))
&& expectAttrName.equals(actual.getAttributeName(j)))
{
actualPos = j;
break;
}
}
String expectN = expectAttrNamespace+":"+expectAttrName;
if(actualPos == -1) {
System.err.println("expected:\n"+expectedXml
+"\nactual:\n"+actualXml);
fail("could not find expected attribute "+expectN
+" actual parser "+actual.getPositionDescription());
}
//and compare ...
assertXml("attribute "+expectN+" namespace", expect, actual,
expectAttrNamespace, actual.getAttributeNamespace(actualPos) );
assertXml("attribute "+expectN+" name", expect, actual,
expectAttrName, actual.getAttributeName(actualPos) );
assertXml("attribute "+expectN+" type", expect, actual,
expectAttrType, actual.getAttributeType(actualPos) );
assertXml("attribute "+expectN+" value", expect, actual,
expectAttrValue, actual.getAttributeValue(actualPos) );
assertXml("attribute "+expectN+" default", expect, actual,
""+expectAttrDefault, ""+actual.isAttributeDefault(actualPos) );
}
}
} else if(expect.getEventType() == XmlPullParser.TEXT) {
assertXml("text content", expect, actual,
expect.getText(), actual.getText());
} else {
fail("unexpected event type "+expect.getEventType()+" "+expect.getPositionDescription());
}
//System.err.print(".");
}
//System.err.println("\nOK");
}
private static void assertXml(String formatted,
XmlPullParser pExpected, XmlPullParser pActual,
String expected, String actual
)
{
if((expected != null && !expected.equals(actual))
|| (expected == null && actual != null))
{
fail(formatted
+" expected:<"+expected+"> but was:<"+actual+">"
+" (expecte parser position:"+pExpected.getPositionDescription()
+" and actual parser positon:"+pActual.getPositionDescription()
);
}
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestSetInput.java 100644 0 0 17324 10525225064 24003 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import junit.framework.TestSuite;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* Tests to determine that setInput works as expected for different encodings.
*
* @author Aleksander Slominski
*/
public class TestSetInput extends UtilTestCase {
private XmlPullParserFactory factory;
public TestSetInput(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
}
protected void tearDown() {
}
public void testSetReader() throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
xpp.setInput(null);
assertEquals(XmlPullParser.START_DOCUMENT, xpp.getEventType());
try {
xpp.next();
fail("exception was expected of next() if no input was set on parser");
} catch(XmlPullParserException ex) {}
// make input suspectible to read ...
ReaderWrapper reader = new ReaderWrapper(
new StringReader(" "));
assertEquals("no read() called in just contructed reader", false, reader.calledRead());
xpp.setInput(reader);
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
assertEquals("read() not called before next()", false, reader.calledRead());
xpp.next();
assertEquals("read() must be called after next()", true, reader.calledRead());
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, true/*empty*/, 0);
}
public void testSetInput() throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
// another test
byte[] binput = (" ").getBytes("UTF-8");
InputStreamWrapper isw = new InputStreamWrapper(
new ByteArrayInputStream( binput ));
assertEquals("no read() called in just contructed reader", false, isw.calledRead());
xpp.setInput(isw, "UTF-8");
assertEquals("UTF-8", xpp.getInputEncoding());
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
assertEquals("read() not called before next()", false, isw.calledRead());
xpp.nextToken();
assertEquals("read() must be called after next()", true, isw.calledRead());
//needs to resolve:
// java.lang.InternalError: Converter malfunction (UTF-16) -- please submit a bug report via http://java.sun.com/cgi-bin/bugreport.cgi
//
// // add BOM
// //byte[] binput1 = new byte[]{((byte)'\u00FE'), ((byte)'\u00FF')};
// //byte[] binput1 = new byte[]{((byte)'\u00FF'), ((byte)'\u00FE')};
// byte[] binput1 = new byte[0];
// byte[] binput2 =
// (" ").getBytes("UTF16");
// binput = new byte[ binput1.length + binput2.length ] ;
// System.arraycopy(binput1, 0, binput, 0, binput1.length);
// System.arraycopy(binput2, 0, binput, binput1.length, binput2.length);
// isw = new InputStreamWrapper(
// new ByteArrayInputStream( binput ));
// assertEquals("no read() called in just contructed reader", false, isw.calledRead());
//
// //xpp.setInput(isw, "UTF-16" ); //TODO why Xerces2 causes java Unicode decoder to fail ????
// xpp.setInput(isw, "UTF16" );
// //assertEquals("UTF-16", xpp.getInputEncoding());
// checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
// assertEquals("read() not called before next()", false, isw.calledRead());
//
// xpp.nextToken();
// assertEquals("read() must be called after next()", true, isw.calledRead());
//
// check input detecting -- for mutlibyte sequences ...
final String FEATURE_DETECT_ENCODING =
"http://xmlpull.org/v1/doc/features.html#detect-encoding";
if(xpp.getFeature(FEATURE_DETECT_ENCODING)) {
PackageTests.addNote("* optional feature "+FEATURE_DETECT_ENCODING+" is supported\n");
isw = new InputStreamWrapper(
new ByteArrayInputStream( binput ));
assertEquals("no read() called in just contructed reader", false, isw.calledRead());
xpp.setInput(isw, null );
assertEquals(null, xpp.getInputEncoding());
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
//assertEquals("read() not called before next()", false, isw.calledRead());
xpp.nextToken();
assertEquals("read() must be called after next()", true, isw.calledRead());
assertEquals("UTF16", xpp.getInputEncoding());
}
// check input detecting -- default
binput =
(" ").getBytes("ISO-8859-1");
isw = new InputStreamWrapper(
new ByteArrayInputStream( binput ));
assertEquals("no read() called in just contructed reader", false, isw.calledRead());
xpp.setInput(isw, null );
assertEquals(null, xpp.getInputEncoding());
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
//assertEquals("read() not called before next()", false, isw.calledRead());
xpp.next();
assertEquals("read() must be called after next()", true, isw.calledRead());
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, true/*empty*/, 0);
if(xpp.getFeature(FEATURE_DETECT_ENCODING)) {
assertEquals("ISO-8859-1", xpp.getInputEncoding());
}
}
// ------ allow to detect if input was read
private static class InputStreamWrapper extends InputStream {
InputStream is;
boolean calledRead;
public boolean calledRead() { return calledRead; }
public InputStreamWrapper(InputStream inputStream) {
is = inputStream;
}
public int read() throws IOException {
calledRead = true;
return is.read();
}
}
private static class ReaderWrapper extends Reader {
Reader r;
boolean calledRead;
public boolean calledRead() { return calledRead; }
public ReaderWrapper(Reader reader) {
r = reader;
}
public int read(char[]ch, int off, int len) throws IOException {
calledRead = true;
return r.read(ch, off, len);
}
public void close() throws IOException {
r.close();
}
}
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestSetInput.class));
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestSimple.java 100644 0 0 13543 10525225064 23460 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
//import junit.framework.Test;
import junit.framework.TestSuite;
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* Simple test ot verify pull parser factory
*
* @author Aleksander Slominski
*/
public class TestSimple extends UtilTestCase {
private XmlPullParserFactory factory;
public TestSimple(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
//assertEquals(false, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
//assertEquals(false, factory.getFeature(XmlPullParser.FEATURE_VALIDATION));
assertEquals(false, factory.isNamespaceAware());
assertEquals(false, factory.isValidating());
}
protected void tearDown() {
}
public void testSimple() throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(false, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
// this SHOULD always be OK
assertEquals("START_DOCUMENT", XmlPullParser.TYPES[XmlPullParser.START_DOCUMENT]);
assertEquals("END_DOCUMENT", XmlPullParser.TYPES[XmlPullParser.END_DOCUMENT]);
assertEquals("START_TAG", XmlPullParser.TYPES[XmlPullParser.START_TAG]);
assertEquals("END_TAG", XmlPullParser.TYPES[XmlPullParser.END_TAG]);
assertEquals("TEXT", XmlPullParser.TYPES[XmlPullParser.TEXT]);
assertEquals("CDSECT", XmlPullParser.TYPES[XmlPullParser.CDSECT]);
assertEquals("ENTITY_REF", XmlPullParser.TYPES[XmlPullParser.ENTITY_REF]);
assertEquals("IGNORABLE_WHITESPACE", XmlPullParser.TYPES[XmlPullParser.IGNORABLE_WHITESPACE]);
assertEquals("PROCESSING_INSTRUCTION", XmlPullParser.TYPES[XmlPullParser.PROCESSING_INSTRUCTION]);
assertEquals("COMMENT", XmlPullParser.TYPES[XmlPullParser.COMMENT]);
assertEquals("DOCDECL", XmlPullParser.TYPES[XmlPullParser.DOCDECL]);
// check setInput semantics
assertEquals(XmlPullParser.START_DOCUMENT, xpp.getEventType());
try {
xpp.next();
fail("exception was expected of next() if no input was set on parser");
} catch(XmlPullParserException ex) {}
xpp.setInput(null);
assertEquals(XmlPullParser.START_DOCUMENT, xpp.getEventType());
try {
xpp.next();
fail("exception was expected of next() if no input was set on parser");
} catch(XmlPullParserException ex) {}
try {
xpp.setInput(null, null);
fail("exception was expected of setInput() if input stream is null");
} catch(IllegalArgumentException ex) {}
xpp.setInput(null);
assertTrue("line number must be -1 or >= 1 not "+xpp.getLineNumber(),
xpp.getLineNumber() == -1 || xpp.getLineNumber() >= 1);
assertTrue("column number must be -1 or >= 0 not "+xpp.getColumnNumber(),
xpp.getColumnNumber() == -1 || xpp.getColumnNumber() >= 0);
// check the simplest possible XML document - just one root element
xpp.setInput(new StringReader(" "));
assertEquals(null, xpp.getInputEncoding());
checkParserState(xpp, 0, XmlPullParser.START_DOCUMENT, null, null, false, -1);
xpp.next();
checkParserState(xpp, 1, XmlPullParser.START_TAG, "foo", null, false /*empty*/, 0);
xpp.next();
checkParserState(xpp, 1, XmlPullParser.END_TAG, "foo", null, false, -1);
xpp.next();
checkParserState(xpp, 0, XmlPullParser.END_DOCUMENT, null, null, false, -1);
//check taking input form input stream
byte[] binput = " ".getBytes("UTF-8"); //Xerces2 doe snot like UTF8 ...
xpp.setInput(new ByteArrayInputStream( binput ), "UTF-8" );
assertEquals("UTF-8", xpp.getInputEncoding());
//xpp.setInput(new StringReader( " " ) );
checkParserState(xpp, 0, XmlPullParser.START_DOCUMENT, null, null, false, -1);
xpp.next();
checkParserState(xpp, 1, XmlPullParser.START_TAG, "foo", null, true /*empty*/, 0);
xpp.next();
checkParserState(xpp, 1, XmlPullParser.END_TAG, "foo", null, false, -1);
xpp.next();
checkParserState(xpp, 0, XmlPullParser.END_DOCUMENT, null, null, false, -1);
// one step further - it has an attribute and content ...
xpp.setInput(new StringReader("bar\r\n\t "));
checkParserState(xpp, 0, XmlPullParser.START_DOCUMENT, null, null, false, -1);
xpp.next();
checkParserState(xpp, 1, XmlPullParser.START_TAG, "foo", null, false, 1);
checkAttrib(xpp, 0, "attrName", "attrVal");
xpp.next();
checkParserState(xpp, 1, XmlPullParser.TEXT, null, "bar", false, -1);
assertEquals(false, xpp.isWhitespace());
xpp.next();
checkParserState(xpp, 2, XmlPullParser.START_TAG, "p:t", null, false, 0);
xpp.next();
checkParserState(xpp, 2, XmlPullParser.TEXT, null, "\n\t ", false, -1);
assertTrue(xpp.isWhitespace());
xpp.next();
checkParserState(xpp, 2, XmlPullParser.END_TAG, "p:t", null, false, -1);
xpp.next();
checkParserState(xpp, 1, XmlPullParser.END_TAG, "foo", null, false, -1);
xpp.next();
checkParserState(xpp, 0, XmlPullParser.END_DOCUMENT, null, null, false, -1);
}
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestSimple.class));
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestSimpleProcessDocdecl.java 100644 0 0 7452 10525225064 26257 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import junit.framework.TestSuite;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* Test FEATURE_PROCESS_DOCDECL (when supported)
*
* @author Aleksander Slominski
*/
public class TestSimpleProcessDocdecl extends UtilTestCase {
private XmlPullParserFactory factory;
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestSimpleProcessDocdecl.class));
}
public TestSimpleProcessDocdecl(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
assertEquals(false, factory.isNamespaceAware());
assertEquals(false, factory.isValidating());
//System.out.println("factory="+factory);
}
public void testProcessDocdecl() throws Exception {
XmlPullParser xpp = factory.newPullParser();
try {
xpp.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
} catch(XmlPullParserException ex) {
return;
}
PackageTests.addNote("* feature "+XmlPullParser.FEATURE_PROCESS_DOCDECL+" is supported\n");
// setting validation MUST enables also PROCESS_DOCDECL
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL));
// default is to have non-validating parser
assertEquals(false, xpp.getFeature(XmlPullParser.FEATURE_VALIDATION));
//http://www.w3.org/TR/REC-xml#NT-extSubsetDecl
// minimum validation
final String XML_MIN_PROLOG =
"\n"+
"\n"+
"]>\n";
final String XML_MIN_VALID = XML_MIN_PROLOG+
"Hello, &name;! \n";
xpp.setInput(new StringReader( XML_MIN_VALID ));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
assertNull(xpp.getProperty(PROPERTY_XMLDECL_VERSION));
assertNull(xpp.getProperty(PROPERTY_XMLDECL_STANDALONE));
assertNull(xpp.getProperty(PROPERTY_XMLDECL_CONTENT));
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "greeting", null, false/*empty*/, 0);
//XMLDecl support is required when PROCESS DOCDECL enabled
assertEquals("1.0", xpp.getProperty(PROPERTY_XMLDECL_VERSION));
assertEquals(Boolean.TRUE, xpp.getProperty(PROPERTY_XMLDECL_STANDALONE));
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, "Hello, world!", false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "greeting", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
//AND WRONG
final String XML_MIN_INVALID = XML_MIN_PROLOG+
"Hello, &world;! \n";
xpp.setInput(new StringReader( XML_MIN_INVALID ));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "greet", null, false/*empty*/, 0);
try {
xpp.next();
fail("exception was expected of next() for undeclared entity");
} catch(XmlPullParserException ex) {}
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestSimpleToken.java 100644 0 0 15160 10525225064 24456 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import junit.framework.TestSuite;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* Simple test for minimal XML tokenizing
*
* @author Aleksander Slominski
*/
public class TestSimpleToken extends UtilTestCase {
private XmlPullParserFactory factory;
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestSimpleToken.class));
}
public TestSimpleToken(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
//System.out.println(getClass()+"-factory="+factory);
}
protected void tearDown() {
}
public void testVerySimpleToken() throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
xpp.setInput(new StringReader(" "));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, false, 0);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.COMMENT, null, 0, null, null, "comment", false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.PROCESSING_INSTRUCTION, null, 0, null, null, "target pi", false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "foo", null, false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
}
public void testSimpleToken() throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
// check setInput semantics
assertEquals(XmlPullParser.START_DOCUMENT, xpp.getEventType());
try {
xpp.nextToken();
fail("exception was expected of nextToken() if no input was set on parser");
} catch(XmlPullParserException ex) {}
xpp.setInput(null);
assertEquals(XmlPullParser.START_DOCUMENT, xpp.getEventType());
try {
xpp.nextToken();
fail("exception was expected of next() if no input was set on parser");
} catch(XmlPullParserException ex) {}
xpp.setInput(null); //reset parser
// attempt to set roundtrip
try {
xpp.setFeature(FEATURE_XML_ROUNDTRIP, true);
} catch(Exception ex) {
}
// did we succeeded?
boolean roundtripSupported = xpp.getFeature(FEATURE_XML_ROUNDTRIP);
// check the simplest possible XML document - just one root element
for(int i = 1; i <= 2; ++i) {
xpp.setInput(new StringReader(i == 1 ? " " : " "));
boolean empty = (i == 1);
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, empty, 0);
if(roundtripSupported) {
if(empty) {
// System.out.println("tag='"+xpp.getText()+"'");
// String foo =" ";
// String foo2 = xpp.getText();
// System.out.println(foo.equals(foo2));
assertEquals("empty tag roundtrip",
printable(" "),
printable(xpp.getText()));
} else {
assertEquals("start tag roundtrip",
printable(""),
printable(xpp.getText()));
}
}
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "foo", null, false, -1);
if(roundtripSupported) {
if(empty) {
assertEquals("empty tag roundtrip",
printable(" "),
printable(xpp.getText()));
} else {
assertEquals("end tag roundtrip",
printable(" "),
printable(xpp.getText()));
}
}
xpp.nextToken();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
}
}
public void testNormalization() throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
testNormalization(xpp);
try{ xpp.setFeature(FEATURE_XML_ROUNDTRIP, false); } catch(Exception ex) {}
testNormalization(xpp);
try{ xpp.setFeature(FEATURE_XML_ROUNDTRIP, true); } catch(Exception ex) {}
testNormalization(xpp);
}
public void testNormalization(XmlPullParser xpp) throws Exception {
xpp.setInput(new StringReader("\n \r\n \n\r "));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, false/*empty*/, 0);
boolean roundtrip = xpp.getFeature(FEATURE_XML_ROUNDTRIP) == false;
String text = nextTokenGathered(xpp, XmlPullParser.TEXT, true);
if(roundtrip) {
assertEquals(printable("\n \n \n\n"), printable(text));
assertEquals("\n \n \n\n", text);
} else {
assertEquals(printable("\n \r\n \n\r"), printable(text));
assertEquals("\n \r\n \n\r", text);
}
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "foo", null, false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestSimpleValidation.java 100644 0 0 6776 10525225064 25465 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import junit.framework.TestSuite;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* Test FEATURE_VALIDATION (when supported)
*
* @author Aleksander Slominski
*/
public class TestSimpleValidation extends UtilTestCase {
private XmlPullParserFactory factory;
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestSimpleValidation.class));
}
public TestSimpleValidation(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
assertEquals(false, factory.isNamespaceAware());
assertEquals(false, factory.isValidating());
//System.out.println("factory="+factory);
}
public void testValidation() throws Exception {
XmlPullParser xpp = factory.newPullParser();
try {
xpp.setFeature(XmlPullParser.FEATURE_VALIDATION, true);
} catch(XmlPullParserException ex) {
return;
}
PackageTests.addNote("* feature "+XmlPullParser.FEATURE_VALIDATION+" is supported\n");
// setting validation MUST enables also PROCESS_DOCDECL
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL));
//http://www.w3.org/TR/REC-xml#NT-extSubsetDecl
// minimum validation
final String XML_MIN_PROLOG =
"\n"+
"\n"+
"]>\n";
final String XML_MIN_VALID = XML_MIN_PROLOG+
"Hello, world! \n";
xpp.setInput(new StringReader( XML_MIN_VALID ));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
assertNull(xpp.getProperty(PROPERTY_XMLDECL_VERSION));
assertNull(xpp.getProperty(PROPERTY_XMLDECL_STANDALONE));
assertNull(xpp.getProperty(PROPERTY_XMLDECL_CONTENT));
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "greeting", null, false/*empty*/, 0);
//XMLDecl support is required when PROCESS DOCDECL enabled
assertEquals("1.0", xpp.getProperty(PROPERTY_XMLDECL_VERSION));
assertEquals(null, xpp.getProperty(PROPERTY_XMLDECL_STANDALONE));
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, "Hello, world!", false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "greeting", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
//AND WRONG
final String XML_MIN_INVALID = XML_MIN_PROLOG+
"Hello, world! \n";
xpp.setInput(new StringReader( XML_MIN_INVALID ));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
try {
xpp.next();
fail("exception was expected of next() for invalid document element root");
} catch(XmlPullParserException ex) {}
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestSimpleWithNs.java 100644 0 0 20227 10525225064 24612 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import junit.framework.TestSuite;
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* Simple test for minimal XML parsing with namespaces
*
* @author Aleksander Slominski
*/
public class TestSimpleWithNs extends UtilTestCase {
private XmlPullParserFactory factory;
public TestSimpleWithNs(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
}
protected void tearDown() {
}
public void testSimpleWithNs() throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
// check setInput semantics
assertEquals(XmlPullParser.START_DOCUMENT, xpp.getEventType());
try {
xpp.next();
fail("exception was expected of next() if no input was set on parser");
} catch(XmlPullParserException ex) {}
xpp.setInput(null);
assertEquals(XmlPullParser.START_DOCUMENT, xpp.getEventType());
try {
xpp.next();
fail("exception was expected of next() if no input was set on parser");
} catch(XmlPullParserException ex) {}
// check the simplest possible XML document - just one root element
xpp.setInput(new StringReader(" "));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, false/*empty*/, 0);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "foo", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.setInput(new StringReader(" "));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, true/*empty*/, 0);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "foo", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
// one step further - it has content ...
xpp.setInput(new StringReader("bar "));
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, false, 1);
checkAttribNs(xpp, 0, null, "", "attrName", "attrVal");
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, "bar", false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "foo", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
byte[] binput = (""+
""+
""+
" "+
" ").getBytes("US-ASCII");
xpp.setInput(new ByteArrayInputStream( binput ), "US-ASCII" );
assertEquals("US-ASCII", xpp.getInputEncoding());
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 3, "n", "foo", null, false, 0);
assertEquals(0, xpp.getNamespaceCount(0));
assertEquals(3, xpp.getNamespaceCount(1));
checkNamespace(xpp, 0, null, "n", true);
checkNamespace(xpp, 1, "ns1", "n1", true);
checkNamespace(xpp, 2, "ns2", "n2", true);
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.START_TAG, "ns1", 6, "x1", "bar", null, false, 0);
assertEquals(0, xpp.getNamespaceCount(0));
assertEquals(3, xpp.getNamespaceCount(1));
assertEquals(6, xpp.getNamespaceCount(2));
checkNamespace(xpp, 3, "ns1", "x1", true);
checkNamespace(xpp, 4, "ns3", "n3", true);
checkNamespace(xpp, 5, null, "n1", true);
xpp.next();
checkParserStateNs(xpp, 3, XmlPullParser.START_TAG, "ns2", 6, "n2", "gugu", null, true, 4);
assertEquals(6, xpp.getNamespaceCount(2));
assertEquals(6, xpp.getNamespaceCount(3));
assertEquals("x1", xpp.getNamespace("ns1"));
assertEquals("n2", xpp.getNamespace("ns2"));
assertEquals("n3", xpp.getNamespace("ns3"));
checkAttribNs(xpp, 0, null, "", "a1", "v1");
checkAttribNs(xpp, 1, "ns2", "n2", "a2", "v2");
checkAttribNs(xpp, 2, "xml", "http://www.w3.org/XML/1998/namespace", "lang", "en");
checkAttribNs(xpp, 3, "ns1", "x1", "a3", "v3");
xpp.next();
checkParserStateNs(xpp, 3, XmlPullParser.END_TAG, "ns2", 6, "n2", "gugu", null, false, -1);
xpp.next();
checkParserStateNs(xpp, 3, XmlPullParser.START_TAG, null, 7, "n1", "baz", null, false, 0);
assertEquals(0, xpp.getNamespaceCount(0));
assertEquals(3, xpp.getNamespaceCount(1));
assertEquals(6, xpp.getNamespaceCount(2));
assertEquals(7, xpp.getNamespaceCount(3));
checkNamespace(xpp, 6, "ns1", "y1", true);
assertEquals("y1", xpp.getNamespace("ns1"));
assertEquals("n2", xpp.getNamespace("ns2"));
assertEquals("n3", xpp.getNamespace("ns3"));
xpp.next();
checkParserStateNs(xpp, 3, XmlPullParser.END_TAG, null, 7, "n1", "baz", null, false, -1);
assertEquals("y1", xpp.getNamespace("ns1"));
assertEquals("n2", xpp.getNamespace("ns2"));
assertEquals("n3", xpp.getNamespace("ns3"));
// check that declared namespaces can be accessed for current end tag
assertEquals(3, xpp.getDepth());
assertEquals(6, xpp.getNamespaceCount(2));
assertEquals(7, xpp.getNamespaceCount(3));
// chekc that namespace is accessible by direct addresssing
assertEquals(null, xpp.getNamespacePrefix(0));
assertEquals("n", xpp.getNamespaceUri(0));
assertEquals("ns1", xpp.getNamespacePrefix(1));
assertEquals("n1", xpp.getNamespaceUri(1));
assertEquals("ns1", xpp.getNamespacePrefix(3));
assertEquals("x1", xpp.getNamespaceUri(3));
assertEquals("ns1", xpp.getNamespacePrefix(6));
assertEquals("y1", xpp.getNamespaceUri(6));
xpp.next();
checkParserStateNs(xpp, 2, XmlPullParser.END_TAG, "ns1", 6, "x1", "bar", null, false, -1);
// check that namespace is undelcared
assertEquals("x1", xpp.getNamespace("ns1"));
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 3, "n", "foo", null, false, -1);
assertEquals("n1", xpp.getNamespace("ns1"));
assertEquals("n2", xpp.getNamespace("ns2"));
assertEquals(null, xpp.getNamespace("ns3"));
xpp.next();
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
assertEquals(null, xpp.getNamespace("ns1"));
assertEquals(null, xpp.getNamespace("ns2"));
assertEquals(null, xpp.getNamespace("ns3"));
}
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestSimpleWithNs.class));
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestToken.java 100644 0 0 44551 10525225064 23312 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import junit.framework.TestSuite;
import java.io.StringReader;
import java.io.StringWriter;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* Conformance test to verify nextToken() behavior.
*
* @author Aleksander Slominski
*/
public class TestToken extends UtilTestCase {
private XmlPullParserFactory factory;
public TestToken(String name) {
super(name);
}
protected void setUp() throws XmlPullParserException {
factory = factoryNewInstance();
factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
assertEquals(false, factory.getFeature(XmlPullParser.FEATURE_VALIDATION));
}
protected void tearDown() {
factory = null;
}
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestToken.class));
}
private static final String FOO_XML =
""+
" "+
"]>"+
"bar"+
"&test;&test;< "+
"&>'" <"+
" ";
private static final String MISC_XML =
//"\n \r\n \n\r"+
//""+
//" \r\n "+
"\n \r\n \n\r"+
" \r\n"+
FOO_XML+
" \r\n";
public void testTokenEventEquivalency() throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
xpp.setInput(new StringReader(MISC_XML));
boolean processDocdecl = xpp.getFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL);
// make sure entity "test" can be resolved even when parser is not parsing DOCDECL
if(!processDocdecl) {
xpp.defineEntityReplacementText("test", "This is test! Do NOT Panic!");
}
checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, false, 1);
checkAttribNs(xpp, 0, null, "", "attrName", "attrVal");
xpp.next();
checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null,
"barThis is test! Do NOT Panic!This is test! Do NOT Panic!< &>'\" < vo"+
" ]";
String gotDocdecl = xpp.getText();
if(roundtripSupported && gotDocdecl == null) {
fail("when roundtrip is enabled DOCDECL content must be reported");
}
if(gotDocdecl != null) {
assertEquals("DOCDECL content", expectedDocdecl, gotDocdecl);
}
try {
xpp.isWhitespace();
fail("whitespace function must fail for DOCDECL");
} catch(XmlPullParserException ex) {
}
// now parse elements
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "foo", null, false, 1);
if(roundtripSupported) {
assertEquals("start tag roundtrip", "", xpp.getText());
}
checkAttribNs(xpp, 0, null, "", "attrName", "attrVal");
try {
xpp.isWhitespace();
fail("whitespace function must fail for START_DOCUMENT");
} catch(XmlPullParserException ex) {
}
{
String text = nextTokenGathered(xpp, XmlPullParser.TEXT, false);
assertEquals(printable("bar"), printable(text));
}
//xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.COMMENT, null, 0, null, null, false, -1);
try {
xpp.isWhitespace();
fail("whitespace function must fail for COMMENT");
} catch(XmlPullParserException ex) {
}
{
String text = xpp.getText();
if(roundtripSupported) {
assertEquals(printable("comment\r\ntest"), printable(text));
} else {
assertEquals(printable("comment\ntest"), printable(text));
}
}
boolean processDocdecl = xpp.getFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL);
// uresolved entity must be reurned as null by nextToken()
xpp.nextToken();
if(!processDocdecl) {
checkParserStateNs(xpp, 1, XmlPullParser.ENTITY_REF, null, 0, null,
"test", null, false, -1);
} else {
checkParserStateNs(xpp, 1, XmlPullParser.ENTITY_REF, null, 0, null,
"test", "This is test! Do NOT Panic!", false, -1);
}
// now we check if we can resolve entity
if(!processDocdecl) {
xpp.defineEntityReplacementText("test", "This is test! Do NOT Panic!");
}
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.ENTITY_REF, null, 0, null,
"test", "This is test! Do NOT Panic!", false, -1);
try {
xpp.isWhitespace();
fail("whitespace function must fail for ENTITY_RED");
} catch(XmlPullParserException ex) {
}
// check standard entities and char refs
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.ENTITY_REF, null, 0, null, "lt", "<", false, -1);
try {
xpp.isWhitespace();
fail("whitespace function must fail for ENTITY_REF");
} catch(XmlPullParserException ex) {
}
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.ENTITY_REF, null, 0, null, "#32", " ", false, -1);
try {
xpp.isWhitespace();
fail("whitespace function must fail for ENTITY_REF");
} catch(XmlPullParserException ex) {
}
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.ENTITY_REF, null, 0, null, "amp", "&", false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.ENTITY_REF, null, 0, null, "gt", ">", false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.ENTITY_REF, null, 0, null, "apos", "'", false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.ENTITY_REF, null, 0, null, "quot", "\"", false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.ENTITY_REF, null, 0, null, "#x20", " ", false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.ENTITY_REF, null, 0, null, "#x3C", "<", false, -1);
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.PROCESSING_INSTRUCTION, null, 0, null, null, false, -1);
try {
xpp.isWhitespace();
fail("whitespace function must fail for START_DOCUMENT");
} catch(XmlPullParserException ex) {
}
{
String text = xpp.getText();
if(roundtripSupported) {
assertEquals(printable("pi ds\r\nda"), printable(text));
} else {
assertEquals(printable("pi ds\nda"), printable(text));
}
}
xpp.nextToken();
checkParserStateNs(xpp, 1, XmlPullParser.CDSECT, null, 0, null, null, " vo", xpp.getText());
}
try {
xpp.isWhitespace();
fail("whitespace function must fail for END_TAG");
} catch(XmlPullParserException ex) {
}
xpp.nextToken();
if(checkPrologAndEpilog) {
//if(unnormalizedSupported) {
if(xpp.getEventType() == XmlPullParser.IGNORABLE_WHITESPACE) {
// xpp.nextToken();
// checkParserStateNs(xpp, 0, xpp.IGNORABLE_WHITESPACE, null, 0, null, null,
// " \r\n", false, -1);
// assertTrue(xpp.isWhitespace());
//String text = nextTokenGathered(xpp, xpp.IGNORABLE_WHITESPACE, true);
String text = gatherTokenText(xpp, XmlPullParser.IGNORABLE_WHITESPACE, true);
if(roundtripSupported) {
assertEquals(printable(" \r\n"), printable(text));
} else {
assertEquals(printable(" \n"), printable(text));
}
}
}
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
try {
xpp.isWhitespace();
fail("whitespace function must fail for END_DOCUMENT");
} catch(XmlPullParserException ex) {
}
}
// one step further - it has content ...
public void testXmlRoundtrip() throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
// reset parser
xpp.setInput(null);
// attempt to set roundtrip
try {
xpp.setFeature(FEATURE_XML_ROUNDTRIP, true);
} catch(Exception ex) {
}
// did we succeeded?
boolean roundtripSupported = xpp.getFeature(FEATURE_XML_ROUNDTRIP);
if(!roundtripSupported) {
return;
}
PackageTests.addNote("* optional feature "+FEATURE_XML_ROUNDTRIP+" is supported\n");
StringWriter sw = new StringWriter();
String s;
//StringWriter st = new StringWriter();
xpp.setInput(new StringReader(MISC_XML));
int[] holderForStartAndLength = new int[2];
char[] buf;
while(xpp.nextToken() != XmlPullParser.END_DOCUMENT) {
switch(xpp.getEventType()) {
case XmlPullParser.START_TAG:
buf = xpp.getTextCharacters(holderForStartAndLength);
s = new String(buf, holderForStartAndLength[0], holderForStartAndLength[1]);
assertEquals("roundtrip START_TAG", xpp.getText(), s);
sw.write(s);
break;
case XmlPullParser.END_TAG:
buf = xpp.getTextCharacters(holderForStartAndLength);
s = new String(buf, holderForStartAndLength[0], holderForStartAndLength[1]);
assertEquals("roundtrip END_TAG", xpp.getText(), s);
sw.write(s);
break;
case XmlPullParser.TEXT:
buf = xpp.getTextCharacters(holderForStartAndLength);
s = new String(buf, holderForStartAndLength[0], holderForStartAndLength[1]);
assertEquals("roundtrip TEXT", xpp.getText(), s);
sw.write(s);
break;
case XmlPullParser.IGNORABLE_WHITESPACE:
buf = xpp.getTextCharacters(holderForStartAndLength);
s = new String(buf, holderForStartAndLength[0], holderForStartAndLength[1]);
assertEquals("roundtrip IGNORABLE_WHITESPACE", xpp.getText(), s);
sw.write(s);
break;
case XmlPullParser.CDSECT:
sw.write("");
break;
case XmlPullParser.PROCESSING_INSTRUCTION:
sw.write("");
buf = xpp.getTextCharacters(holderForStartAndLength);
s = new String(buf, holderForStartAndLength[0], holderForStartAndLength[1]);
assertEquals("roundtrip PROCESSING_INSTRUCTION", xpp.getText(), s);
sw.write(s);
sw.write("?>");
break;
case XmlPullParser.COMMENT:
sw.write("");
break;
case XmlPullParser.ENTITY_REF:
sw.write("&");
buf = xpp.getTextCharacters(holderForStartAndLength);
s = new String(buf, holderForStartAndLength[0], holderForStartAndLength[1]);
assertEquals("roundtrip ENTITY_REF", xpp.getName(), s);
sw.write(s);
sw.write(";");
break;
case XmlPullParser.DOCDECL:
sw.write("");
break;
default:
throw new RuntimeException("unknown token type");
}
}
sw.close();
String RESULT_XML_BUF = sw.toString();
assertEquals("rountrip XML", printable(MISC_XML), printable(RESULT_XML_BUF));
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestXmlCdsect.java 100644 0 0 2130 10525225064 24063 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import java.io.IOException;
import junit.framework.TestSuite;
import org.xmlpull.v1.XmlPullParserException;
public class TestXmlCdsect extends XmlTestCase {
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestXmlCdsect.class));
}
public TestXmlCdsect(String name) {
super(name);
}
public void testCdsect()
throws IOException, XmlPullParserException
{
testXml("cdsect.xml");
}
public void testCdsectEol()
throws IOException, XmlPullParserException
{
testXml("cdsect_eol.xml");
}
public void testCdsectMixed()
throws IOException, XmlPullParserException
{
testXml("cdsect_mixed.xml");
}
public void testCdsectMore()
throws IOException, XmlPullParserException
{
testXml("cdsect_more.xml");
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestXmlSimple.java 100644 0 0 1450 10525225064 24113 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import java.io.*;
import junit.framework.TestSuite;
import org.xmlpull.v1.*;
public class TestXmlSimple extends XmlTestCase {
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestXmlSimple.class));
}
public TestXmlSimple(String name) {
super(name);
}
public void testSimple()
throws IOException, XmlPullParserException
{
testXml("simple.xml");
}
public void testSimple2()
throws IOException, XmlPullParserException
{
testXml("simple2.xml");
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/TestXmlTypical.java 100644 0 0 1260 10525225064 24266 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import java.io.*;
import junit.framework.TestSuite;
import org.xmlpull.v1.XmlPullParserException;
public class TestXmlTypical extends XmlTestCase {
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestXmlTypical.class));
}
public TestXmlTypical(String name) {
super(name);
}
public void testTypical()
throws IOException, XmlPullParserException
{
testXml("typical.xml");
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/UtilTestCase.java 100644 0 0 31465 10525225064 23743 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
package org.xmlpull.v1.tests;
import java.io.IOException;
import junit.framework.TestCase;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
* Some common utilities to help with XMLPULL tests.
*
* @author Aleksander Slominski
*/
public class UtilTestCase extends TestCase {
protected static final String FEATURE_XML_ROUNDTRIP=
"http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
protected final static String PROPERTY_XMLDECL_VERSION =
"http://xmlpull.org/v1/doc/properties.html#xmldecl-version";
protected final static String PROPERTY_XMLDECL_STANDALONE =
"http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone";
protected final static String PROPERTY_XMLDECL_CONTENT =
"http://xmlpull.org/v1/doc/properties.html#xmldecl-content";
protected final static String TEST_XML =
"\n"+
"bar \r\n"+
" \n\r \n"+
" This is in a new namespace "+
" \t\n"+
" "+
" \n"+
"\n"+
"\n";
//private static XmlPullParserFactory factory;
private static boolean printedFactoryName;
public UtilTestCase(String name) {
super(name);
}
public static XmlPullParserFactory factoryNewInstance() throws XmlPullParserException {
String property = System.getProperty(XmlPullParserFactory.PROPERTY_NAME);
//property = "org.xmlpull.mxp1.MXParserFactory";
//"org.xmlpull.v1.xni2xmlpull1.X2ParserFactory",
//property = "org.xmlpull.mxp1.MXParser,org.xmlpull.mxp1_serializer.MXSerializer";
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
property,
null //Thread.currentThread().getContextClassLoader().getClass(), //NOT ON JDK 1.1
);
//System.out.println("factory="+factory+" property="+property);
if(PackageTests.runnigAllTests() == false && printedFactoryName == false) {
System.out.println("factory="+factory+" property="+property);
printedFactoryName = true;
}
return factory;
}
/**
*
* Mpve to next token and gather getText() for successive tokens of the same type.
* Parser will be positioned on next token of different type.
*/
public String nextTokenGathered(XmlPullParser xpp, int type, boolean expectedWhitespaces)
throws XmlPullParserException, IOException
{
xpp.nextToken();
return gatherTokenText(xpp, type, expectedWhitespaces);
}
/**
* Gathers getText() for successive tokens of the same type.
* Parser will be positioned on next token of different type.
*/
public String gatherTokenText(XmlPullParser xpp, int type, boolean expectedWhitespaces)
throws XmlPullParserException, IOException
{
StringBuffer buf = new StringBuffer();
assertEquals(XmlPullParser.TYPES[ type ], XmlPullParser.TYPES[ xpp.getEventType() ]);
do {
buf.append(xpp.getText());
if(expectedWhitespaces) {
assertTrue(xpp.isWhitespace());
}
} while(xpp.nextToken() == type);
return buf.toString();
}
public void checkParserState(
XmlPullParser xpp,
int depth,
int type,
String name,
String text,
boolean isEmpty,
int attribCount
) throws XmlPullParserException, IOException
{
assertTrue("line number must be -1 or >= 1 not "+xpp.getLineNumber(),
xpp.getLineNumber() == -1 || xpp.getLineNumber() >= 1);
assertTrue("column number must be -1 or >= 0 not "+xpp.getColumnNumber(),
xpp.getColumnNumber() == -1 || xpp.getColumnNumber() >= 0);
assertEquals("PROCESS_NAMESPACES", false, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
assertEquals("TYPES[getType()]", XmlPullParser.TYPES[type], XmlPullParser.TYPES[xpp.getEventType()]);
assertEquals("getType()", type, xpp.getEventType());
assertEquals("getDepth()", depth, xpp.getDepth());
assertEquals("getPrefix()", null, xpp.getPrefix());
assertEquals("getNamespacesCount(getDepth())", 0, xpp.getNamespaceCount(depth));
if(xpp.getEventType() == XmlPullParser.START_TAG || xpp.getEventType() == XmlPullParser.END_TAG) {
assertEquals("getNamespace()", "", xpp.getNamespace());
} else {
assertEquals("getNamespace()", null, xpp.getNamespace());
}
assertEquals("getName()", name, xpp.getName());
if(xpp.getEventType() != XmlPullParser.START_TAG && xpp.getEventType() != XmlPullParser.END_TAG) {
assertEquals("getText()", printable(text), printable(xpp.getText()));
int [] holderForStartAndLength = new int[2];
char[] buf = xpp.getTextCharacters(holderForStartAndLength);
if(buf != null) {
String s = new String(buf, holderForStartAndLength[0], holderForStartAndLength[1]);
assertEquals("getText(holder)", printable(text), printable(s));
} else {
assertEquals("getTextCharacters()", null, text);
}
}
if(type == XmlPullParser.START_TAG) {
assertEquals("isEmptyElementTag()", isEmpty, xpp.isEmptyElementTag());
} else {
try {
xpp.isEmptyElementTag();
fail("isEmptyElementTag() must throw exception if parser not on START_TAG");
} catch(XmlPullParserException ex) {
}
}
assertEquals("getAttributeCount()", attribCount, xpp.getAttributeCount());
}
public void checkParserStateNs(
XmlPullParser xpp,
int depth,
int type,
int nsCount,
String namespace,
String name,
boolean isEmpty,
int attribCount
) throws XmlPullParserException, IOException
{
assertTrue("line number must be -1 or >= 1 not "+xpp.getLineNumber(),
xpp.getLineNumber() == -1 || xpp.getLineNumber() >= 1);
assertTrue("column number must be -1 or >= 0 not "+xpp.getColumnNumber(),
xpp.getColumnNumber() == -1 || xpp.getColumnNumber() >= 0);
// this methid can be used with enabled and not enabled namespaces
//assertEquals("PROCESS_NAMESPACES", true, xpp.getFeature(xpp.FEATURE_PROCESS_NAMESPACES));
assertEquals("TYPES[getEventType()]", XmlPullParser.TYPES[type], XmlPullParser.TYPES[xpp.getEventType()]);
assertEquals("getEventType()", type, xpp.getEventType());
assertEquals("getName()", name, xpp.getName());
assertEquals("getDepth()", depth, xpp.getDepth());
assertEquals("getNamespacesCount(getDepth())", nsCount, xpp.getNamespaceCount(depth));
assertEquals("getNamespace()", namespace, xpp.getNamespace());
if(type == XmlPullParser.START_TAG) {
assertEquals("isEmptyElementTag()", isEmpty, xpp.isEmptyElementTag());
} else {
try {
xpp.isEmptyElementTag();
fail("isEmptyElementTag() must throw exception if parser not on START_TAG");
} catch(XmlPullParserException ex) {
}
}
assertEquals("getAttributeCount()", attribCount, xpp.getAttributeCount());
}
public void checkParserStateNs(
XmlPullParser xpp,
int depth,
int type,
String prefix,
int nsCount,
String namespace,
String name,
boolean isEmpty,
int attribCount
) throws XmlPullParserException, IOException
{
checkParserStateNs(xpp, depth, type, nsCount, namespace, name, isEmpty, attribCount);
assertEquals("getPrefix()", prefix, xpp.getPrefix());
}
public void checkParserStateNs(
XmlPullParser xpp,
int depth,
int type,
String prefix,
int nsCount,
String namespace,
String name,
String text,
boolean isEmpty,
int attribCount
) throws XmlPullParserException, IOException
{
checkParserStateNs(xpp, depth, type, prefix, nsCount, namespace, name, isEmpty, attribCount);
if(xpp.getEventType() != XmlPullParser.START_TAG && xpp.getEventType() != XmlPullParser.END_TAG) {
assertEquals("getText()", printable(text), printable(xpp.getText()));
int [] holderForStartAndLength = new int[2];
char[] buf = xpp.getTextCharacters(holderForStartAndLength);
if(buf != null) {
String s = new String(buf, holderForStartAndLength[0], holderForStartAndLength[1]);
// ENTITY_REF is a special case when getText != (getTextCharacters == getName)
if(xpp.getEventType() != XmlPullParser.ENTITY_REF) {
assertEquals("getText(holder)", printable(text), printable(s));
} else {
assertEquals("getText(holder) ENTITY_REF", printable(name), printable(s));
}
} else {
assertEquals("getTextCharacters()", null, text);
}
}
}
public void checkAttrib(
XmlPullParser xpp,
int pos,
String name,
String value
) throws XmlPullParserException, IOException
{
assertEquals("must be on START_TAG", XmlPullParser.START_TAG, xpp.getEventType());
assertEquals("getAttributePrefix()",null, xpp.getAttributePrefix(pos));
assertEquals("getAttributeNamespace()","", xpp.getAttributeNamespace(pos));
assertEquals("getAttributeName()",name, xpp.getAttributeName(pos));
assertEquals("getAttributeValue()",value, xpp.getAttributeValue(pos));
assertEquals("getAttributeValue(name)",value, xpp.getAttributeValue(null, name));
assertEquals("getAttributeType()","CDATA", xpp.getAttributeType(pos));
assertEquals("isAttributeDefault()",false, xpp.isAttributeDefault(pos));
}
public void checkAttribNs(
XmlPullParser xpp,
int pos,
String namespace,
String name,
String value
) throws XmlPullParserException, IOException
{
assertEquals("must be on START_TAG", XmlPullParser.START_TAG, xpp.getEventType());
assertEquals("getAttributeNamespace()",namespace, xpp.getAttributeNamespace(pos));
assertEquals("getAttributeName()",name, xpp.getAttributeName(pos));
assertEquals("getAttributeValue()",printable(value), printable(xpp.getAttributeValue(pos)));
assertEquals("getAttributeValue(ns,name)",
printable(value), printable(xpp.getAttributeValue(namespace, name)));
assertEquals("getAttributeType()","CDATA", xpp.getAttributeType(pos));
assertEquals("isAttributeDefault()",false, xpp.isAttributeDefault(pos));
}
public void checkAttribNs(
XmlPullParser xpp,
int pos,
String prefix,
String namespace,
String name,
String value
) throws XmlPullParserException, IOException
{
checkAttribNs(xpp, pos, namespace, name, value);
assertEquals("getAttributePrefix()",prefix, xpp.getAttributePrefix(pos));
}
public void checkNamespace(
XmlPullParser xpp,
int pos,
String prefix,
String uri,
boolean checkMapping
) throws XmlPullParserException, IOException
{
assertEquals("getNamespacePrefix(pos)",prefix, xpp.getNamespacePrefix(pos));
assertEquals("getNamespaceUri(pos)",uri, xpp.getNamespaceUri(pos));
if(checkMapping) {
assertEquals("getNamespace(prefix)", uri, xpp.getNamespace (prefix));
}
}
protected String printable(char ch) {
if(ch == '\n') {
return "\\n";
} else if(ch == '\r') {
return "\\r";
} else if(ch == '\t') {
return "\\t";
} if(ch > 127 || ch < 32) {
StringBuffer buf = new StringBuffer("\\u");
String hex = Integer.toHexString((int)ch);
for (int i = 0; i < 4-hex.length(); i++)
{
buf.append('0');
}
buf.append(hex);
return buf.toString();
}
return ""+ch;
}
protected String printable(String s) {
if(s == null) return null;
StringBuffer buf = new StringBuffer();
for(int i = 0; i < s.length(); ++i) {
buf.append(printable(s.charAt(i)));
}
s = buf.toString();
return s;
}
}
xpp3-1.1.4c/src/java/tests/org/xmlpull/v1/tests/XmlTestCase.java 100644 0 0 22603 10525225064 23560 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
/*
SYNTAX: (// marks unimplemented)
inlined xml ?
// name of file ?
name of feature *
//
*
// *
// *
// *
// |*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.util;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
/**
* Handy functions that combines XmlPull API into higher level functionality.
*
* @author Aleksander Slominski
* @author Naresh Bhatia
*/
public class XmlPullUtil {
public static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";
private XmlPullUtil() {}
/**
* Return value of attribute with given name and no namespace.
*/
public static String getAttributeValue(XmlPullParser pp, String name) {
return pp.getAttributeValue(XmlPullParser.NO_NAMESPACE, name);
}
/**
* Return PITarget from Processing Instruction (PI) as defined in
* XML 1.0 Section 2.6 Processing Instructions
* [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
*/
public static String getPITarget(XmlPullParser pp) throws IllegalStateException
{
int eventType;
try {
eventType = pp.getEventType();
} catch(XmlPullParserException ex) {
// should never happen ...
throw new IllegalStateException(
"could not determine parser state: "+ex+pp.getPositionDescription());
}
if( eventType != XmlPullParser.PROCESSING_INSTRUCTION ) {
throw new IllegalStateException(
"parser must be on processing instruction and not "
+XmlPullParser.TYPES[ eventType ]+pp.getPositionDescription());
}
final String PI = pp.getText();
for (int i = 0; i < PI.length(); i++)
{
if( isS(PI.charAt(i)) ) {
// assert i > 0
return PI.substring(0,i);
}
}
return PI;
}
/**
* Return everything past PITarget and S from Processing Instruction (PI) as defined in
* XML 1.0 Section 2.6 Processing Instructions
* [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
*
* NOTE: if there is no PI data it returns empty string.
*/
public static String getPIData(XmlPullParser pp) throws IllegalStateException
{
int eventType;
try {
eventType = pp.getEventType();
} catch(XmlPullParserException ex) {
// should never happen ...
throw new IllegalStateException(
"could not determine parser state: "+ex+pp.getPositionDescription());
}
if( eventType != XmlPullParser.PROCESSING_INSTRUCTION ) {
throw new IllegalStateException(
"parser must be on processing instruction and not "
+XmlPullParser.TYPES[ eventType ]+pp.getPositionDescription());
}
final String PI = pp.getText();
int pos = -1;
for (int i = 0; i < PI.length(); i++)
{
if( isS(PI.charAt(i)) ) {
pos = i;
} else if(pos > 0) {
return PI.substring(i);
}
}
return "";
}
/**
* Return true if chacters is S as defined in XML 1.0
* S ::= (#x20 | #x9 | #xD | #xA)+
*/
private static boolean isS(char ch) {
return (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t');
}
/**
* Skip sub tree that is currently porser positioned on.
* NOTE: parser must be on START_TAG and when funtion returns
* parser will be positioned on corresponding END_TAG
*/
public static void skipSubTree(XmlPullParser pp)
throws XmlPullParserException, IOException
{
pp.require(XmlPullParser.START_TAG, null, null);
int level = 1;
while(level > 0) {
int eventType = pp.next();
if(eventType == XmlPullParser.END_TAG) {
--level;
} else if(eventType == XmlPullParser.START_TAG) {
++level;
}
}
}
/**
* call parser nextTag() and check that it is START_TAG, throw exception if not.
*/
public static void nextStartTag(XmlPullParser pp)
throws XmlPullParserException, IOException
{
if(pp.nextTag() != XmlPullParser.START_TAG) {
throw new XmlPullParserException(
"expected START_TAG and not "+pp.getPositionDescription());
}
}
/**
* combine nextTag(); pp.require(XmlPullParser.START_TAG, null, name);
*/
public static void nextStartTag(XmlPullParser pp, String name)
throws XmlPullParserException, IOException
{
pp.nextTag();
pp.require(XmlPullParser.START_TAG, null, name);
}
/**
* combine nextTag(); pp.require(XmlPullParser.START_TAG, namespace, name);
*/
public static void nextStartTag(XmlPullParser pp, String namespace, String name)
throws XmlPullParserException, IOException
{
pp.nextTag();
pp.require(XmlPullParser.START_TAG, namespace, name);
}
/**
* combine nextTag(); pp.require(XmlPullParser.END_TAG, namespace, name);
*/
public static void nextEndTag(XmlPullParser pp, String namespace, String name)
throws XmlPullParserException, IOException
{
pp.nextTag();
pp.require(XmlPullParser.END_TAG, namespace, name);
}
/**
* Read text content of element ith given namespace and name
* (use null namespace do indicate that nemspace should not be checked)
*/
public static String nextText(XmlPullParser pp, String namespace, String name)
throws IOException, XmlPullParserException
{
if(name == null) {
throw new XmlPullParserException("name for element can not be null");
}
pp.require(XmlPullParser.START_TAG, namespace, name);
return pp.nextText();
}
/**
* Read attribute value and return it or throw exception if
* current element does not have such attribute.
*/
public static String getRequiredAttributeValue(XmlPullParser pp, String namespace, String name)
throws IOException, XmlPullParserException
{
String value = pp.getAttributeValue(namespace, name);
if (value == null) {
throw new XmlPullParserException("required attribute "+name+" is not present");
} else {
return value;
}
}
/**
* Call parser nextTag() and check that it is END_TAG, throw exception if not.
*/
public static void nextEndTag(XmlPullParser pp) throws XmlPullParserException, IOException
{
if(pp.nextTag() != XmlPullParser.END_TAG) {
throw new XmlPullParserException(
"expected END_TAG and not"+pp.getPositionDescription());
}
}
/**
* Tests if the current event is of the given type and if the namespace and name match.
* null will match any namespace and any name. If the test passes a true is returned
* otherwise a false is returned.
*/
public static boolean matches(XmlPullParser pp, int type, String namespace, String name)
throws XmlPullParserException
{
boolean matches = type == pp.getEventType()
&& (namespace == null || namespace.equals (pp.getNamespace()))
&& (name == null || name.equals (pp.getName ()));
return matches;
}
/**
* Writes a simple element such as johndoe . The namespace
* and elementText are allowed to be null. If elementText is null, an xsi:nil="true"
* will be added as an attribute.
*/
public static void writeSimpleElement(XmlSerializer serializer,
String namespace,
String elementName,
String elementText)
throws IOException, XmlPullParserException {
if (elementName == null) {
throw new XmlPullParserException("name for element can not be null");
}
serializer.startTag(namespace, elementName);
if (elementText == null) {
serializer.attribute(XSI_NS, "nil", "true");
} else {
serializer.text(elementText);
}
serializer.endTag(namespace, elementName);
}
}
xpp3-1.1.4c/src/java/wrapper/org/xmlpull/v1/wrapper/XmlPullParserWrapper.java 100644 0 0 16601 10525225063 26333 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.wrapper;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* Extensions to XmlPullParser interface
*
* @author Aleksander Slominski
* @author Naresh Bhatia
*/
public interface XmlPullParserWrapper extends XmlPullParser {
public static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";
public static final String XSD_NS = "http://www.w3.org/2001/XMLSchema";
/**
* Return value of attribute with given name and no namespace.
*/
public String getAttributeValue(String name);
/**
* Return PITarget from Processing Instruction (PI) as defined in
* XML 1.0 Section 2.6 Processing Instructions
* [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
*/
public String getPITarget() throws IllegalStateException;
/**
* Return everything past PITarget and S from Processing Instruction (PI) as defined in
* XML 1.0 Section 2.6 Processing Instructions
* [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
*
*
NOTE: if there is no PI data it returns empty string.
*/
public String getPIData() throws IllegalStateException;
/**
* Read attribute value and return it or throw exception if
* current element does not have such attribute.
*/
public String getRequiredAttributeValue(String name)
throws IOException, XmlPullParserException;
/**
* Read attribute value and return it or throw exception if
* current element does not have such attribute.
*/
public String getRequiredAttributeValue(String namespace, String name)
throws IOException, XmlPullParserException;
/**
* Read the text of a required element and return it or throw exception if
* required element is not found. Useful for getting the text of simple
* elements such as johndoe . Assumes that parser is
* just before the start tag and leaves the parser at the end tag. If the
* text is nil (e.g. ), then a null will be returned.
*/
public String getRequiredElementText(String namespace, String name)
throws IOException, XmlPullParserException;
/**
* Is the current tag nil? Checks for xsi:nil="true".
*/
public boolean isNil() throws IOException, XmlPullParserException;
/**
* Tests if the current event is of the given type and if the namespace and name match.
* null will match any namespace and any name. If the test passes a true is returned
* otherwise a false is returned.
*/
public boolean matches(int type, String namespace, String name)
throws XmlPullParserException;
/**
* call parser nextTag() and check that it is START_TAG, throw exception if not.
*/
public void nextStartTag()
throws XmlPullParserException, IOException;
/**
* combine nextTag(); pp.require(XmlPullParser.START_TAG, null, name);
*/
public void nextStartTag(String name)
throws XmlPullParserException, IOException;
/**
* combine nextTag(); pp.require(XmlPullParser.START_TAG, namespace, name);
*/
public void nextStartTag(String namespace, String name)
throws XmlPullParserException, IOException;
/**
* Call parser nextTag() and check that it is END_TAG, throw exception if not.
*/
public void nextEndTag() throws XmlPullParserException, IOException;
/**
* combine nextTag(); pp.require(XmlPullParser.END_TAG, null, name);
*/
public void nextEndTag(String name)
throws XmlPullParserException, IOException;
/**
* combine nextTag(); pp.require(XmlPullParser.END_TAG, namespace, name);
*/
public void nextEndTag(String namespace, String name)
throws XmlPullParserException, IOException;
/**
* Read text content of element ith given namespace and name
* (use null namespace do indicate that nemspace should not be checked)
*/
public String nextText(String namespace, String name)
throws IOException, XmlPullParserException;
/**
* Skip sub tree that is currently porser positioned on.
* NOTE: parser must be on START_TAG and when funtion returns
* parser will be positioned on matching END_TAG
*
* This is typically optimized internally by parser but the logic should follow this:
*
* pp.require(XmlPullParser.START_TAG, null, null);
* int level = 1;
* while(level > 0) {
* int eventType = pp.next();
* if(eventType == XmlPullParser.END_TAG) {
* --level;
* } else if(eventType == XmlPullParser.START_TAG) {
* ++level;
* }
* }
*
*/
public void skipSubTree()
throws XmlPullParserException, IOException;
// set of methods to read XSD types
// /**
// * Read string content of elment and try to convert it to double.
// * Take special care of INF, Infinity and NaN.
// * After this method executed the parser is positioned on END_TAG.
// */
// public double readDouble() throws XmlPullParserException, IOException;
//
// /**
// * Read string content of elment and convert it to float.
// * Take special care of INF, Infinity and NaN.
// * After this method executed the parser is positioned on END_TAG.
// */
// public float readFloat() throws XmlPullParserException, IOException;
//
// /**
// * Read string content of elment and try to convert it to int.
// * Take special care of INF, Infinity and NaN.
// * After this method executed the parser is positioned on END_TAG.
// */
// public int readInt() throws XmlPullParserException, IOException;
//
// /**
// * Check for xsi:nil and if it has value 'true' returns null
// * as described in
// * XML Schemas
// * Part 1
// * otherwise it calls nextText().
// * After this method executed the parser is positioned on END_TAG.
// */
// public String readString() throws XmlPullParserException, IOException;
//
// /**
// * Check that parser is on START_TAG with given namespace and name
// * and then call readDouble().
// */
// public double readDoubleElement(String namespace, String name)
// throws XmlPullParserException, IOException;
//
// /**
// * Check that parser is on START_TAG with given namespace and name
// * and then call readFloat().
// */
// public float readFloatElement(String namespace, String name)
// throws XmlPullParserException, IOException;
//
// /**
// * Check that parser is on START_TAG with given namespace and name
// * and then call readInt().
// */
// public int readIntElement(String namespace, String name)
// throws XmlPullParserException, IOException;
//
// /**
// * Check that parser is on START_TAG with given namespace and name
// * and then call readString().
// */
// public String readStringElemet(String namespace, String name)
// throws XmlPullParserException, IOException;
//
}
xpp3-1.1.4c/src/java/wrapper/org/xmlpull/v1/wrapper/XmlPullWrapperFactory.java 100644 0 0 7146 10525225063 26472 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.wrapper;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
import org.xmlpull.v1.wrapper.classic.StaticXmlPullParserWrapper;
import org.xmlpull.v1.wrapper.classic.StaticXmlSerializerWrapper;
/**
* Handy functions that combines XmlPull API into higher level functionality.
*
NOTE: returned wrapper object is not multi-thread safe
*
* @author Aleksander Slominski
*/
public class XmlPullWrapperFactory {
private final static boolean DEBUG = false;
//protected ClassLoader classLoader;
protected XmlPullParserFactory f;
//protected boolean useDynamic;
public static XmlPullWrapperFactory newInstance() throws XmlPullParserException
{
//TODO: make into real pluggable factory service (later ...)?
return new XmlPullWrapperFactory(null);
}
public static XmlPullWrapperFactory newInstance(XmlPullParserFactory factory)
throws XmlPullParserException
{
return new XmlPullWrapperFactory(factory);
}
public static XmlPullWrapperFactory newInstance (String classNames, Class context)
throws XmlPullParserException
{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(classNames, context);
return new XmlPullWrapperFactory(factory);
}
// ------------ IMPLEMENTATION
protected XmlPullWrapperFactory(XmlPullParserFactory factory) throws XmlPullParserException {
if(factory != null) {
this.f = factory;
} else {
this.f = XmlPullParserFactory.newInstance();
}
}
public XmlPullParserFactory getFactory() throws XmlPullParserException {
return f;
}
public void setFeature(String name,
boolean state) throws XmlPullParserException
{
f.setFeature(name, state);
}
public boolean getFeature (String name) {
return f.getFeature(name);
}
public void setNamespaceAware(boolean awareness) {
f.setNamespaceAware(awareness);
}
public boolean isNamespaceAware() {
return f.isNamespaceAware();
}
public void setValidating(boolean validating) {
f.setValidating(validating);
}
public boolean isValidating() {
return f.isValidating();
}
//public void setUseDynamic(boolean enable) { useDynamic = enable; };
//public boolean getUseDynamic() { return useDynamic; };
public XmlPullParserWrapper newPullParserWrapper() throws XmlPullParserException {
XmlPullParser pp = f.newPullParser();
// if(useDynamic) {
// return (XmlPullParserWrapper) DynamicXmlPullParserWrapper.newProxy(pp, classLoader);
// } else {
return new StaticXmlPullParserWrapper(pp);
}
public XmlPullParserWrapper newPullParserWrapper(XmlPullParser pp) throws XmlPullParserException {
return new StaticXmlPullParserWrapper(pp);
}
public XmlSerializerWrapper newSerializerWrapper() throws XmlPullParserException {
XmlSerializer xs = f.newSerializer();
return new StaticXmlSerializerWrapper(xs, this);
}
public XmlSerializerWrapper newSerializerWrapper(XmlSerializer xs) throws XmlPullParserException {
return new StaticXmlSerializerWrapper(xs, this);
}
}
xpp3-1.1.4c/src/java/wrapper/org/xmlpull/v1/wrapper/XmlSerializerWrapper.java 100644 0 0 11201 10525225063 26342 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.wrapper;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
/**
* Extensions to XmlSerialzier interface
*
* @author Aleksander Slominski
* @author Naresh Bhatia
*/
public interface XmlSerializerWrapper extends XmlSerializer {
public static final String NO_NAMESPACE = XmlPullParserWrapper.NO_NAMESPACE;
public static final String XSI_NS = XmlPullParserWrapper.XSI_NS;
public static final String XSD_NS = XmlPullParserWrapper.XSD_NS;
/**
* Get namespace that is used as default when no namespace parameter is used for
* startTag(), endTag() and element()
*/
public String getCurrentNamespaceForElements();
/**
* Set namespace to use in startTag(), endTag() and element()
* when methods called are those without namespace parameter.
*/
public String setCurrentNamespaceForElements(String value);
/**
* Write an attribute without namespace.
* Calls to attribute() MUST follow a call to
* startTag() immediately. If there is no prefix defined for the
* given namespace, a prefix will be defined automatically.
* NOTE: current element namespace is not used attribute and attributre has no namespace.
*/
public XmlSerializerWrapper attribute (String name, String value)
throws IOException, IllegalArgumentException, IllegalStateException;
/** Write start tag in current namespace with name given as argument. */
public XmlSerializerWrapper startTag(String name)
throws IOException, IllegalArgumentException, IllegalStateException;
/** Write end tag in current namespace with name given as argument. */
public XmlSerializerWrapper endTag(String name)
throws IOException, IllegalArgumentException, IllegalStateException;
/**
* Writes a simple element such as <username>johndoe</username>. The namespace
* and elementText are allowed to be null. If elementText is null, an xsi:nil="true"
* will be added as an attribute.
*/
public XmlSerializerWrapper element(String namespace, String elementName, String elementText)
throws IOException, XmlPullParserException;
/** Write simple text element in current namespace */
public XmlSerializerWrapper element(String elementName, String elementText)
throws IOException, XmlPullParserException;
/** Write XML fragment using currently set namespace prefixes */
public void fragment(String xmlFragment)
throws IOException, IllegalArgumentException, IllegalStateException, XmlPullParserException;
/** Serializer current event form pull parser */
public void event(XmlPullParser pp)
throws IOException, IllegalArgumentException, IllegalStateException, XmlPullParserException;
public String escapeText(String text) throws IllegalArgumentException;
public String escapeAttributeValue(String text) throws IllegalArgumentException;
// set of methods to make easy to write XSD types
// /**
// * Write as text value of argument (just calls text!).
// */
// public void writeDouble(double d)
// throws XmlPullParserException, IOException, IllegalArgumentException;
// public void writeFloat(float f)
// throws XmlPullParserException, IOException, IllegalArgumentException;
// public void writeInt(int i)
// throws XmlPullParserException, IOException, IllegalArgumentException;
// public void writeString(String s)
// throws XmlPullParserException, IOException, IllegalArgumentException;
//
// /**
// * Write as element with namesoace and name and value inside
// * (looks like <ns:name>value</ns:name> where ns is prefix
// * for namespace autoatically declared if needed).
// */
// public void writeDoubleElement(String namespace, String name, double d)
// throws XmlPullParserException, IOException, IllegalArgumentException;
// public void writeFloatElement(String namespace, String name, float f)
// throws XmlPullParserException, IOException, IllegalArgumentException;
// public void writeIntElement(String namespace, String name, int i)
// throws XmlPullParserException, IOException, IllegalArgumentException;
// public void writeStringElement(String namespace, String name, String s)
// throws XmlPullParserException, IOException, IllegalArgumentException;
}
xpp3-1.1.4c/src/java/wrapper/org/xmlpull/v1/wrapper/classic/StaticXmlPullParserWrapper.java 100644 0 0 23340 10525225063 31122 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.wrapper.classic;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.wrapper.XmlPullParserWrapper;
import org.xmlpull.v1.util.XmlPullUtil;
/**
* This class seemlesly extends exisiting parser implementation by adding new methods
* (provided by XmlPullUtil) and delegating exisiting methods to parser implementation.
*
* @author Aleksander Slominski
* @author Naresh Bhatia
*/
public class StaticXmlPullParserWrapper extends XmlPullParserDelegate
implements XmlPullParserWrapper
{
public StaticXmlPullParserWrapper(XmlPullParser pp) {
super(pp);
}
public String getAttributeValue(String name)
{
return XmlPullUtil.getAttributeValue(pp, name);
}
public String getRequiredAttributeValue(String name)
throws IOException, XmlPullParserException
{
return XmlPullUtil.getRequiredAttributeValue(pp, null, name);
}
public String getRequiredAttributeValue(String namespace, String name)
throws IOException, XmlPullParserException
{
return XmlPullUtil.getRequiredAttributeValue(pp, namespace, name);
}
/**
* Read the text of a required element and return it or throw exception if
* required element is not found. Useful for getting the text of simple
* elements such as johndoe . Assumes that parser is
* just before the start tag and leaves the parser at the end tag. If the
* text is nil (e.g. ), then a null will be returned.
*/
public String getRequiredElementText(String namespace, String name)
throws IOException, XmlPullParserException
{
if (name == null) {
throw new XmlPullParserException("name for element can not be null");
}
String text = null;
nextStartTag(namespace, name);
if (isNil()) {
nextEndTag(namespace, name);
}
else {
text = pp.nextText();
}
pp.require(XmlPullParser.END_TAG, namespace, name);
return text;
}
public boolean isNil()
throws IOException, XmlPullParserException
{
boolean result = false;
String value = pp.getAttributeValue(XSI_NS, "nil");
if ("true".equals(value)) {
result = true;
}
return result;
}
public String getPITarget() throws IllegalStateException {
return XmlPullUtil.getPITarget(pp);
}
public String getPIData() throws IllegalStateException {
return XmlPullUtil.getPIData(pp);
}
public boolean matches(int type, String namespace, String name)
throws XmlPullParserException
{
return XmlPullUtil.matches(pp, type, namespace, name);
}
public void nextStartTag()
throws XmlPullParserException, IOException
{
if(pp.nextTag() != XmlPullParser.START_TAG) {
throw new XmlPullParserException(
"expected START_TAG and not "+pp.getPositionDescription());
}
}
public void nextStartTag(String name)
throws XmlPullParserException, IOException
{
pp.nextTag();
pp.require(XmlPullParser.START_TAG, null, name);
}
public void nextStartTag(String namespace, String name)
throws XmlPullParserException, IOException
{
pp.nextTag();
pp.require(XmlPullParser.START_TAG, namespace, name);
}
public void nextEndTag() throws XmlPullParserException, IOException {
XmlPullUtil.nextEndTag(pp);
}
public void nextEndTag(String name)
throws XmlPullParserException, IOException
{
XmlPullUtil.nextEndTag(pp, null, name);
}
public void nextEndTag(String namespace, String name)
throws XmlPullParserException, IOException
{
XmlPullUtil.nextEndTag(pp, namespace, name);
}
public String nextText(String namespace, String name)
throws IOException, XmlPullParserException
{
return XmlPullUtil.nextText(pp, namespace, name);
}
public void skipSubTree() throws XmlPullParserException, IOException {
XmlPullUtil.skipSubTree(pp);
}
public double readDouble() throws XmlPullParserException, IOException {
String value = pp.nextText();
double d;
try {
d = Double.parseDouble(value);
} catch(NumberFormatException ex) {
if(value.equals("INF") || value.toLowerCase().equals("infinity")) {
d = Double.POSITIVE_INFINITY;
} else if (value.equals("-INF")
|| value.toLowerCase().equals("-infinity")) {
d = Double.NEGATIVE_INFINITY;
} else if (value.equals("NaN")) {
d = Double.NaN;
} else {
throw new XmlPullParserException("can't parse double value '"+value+"'", this, ex);
}
}
return d;
}
public float readFloat() throws XmlPullParserException, IOException {
String value = pp.nextText();
float f;
try {
f = Float.parseFloat(value);
} catch(NumberFormatException ex) {
if(value.equals("INF") || value.toLowerCase().equals("infinity")) {
f = Float.POSITIVE_INFINITY;
} else if (value.equals("-INF")
|| value.toLowerCase().equals("-infinity")) {
f = Float.NEGATIVE_INFINITY;
} else if (value.equals("NaN")) {
f = Float.NaN;
} else {
throw new XmlPullParserException("can't parse float value '"+value+"'", this, ex);
}
}
return f;
}
// method copied from JiBX see http://sourceforge.net/projects/jibx/ for details
private int parseDigits(String text, int offset, int length)
throws XmlPullParserException
{
// check if overflow a potential problem
int value = 0;
if (length > 9) {
// use library parse code for potential overflow
try {
value = Integer.parseInt(text.substring(offset, offset+length));
} catch (NumberFormatException ex) {
throw new XmlPullParserException(ex.getMessage());
}
} else {
// parse with no overflow worries
int limit = offset + length;
while (offset < limit) {
char chr = text.charAt(offset++);
if (chr >= '0' && chr <= '9') {
value = value * 10 + (chr - '0');
} else {
throw new XmlPullParserException("non-digit in number value",this, null);
}
}
}
return value;
}
// method copied from JiBX see http://sourceforge.net/projects/jibx/ for details
private int parseInt(String text) throws XmlPullParserException {
// make sure there's text to be processed
int offset = 0;
int limit = text.length();
if (limit == 0) {
throw new XmlPullParserException("empty number value", this, null);
}
// check leading sign present in text
boolean negate = false;
char chr = text.charAt(0);
if (chr == '-') {
if (limit > 9) {
// special case to make sure maximum negative value handled
try {
return Integer.parseInt(text);
} catch (NumberFormatException ex) {
throw new XmlPullParserException(ex.getMessage(), this, null);
}
} else {
negate = true;
offset++;
}
} else if (chr == '+') {
offset++;
}
if (offset >= limit) {
throw new XmlPullParserException("Invalid number format", this, null);
}
// handle actual value conversion
int value = parseDigits(text, offset, limit-offset);
if (negate) {
return -value;
} else {
return value;
}
}
public int readInt() throws XmlPullParserException, IOException {
try {
//int i = Integer.parseInt(pp.nextText());
int i = parseInt(pp.nextText());
return i;
} catch(NumberFormatException ex) {
throw new XmlPullParserException("can't parse int value", this, ex);
}
}
public String readString() throws XmlPullParserException, IOException {
String xsiNil = pp.getAttributeValue(XSD_NS, "nil");
if("true".equals(xsiNil)) {
nextEndTag();
return null;
}
return pp.nextText();
}
public double readDoubleElement(String namespace, String name)
throws XmlPullParserException, IOException
{
pp.require(XmlPullParser.START_TAG, namespace, name);
return readDouble();
}
public float readFloatElement(String namespace, String name)
throws XmlPullParserException, IOException
{
pp.require(XmlPullParser.START_TAG, namespace, name);
return readFloat();
}
public int readIntElement(String namespace, String name)
throws XmlPullParserException, IOException
{
pp.require(XmlPullParser.START_TAG, namespace, name);
return readInt();
}
public String readStringElemet(String namespace, String name)
throws XmlPullParserException, IOException
{
pp.require(XmlPullParser.START_TAG, namespace, name);
return readString();
}
}
xpp3-1.1.4c/src/java/wrapper/org/xmlpull/v1/wrapper/classic/StaticXmlSerializerWrapper.java 100644 0 0 34221 10525225063 31142 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.wrapper.classic;
import java.io.IOException;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
import org.xmlpull.v1.wrapper.XmlPullParserWrapper;
import org.xmlpull.v1.wrapper.XmlPullWrapperFactory;
import org.xmlpull.v1.wrapper.XmlSerializerWrapper;
/**
* This class seemlesly extends exisiting serialzier implementation by adding new methods
* (provided by XmlPullUtil) and delegating exisiting methods to parser implementation.
*
* @author Aleksander Slominski
* @author Naresh Bhatia
*/
public class StaticXmlSerializerWrapper extends XmlSerializerDelegate
implements XmlSerializerWrapper
{
private final static String PROPERTY_XMLDECL_STANDALONE =
"http://xmlpull.org/v1/doc/features.html#xmldecl-standalone";
private static final boolean TRACE_SIZING = false;
protected String currentNs;
protected XmlPullWrapperFactory wf;
protected XmlPullParserWrapper fragmentParser;
public StaticXmlSerializerWrapper(XmlSerializer xs, XmlPullWrapperFactory wf) {
super(xs);
this.wf = wf;
}
public String getCurrentNamespaceForElements() { return currentNs; }
public String setCurrentNamespaceForElements(String value)
{
String old = currentNs;
currentNs = value;
return old;
}
public XmlSerializerWrapper attribute (String name, String value)
throws IOException, IllegalArgumentException, IllegalStateException
{
xs.attribute(null, name, value);
return this;
}
public XmlSerializerWrapper startTag (String name)
throws IOException, IllegalArgumentException, IllegalStateException
{
xs.startTag(currentNs, name);
return this;
}
public XmlSerializerWrapper endTag(String name)
throws IOException, IllegalArgumentException, IllegalStateException
{
endTag(currentNs, name);
return this;
}
/** Write simple text element in current namespace */
public XmlSerializerWrapper element(String elementName, String elementText)
throws IOException, XmlPullParserException
{
return element(currentNs, elementName, elementText);
}
public XmlSerializerWrapper element(String namespace, String elementName, String elementText)
throws IOException, XmlPullParserException
{
if (elementName == null) {
throw new XmlPullParserException("name for element can not be null");
}
xs.startTag(namespace, elementName);
if (elementText == null) {
xs.attribute(XSI_NS, "nil", "true");
}
else {
xs.text(elementText);
}
xs.endTag(namespace, elementName);
return this;
}
//namespace stack
//protected int elNamespaceCount[] = new int[ 2 ];
//protected int currentDepth = -1;
protected int namespaceEnd = 0;
protected String namespacePrefix[] = new String[ 8 ];
protected String namespaceUri[] = new String[ namespacePrefix.length ];
protected int namespaceDepth[] = new int[ namespacePrefix.length ];
private void ensureNamespacesCapacity() {
int newSize = namespaceEnd > 7 ? 2 * namespaceEnd : 8;
if(TRACE_SIZING) {
System.err.println(
getClass().getName()+" namespaceSize "+namespacePrefix.length+" ==> "+newSize);
}
String[] newNamespacePrefix = new String[newSize];
String[] newNamespaceUri = new String[newSize];
int[] newNamespaceDepth = new int[newSize];
if(namespacePrefix != null) {
System.arraycopy(namespacePrefix, 0, newNamespacePrefix, 0, namespaceEnd);
System.arraycopy(namespaceUri, 0, newNamespaceUri, 0, namespaceEnd);
System.arraycopy(namespaceDepth, 0, newNamespaceDepth, 0, namespaceEnd);
}
namespacePrefix = newNamespacePrefix;
namespaceUri = newNamespaceUri;
namespaceDepth = newNamespaceDepth;
}
// public XmlSerializer endTag(String namespace, String name) throws IOException
// {
// xs.endTag(currentNs, name);
// namespaceEnd = elNamespaceCount[ getDepth() ];
// return this;
// }
public void setPrefix(String prefix, String namespace)
throws IOException, IllegalArgumentException, IllegalStateException
{
xs.setPrefix(prefix, namespace);
int depth = getDepth();
for(int pos = namespaceEnd - 1; pos >= 0; --pos) {
if(namespaceDepth[ pos ] <= depth) {
break;
}
--namespaceEnd;
}
if(namespaceEnd >= namespacePrefix.length) {
ensureNamespacesCapacity();
}
namespacePrefix[ namespaceEnd ] = prefix;
namespaceUri[ namespaceEnd ] = namespace;
++namespaceEnd;
}
public void fragment(String xmlFragment)
throws IOException, IllegalArgumentException, IllegalStateException, XmlPullParserException
{
StringBuffer buf = new StringBuffer(xmlFragment.length() + namespaceEnd * 30);
buf.append("= 0; --pos) {
String prefix = namespacePrefix[ pos ];
for(int i = namespaceEnd - 1; i > pos; --i) {
if(prefix.equals( namespacePrefix[i] )) {
continue LOOP;
}
}
buf.append(" xmlns");
if(prefix.length() > 0) {
buf.append(':').append(prefix);
}
buf.append("='");
buf.append(escapeAttributeValue(namespaceUri[ pos ]));
buf.append("'");
}
buf.append(">");
buf.append(xmlFragment);
buf.append(" ");
if(fragmentParser == null) {
fragmentParser = wf.newPullParserWrapper();
}
String s = buf.toString();
//System.err.println(getClass().getName()+" fragment XML="+s);
fragmentParser.setInput(new StringReader( s ) );
fragmentParser.nextTag();
fragmentParser.require(XmlPullParser.START_TAG, null, "fragment");
while(true) {
fragmentParser.nextToken();
if(fragmentParser.getDepth() == 1
&& fragmentParser.getEventType() == XmlPullParser.END_TAG)
{
break;
}
event(fragmentParser);
}
fragmentParser.require(XmlPullParser.END_TAG, null, "fragment");
}
public void event(XmlPullParser pp) throws XmlPullParserException, IOException {
int eventType = pp.getEventType();
switch (eventType) {
case XmlPullParser.START_DOCUMENT:
//use Boolean.TRUE to make it standalone
Boolean standalone = (Boolean) pp.getProperty(PROPERTY_XMLDECL_STANDALONE);
startDocument(pp.getInputEncoding(), standalone);
break;
case XmlPullParser.END_DOCUMENT:
endDocument();
break;
case XmlPullParser.START_TAG:
writeStartTag(pp);
break;
case XmlPullParser.END_TAG:
endTag(pp.getNamespace (), pp.getName ());
break;
case XmlPullParser.IGNORABLE_WHITESPACE:
//comment it to remove ignorable whtespaces from XML infoset
String s = pp.getText ();
ignorableWhitespace(s);
break;
case XmlPullParser.TEXT:
if(pp.getDepth() > 0) {
text(pp.getText ());
} else {
ignorableWhitespace(pp.getText ());
}
break;
case XmlPullParser.ENTITY_REF:
entityRef (pp.getName ());
break;
case XmlPullParser.CDSECT:
cdsect( pp.getText () );
break;
case XmlPullParser.PROCESSING_INSTRUCTION:
processingInstruction( pp.getText ());
break;
case XmlPullParser.COMMENT:
comment (pp.getText ());
break;
case XmlPullParser.DOCDECL:
docdecl (pp.getText ());
break;
}
}
private void writeStartTag(XmlPullParser pp) throws XmlPullParserException, IOException {
if (!pp.getFeature (XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES)) {
int nsStart = pp.getNamespaceCount(pp.getDepth()-1);
int nsEnd = pp.getNamespaceCount(pp.getDepth());
for (int i = nsStart; i < nsEnd; i++) {
String prefix = pp.getNamespacePrefix(i);
String ns = pp.getNamespaceUri(i);
setPrefix(prefix, ns);
}
}
startTag(pp.getNamespace(), pp.getName());
for (int i = 0; i < pp.getAttributeCount(); i++) {
attribute
(pp.getAttributeNamespace (i),
pp.getAttributeName (i),
pp.getAttributeValue (i));
}
//ser.closeStartTag();
}
public String escapeAttributeValue(String value)
//protected void writeAttributeValue(String value, Writer out) throws IOException
{
int posLt = value.indexOf('<');
int posAmp = value.indexOf('&');
int posQuot = value.indexOf('"');
int posApos = value.indexOf('\'');
if(posLt == -1 && posAmp == -1 && posQuot == -1 && posApos == -1) {
return value;
}
StringBuffer buf = new StringBuffer(value.length() + 10);
// painful loop ...
for(int pos = 0, len = value.length(); pos < len; ++pos) {
char ch = value.charAt(pos);
switch(ch) {
case '<':
buf.append("<");
break;
case '&':
buf.append("&");
break;
case '\'':
buf.append("'");
break;
case '"':
buf.append(""");
break;
default:
buf.append(ch);
}
}
return buf.toString();
}
//protected void writeElementContent(String text, Writer out) throws IOException
public String escapeText(String text)
{
//<, & esccaped]
//out.write(text);
int posLt = text.indexOf('<');
int posAmp = text.indexOf('&');
if(posLt == -1 && posAmp == -1) { // this is shortcut
return text;
}
StringBuffer buf = new StringBuffer(text.length() + 10);
// painful loop ...
int pos = 0;
while(true) {
if(posLt == -1 && posAmp == -1) { // this is shortcut
buf.append(text.substring(pos));
break;
} else if(posLt == -1
|| (posLt != -1 && posAmp != -1 && posAmp < posLt))
{
if(pos < posAmp) buf.append(text.substring(pos, posAmp));
buf.append("&");
pos = posAmp + 1;
posAmp = text.indexOf('&', pos);
} else if(posAmp == -1
|| (posLt != -1 && posAmp != -1 && posLt < posAmp))
{
if(pos < posLt) buf.append(text.substring(pos, posLt));
buf.append("<");
pos = posLt + 1;
posLt = text.indexOf('<', pos);
} else {
throw new IllegalStateException("wrong state posLt="+posLt
+" posAmp="+posAmp+" for "+text);
}
}
return buf.toString();
}
public void writeDouble(double d)
throws XmlPullParserException, IOException, IllegalArgumentException
{
if(d == Double.POSITIVE_INFINITY) {
xs.text("INF");
} else if(d == Double.NEGATIVE_INFINITY) {
xs.text("-INF");
} else {
xs.text(Double.toString(d));
}
}
public void writeFloat(float f)
throws XmlPullParserException, IOException, IllegalArgumentException
{
if(f == Float.POSITIVE_INFINITY) {
xs.text("INF");
} else if(f == Float.NEGATIVE_INFINITY) {
xs.text("-INF");
} else {
xs.text(Float.toString(f));
}
}
public void writeInt(int i)
throws XmlPullParserException, IOException, IllegalArgumentException
{
xs.text(Integer.toString(i));
}
public void writeString(String s)
throws XmlPullParserException, IOException, IllegalArgumentException
{
if( s == null ) {
throw new IllegalArgumentException("null string can not be written");
}
xs.text(s);
}
public void writeDoubleElement(String namespace, String name, double d)
throws XmlPullParserException, IOException, IllegalArgumentException
{
xs.startTag(namespace, name);
writeDouble(d);
xs.endTag(namespace, name);
}
public void writeFloatElement(String namespace, String name, float f)
throws XmlPullParserException, IOException, IllegalArgumentException
{
xs.startTag(namespace, name);
writeFloat(f);
xs.endTag(namespace, name);
}
public void writeIntElement(String namespace, String name, int i)
throws XmlPullParserException, IOException, IllegalArgumentException
{
xs.startTag(namespace, name);
writeInt(i);
xs.endTag(namespace, name);
}
public void writeStringElement(String namespace, String name, String s)
throws XmlPullParserException, IOException, IllegalArgumentException
{
xs.startTag(namespace, name);
if(s == null) {
xs.attribute(XSD_NS, "nil", "true");
} else {
writeString(s);
}
xs.endTag(namespace, name);
}
}
xpp3-1.1.4c/src/java/wrapper/org/xmlpull/v1/wrapper/classic/XmlPullParserDelegate.java 100644 0 0 11554 10525225063 30050 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.wrapper.classic;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* This is simple class that implements parser interface by delegating
* all calls to actual wrapped class implementation that is passed in constructor.
* Purpose of this class is to work as a base class when extending parser interface
* by wrapping exsiting parser implementation and allowing to add new methods.
*
* @author Aleksander Slominski
*/
public class XmlPullParserDelegate implements XmlPullParser {
protected XmlPullParser pp;
public XmlPullParserDelegate(XmlPullParser pp) {
this.pp = pp;
}
public String getText() {
return pp.getText();
}
public void setFeature(String name, boolean state) throws XmlPullParserException {
pp.setFeature(name, state);
}
public char[] getTextCharacters(int[] holderForStartAndLength) {
return pp.getTextCharacters(holderForStartAndLength);
}
public int getColumnNumber() {
return pp.getColumnNumber();
}
public int getNamespaceCount(int depth) throws XmlPullParserException {
return pp.getNamespaceCount(depth);
}
public String getNamespacePrefix(int pos) throws XmlPullParserException {
return pp.getNamespacePrefix(pos);
}
public String getAttributeName(int index) {
return pp.getAttributeName(index);
}
public String getName() {
return pp.getName();
}
public boolean getFeature(String name) {
return pp.getFeature(name);
}
public String getInputEncoding() {
return pp.getInputEncoding();
}
public String getAttributeValue(int index) {
return pp.getAttributeValue(index);
}
public String getNamespace(String prefix) {
return pp.getNamespace(prefix);
}
public void setInput(Reader in) throws XmlPullParserException {
pp.setInput(in);
}
public int getLineNumber() {
return pp.getLineNumber();
}
public Object getProperty(String name) {
return pp.getProperty(name);
}
public boolean isEmptyElementTag() throws XmlPullParserException {
return pp.isEmptyElementTag();
}
public boolean isAttributeDefault(int index) {
return pp.isAttributeDefault(index);
}
public String getNamespaceUri(int pos) throws XmlPullParserException {
return pp.getNamespaceUri(pos);
}
public int next() throws XmlPullParserException, IOException {
return pp.next();
}
public int nextToken() throws XmlPullParserException, IOException {
return pp.nextToken();
}
public void defineEntityReplacementText(String entityName,
String replacementText)
throws XmlPullParserException
{
pp.defineEntityReplacementText(entityName, replacementText);
}
public int getAttributeCount() {
return pp.getAttributeCount();
}
public boolean isWhitespace() throws XmlPullParserException {
return pp.isWhitespace();
}
public String getPrefix() {
return pp.getPrefix();
}
public void require(int type, String namespace, String name) throws XmlPullParserException, IOException {
pp.require(type, namespace, name);
}
public String nextText() throws XmlPullParserException, IOException {
return pp.nextText();
}
public String getAttributeType(int index) {
return pp.getAttributeType(index);
}
public int getDepth() {
return pp.getDepth();
}
public int nextTag() throws XmlPullParserException, IOException {
return pp.nextTag();
}
public int getEventType() throws XmlPullParserException {
return pp.getEventType();
}
public String getAttributePrefix(int index) {
return pp.getAttributePrefix(index);
}
public void setInput(InputStream inputStream, String inputEncoding) throws XmlPullParserException {
pp.setInput(inputStream, inputEncoding);
}
public String getAttributeValue(String namespace, String name) {
return pp.getAttributeValue(namespace, name);
}
public void setProperty(String name, Object value) throws XmlPullParserException {
pp.setProperty(name, value);
}
public String getPositionDescription() {
return pp.getPositionDescription();
}
public String getNamespace() {
return pp.getNamespace();
}
public String getAttributeNamespace(int index) {
return pp.getAttributeNamespace(index);
}
}
xpp3-1.1.4c/src/java/wrapper/org/xmlpull/v1/wrapper/classic/XmlSerializerDelegate.java 100644 0 0 10700 10525225063 30060 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)
package org.xmlpull.v1.wrapper.classic;
import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
/**
* This is simple class that implements serializer interface by delegating
* all calls to actual serialzier implementation passed in constructor.
* Purpose of this class is to work as base class to allow extending interface
* by wrapping exsiting parser implementation and allowing ot add new methods.
*
* @author Aleksander Slominski
*/
public class XmlSerializerDelegate implements XmlSerializer {
protected XmlSerializer xs;
public XmlSerializerDelegate(XmlSerializer serializer) {
this.xs = serializer;
}
public String getName() {
return xs.getName();
}
public void setPrefix(String prefix, String namespace)
throws IOException, IllegalArgumentException, IllegalStateException
{
xs.setPrefix(prefix, namespace);
}
public void setOutput(OutputStream os, String encoding) throws IOException, IllegalArgumentException, IllegalStateException {
xs.setOutput(os, encoding);
}
public void endDocument() throws IOException, IllegalArgumentException, IllegalStateException {
xs.endDocument();
}
public void comment(String text) throws IOException, IllegalArgumentException, IllegalStateException {
xs.comment(text);
}
public int getDepth() {
return xs.getDepth();
}
public void setProperty(String name, Object value) throws IllegalArgumentException, IllegalStateException {
xs.setProperty(name, value);
}
public void cdsect(String text) throws IOException, IllegalArgumentException, IllegalStateException {
xs.cdsect(text);
}
public void setFeature(String name, boolean state) throws IllegalArgumentException, IllegalStateException {
xs.setFeature(name, state);
}
public void entityRef(String text) throws IOException, IllegalArgumentException, IllegalStateException {
xs.entityRef(text);
}
public void processingInstruction(String text) throws IOException, IllegalArgumentException, IllegalStateException {
xs.processingInstruction(text);
}
public void setOutput(Writer writer) throws IOException, IllegalArgumentException, IllegalStateException {
xs.setOutput(writer);
}
public void docdecl(String text) throws IOException, IllegalArgumentException, IllegalStateException {
xs.docdecl(text);
}
public void flush() throws IOException {
xs.flush();
}
public Object getProperty(String name) {
return xs.getProperty(name);
}
public XmlSerializer startTag(String namespace, String name) throws IOException, IllegalArgumentException, IllegalStateException {
return xs.startTag(namespace, name);
}
public void ignorableWhitespace(String text) throws IOException, IllegalArgumentException, IllegalStateException {
xs.ignorableWhitespace(text);
}
public XmlSerializer text(String text) throws IOException, IllegalArgumentException, IllegalStateException {
return xs.text(text);
}
public boolean getFeature(String name) {
return xs.getFeature(name);
}
public XmlSerializer attribute(String namespace, String name, String value) throws IOException, IllegalArgumentException, IllegalStateException {
return xs.attribute(namespace, name, value);
}
public void startDocument(String encoding, Boolean standalone) throws IOException, IllegalArgumentException, IllegalStateException {
xs.startDocument(encoding, standalone);
}
public String getPrefix(String namespace, boolean generatePrefix) throws IllegalArgumentException {
return xs.getPrefix(namespace, generatePrefix);
}
public String getNamespace() {
return xs.getNamespace();
}
public XmlSerializer endTag(String namespace, String name)
throws IOException, IllegalArgumentException, IllegalStateException
{
return xs.endTag(namespace, name);
}
public XmlSerializer text(char[] buf, int start, int len) throws IOException, IllegalArgumentException, IllegalStateException {
return xs.text(buf, start, len);
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/Xb1XPath.java 100644 0 0 7642 10525225063 24342 0 ustar aslom ewww 0 0 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
/*
* Copyright (c) 2002-2004 Extreme! Lab, Indiana University. All rights reserved.
*
* This software is open source. See the bottom of this file for the licence.
*
* $Id: Xb1XPath.java,v 1.1 2004/06/16 15:55:43 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath;
import org.xmlpull.v1.builder.xpath.jaxen.BaseXPath;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.impl.DocumentNavigator;
/**
* An XPath implementation for the XB1 model
* for more details on XB1 see
* XB1
*
* @author Aleksander Slominski
*
* @version $Revision: 1.1 $
*/
public class Xb1XPath extends BaseXPath {
/**
* Compile XPath expression into an executable form suitable to use with XB1.
*
* @param xpathExpr The XPath expression.
*
* @throws JaxenException if there is a syntax error while
* parsing the expression.
*/
public Xb1XPath(String xpathExpr) throws JaxenException
{
super( xpathExpr, DocumentNavigator.getInstance() );
}
}
/*
* Indiana University Extreme! Lab Software License, Version 1.2
*
* Copyright (c) 2002-2004 The Trustees of Indiana University.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1) All redistributions of source code must retain the above
* copyright notice, the list of authors in the original source
* code, this list of conditions and the disclaimer listed in this
* license;
*
* 2) All redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the disclaimer
* listed in this license in the documentation and/or other
* materials provided with the distribution;
*
* 3) Any documentation included with all redistributions must include
* the following acknowledgement:
*
* "This product includes software developed by the Indiana
* University Extreme! Lab. For further information please visit
* http://www.extreme.indiana.edu/"
*
* Alternatively, this acknowledgment may appear in the software
* itself, and wherever such third-party acknowledgments normally
* appear.
*
* 4) The name "Indiana University" or "Indiana University
* Extreme! Lab" shall not be used to endorse or promote
* products derived from this software without prior written
* permission from Indiana University. For written permission,
* please contact http://www.extreme.indiana.edu/.
*
* 5) Products derived from this software may not use "Indiana
* University" name nor may "Indiana University" appear in their name,
* without prior written permission of the Indiana University.
*
* Indiana University provides no reassurances that the source code
* provided does not infringe the patent or any other intellectual
* property rights of any other entity. Indiana University disclaims any
* liability to any recipient for claims brought by any other entity
* based on infringement of intellectual property rights or otherwise.
*
* LICENSEE UNDERSTANDS THAT SOFTWARE IS PROVIDED "AS IS" FOR WHICH
* NO WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. INDIANA
* UNIVERSITY GIVES NO WARRANTIES AND MAKES NO REPRESENTATION THAT
* SOFTWARE IS FREE OF INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR
* OTHER PROPRIETARY RIGHTS. INDIANA UNIVERSITY MAKES NO WARRANTIES THAT
* SOFTWARE IS FREE FROM "BUGS", "VIRUSES", "TROJAN HORSES", "TRAP
* DOORS", "WORMS", OR OTHER HARMFUL CODE. LICENSEE ASSUMES THE ENTIRE
* RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR ASSOCIATED MATERIALS,
* AND TO THE PERFORMANCE AND VALIDITY OF INFORMATION GENERATED USING
* SOFTWARE.
*/
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/impl/DocumentNavigator.java 100644 0 0 30541 10525225063 27347 0 ustar aslom ewww 0 0
package org.xmlpull.v1.builder.xpath.impl;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.xmlpull.v1.builder.XmlAttribute;
import org.xmlpull.v1.builder.XmlCharacters;
import org.xmlpull.v1.builder.XmlComment;
import org.xmlpull.v1.builder.XmlContainer;
import org.xmlpull.v1.builder.XmlDocument;
import org.xmlpull.v1.builder.XmlElement;
import org.xmlpull.v1.builder.XmlInfosetBuilder;
import org.xmlpull.v1.builder.XmlNamespace;
import org.xmlpull.v1.builder.XmlProcessingInstruction;
import org.xmlpull.v1.builder.xpath.Xb1XPath;
import org.xmlpull.v1.builder.xpath.jaxen.DefaultNavigator;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import org.xmlpull.v1.builder.xpath.jaxen.XPath;
import org.xmlpull.v1.builder.xpath.jaxen.util.SingleObjectIterator;
import org.xmlpull.v1.builder.xpath.saxpath.SAXPathException;
/**
* Interface for navigating around the XB1 object model
* to use with Jaxen XPATH implementation.
*
* @author Alek
*/
public class DocumentNavigator extends DefaultNavigator
{
private static DocumentNavigator instance = new DocumentNavigator();
public static DocumentNavigator getInstance()
{
return instance;
}
public boolean isElement(Object obj)
{
return obj instanceof XmlElement;
}
public boolean isComment(Object obj)
{
return obj instanceof XmlComment;
}
public boolean isText(Object obj)
{
return ( obj instanceof String
||
obj instanceof XmlCharacters );
}
public boolean isAttribute(Object obj)
{
return obj instanceof XmlAttribute;
}
public boolean isProcessingInstruction(Object obj)
{
return obj instanceof XmlProcessingInstruction;
}
public boolean isDocument(Object obj)
{
return obj instanceof XmlDocument;
}
public boolean isNamespace(Object obj)
{
return obj instanceof XmlNamespace || obj instanceof XPathNamespace;
}
public String getElementName(Object obj)
{
XmlElement elem = (XmlElement) obj;
return elem.getName();
}
public String getElementNamespaceUri(Object obj)
{
XmlElement elem = (XmlElement) obj;
String uri = elem.getNamespaceName();
if ( uri != null && uri.length() == 0 )
return null;
else
return uri;
}
public String getAttributeName(Object obj)
{
XmlAttribute attr = (XmlAttribute) obj;
return attr.getName();
}
public String getAttributeNamespaceUri(Object obj)
{
XmlAttribute attr = (XmlAttribute) obj;
String uri = attr.getNamespaceName();
if ( uri != null && uri.length() == 0 )
return null;
else
return uri;
}
public Iterator getChildAxisIterator(Object contextNode)
{
if ( contextNode instanceof XmlElement )
{
return ((XmlElement)contextNode).children();
}
else if ( contextNode instanceof XmlDocument )
{
return ((XmlDocument)contextNode).children().iterator();
}
return null;
}
public Iterator getNamespaceAxisIterator(Object contextNode)
{
if ( ! ( contextNode instanceof XmlElement ) )
{
return null;
}
XmlElement elem = (XmlElement) contextNode;
Map nsMap = new HashMap();
XmlElement current = elem;
while ( current != null ) {
XmlNamespace ns = current.getNamespace();
//if ( ns != Namespace.NO_NAMESPACE ) {
if ( ns != null && ns.getPrefix() != null ) {
if ( !nsMap.containsKey(ns.getPrefix()) )
nsMap.put( ns.getPrefix(), new XPathNamespace(elem, ns) );
}
Iterator declaredNamespaces = current.namespaces();
while ( declaredNamespaces.hasNext() ) {
ns = (XmlNamespace)declaredNamespaces.next();
if ( !nsMap.containsKey(ns.getPrefix()) )
nsMap.put( ns.getPrefix(), new XPathNamespace(elem, ns) );
}
if(current.getParent() instanceof XmlElement) {
current = (XmlElement) current.getParent();
} else {
current = null;
}
}
//TODO: should we really add it or is it already added by XPP3?
//nsMap.put( "xml", new XPathNamespace(elem, Namespace.XML_NAMESPACE) );
return nsMap.values().iterator();
}
public Iterator getParentAxisIterator(Object contextNode)
{
Object parent = null;
if ( contextNode instanceof XmlDocument )
{
parent = contextNode;
}
else if ( contextNode instanceof XmlElement )
{
parent = ((XmlElement)contextNode).getParent();
// if ( parent == null )
// {
// if ( ((XmlElement)contextNode).isRootElement() )
// {
// parent = ((Element)contextNode).getDocument();
// }
// }
}
else if ( contextNode instanceof XmlAttribute )
{
parent = ((XmlAttribute)contextNode).getOwner();
}
else if ( contextNode instanceof XPathNamespace )
{
parent = ((XPathNamespace)contextNode).getElement();
}
else if ( contextNode instanceof XmlProcessingInstruction )
{
parent = ((XmlProcessingInstruction)contextNode).getParent();
}
else if ( contextNode instanceof XmlComment )
{
parent = ((XmlComment)contextNode).getParent();
}
else if ( contextNode instanceof XmlCharacters ) {
parent = ((XmlCharacters)contextNode).getParent();
}
else if ( contextNode instanceof String )
{
throw new IllegalStateException("XB1 XML tree shoul dnot contain Strings directly");
}
if ( parent != null )
{
return new SingleObjectIterator( parent );
}
return null;
}
public Iterator getAttributeAxisIterator(Object contextNode)
{
if ( ! ( contextNode instanceof XmlElement ) )
{
return null;
}
XmlElement elem = (XmlElement) contextNode;
return elem.attributes();
}
public XPath parseXPath (String xpath) throws SAXPathException
{
return new Xb1XPath(xpath);
}
private static XmlDocument getDocument(XmlElement el) {
//TODO recursively work until parent document
XmlElement root = el;
while(root.getParent() instanceof XmlElement) {
root = (XmlElement) root.getParent();
}
return (XmlDocument) root.getParent();
}
public Object getDocumentNode(Object contextNode)
{
if ( contextNode instanceof XmlDocument )
{
return contextNode;
}
XmlElement elem = (XmlElement) contextNode;
return getDocument(elem);
}
public String getElementQName(Object obj)
{
XmlElement elem = (XmlElement) obj;
String prefix = null;
if(elem.getNamespace() != null) {
//TODO REVISIT: needs to declare prefix if namesapce name != null ... or not?
prefix = elem.getNamespace().getPrefix();
}
if ( prefix == null || "".equals( prefix ) )
{
return elem.getName();
}
return prefix + ":" + elem.getName();
}
public String getAttributeQName(Object obj)
{
XmlAttribute attr = (XmlAttribute) obj;
//String prefix = attr.getNamespacePrefix();
String prefix = null;
if(attr.getNamespace() != null) {
//TODO REVISIT: needs to declare prefix if namesapce name != null ... or not?
prefix = attr.getNamespace().getPrefix();
}
if ( prefix == null || "".equals( prefix ) )
{
return attr.getName();
}
return prefix + ":" + attr.getName();
}
public String getNamespaceStringValue(Object obj)
{
if (obj instanceof XmlNamespace) {
XmlNamespace ns = (XmlNamespace) obj;
return ns.getNamespaceName();
} else {
XPathNamespace ns = (XPathNamespace) obj;
return ns.getNamespace().getNamespaceName();
}
}
public String getNamespacePrefix(Object obj)
{
if (obj instanceof XmlNamespace) {
XmlNamespace ns = (XmlNamespace) obj;
return ns.getPrefix();
} else {
XPathNamespace ns = (XPathNamespace) obj;
return ns.getNamespace().getPrefix();
}
}
public String getTextStringValue(Object obj)
{
if ( obj instanceof XmlCharacters )
{
return ((XmlCharacters)obj).getText();
}
if ( obj instanceof String )
{
return ((String)obj);
}
return "";
}
public String getAttributeStringValue(Object obj)
{
XmlAttribute attr = (XmlAttribute) obj;
return attr.getValue();
}
public String getElementStringValue(Object obj)
{
XmlElement elem = (XmlElement) obj;
StringBuffer buf = new StringBuffer();
Iterator contentIter = elem.children();
Object each = null;
while ( contentIter.hasNext() )
{
each = contentIter.next();
if ( each instanceof String )
{
buf.append( ((String)each) );
}
else if ( each instanceof XmlCharacters )
{
buf.append( ((XmlCharacters)each).getText() );
}
else if ( each instanceof XmlElement )
{
buf.append( getElementStringValue( each ) );
}
}
return buf.toString();
}
public String getProcessingInstructionTarget(Object obj)
{
XmlProcessingInstruction pi = (XmlProcessingInstruction) obj;
return pi.getTarget();
}
public String getProcessingInstructionData(Object obj)
{
XmlProcessingInstruction pi = (XmlProcessingInstruction) obj;
return pi.getContent();
}
public String getCommentStringValue(Object obj)
{
XmlComment cmt = (XmlComment) obj;
return cmt.getContent();
}
public String translateNamespacePrefixToUri(String prefix, Object context)
{
XmlElement element = null;
if ( context instanceof XmlElement )
{
element = (XmlElement) context;
}
else if ( context instanceof XmlCharacters )
{
element = (XmlElement) ((XmlCharacters)context).getParent();
}
else if ( context instanceof XmlAttribute )
{
element = ((XmlAttribute)context).getOwner();
}
else if ( context instanceof XPathNamespace )
{
element = ((XPathNamespace)context).getElement();
}
else if ( context instanceof XmlComment )
{
XmlContainer container = ((XmlComment)context).getParent();
if(container instanceof XmlElement) {
element = (XmlElement) container;
}
}
else if ( context instanceof XmlProcessingInstruction )
{
XmlContainer container = ((XmlProcessingInstruction)context).getParent();
if(container instanceof XmlElement) {
element = (XmlElement) container;
}
}
else if ( context instanceof String )
{
//TODO REVISIT to do automatic wrapping ....
//element = ((String)context).getParent();
throw new IllegalArgumentException("could not determine parent string in "+context);
}
if ( element != null )
{
XmlNamespace namespace = element.lookupNamespaceByPrefix( prefix );
if ( namespace != null )
{
return namespace.getNamespaceName();
}
}
return null;
}
public Object getDocument(String url) throws FunctionCallException
{
try
{
XmlInfosetBuilder builder = XmlInfosetBuilder.newInstance();
return builder.parseLocation( url );
}
catch (Exception e)
{
throw new FunctionCallException( e.getMessage() );
}
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/impl/XPathNamespace.java 100644 0 0 2035 10525225063 26534 0 ustar aslom ewww 0 0
package org.xmlpull.v1.builder.xpath.impl;
import org.xmlpull.v1.builder.XmlElement;
import org.xmlpull.v1.builder.XmlNamespace;
/**
* Wrap namespace with parent so we can find parent as required by JAXEN ....
*
* @author
*/
public class XPathNamespace
{
private XmlElement element;
private XmlNamespace namespace;
public XPathNamespace( XmlNamespace namespace )
{
this.namespace = namespace;
}
public XPathNamespace( XmlElement element, XmlNamespace namespace )
{
this.element = element;
this.namespace = namespace;
}
public XmlElement getElement()
{
return element;
}
// public void setElement( XmlElement element )
// {
// this.element = element;
// }
public XmlNamespace getNamespace()
{
return namespace;
}
public String toString()
{
return ( "[xmlns:" + namespace.getPrefix() + "=\"" +
namespace.getNamespaceName() + "\", element=" +
element.getName() + "]" );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/BaseXPath.java 100644 0 0 61211 10525225063 25677 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/BaseXPath.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: BaseXPath.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
import org.xmlpull.v1.builder.xpath.jaxen.expr.Expr;
import org.xmlpull.v1.builder.xpath.jaxen.expr.XPathExpr;
import org.xmlpull.v1.builder.xpath.jaxen.function.BooleanFunction;
import org.xmlpull.v1.builder.xpath.jaxen.function.StringFunction;
import org.xmlpull.v1.builder.xpath.jaxen.function.NumberFunction;
import org.xmlpull.v1.builder.xpath.saxpath.XPathReader;
import org.xmlpull.v1.builder.xpath.saxpath.SAXPathException;
import org.xmlpull.v1.builder.xpath.saxpath.helpers.XPathReaderFactory;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/** Base functionality for all concrete, implementation-specific XPaths.
*
*
* This class provides generic functionality for further-defined
* implementation-specific XPaths.
*
*
*
* If you want to adapt the Jaxen engine so that it can traverse your own
* object model then this is a good base class to derive from.
* Typically you only really need to provide your own
* {@link org.jaxen.Navigator} implementation.
*
*
* @see org.jaxen.dom4j.Dom4jXPath XPath for dom4j
* @see org.jaxen.jdom.JDOMXPath XPath for JDOM
* @see org.jaxen.dom.DOMXPath XPath for W3C DOM
* @see org.jaxen.exml.ElectricXPath XPath for Electric XML
*
* @author bob mcwhirter
* @author James Strachan
*/
public class BaseXPath implements XPath, Serializable
{
/** the parsed form of the xpath expression */
private XPathExpr xpath;
/** the support information and function, namespace and variable contexts */
private ContextSupport support;
/** the implementation-specific Navigator for retrieving XML nodes **/
private Navigator navigator;
/** Construct given an XPath expression string.
*
* @param xpathExpr The XPath expression.
*
* @throws JaxenException if there is a syntax error while
* parsing the expression.
*/
protected BaseXPath(String xpathExpr) throws JaxenException
{
try
{
XPathReader reader = XPathReaderFactory.createReader();
JaxenHandler handler = new JaxenHandler();
reader.setXPathHandler( handler );
reader.parse( xpathExpr );
this.xpath = handler.getXPathExpr();
}
catch (org.xmlpull.v1.builder.xpath.saxpath.XPathSyntaxException e)
{
throw new org.xmlpull.v1.builder.xpath.jaxen.XPathSyntaxException( e.getXPath(),
e.getPosition(),
e.getMessage() );
}
catch (SAXPathException e)
{
throw new JaxenException( e );
}
}
/** Construct given an XPath expression string.
*
* @param xpathExpr The XPath expression.
*
* @param navigator the XML navigator to use
*
* @throws JaxenException if there is a syntax error while
* parsing the expression.
*/
public BaseXPath(String xpathExpr, Navigator navigator) throws JaxenException
{
this( xpathExpr );
this.navigator = navigator;
}
/** Evaluate this XPath against a given context.
*
*
* The context of evaluation my be a document ,
* an element , or a set of elements .
*
*
*
* If the expression evaluates to a single primitive
* (String, Number or Boolean) type, it is returned
* directly. Otherwise, the returned value is a
* List (a node-set
, in the terms of the
* specification) of values.
*
*
*
* When using this method, one must be careful to
* test the class of the returned objects, and of
* each of the composite members if a List
* is returned. If the returned members are XML entities,
* they will be the actual Document
,
* Element
or Attribute
objects
* as defined by the concrete XML object-model implementation,
* directly from the context document. This does not
* return copies of anything , but merely returns
* references to entities within the source document.
*
*
* @param node The node, nodeset or Context object for evaluation. This value can be null.
*
* @return The result of evaluating the XPath expression
* against the supplied context.
*/
public Object evaluate(Object node) throws JaxenException
{
List answer = selectNodes(node);
if ( answer != null
&&
answer.size() == 1 )
{
Object first = answer.get(0);
if ( first instanceof String
||
first instanceof Number
||
first instanceof Boolean )
{
return first;
}
}
return answer;
}
/** Select all nodes that are selectable by this XPath
* expression. If multiple nodes match, multiple nodes
* will be returned.
*
*
* NOTE: In most cases, nodes will be returned
* in document-order, as defined by the XML Canonicalization
* specification. The exception occurs when using XPath
* expressions involving the union
operator
* (denoted with the pipe '|' character).
*
*
* @param node The node, nodeset or Context object for evaluation. This value can be null.
*
* @return The node-set
of all items selected
* by this XPath expression.
*
* @see #selectSingleNode
*/
public List selectNodes(Object node) throws JaxenException
{
Context context = getContext( node );
return selectNodesForContext( context );
}
/** Select only the first node that is selectable by this XPath
* expression. If multiple nodes match, only one node will be
* returned.
*
* NOTE: In most cases, the selected node will be the first
* selectable node in document-order, as defined by the XML Canonicalization
* specification. The exception occurs when using XPath
* expressions involving the union
operator
* (denoted with the pipe '|' character).
*
*
* @param node The node, nodeset or Context object for evaluation. This value can be null.
*
* @return The node-set
of all items selected
* by this XPath expression.
*
* @see #selectNodes
*/
public Object selectSingleNode(Object node) throws JaxenException
{
List results = selectNodes( node );
if ( results.isEmpty() )
{
return null;
}
return results.get( 0 );
}
public String valueOf(Object node) throws JaxenException
{
return stringValueOf( node );
}
public String stringValueOf(Object node) throws JaxenException
{
Context context = getContext( node );
Object result = selectSingleNodeForContext( context );
if ( result == null )
{
return "";
}
return StringFunction.evaluate( result,
context.getNavigator() );
}
/** Retrieve a boolean-value interpretation of this XPath
* expression when evaluated against a given context.
*
*
* The boolean-value of the expression is determined per
* the boolean(..)
core function as defined
* in the XPath specification. This means that an expression
* that selects zero nodes will return false
,
* while an expression that selects one-or-more nodes will
* return true
.
*
*
* @param node The node, nodeset or Context object for evaluation. This value can be null.
*
* @return The boolean-value interpretation of this expression.
*/
public boolean booleanValueOf(Object node) throws JaxenException
{
Context context = getContext( node );
List result = selectNodesForContext( context );
if ( result == null )
return false;
return BooleanFunction.evaluate( result, context.getNavigator() ).booleanValue();
}
/** Retrieve a number-value interpretation of this XPath
* expression when evaluated against a given context.
*
*
* The number-value of the expression is determined per
* the number(..)
core function as defined
* in the XPath specification. This means that if this
* expression selects multiple nodes, the number-value
* of the first node is returned.
*
*
* @param node The node, nodeset or Context object for evaluation. This value can be null.
*
* @return The number-value interpretation of this expression.
*/
public Number numberValueOf(Object node) throws JaxenException
{
Context context = getContext( node );
Object result = selectSingleNodeForContext( context );
if ( result == null )
{
return null;
}
return NumberFunction.evaluate( result,
context.getNavigator() );
}
// Helpers
/** Add a namespace prefix-to-URI mapping for this XPath
* expression.
*
*
* Namespace prefix-to-URI mappings in an XPath are independant
* of those used within any document. Only the mapping explicitly
* added to this XPath will be available for resolving the
* XPath expression.
*
*
*
* This is a convenience method for adding mappings to the
* default {@link NamespaceContext} in place for this XPath.
* If you have installed a specific custom NamespaceContext
,
* then this method will throw a JaxenException
.
*
*
* @param prefix The namespace prefix.
* @param uri The namespace URI.
*
* @throws JaxenException If a NamespaceContext
* used by this XPath has been explicitly installed.
*/
public void addNamespace(String prefix,
String uri) throws JaxenException
{
NamespaceContext nsContext = getNamespaceContext();
if ( nsContext instanceof SimpleNamespaceContext )
{
((SimpleNamespaceContext)nsContext).addNamespace( prefix,
uri );
return;
}
throw new JaxenException("Operation not permitted while using a custom namespace context.");
}
// ------------------------------------------------------------
// ------------------------------------------------------------
// Properties
// ------------------------------------------------------------
// ------------------------------------------------------------
/** Set a NamespaceContext
for use with this
* XPath expression.
*
*
* A NamespaceContext
is responsible for translating
* namespace prefixes within the expression into namespace URIs.
*
*
* @param namespaceContext The NamespaceContext
to
* install for this expression.
*
* @see NamespaceContext
* @see NamespaceContext#translateNamespacePrefixToUri
*/
public void setNamespaceContext(NamespaceContext namespaceContext)
{
getContextSupport().setNamespaceContext(namespaceContext);
}
/** Set a FunctionContext
for use with this XPath
* expression.
*
*
* A FunctionContext
is responsible for resolving
* all function calls used within the expression.
*
*
* @param functionContext The FunctionContext
to
* install for this expression.
*
* @see FunctionContext
* @see FunctionContext#getFunction
*/
public void setFunctionContext(FunctionContext functionContext)
{
getContextSupport().setFunctionContext(functionContext);
}
/** Set a VariableContext
for use with this XPath
* expression.
*
*
* A VariableContext
is responsible for resolving
* all variables referenced within the expression.
*
*
* @param variableContext The VariableContext
to
* install for this expression.
*
* @see VariableContext
* @see VariableContext#getVariableValue
*/
public void setVariableContext(VariableContext variableContext)
{
getContextSupport().setVariableContext(variableContext);
}
/** Retrieve the NamespaceContext
used by this XPath
* expression.
*
*
* A FunctionContext
is responsible for resolving
* all function calls used within the expression.
*
*
*
* If this XPath expression has not previously had a NamespaceContext
* installed, a new default NamespaceContext
will be created,
* installed and returned.
*
*
* @return The NamespaceContext
used by this expression.
*
* @see NamespaceContext
*/
public NamespaceContext getNamespaceContext()
{
NamespaceContext answer = getContextSupport().getNamespaceContext();
if ( answer == null ) {
answer = createNamespaceContext();
getContextSupport().setNamespaceContext( answer );
}
return answer;
}
/** Retrieve the FunctionContext
used by this XPath
* expression.
*
*
* A FunctionContext
is responsible for resolving
* all function calls used within the expression.
*
*
*
* If this XPath expression has not previously had a FunctionContext
* installed, a new default FunctionContext
will be created,
* installed and returned.
*
*
* @return The FunctionContext
used by this expression.
*
* @see FunctionContext
*/
public FunctionContext getFunctionContext()
{
FunctionContext answer = getContextSupport().getFunctionContext();
if ( answer == null ) {
answer = createFunctionContext();
getContextSupport().setFunctionContext( answer );
}
return answer;
}
/** Retrieve the VariableContext
used by this XPath
* expression.
*
*
* A VariableContext
is responsible for resolving
* all variables referenced within the expression.
*
*
*
* If this XPath expression has not previously had a VariableContext
* installed, a new default VariableContext
will be created,
* installed and returned.
*
*
* @return The VariableContext
used by this expression.
*
* @see VariableContext
*/
public VariableContext getVariableContext()
{
VariableContext answer = getContextSupport().getVariableContext();
if ( answer == null ) {
answer = createVariableContext();
getContextSupport().setVariableContext( answer );
}
return answer;
}
/** Retrieve the root expression of the internal
* compiled form of this XPath expression.
*
*
* Internally, Jaxen maintains a form of Abstract Syntax
* Tree (AST) to represent the structure of the XPath expression.
* This is normally not required during normal consumer-grade
* usage of Jaxen. This method is provided for hard-core users
* who wish to manipulate or inspect a tree-based version of
* the expression.
*
*
* @return The root of the AST of this expression.
*/
public Expr getRootExpr()
{
return xpath.getRootExpr();
}
/** Return the normalized string of this XPath expression.
*
*
* During parsing, the XPath expression is normalized,
* removing abbreviations and other convenience notation.
* This method returns the fully normalized representation
* of the original expression.
*
*
* @return The normalized XPath expression string.
*/
public String toString()
{
return this.xpath.getText();
}
/** Returns the string version of this xpath.
*
* @return The normalized XPath expression string.
*
* @see #toString
*/
public String debug()
{
return this.xpath.toString();
}
// ------------------------------------------------------------
// ------------------------------------------------------------
// Implementation methods
// ------------------------------------------------------------
// ------------------------------------------------------------
/** Create a {@link Context} wrapper for the provided
* implementation-specific object.
*
* @param node The implementation-specific object
* to be used as the context.
*
* @return A Context
wrapper around the object.
*/
protected Context getContext(Object node)
{
if ( node instanceof Context )
{
return (Context) node;
}
Context fullContext = new Context( getContextSupport() );
if ( node instanceof List )
{
fullContext.setNodeSet( (List) node );
}
else
{
List list = new ArrayList( 1 );
list.add( node );
fullContext.setNodeSet( list );
}
return fullContext;
}
/** Retrieve the {@link ContextSupport} aggregation of
* NamespaceContext
, FunctionContext
,
* VariableContext
, and {@link Navigator}.
*
* @return Aggregate ContextSupport
for this
* XPath expression.
*/
protected ContextSupport getContextSupport()
{
if ( support == null )
{
support = new ContextSupport(
createNamespaceContext(),
createFunctionContext(),
createVariableContext(),
getNavigator()
);
}
return support;
}
/** Retrieve the XML object-model-specific {@link Navigator}
* for us in evaluating this XPath expression.
*
* @return The implementation-specific Navigator
.
*/
public Navigator getNavigator()
{
return navigator;
}
// ------------------------------------------------------------
// ------------------------------------------------------------
// Factory methods for default contexts
// ------------------------------------------------------------
// ------------------------------------------------------------
/** Create a default FunctionContext
.
*
* @return The default FunctionContext
.
*/
protected FunctionContext createFunctionContext()
{
return XPathFunctionContext.getInstance();
}
/** Create a default NamespaceContext
.
*
* @return A default NamespaceContext
instance.
*/
protected NamespaceContext createNamespaceContext()
{
return new SimpleNamespaceContext();
}
/** Create a default VariableContext
.
*
* @return A default VariableContext
instance.
*/
protected VariableContext createVariableContext()
{
return new SimpleVariableContext();
}
/** Select all nodes that are selectable by this XPath
* expression on the given Context object.
* If multiple nodes match, multiple nodes
* will be returned.
*
*
* NOTE: In most cases, nodes will be returned
* in document-order, as defined by the XML Canonicalization
* specification. The exception occurs when using XPath
* expressions involving the union
operator
* (denoted with the pipe '|' character).
*
*
* @param context is the Context which gets evaluated.
*
* @return The node-set
of all items selected
* by this XPath expression.
*
*/
protected List selectNodesForContext(Context context) throws JaxenException
{
return this.xpath.asList( context );
}
/** Select only the first node that is selectable by this XPath
* expression. If multiple nodes match, only one node will be
* returned.
*
* NOTE: In most cases, the selected node will be the first
* selectable node in document-order, as defined by the XML Canonicalization
* specification. The exception occurs when using XPath
* expressions involving the union
operator
* (denoted with the pipe '|' character).
*
*
* @param context is the Context which gets evaluated.
*
* @return The node-set
of all items selected
* by this XPath expression.
*
* @see #selectNodesForContext
*/
protected Object selectSingleNodeForContext(Context context) throws JaxenException
{
List results = selectNodesForContext( context );
if ( results.isEmpty() )
{
return null;
}
return results.get( 0 );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/Context.java 100644 0 0 14262 10525225063 25510 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/Context.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: Context.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
/** Wrapper around implementation-specific objects used
* as the context of an expression evaluation.
*
*
* NOTE: This class is not typically used directly,
* but is exposed for writers of implementation-specific
* XPath packages.
*
*
*
* The Context
bundles utilities together
* for evaluation of the expression. It wraps the provided
* objects for ease-of-passage through the expression AST.
*
*
* @see ContextSupport
* @see BaseXPath
* @see org.jaxen.dom4j.Dom4jXPath XPath for dom4j
* @see org.jaxen.jdom.JDOMXPath XPath for JDOM
* @see org.jaxen.dom.DOMXPath XPath for W3C DOM
* @see org.jaxen.exml.ElectricXPath XPath for Electric XML
*
* @author bob mcwhirter
*/
public class Context implements Serializable
{
private ContextSupport contextSupport;
private List nodeSet;
private int size;
private int position;
public Context(ContextSupport contextSupport)
{
this.contextSupport = contextSupport;
this.nodeSet = new ArrayList(0);
}
public List getNodeSet()
{
return this.nodeSet;
}
public void setNodeSet(List nodeSet)
{
this.nodeSet = nodeSet;
}
public ContextSupport getContextSupport()
{
return this.contextSupport;
}
public void setContextSupport(ContextSupport contextSupport)
{
this.contextSupport = contextSupport;
}
public Navigator getNavigator()
{
return getContextSupport().getNavigator();
}
public String translateNamespacePrefixToUri(String prefix)
{
return getContextSupport().translateNamespacePrefixToUri( prefix );
}
public Object getVariableValue( String namespaceURI,
String prefix,
String localName )
throws UnresolvableException
{
return getContextSupport().getVariableValue( namespaceURI,
prefix,
localName );
}
public Function getFunction( String namespaceURI,
String prefix,
String localName )
throws UnresolvableException
{
return getContextSupport().getFunction( namespaceURI,
prefix,
localName );
}
public void setSize(int size)
{
this.size = size;
}
public void setPosition(int position)
{
this.position = position;
}
public int getSize()
{
return this.size;
}
public int getPosition()
{
return this.position;
}
public Context duplicate()
{
Context dupe = new Context( getContextSupport() );
List thisNodeSet = getNodeSet();
if ( thisNodeSet != null )
{
List dupeNodeSet = new ArrayList( thisNodeSet.size() );
dupeNodeSet.addAll( thisNodeSet );
dupe.setNodeSet( dupeNodeSet );
}
return dupe;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/ContextSupport.java 100644 0 0 15016 10525225063 27103 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/ContextSupport.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: ContextSupport.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
import java.io.Serializable;
/** Supporting context information for resolving
* namespace prefixess, functions, and variables.
*
*
* NOTE: This class is not typically used directly,
* but is exposed for writers of implementation-specific
* XPath packages.
*
*
* @see org.jaxen.dom4j.Dom4jXPath XPath for dom4j
* @see org.jaxen.jdom.JDOMXPath XPath for JDOM
* @see org.jaxen.dom.DOMXPath XPath for W3C DOM
* @see org.jaxen.exml.ElectricXPath XPath for Electric XML
*
* @author bob mcwhirter (bob@werken.com)
*/
public class ContextSupport implements Serializable
{
private transient FunctionContext functionContext;
private NamespaceContext namespaceContext;
private VariableContext variableContext;
private Navigator navigator;
/** Construct an empty ContextSupport
.
*/
public ContextSupport()
{
// intentionally left blank
}
/** Construct.
*
* @param namespaceContext The NamespaceContext.
* @param functionContext The FunctionContext.
* @param variableContext The VariableContext.
*/
public ContextSupport(NamespaceContext namespaceContext,
FunctionContext functionContext,
VariableContext variableContext,
Navigator navigator)
{
setNamespaceContext( namespaceContext );
setFunctionContext( functionContext );
setVariableContext( variableContext );
this.navigator = navigator;
}
public void setNamespaceContext(NamespaceContext namespaceContext)
{
this.namespaceContext = namespaceContext;
}
public void setFunctionContext(FunctionContext functionContext)
{
this.functionContext = functionContext;
}
public void setVariableContext(VariableContext variableContext)
{
this.variableContext = variableContext;
}
public NamespaceContext getNamespaceContext()
{
return this.namespaceContext;
}
public FunctionContext getFunctionContext()
{
return this.functionContext;
}
public VariableContext getVariableContext()
{
return this.variableContext;
}
public Navigator getNavigator()
{
return this.navigator;
}
public String translateNamespacePrefixToUri(String prefix)
{
NamespaceContext context = getNamespaceContext();
if ( context != null )
{
return context.translateNamespacePrefixToUri( prefix );
}
return null;
}
public Object getVariableValue( String namespaceURI,
String prefix,
String localName )
throws UnresolvableException
{
VariableContext context = getVariableContext();
if ( context != null )
{
return context.getVariableValue( namespaceURI, prefix, localName );
}
else
{
throw new UnresolvableException( "No variable context installed" );
}
}
public Function getFunction( String namespaceURI,
String prefix,
String localName )
throws UnresolvableException
{
FunctionContext context = getFunctionContext();
if ( context != null )
{
return context.getFunction( namespaceURI, prefix, localName );
}
else
{
throw new UnresolvableException( "No function context installed" );
}
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/DefaultNavigator.java 100644 0 0 22567 10525225063 27332 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/DefaultNavigator.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultNavigator.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
import org.xmlpull.v1.builder.xpath.jaxen.pattern.Pattern;
import org.xmlpull.v1.builder.xpath.jaxen.util.SelfAxisIterator;
import org.xmlpull.v1.builder.xpath.jaxen.util.DescendantOrSelfAxisIterator;
import org.xmlpull.v1.builder.xpath.jaxen.util.AncestorOrSelfAxisIterator;
import org.xmlpull.v1.builder.xpath.jaxen.util.AncestorAxisIterator;
import org.xmlpull.v1.builder.xpath.jaxen.util.DescendantAxisIterator;
import org.xmlpull.v1.builder.xpath.jaxen.util.PrecedingAxisIterator;
import org.xmlpull.v1.builder.xpath.jaxen.util.FollowingAxisIterator;
import org.xmlpull.v1.builder.xpath.jaxen.util.PrecedingSiblingAxisIterator;
import org.xmlpull.v1.builder.xpath.jaxen.util.FollowingSiblingAxisIterator;
import java.util.Iterator;
/** Default implementation of {@link Navigator}.
*
*
* This implementation is an abstract class, since
* some required operations cannot be implemented without
* additional knowledge of the object model.
*
*
*
* When possible, default method implementations build
* upon each other, to reduce the number of methods required
* to be implemented for each object model. All methods,
* of course, may be overridden, to provide more-efficient
* implementations.
*
*
* @author bob mcwhirter (bob@werken.com)
* @author Erwin Bolwidt (ejb@klomp.org)
*/
public abstract class DefaultNavigator implements Navigator
{
/** Throws UnsupportedAxisException
*/
public Iterator getChildAxisIterator(Object contextNode) throws UnsupportedAxisException
{
throw new UnsupportedAxisException("child");
}
public Iterator getDescendantAxisIterator(Object contextNode) throws UnsupportedAxisException
{
return new DescendantAxisIterator( contextNode,
this );
}
/** Throws UnsupportedAxisException
*/
public Iterator getParentAxisIterator(Object contextNode) throws UnsupportedAxisException
{
throw new UnsupportedAxisException("parent");
}
public Iterator getAncestorAxisIterator(Object contextNode) throws UnsupportedAxisException
{
return new AncestorAxisIterator( contextNode,
this );
}
/** Throws UnsupportedAxisException
*/
public Iterator getFollowingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException
{
return new FollowingSiblingAxisIterator( contextNode,
this );
}
/** Throws UnsupportedAxisException
*/
public Iterator getPrecedingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException
{
return new PrecedingSiblingAxisIterator( contextNode,
this );
}
/** Throws UnsupportedAxisException
*/
public Iterator getFollowingAxisIterator(Object contextNode) throws UnsupportedAxisException
{
return new FollowingAxisIterator( contextNode,
this );
// throw new UnsupportedAxisException("following");
}
/** Throws UnsupportedAxisException
*/
public Iterator getPrecedingAxisIterator(Object contextNode) throws UnsupportedAxisException
{
return new PrecedingAxisIterator( contextNode,
this );
// throw new UnsupportedAxisException("preceding");
}
/** Throws UnsupportedAxisException
*/
public Iterator getAttributeAxisIterator(Object contextNode) throws UnsupportedAxisException
{
throw new UnsupportedAxisException("attribute");
}
/** Throws UnsupportedAxisException
*/
public Iterator getNamespaceAxisIterator(Object contextNode) throws UnsupportedAxisException
{
throw new UnsupportedAxisException("namespace");
}
public Iterator getSelfAxisIterator(Object contextNode) throws UnsupportedAxisException
{
return new SelfAxisIterator( contextNode );
}
public Iterator getDescendantOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException
{
return new DescendantOrSelfAxisIterator( contextNode,
this );
}
public Iterator getAncestorOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException
{
return new AncestorOrSelfAxisIterator( contextNode,
this );
}
public Object getDocumentNode(Object contextNode)
{
return null;
}
public String translateNamespacePrefixToUri(String prefix, Object element)
{
return null;
}
public String getProcessingInstructionTarget(Object obj)
{
return null;
}
public String getProcessingInstructionData(Object obj)
{
return null;
}
public short getNodeType(Object node)
{
if ( isElement(node) )
{
return Pattern.ELEMENT_NODE;
}
else if ( isAttribute(node) )
{
return Pattern.ATTRIBUTE_NODE;
}
else if ( isText(node) )
{
return Pattern.TEXT_NODE;
}
else if ( isComment(node) )
{
return Pattern.COMMENT_NODE;
}
else if ( isDocument(node) )
{
return Pattern.DOCUMENT_NODE;
}
else if ( isProcessingInstruction(node) )
{
return Pattern.DOCUMENT_NODE;
}
else {
return Pattern.UNKNOWN_NODE;
}
}
public Object getParentNode(Object contextNode) throws UnsupportedAxisException
{
Iterator iter = getParentAxisIterator( contextNode );
if ( iter != null && iter.hasNext() )
{
return iter.next();
}
return null;
}
public Object getDocument(String url) throws FunctionCallException
{
return null;
}
/**
* Default implementation that can not find elements. Override in subclass
* if subclass does know about attribute types.
*
* @param contextNode a node from the document in which to look for the
* id
* @param elementId id to look for
*
* @return null
*/
public Object getElementById(Object object, String elementId)
{
return null;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/Function.java 100644 0 0 7424 10525225063 25633 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/Function.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: Function.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
import java.util.List;
/** Interface for the extensible function framework.
*
*
* NOTE: This class is not typically used directly,
* but is exposed for writers of extended XPath packages.
*
*
*
* Implementations of Function
are functors
* which are used to evaluate a function-call within an
* XPath expression.
*
*
* @see FunctionContext
*
* @author bob mcwhirter
*/
public interface Function
{
/** Call this function.
*
* @param context The context at the point in the
* expression when the function is called.
* @param args List of arguments provided during
* the call of the function.
*/
Object call(Context context,
List args) throws FunctionCallException;
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/FunctionCallException.java 100644 0 0 12012 10525225063 30313 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/FunctionCallException.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: FunctionCallException.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
import java.io.PrintStream;
import java.io.PrintWriter;
/** FunctionCallException
is thrown if an exception
* occurs during the evaluation of a function.
* This exception may include a root exception, such as if the
* real exception was failure to load an XML document via the
* document() function call.
*
* @author bob mcwhirter (bob @ werken.com)
* @author James Strachan
*/
public class FunctionCallException extends JaxenException
{
private Throwable nestedException;
public FunctionCallException(String message) {
super( message );
}
public FunctionCallException(Throwable nestedException) {
super( nestedException.getMessage() );
this.nestedException = nestedException;
}
public FunctionCallException(String message, Exception nestedException) {
super( message );
this.nestedException = nestedException;
}
public void printStackTrace( PrintStream s ) {
super.printStackTrace();
if ( nestedException != null )
{
s.println( "Root cause:" );
nestedException.printStackTrace( s );
}
}
public void printStackTrace( PrintWriter w ) {
super.printStackTrace();
if ( nestedException != null )
{
w.println( "Root cause:" );
nestedException.printStackTrace( w );
}
}
public void printStackTrace() {
super.printStackTrace();
if ( nestedException != null )
{
System.out.println( "Root cause:" );
nestedException.printStackTrace();
}
}
public Throwable fillInStackTrace() {
if ( nestedException == null ) {
return super.fillInStackTrace();
} else {
return nestedException.fillInStackTrace();
}
}
// Properties
//-------------------------------------------------------------------------
public Throwable getNestedException() {
return nestedException;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/FunctionContext.java 100644 0 0 11414 10525225063 27212 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/FunctionContext.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: FunctionContext.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
/** Implemented by classes that know how to resolve xpath function names and
* namespaces to implementations of these functions.
*
*
* By using a custom FunctionContext
, new or different
* functions may be installed and available to XPath expression writers.
*
*
* @see XPathFunctionContext
*
* @author bob mcwhirter
*/
public interface FunctionContext
{
/** An implementation should return a Function
implementation object
* based on the namespace uri and local name of the function-call
* expression.
*
*
* It must not use the prefix parameter to select an implementation,
* because a prefix could be bound to any namespace; the prefix parameter
* could be used in debugging output or other generated information.
* The prefix may otherwise be completely ignored.
*
*
* @param namespaceURI the namespace uri to which the prefix parameter
* is bound in the xpath expression. If the function
* call expression had no prefix, the namespace uri
* is null
.
* @param prefix the prefix that was used in the function call
* expression.
* @param localName the local name of the function-call expression;
* if there is no prefix, then this is the whole
* name of the function.
*
* @return a Function implementation object.
* @throws UnresolvableException when the function cannot be resolved.
*/
Function getFunction( String namespaceURI,
String prefix,
String localName ) throws UnresolvableException;
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/JaxenException.java 100644 0 0 7642 10525225063 26774 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/JaxenException.java,v 1.2 2004/10/01 08:33:20 aslom Exp $
* $Revision: 1.2 $
* $Date: 2004/10/01 08:33:20 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: JaxenException.java,v 1.2 2004/10/01 08:33:20 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
import org.xmlpull.v1.builder.xpath.saxpath.SAXPathException;
/** Generic Jaxen exception.
*
*
* This is the root of all Jaxen exceptions.
* It may wrap other exceptions. See {@link #getRootCause}.
*
* @author bob mcwhirter
*/
public class JaxenException extends SAXPathException
{
/** Root cause, if any. */
//private Throwable rootCause;
/** Construct with a message.
*
* @param message The error message.
*/
public JaxenException(String message)
{
super( message );
}
/** Construct with a root cause.
*
* @param rootCause Root cause of the error.
*/
public JaxenException(Throwable rootCause)
{
super( "wrapped exception" );
this.detail = rootCause;
}
/** Retrieve the root cause, if any.
*
* @return Root cause of the error.
*/
public Throwable getRootCause()
{
return this.detail;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/JaxenHandler.java 100644 0 0 47311 10525225063 26430 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/JaxenHandler.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: JaxenHandler.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
import org.xmlpull.v1.builder.xpath.jaxen.expr.XPathFactory;
import org.xmlpull.v1.builder.xpath.jaxen.expr.DefaultXPathFactory;
import org.xmlpull.v1.builder.xpath.jaxen.expr.XPathExpr;
import org.xmlpull.v1.builder.xpath.jaxen.expr.LocationPath;
import org.xmlpull.v1.builder.xpath.jaxen.expr.FilterExpr;
import org.xmlpull.v1.builder.xpath.jaxen.expr.Expr;
import org.xmlpull.v1.builder.xpath.jaxen.expr.Step;
import org.xmlpull.v1.builder.xpath.jaxen.expr.Predicate;
import org.xmlpull.v1.builder.xpath.jaxen.expr.Predicated;
import org.xmlpull.v1.builder.xpath.jaxen.expr.FunctionCallExpr;
import org.xmlpull.v1.builder.xpath.saxpath.XPathHandler;
import org.xmlpull.v1.builder.xpath.saxpath.Operator;
import java.util.LinkedList;
import java.util.Iterator;
/** SAXPath XPathHandler
implementation capable
* of building Jaxen expression trees which can walk various
* different object models.
*
* @author bob mcwhirter (bob@werken.com)
*/
public class JaxenHandler implements XPathHandler
{
private XPathFactory xpathFactory;
private XPathExpr xpath;
protected boolean simplified;
protected LinkedList stack;
/** Construct.
*/
public JaxenHandler()
{
this.stack = new LinkedList();
this.xpathFactory = new DefaultXPathFactory();
}
/** Set the Jaxen XPathFactory
to use
* during the parse to construct the XPath expression tree.
*
* @param xpathFactory The factory to use during the parse.
*/
public void setXPathFactory(XPathFactory xpathFactory)
{
this.xpathFactory = xpathFactory;
}
/** Retrieve the Jaxen XPathFactory
used
* during the parse to construct the XPath expression tree.
*
* @return The XPathFactory
used during the parse.
*/
public XPathFactory getXPathFactory()
{
return this.xpathFactory;
}
/** Retrieve the simplified Jaxen XPath expression tree.
*
*
* This method is only valid once XPathReader.parse(...)
* successfully returned.
*
*
* @return The XPath expression tree.
*/
public XPathExpr getXPathExpr()
{
return getXPathExpr( true );
}
/** Retrieve the Jaxen XPath expression tree, optionally
* simplified.
*
*
* This method is only valid once XPathReader.parse(...)
* successfully returned.
*
*
* @return The XPath expression tree.
*/
public XPathExpr getXPathExpr(boolean shouldSimplify)
{
if ( shouldSimplify && ! this.simplified )
{
//System.err.println("simplifyin....");
this.xpath.simplify();
this.simplified = true;
}
return this.xpath;
}
public void startXPath() throws JaxenException
{
//System.err.println("startXPath()");
this.simplified = false;
pushFrame();
}
public void endXPath() throws JaxenException
{
//System.err.println("endXPath()");
this.xpath = getXPathFactory().createXPath( (Expr) pop() );
popFrame();
}
public void startPathExpr() throws JaxenException
{
//System.err.println("startPathExpr()");
pushFrame();
}
public void endPathExpr() throws JaxenException
{
//System.err.println("endPathExpr()");
// PathExpr ::= LocationPath
// | FilterExpr
// | FilterExpr / RelativeLocationPath
// | FilterExpr // RelativeLocationPath
//
// If the current stack-frame has two items, it's a
// FilterExpr and a LocationPath (of some flavor).
//
// If the current stack-frame has one item, it's simply
// a FilterExpr, and more than like boils down to a
// primary expr of some flavor. But that's for another
// method...
FilterExpr filterExpr;
LocationPath locationPath;
Object popped;
//System.err.println("stackSize() == " + stackSize() );
if ( stackSize() == 2 )
{
locationPath = (LocationPath) pop();
filterExpr = (FilterExpr) pop();
}
else
{
popped = pop();
if ( popped instanceof LocationPath )
{
locationPath = (LocationPath) popped;
filterExpr = null;
}
else
{
locationPath = null;
filterExpr = (FilterExpr) popped;
}
}
popFrame();
push( getXPathFactory().createPathExpr( filterExpr,
locationPath ) );
}
public void startAbsoluteLocationPath() throws JaxenException
{
//System.err.println("startAbsoluteLocationPath()");
pushFrame();
push( getXPathFactory().createAbsoluteLocationPath() );
}
public void endAbsoluteLocationPath() throws JaxenException
{
//System.err.println("endAbsoluteLocationPath()");
endLocationPath();
}
public void startRelativeLocationPath() throws JaxenException
{
//System.err.println("startRelativeLocationPath()");
pushFrame();
push( getXPathFactory().createRelativeLocationPath() );
}
public void endRelativeLocationPath() throws JaxenException
{
//System.err.println("endRelativeLocationPath()");
endLocationPath();
}
protected void endLocationPath() throws JaxenException
{
LocationPath path = (LocationPath) peekFrame().removeFirst();
addSteps( path,
popFrame().iterator() );
push( path );
}
protected void addSteps(LocationPath locationPath,
Iterator stepIter)
{
while ( stepIter.hasNext() )
{
locationPath.addStep( (Step) stepIter.next() );
}
}
public void startNameStep(int axis,
String prefix,
String localName) throws JaxenException
{
//System.err.println("startNameStep(" + axis + ", " + prefix + ", " + localName + ")");
pushFrame();
push( getXPathFactory().createNameStep( axis,
prefix,
localName ) );
}
public void endNameStep() throws JaxenException
{
//System.err.println("endNameStep()");
endStep();
}
public void startTextNodeStep(int axis) throws JaxenException
{
//System.err.println("startTextNodeStep()");
pushFrame();
push( getXPathFactory().createTextNodeStep( axis ) );
}
public void endTextNodeStep() throws JaxenException
{
//System.err.println("endTextNodeStep()");
endStep();
}
public void startCommentNodeStep(int axis) throws JaxenException
{
//System.err.println("startCommentNodeStep()");
pushFrame();
push( getXPathFactory().createCommentNodeStep( axis ) );
}
public void endCommentNodeStep() throws JaxenException
{
//System.err.println("endCommentNodeStep()");
endStep();
}
public void startAllNodeStep(int axis) throws JaxenException
{
//System.err.println("startAllNodeStep()");
pushFrame();
push( getXPathFactory().createAllNodeStep( axis ) );
}
public void endAllNodeStep() throws JaxenException
{
//System.err.println("endAllNodeStep()");
endStep();
}
public void startProcessingInstructionNodeStep(int axis,
String name) throws JaxenException
{
//System.err.println("startProcessingInstructionStep()");
pushFrame();
push( getXPathFactory().createProcessingInstructionNodeStep( axis,
name ) );
}
public void endProcessingInstructionNodeStep() throws JaxenException
{
//System.err.println("endProcessingInstructionStep()");
endStep();
}
protected void endStep()
{
Step step = (Step) peekFrame().removeFirst();
addPredicates( step,
popFrame().iterator() );
push( step );
}
public void startPredicate() throws JaxenException
{
//System.err.println("startPredicate()");
pushFrame();
}
public void endPredicate() throws JaxenException
{
//System.err.println("endPredicate()");
Predicate predicate = getXPathFactory().createPredicate( (Expr) pop() );
popFrame();
push( predicate );
}
public void startFilterExpr() throws JaxenException
{
//System.err.println("startFilterExpr()");
pushFrame();
}
public void endFilterExpr() throws JaxenException
{
//System.err.println("endFilterExpr()");
Expr expr = (Expr) peekFrame().removeFirst();
FilterExpr filter = getXPathFactory().createFilterExpr( expr );
Iterator predIter = popFrame().iterator();
addPredicates( filter,
predIter );
push( filter );
}
protected void addPredicates(Predicated obj,
Iterator predIter)
{
while ( predIter.hasNext() )
{
obj.addPredicate( (Predicate) predIter.next() );
}
}
protected void returnExpr()
{
Expr expr = (Expr) pop();
popFrame();
push( expr );
}
public void startOrExpr() throws JaxenException
{
//System.err.println("startOrExpr()");
}
public void endOrExpr(boolean create) throws JaxenException
{
//System.err.println("endOrExpr()");
if ( create )
{
//System.err.println("makeOrExpr");
Expr rhs = (Expr) pop();
Expr lhs = (Expr) pop();
push( getXPathFactory().createOrExpr( lhs,
rhs ) );
}
}
public void startAndExpr() throws JaxenException
{
//System.err.println("startAndExpr()");
}
public void endAndExpr(boolean create) throws JaxenException
{
//System.err.println("endAndExpr()");
if ( create )
{
//System.err.println("makeAndExpr");
Expr rhs = (Expr) pop();
Expr lhs = (Expr) pop();
push( getXPathFactory().createAndExpr( lhs,
rhs ) );
}
}
public void startEqualityExpr() throws JaxenException
{
//System.err.println("startEqualityExpr()");
}
public void endEqualityExpr(int operator) throws JaxenException
{
//System.err.println("endEqualityExpr(" + operator + ")");
if ( operator != Operator.NO_OP )
{
//System.err.println("makeEqualityExpr");
Expr rhs = (Expr) pop();
Expr lhs = (Expr) pop();
push( getXPathFactory().createEqualityExpr( lhs,
rhs,
operator ) );
}
}
public void startRelationalExpr() throws JaxenException
{
//System.err.println("startRelationalExpr()");
}
public void endRelationalExpr(int operator) throws JaxenException
{
//System.err.println("endRelationalExpr(" + operator + ")");
if ( operator != Operator.NO_OP )
{
//System.err.println("makeRelationalExpr");
Expr rhs = (Expr) pop();
Expr lhs = (Expr) pop();
push( getXPathFactory().createRelationalExpr( lhs,
rhs,
operator ) );
}
}
public void startAdditiveExpr() throws JaxenException
{
//System.err.println("startAdditiveExpr()");
}
public void endAdditiveExpr(int operator) throws JaxenException
{
//System.err.println("endAdditiveExpr(" + operator + ")");
if ( operator != Operator.NO_OP )
{
//System.err.println("makeAdditiveExpr");
Expr rhs = (Expr) pop();
Expr lhs = (Expr) pop();
push( getXPathFactory().createAdditiveExpr( lhs,
rhs,
operator ) );
}
}
public void startMultiplicativeExpr() throws JaxenException
{
//System.err.println("startMultiplicativeExpr()");
}
public void endMultiplicativeExpr(int operator) throws JaxenException
{
//System.err.println("endMultiplicativeExpr(" + operator + ")");
if ( operator != Operator.NO_OP )
{
//System.err.println("makeMulitiplicativeExpr");
Expr rhs = (Expr) pop();
Expr lhs = (Expr) pop();
push( getXPathFactory().createMultiplicativeExpr( lhs,
rhs,
operator ) );
}
}
public void startUnaryExpr() throws JaxenException
{
//System.err.println("startUnaryExpr()");
}
public void endUnaryExpr(int operator) throws JaxenException
{
//System.err.println("endUnaryExpr(" + operator + ")");
if ( operator != Operator.NO_OP )
{
push( getXPathFactory().createUnaryExpr( (Expr) pop(),
operator ) );
}
}
public void startUnionExpr() throws JaxenException
{
//System.err.println("startUnionExpr()");
}
public void endUnionExpr(boolean create) throws JaxenException
{
//System.err.println("endUnionExpr()");
if ( create )
{
//System.err.println("makeUnionExpr");
Expr rhs = (Expr) pop();
Expr lhs = (Expr) pop();
push( getXPathFactory().createUnionExpr( lhs,
rhs ) );
}
}
public void number(int number) throws JaxenException
{
//System.err.println("number(" + number + ")");
push( getXPathFactory().createNumberExpr( number ) );
}
public void number(double number) throws JaxenException
{
//System.err.println("number(" + number + ")");
push( getXPathFactory().createNumberExpr( number ) );
}
public void literal(String literal) throws JaxenException
{
push( getXPathFactory().createLiteralExpr( literal ) );
}
public void variableReference(String prefix,
String variableName) throws JaxenException
{
push( getXPathFactory().createVariableReferenceExpr( prefix,
variableName ) );
}
public void startFunction(String prefix,
String functionName) throws JaxenException
{
pushFrame();
push( getXPathFactory().createFunctionCallExpr( prefix,
functionName ) );
}
public void endFunction() throws JaxenException
{
FunctionCallExpr function = (FunctionCallExpr) peekFrame().removeFirst();
addParameters( function,
popFrame().iterator() );
push( function );
}
protected void addParameters(FunctionCallExpr function,
Iterator paramIter)
{
while ( paramIter.hasNext() )
{
function.addParameter( (Expr) paramIter.next() );
}
}
protected int stackSize()
{
return peekFrame().size();
}
protected void push(Object obj)
{
peekFrame().addLast( obj );
//System.err.println("push(" + this.stack.size() + "/" + peekFrame().size() + ") == " + obj );
}
protected Object pop()
{
//System.err.println("pop(" + this.stack.size() + "/" + peekFrame().size() + ")");
return peekFrame().removeLast();
}
protected boolean canPop()
{
return ( peekFrame().size() > 0 );
}
protected void pushFrame()
{
this.stack.addLast( new LinkedList() );
//System.err.println("pushFrame(" + this.stack.size() + ")");
}
protected LinkedList popFrame()
{
//System.err.println("popFrame(" + this.stack.size() + ")");
return (LinkedList) this.stack.removeLast();
}
protected LinkedList peekFrame()
{
return (LinkedList) this.stack.getLast();
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/NamespaceContext.java 100644 0 0 10310 10525225063 27313 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/NamespaceContext.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: NamespaceContext.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
/** Resolves namespace prefixes to namespace URIs.
*
*
* The prefixes used within an XPath expression are
* independant of those used within any target document.
* When evaluating an XPath against a document, only
* the resolved namespace URIs are compared, not their
* prefixes.
*
*
*
* A NamespaceContext
is responsible for
* translating prefixes as they appear in XPath expressions
* into URIs for comparison. A document's prefixes are
* resolved internal to the document based upon its own
* namespace nodes.
*
*
* @see BaseXPath
* @see Navigator#getElementNamespaceUri
* @see Navigator#getAttributeNamespaceUri
*
* @author bob mcwhirter
*/
public interface NamespaceContext
{
/** Translate the provided namespace prefix into
* the matching bound namespace URI.
*
*
* In XPath, there is no such thing as a 'default namespace'.
* The empty prefix always resolves to the empty
* namespace URI.
*
*
* @param prefix The namespace prefix to resolve.
*
* @return The namespace URI matching the prefix.
*/
String translateNamespacePrefixToUri(String prefix);
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/Navigator.java 100644 0 0 45512 10525225063 26020 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/Navigator.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: Navigator.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
import java.io.Serializable;
import java.util.Iterator;
import org.xmlpull.v1.builder.xpath.saxpath.SAXPathException;
/** Interface for navigating around an arbitrary object
* model, using xpath semantics.
*
*
* There is a method to obtain a java.util.Iterator
,
* for each axis specified by XPath. If the target object model
* does not support the semantics of a particular axis, an
* {@link UnsupportedAxisException} is to be thrown.
*
*
* @author bob mcwhirter (bob@werken.com)
* @author James Strachan
*/
public interface Navigator extends Serializable
{
// ------------------------------------------------------------
// ------------------------------------------------------------
// Axis Iterators
// ------------------------------------------------------------
// ------------------------------------------------------------
/** Retrieve an Iterator
matching the child
* xpath axis.
*
* @param contextNode The origin context node.
*
* @return An Iterator capable of traversing the axis.
*
* @throws UnsupportedAxisException is the semantics of this axis are
* not supported by this object model.
*/
Iterator getChildAxisIterator(Object contextNode) throws UnsupportedAxisException;
/** Retrieve an Iterator
matching the descendant
* xpath axis.
*
* @param contextNode The origin context node.
*
* @return An Iterator capable of traversing the axis.
*
* @throws UnsupportedAxisException is the semantics of this axis are
* not supported by this object model.
*/
Iterator getDescendantAxisIterator(Object contextNode) throws UnsupportedAxisException;
/** Retrieve an Iterator
matching the parent
xpath axis.
*
* @param contextNode The origin context node.
*
* @return An Iterator capable of traversing the axis.
*
* @throws UnsupportedAxisException is the semantics of this axis are
* not supported by this object model.
*/
Iterator getParentAxisIterator(Object contextNode) throws UnsupportedAxisException;
/** Retrieve an Iterator
matching the ancestor
* xpath axis.
*
* @param contextNode The origin context node.
*
* @return An Iterator capable of traversing the axis.
*
* @throws UnsupportedAxisException is the semantics of this axis are
* not supported by this object model.
*/
Iterator getAncestorAxisIterator(Object contextNode) throws UnsupportedAxisException;
/** Retrieve an Iterator
matching the
* following-sibling
xpath axis.
*
* @param contextNode The origin context node.
*
* @return An Iterator capable of traversing the axis.
*
* @throws UnsupportedAxisException is the semantics of this axis are
* not supported by this object model.
*/
Iterator getFollowingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException;
/** Retrieve an Iterator
matching the
* preceding-sibling
xpath axis.
*
* @param contextNode The origin context node.
*
* @return An Iterator capable of traversing the axis.
*
* @throws UnsupportedAxisException is the semantics of this axis are
* not supported by this object model.
*/
Iterator getPrecedingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException;
/** Retrieve an Iterator
matching the following
* xpath axis.
*
* @param contextNode The origin context node.
*
* @return An Iterator capable of traversing the axis.
*
* @throws UnsupportedAxisException is the semantics of this axis are
* not supported by this object model.
*/
Iterator getFollowingAxisIterator(Object contextNode) throws UnsupportedAxisException;
/** Retrieve an Iterator
matching the preceding
xpath axis.
*
* @param contextNode The origin context node.
*
* @return An Iterator capable of traversing the axis.
*
* @throws UnsupportedAxisException is the semantics of this axis are
* not supported by this object model.
*/
Iterator getPrecedingAxisIterator(Object contextNode) throws UnsupportedAxisException;
/** Retrieve an Iterator
matching the attribute
* xpath axis.
*
* @param contextNode The origin context node.
*
* @return An Iterator capable of traversing the axis.
*
* @throws UnsupportedAxisException is the semantics of this axis are
* not supported by this object model.
*/
Iterator getAttributeAxisIterator(Object contextNode) throws UnsupportedAxisException;
/** Retrieve an Iterator
matching the namespace
* xpath axis.
*
* @param contextNode The origin context node.
*
* @return An Iterator capable of traversing the axis.
*
* @throws UnsupportedAxisException is the semantics of this axis are
* not supported by this object model.
*/
Iterator getNamespaceAxisIterator(Object contextNode) throws UnsupportedAxisException;
/** Retrieve an Iterator
matching the self
xpath
* axis.
*
* @param contextNode The origin context node.
*
* @return An Iterator capable of traversing the axis.
*
* @throws UnsupportedAxisException is the semantics of this axis are
* not supported by this object model.
*/
Iterator getSelfAxisIterator(Object contextNode) throws UnsupportedAxisException;
/** Retrieve an Iterator
matching the
* descendant-or-self
xpath axis.
*
* @param contextNode The origin context node.
*
* @return An Iterator capable of traversing the axis.
*
* @throws UnsupportedAxisException is the semantics of this axis are
* not supported by this object model.
*/
Iterator getDescendantOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException;
/** Retrieve an Iterator
matching the
* ancestor-or-self
xpath axis.
*
* @param contextNode The origin context node.
*
* @return An Iterator capable of traversing the axis.
*
* @throws UnsupportedAxisException is the semantics of this axis are
* not supported by this object model.
*/
Iterator getAncestorOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException;
// ------------------------------------------------------------
// ------------------------------------------------------------
// Extractors
// ------------------------------------------------------------
// ------------------------------------------------------------
/** Loads a document from the given URI
*
* @param uri is the URI of the document to load
*
* @throws FunctionCallException if the document could not be loaded
*/
Object getDocument(String uri) throws FunctionCallException;
/** Returns the document node that contains the given context node.
*
* @param object The context node.
*
* @return The document of the context node.
*
* @see #isDocument(Object)
*/
Object getDocumentNode(Object contextNode);
/** Returns the parent of the given context node.
*
*
* The parent of any node must either be a document
* node or an element node.
*
*
* @param object The context node.
*
* @return The parent of the context node.
*
* @see #isDocument
* @see #isElement
*/
Object getParentNode(Object contextNode) throws UnsupportedAxisException;
/** Retrieve the namespace URI of the given element node.
*
* @param element The context element node.
*
* @return The namespace URI of the element node.
*/
String getElementNamespaceUri(Object element);
/** Retrieve the name of the given element node.
*
* @param element The context element node.
*
* @return The name of the element node.
*/
String getElementName(Object element);
/** Retrieve the QName of the given element node.
*
* @param element The context element node.
*
* @return The QName of the element node.
*/
String getElementQName(Object element);
/** Retrieve the namespace URI of the given attribute node.
*
* @param element The context attribute node.
*
* @return The namespace URI of the attribute node.
*/
String getAttributeNamespaceUri(Object attr);
/** Retrieve the name of the given attribute node.
*
* @param element The context attribute node.
*
* @return The name of the attribute node.
*/
String getAttributeName(Object attr);
/** Retrieve the QName of the given attribute node.
*
* @param element The context attribute node.
*
* @return The QName of the attribute node.
*/
String getAttributeQName(Object attr);
/** Retrieve the target of a processing-instruction.
*
* @param pi The context processing-instruction node.
*
* @return The target of the processing-instruction node.
*/
String getProcessingInstructionTarget(Object pi);
/** Retrieve the data of a processing-instruction.
*
* @param pi The context processing-instruction node.
*
* @return The data of the processing-instruction node.
*/
String getProcessingInstructionData(Object pi);
// ------------------------------------------------------------
// ------------------------------------------------------------
// isXXX testers
// ------------------------------------------------------------
// ------------------------------------------------------------
/** Returns whether the given object is a document node. A document node
* is the node that is selected by the xpath expression /
.
*
* @param object The object to test.
*
* @return true
if the object is a document node,
* else false
*/
boolean isDocument(Object object);
/** Returns whether the given object is an element node.
*
* @param object The object to test.
*
* @return true
if the object is an element node,
* else false
*/
boolean isElement(Object object);
/** Returns whether the given object is an attribute node.
*
* @param object The object to test.
*
* @return true
if the object is an attribute node,
* else false
*/
boolean isAttribute(Object object);
/** Returns whether the given object is a namespace node.
*
* @param object The object to test.
*
* @return true
if the object is a namespace node,
* else false
*/
boolean isNamespace(Object object);
/** Returns whether the given object is a comment node.
*
* @param object The object to test.
*
* @return true
if the object is a comment node,
* else false
*/
boolean isComment(Object object);
/** Returns whether the given object is a text node.
*
* @param object The object to test.
*
* @return true
if the object is a text node,
* else false
*/
boolean isText(Object object);
/** Returns whether the given object is a processing-instruction node.
*
* @param object The object to test.
*
* @return true
if the object is a processing-instruction node,
* else false
*/
boolean isProcessingInstruction(Object object);
// ------------------------------------------------------------
// ------------------------------------------------------------
// String-Value extractors
// ------------------------------------------------------------
// ------------------------------------------------------------
/** Retrieve the string-value of a comment node.
*
* @param comment The comment node.
*
* @return The string-value of the node.
*/
String getCommentStringValue(Object comment);
/** Retrieve the string-value of an element node.
*
* @param element The comment node.
*
* @return The string-value of the node.
*/
String getElementStringValue(Object element);
/** Retrieve the string-value of an attribute node.
*
* @param attr The attribute node.
*
* @return The string-value of the node.
*/
String getAttributeStringValue(Object attr);
/** Retrieve the string-value of a namespace node.
*
* @param attr The namespace node.
*
* @return The string-value of the node.
*/
String getNamespaceStringValue(Object ns);
/** Retrieve the string-value of a text node.
*
* @param attr The text node.
*
* @return The string-value of the node.
*/
String getTextStringValue(Object txt);
// ------------------------------------------------------------
// ------------------------------------------------------------
// General utilities
// ------------------------------------------------------------
// ------------------------------------------------------------
/** Retrieve the namespace prefix of a namespace node.
*
* @param ns The namespace node.
*
* @return The prefix associated with the node.
*/
String getNamespacePrefix(Object ns);
/** Translate a namespace prefix to a namespace URI, possibly
* considering a particular element node.
*
*
* Strictly speaking, prefix-to-URI translation should occur
* irrespective of any element in the document. This method
* is provided to allow a non-conforming ease-of-use enhancement.
*
*
* @param prefix The prefix to translate.
* @param element The element to consider during translation.
*
* @return The namespace URI associated with the prefix.
*
* @see NamespaceContext
*/
String translateNamespacePrefixToUri(String prefix, Object element);
/** Returns a parsed form of the given xpath string, which will be suitable
* for queries on documents that use the same navigator as this one.
*
* @param xpath The xpath expression.
*
* @return A new XPath expression object.
*
* @see XPath
*/
XPath parseXPath(String xpath) throws SAXPathException;
/**
* Returns the element whose ID is given by elementId.
* If no such element exists, returns null.
* Attributes with the name "ID" are not of type ID unless so defined.
* Implementations that do not know whether attributes are of type ID or
* not are expected to return null.
*
* @param contextNode a node from the document in which to look for the
* id
* @param elementId id to look for
*
* @return element whose ID is given by elementId, or null if no such
* element exists in the document or if the implementation
* does not know about attribute types
*/
Object getElementById(Object contextNode, String elementId);
/** Returns a number that identifies the type of node that the given
* object represents in this navigator.
*
* @see org.jaxen.pattern.Pattern
*/
short getNodeType(Object node);
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/QualifiedName.java 100644 0 0 10706 10525225063 26567 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/QualifiedName.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: QualifiedName.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
/** A local name (that matches the XML NCName production) and a namespace uri
* with which the local name is qualified.
*
* @author Erwin Bolwidt ( ejb @ klomp.org )
*/
class QualifiedName
{
private String namespaceURI;
private String localName;
/** Constructs a QualifiedName object.
*
* @param namespaceURI namespace URI that qualifies the name, or
* null
for default namespace.
* @param localName local name that is qualified by the namespace uri.
* must not be null
.
*/
QualifiedName( String namespaceURI, String localName )
{
this.namespaceURI = namespaceURI;
this.localName = localName;
}
public String getNamespaceURI()
{
return namespaceURI;
}
public String getLocalName()
{
return localName;
}
public int hashCode()
{
return ( localName.hashCode() ^
( namespaceURI == null ? 0 : namespaceURI.hashCode() ) );
}
public boolean equals( Object o )
{
if ( !(o instanceof QualifiedName) )
return false;
QualifiedName other = (QualifiedName)o;
if ( namespaceURI == null )
return ( other.namespaceURI == null &&
other.localName.equals(localName) );
else
return ( namespaceURI.equals(other.namespaceURI) &&
other.localName.equals(localName) );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/SimpleFunctionContext.java 100644 0 0 13013 10525225063 30361 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/SimpleFunctionContext.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: SimpleFunctionContext.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
import java.util.HashMap;
/** Simple default implementation of FunctionContext
.
*
*
* This is a simple table-based key-lookup implementation
* for FunctionContext
which can be programmatically
* extended by registering additional functions.
*
*
* @see XPathFunctionContext
*
* @author bob mcwhirter
*/
public class SimpleFunctionContext implements FunctionContext
{
/** Table of functions. */
private HashMap functions;
/** Construct.
*
*
* Construct with an empty function lookup table.
*
*/
public SimpleFunctionContext()
{
this.functions = new HashMap();
}
/** Register a new function.
*
*
* By registering a new function, any XPath expression
* that utilizes this FunctionContext
may
* refer-to and use the new function.
*
*
*
* Functions may exist either in an namespace or not.
* Namespace prefix-to-URI resolution is the responsibility
* of a {@link NamespaceContext}. Within this FunctionContext
* functions are only referenced using the URI, not
* the prefix.
*
*
*
* The namespace URI of a function may be null
* to indicate that it exists without a namespace.
*
*
* @param namespaceURI The namespace URI of the function to
* be registered with this context.
* @param localName The non-prefixed local portion of the
* function to be registered with this context.
* @param function A {@link Function} implementation object
* to be used when evaluating the function.
*/
public void registerFunction(String namespaceURI,
String localName,
Function function )
{
this.functions.put( new QualifiedName(namespaceURI, localName),
function );
}
public Function getFunction(String namespaceURI,
String prefix,
String localName )
throws UnresolvableException
{
Object key = new QualifiedName( namespaceURI, localName );
if ( this.functions.containsKey(key) )
return (Function) this.functions.get( key );
else
throw new UnresolvableException( "Function " +
prefix + ":" + localName );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/SimpleNamespaceContext.java 100644 0 0 11574 10525225063 30502 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/SimpleNamespaceContext.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: SimpleNamespaceContext.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
/**
* Provides mappings from namespace prefix to namespace URI to the xpath
* engine.
*/
public class SimpleNamespaceContext implements NamespaceContext, Serializable
{
private Map namespaces;
public SimpleNamespaceContext()
{
this.namespaces = new HashMap();
}
public SimpleNamespaceContext(Map namespaces)
{
this.namespaces = namespaces;
}
/**
* Adds all the namespace declarations that are in scope on the given
* element. In the case of an XSLT stylesheet, this would be the element
* that has the xpath expression in one of its attributes; i.e.
* <xsl:if test="condition/xpath/expression">
.
*
* @param nav the navigator for use in conjunction with
* element
* @param element the element to copy the namespaces from
*/
public void addElementNamespaces( Navigator nav, Object element )
throws UnsupportedAxisException
{
Iterator namespaceAxis = nav.getNamespaceAxisIterator( element );
while ( namespaceAxis.hasNext() ) {
Object namespace = namespaceAxis.next();
String prefix = nav.getNamespacePrefix( namespace );
String uri = nav.getNamespaceStringValue( namespace );
if ( translateNamespacePrefixToUri(prefix) == null ) {
addNamespace( prefix, uri );
}
}
}
public void addNamespace(String prefix, String namespaceUri)
{
this.namespaces.put( prefix,
namespaceUri );
}
public String translateNamespacePrefixToUri(String prefix)
{
if ( this.namespaces.containsKey( prefix ) )
{
return (String) this.namespaces.get( prefix );
}
return null;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/SimpleVariableContext.java 100644 0 0 13466 10525225063 30335 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/SimpleVariableContext.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: SimpleVariableContext.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
import java.io.Serializable;
import java.util.Map;
import java.util.HashMap;
/** Simple default implementation for VariableContext
.
*
*
* This is a simple table-based key-lookup implementation
* for VariableContext
which can be programmatically
* extended by setting additional variables.
*
*
* @author bob mcwhirter
*/
public class SimpleVariableContext implements VariableContext, Serializable
{
/** Table of variable bindings. */
private Map variables;
/** Construct.
*
*
* Construct with an empty variable lookup table.
*
*/
public SimpleVariableContext()
{
variables = new HashMap();
}
/** Set the value associated with a variable.
*
*
* This method sets a variable that is
* associated with any particular namespace.
* These variables appear such as $prefix:foo
* in an XPath expression. Prefix to URI resolution
* is the responsibility of a NamespaceContext
.
* Variables within a VariableContext
are
* refered to purely based upon their namespace URI,
* if any.
*
*
* @param namespaceURI The namespace URI of the variable.
* @param localName The local name of the variable
* @param value The value to be bound to the variable.
*/
public void setVariableValue( String namespaceURI,
String localName,
Object value )
{
this.variables.put( new QualifiedName(namespaceURI, localName),
value );
}
/** Set the value associated with a variable.
*
*
* This method sets a variable that is not
* associated with any particular namespace.
* These variables appear such as $foo
* in an XPath expression.
*
*
* @param localName The local name of the variable
* @param value The value to be bound to the variable.
*/
public void setVariableValue( String localName,
Object value )
{
this.variables.put( new QualifiedName(null, localName), value );
}
public Object getVariableValue( String namespaceURI,
String prefix,
String localName )
throws UnresolvableException
{
Object key = new QualifiedName( namespaceURI, localName );
if ( this.variables.containsKey(key) )
{
return this.variables.get( key );
}
else
{
throw new UnresolvableException( "Variable {" + namespaceURI +
"}" + prefix + ":" + localName );
}
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/UnresolvableException.java 100644 0 0 6465 10525225063 30372 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/UnresolvableException.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: UnresolvableException.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
/** Used when a function-call or variable-reference, or any other lookup
* based on namespace and local name, couldn't be resolved.
*
* @author Erwin Bolwidt (ejb @ klomp.org)
*/
public class UnresolvableException extends JaxenException
{
public UnresolvableException(String message)
{
super( message );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/UnsupportedAxisException.java 100644 0 0 6562 10525225063 31104 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/UnsupportedAxisException.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: UnsupportedAxisException.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
/** Indicates attempt to evaluate an XPath axis that
* is unsupported by the current object-model.
*
* @author bob mcwhirter
*/
public class UnsupportedAxisException extends JaxenException
{
/** Construct.
*
* @param msg The error message.
*/
public UnsupportedAxisException(String msg)
{
super( msg );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/VariableContext.java 100644 0 0 12607 10525225063 27157 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/VariableContext.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: VariableContext.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
/** Resolves variable bindings within an XPath expression.
*
*
* Variables within an XPath expression are denoted using
* notation such as $varName or $nsPrefix:varName, and may
* refer to primitive types (Boolean, Number or String),
* node-sets
or individual XML nodes.
*
*
*
* When a variable is bound to a node-set
, the
* actual Java object returned should be a java.util.List
* containing XML nodes from the object-model (dom4j, JDOM, DOM, EXML)
* being used with the XPath.
*
*
*
* A variable may validly be assigned the null
value,
* but an unbound variable (one that this context does not know about)
* should cause an {@link UnresolvableException} to be thrown.
*
*
* @see SimpleVariableContext
* @see NamespaceContext
*
* @author bob mcwhirter
* @author James Strachan
*/
public interface VariableContext
{
/** An implementation should return the value of an xpath variable
* based on the namespace uri and local name of the variable-reference
* expression.
*
*
* It must not use the prefix parameter to select a variable,
* because a prefix could be bound to any namespace; the prefix parameter
* could be used in debugging output or other generated information.
* The prefix may otherwise be ignored.
*
*
* @param namespaceURI the namespace uri to which the prefix parameter
* is bound in the xpath expression. If the variable
* reference expression had no prefix, the namespace
* uri is null
.
* @param prefix the prefix that was used in the variable reference
* expression.
* @param localName the local name of the variable-reference
* expression; if there is no prefix, then this is
* the whole name of the variable.
*
* @return the variable's value (which can be null
)
* @throws UnresolvableException when the variable cannot be resolved.
*/
public Object getVariableValue( String namespaceURI,
String prefix,
String localName )
throws UnresolvableException;
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/XPath.java 100644 0 0 35265 10525225063 25116 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/XPath.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: XPath.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
import java.util.List;
/**
* Defines the interface to an object which represents an XPath 1.0 expression which
* can be evaluated against a variety of different XML object models.
*
*
* Most of the evaluation methods take a context object. This is typically a
* node or node set object (which is typically a List of node objects) or
* a Jaxen Context object.
* A null context is allowed, meaning that
* there is no XML nodes on which to evaluate.
*
*
* @see org.jaxen.dom4j.Dom4jXPath XPath for dom4j
* @see org.jaxen.jdom.JDOMXPath XPath for JDOM
* @see org.jaxen.dom.DOMXPath XPath for W3C DOM
* @see org.jaxen.exml.ElectricXPath XPath for Electric XML
*
* @author bob mcwhirter
* @author James Strachan
*/
public interface XPath {
/** Evaluate this XPath against a given context.
*
*
* The context of evaluation my be a document ,
* an element , or a set of elements .
*
*
*
* If the expression evaluates to a single primitive
* (String, Number or Boolean) type, it is returned
* directly. Otherwise, the returned value is a
* List (a node-set
, in the terms of the
* specification) of values.
*
*
*
* When using this method, one must be careful to
* test the class of the returned objects, and of
* each of the composite members if a List
* is returned. If the returned members are XML entities,
* they will be the actual Document
,
* Element
or Attribute
objects
* as defined by the concrete XML object-model implementation,
* directly from the context document. This does not
* return copies of anything , but merely returns
* references to entities within the source document.
*
*
* @param The node, nodeset or Context object for evaluation. This value can be null
*
* @return The result of evaluating the XPath expression
* against the supplied context.
*/
public Object evaluate(Object context) throws JaxenException;
/** Select all nodes that are selectable by this XPath
* expression. If multiple nodes match, multiple nodes
* will be returned.
*
*
* NOTE: In most cases, nodes will be returned
* in document-order, as defined by the XML Canonicalization
* specification. The exception occurs when using XPath
* expressions involving the union
operator
* (denoted with the pipe '|' character).
*
*
* @param The node, nodeset or Context object for evaluation. This value can be null
*
* @return The node-set
of all items selected
* by this XPath expression.
*
* @see #selectSingleNode
*/
public List selectNodes(Object context) throws JaxenException;
/** Select only the first node that is selectable by this XPath
* expression. If multiple nodes match, only one node will be
* returned.
*
* NOTE: In most cases, the selected node will be the first
* selectable node in document-order, as defined by the XML Canonicalization
* specification. The exception occurs when using XPath
* expressions involving the union
operator
* (denoted with the pipe '|' character).
*
*
* @param The node, nodeset or Context object for evaluation. This value can be null
*
* @return The node-set
of all items selected
* by this XPath expression.
*
* @see #selectNodes
*/
public Object selectSingleNode(Object context) throws JaxenException;
/** Retrieve a string-value interpretation of this XPath
* expression when evaluated against a given context.
*
*
* The string-value of the expression is determined per
* the string(..)
core function as defined
* in the XPath specification. This means that an expression
* that selects more than one nodes will return the string value
* of the first node in the node set..
*
*
* @param The node, nodeset or Context object for evaluation. This value can be null
*
* @return The string-value interpretation of this expression.
*
* @deprecated As of Jaxen 1.0 RC1 please use
* {@link #stringValueOf(Object) instead}
*/
public String valueOf(Object context) throws JaxenException;
/** Retrieve a string-value interpretation of this XPath
* expression when evaluated against a given context.
*
*
* The string-value of the expression is determined per
* the string(..)
core function as defined
* in the XPath specification. This means that an expression
* that selects more than one nodes will return the string value
* of the first node in the node set..
*
*
* @param The node, nodeset or Context object for evaluation. This value can be null
*
* @return The string-value interpretation of this expression.
*/
public String stringValueOf(Object context) throws JaxenException;
/** Retrieve a boolean-value interpretation of this XPath
* expression when evaluated against a given context.
*
*
* The boolean-value of the expression is determined per
* the boolean(..)
core function as defined
* in the XPath specification. This means that an expression
* that selects zero nodes will return false
,
* while an expression that selects one-or-more nodes will
* return true
.
*
*
* @param The node, nodeset or Context object for evaluation. This value can be null
*
* @return The boolean-value interpretation of this expression.
*/
public boolean booleanValueOf(Object context) throws JaxenException;
/** Retrieve a number-value interpretation of this XPath
* expression when evaluated against a given context.
*
*
* The number-value of the expression is determined per
* the number(..)
core function as defined
* in the XPath specification. This means that if this
* expression selects multiple nodes, the number-value
* of the first node is returned.
*
*
* @param The node, nodeset or Context object for evaluation. This value can be null
*
* @return The number-value interpretation of this expression.
*/
public Number numberValueOf(Object context) throws JaxenException;
// Helpers
/** Add a namespace prefix-to-URI mapping for this XPath
* expression.
*
*
* Namespace prefix-to-URI mappings in an XPath are independant
* of those used within any document. Only the mapping explicitly
* added to this XPath will be available for resolving the
* XPath expression.
*
*
*
* This is a convenience method for adding mappings to the
* default {@link NamespaceContext} in place for this XPath.
* If you have installed a specific custom NamespaceContext
,
* then this method will throw a JaxenException
.
*
*
* @param prefix The namespace prefix.
* @param uri The namespace URI.
*
* @throws JaxenException If a NamespaceContext
* used by this XPath has been explicitly installed.
*/
public void addNamespace(String prefix,
String uri) throws JaxenException;
// ------------------------------------------------------------
// ------------------------------------------------------------
// Properties
// ------------------------------------------------------------
// ------------------------------------------------------------
/** Set a NamespaceContext
for use with this
* XPath expression.
*
*
* A NamespaceContext
is responsible for translating
* namespace prefixes within the expression into namespace URIs.
*
*
* @param namespaceContext The NamespaceContext
to
* install for this expression.
*
* @see NamespaceContext
* @see NamespaceContext#translateNamespacePrefixToUri
*/
public void setNamespaceContext(NamespaceContext namespaceContext);
/** Set a FunctionContext
for use with this XPath
* expression.
*
*
* A FunctionContext
is responsible for resolving
* all function calls used within the expression.
*
*
* @param functionContext The FunctionContext
to
* install for this expression.
*
* @see FunctionContext
* @see FunctionContext#getFunction
*/
public void setFunctionContext(FunctionContext functionContext);
/** Set a VariableContext
for use with this XPath
* expression.
*
*
* A VariableContext
is responsible for resolving
* all variables referenced within the expression.
*
*
* @param variableContext The VariableContext
to
* install for this expression.
*
* @see VariableContext
* @see VariableContext#getVariableValue
*/
public void setVariableContext(VariableContext variableContext);
/** Retrieve the NamespaceContext
used by this XPath
* expression.
*
*
* A FunctionContext
is responsible for resolving
* all function calls used within the expression.
*
*
*
* If this XPath expression has not previously had a NamespaceContext
* installed, a new default NamespaceContext
will be created,
* installed and returned.
*
*
* @return The NamespaceContext
used by this expression.
*
* @see NamespaceContext
*/
public NamespaceContext getNamespaceContext();
/** Retrieve the FunctionContext
used by this XPath
* expression.
*
*
* A FunctionContext
is responsible for resolving
* all function calls used within the expression.
*
*
*
* If this XPath expression has not previously had a FunctionContext
* installed, a new default FunctionContext
will be created,
* installed and returned.
*
*
* @return The FunctionContext
used by this expression.
*
* @see FunctionContext
*/
public FunctionContext getFunctionContext();
/** Retrieve the VariableContext
used by this XPath
* expression.
*
*
* A VariableContext
is responsible for resolving
* all variables referenced within the expression.
*
*
*
* If this XPath expression has not previously had a VariableContext
* installed, a new default VariableContext
will be created,
* installed and returned.
*
*
* @return The VariableContext
used by this expression.
*
* @see VariableContext
*/
public VariableContext getVariableContext();
/** Retrieve the XML object-model-specific {@link Navigator}
* for us in evaluating this XPath expression.
*
* @return The implementation-specific Navigator
.
*/
public Navigator getNavigator();
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/XPathFunctionContext.java 100644 0 0 22426 10525225063 30164 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/XPathFunctionContext.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: XPathFunctionContext.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
import org.xmlpull.v1.builder.xpath.jaxen.function.*;
import org.xmlpull.v1.builder.xpath.jaxen.function.ext.*;
/** A FunctionContext
implementing the core XPath
* function library, with extensions.
*
*
* The core XPath function library is provided through this
* implementation of FunctionContext
. Additionally,
* extension functions have been provided, as enumerated below.
*
*
*
* This class implements a Singleton pattern (see {@link #getInstance}),
* as it is perfectly re-entrant and thread-safe. If using the
* singleton, it is inadvisable to call {@link #registerFunction}
* as that will extend the global function context, affecting other
* users of the singleton. But that's your call, really, now isn't
* it? That may be what you really want to do.
*
*
*
* Extension functions:
*
*
* matrix-concat(..)
* evaluate(..)
*
*
* @see FunctionContext
*
* @author bob mcwhirter
*/
public class XPathFunctionContext extends SimpleFunctionContext
{
/** Singleton implementation.
*/
private static class Singleton
{
/** Singleton instance.
*/
private static XPathFunctionContext instance = new XPathFunctionContext();
}
/** Retrieve the singleton instance.
*
* @return The singleton instance.
*/
public static FunctionContext getInstance()
{
return Singleton.instance;
}
/** Construct.
*
*
* Construct with all core XPath functions registered.
*
*/
public XPathFunctionContext()
{
registerFunction( null, // namespace URI
"boolean",
new BooleanFunction() );
registerFunction( null, // namespace URI
"ceiling",
new CeilingFunction() );
registerFunction( null, // namespace URI
"concat",
new ConcatFunction() );
registerFunction( null, // namespace URI
"contains",
new ContainsFunction() );
registerFunction( null, // namespace URI
"count",
new CountFunction() );
registerFunction( null, // namespace URI
"document",
new DocumentFunction() );
registerFunction( null, // namespace URI
"false",
new FalseFunction() );
registerFunction( null, // namespace URI
"floor",
new FloorFunction() );
registerFunction( null, // namespace URI
"id",
new IdFunction() );
registerFunction( null, // namespace URI
"last",
new LastFunction() );
registerFunction( null, // namespace URI
"local-name",
new LocalNameFunction() );
registerFunction( null, // namespace URI
"name",
new NameFunction() );
registerFunction( null, // namespace URI
"namespace-uri",
new NamespaceUriFunction() );
registerFunction( null, // namespace URI
"normalize-space",
new NormalizeSpaceFunction() );
registerFunction( null, // namespace URI
"not",
new NotFunction() );
registerFunction( null, // namespace URI
"number",
new NumberFunction() );
registerFunction( null, // namespace URI
"position",
new PositionFunction() );
registerFunction( null, // namespace URI
"round",
new RoundFunction() );
registerFunction( null, // namespace URI
"starts-with",
new StartsWithFunction() );
registerFunction( null, // namespace URI
"string",
new StringFunction() );
registerFunction( null, // namespace URI
"string-length",
new StringLengthFunction() );
registerFunction( null, // namespace URI
"substring-after",
new SubstringAfterFunction() );
registerFunction( null, // namespace URI
"substring-before",
new SubstringBeforeFunction() );
registerFunction( null, // namespace URI
"substring",
new SubstringFunction() );
registerFunction( null, // namespace URI
"sum",
new SumFunction() );
registerFunction( null, // namespace URI
"true",
new TrueFunction() );
registerFunction( null, // namespace URI
"translate",
new TranslateFunction() );
// register extension functions
// extension functions should go into a namespace, but which one?
// for now, keep them in default namespace to not to break any code
registerFunction( null, // namespace URI
"matrix-concat",
new MatrixConcatFunction() );
registerFunction( null, // namespace URI
"evaluate",
new EvaluateFunction() );
registerFunction( null, // namespace URI
"lower-case",
new LowerFunction() );
registerFunction( null, // namespace URI
"upper-case",
new UpperFunction() );
registerFunction( null, // namespace URI
"ends-with",
new EndsWithFunction() );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/XPathSyntaxException.java 100644 0 0 12642 10525225063 30176 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/XPathSyntaxException.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:34 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: XPathSyntaxException.java,v 1.1 2004/06/16 15:55:34 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen;
/** Indicates an error during parsing of an XPath
* expression.
*
* @see XPath
*
* @author bob mcwhirter
* @author James Strachan
*/
public class XPathSyntaxException extends JaxenException
{
/** The textual xpath expression. */
private String xpath;
/** The position of the error. */
private int position;
/** Construct.
*
* @param xpath The erroneous xpath.
* @param position The position of the error.
* @param message The error message.
*/
public XPathSyntaxException(String xpath,
int position,
String message)
{
super( message );
this.xpath = xpath;
this.position = position;
}
/** Retrieve the position of the error.
*
* @return The position of the error.
*/
public int getPosition()
{
return this.position;
}
/** Retrieve the expression containing the error.
*
* @return The erroneous expression.
*/
public String getXPath()
{
return this.xpath;
}
/** Retrieve a string useful for denoting where
* the error occured.
*
*
* This is a string composed of whitespace and
* a marker at the position (see {@link #getPosition})
* of the error. This is useful for creating
* friendly multi-line error displays.
*
*
* @return The error position marker.
*/
public String getPositionMarker()
{
StringBuffer buf = new StringBuffer();
int pos = getPosition();
for ( int i = 0 ; i < pos ; ++i )
{
buf.append(" ");
}
buf.append("^");
return buf.toString();
}
/** Retrieve the friendly multi-line error message.
*
*
* This returns a multi-line string that contains
* the original erroneous xpath expression with a
* marker underneath indicating exactly where the
* error occurred.
*
*
* @return The multi-line error message.
*/
public String getMultilineMessage()
{
StringBuffer buf = new StringBuffer();
buf.append( getMessage() );
buf.append( "\n" );
buf.append( getXPath() );
buf.append( "\n" );
buf.append( getPositionMarker() );
return buf.toString();
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/BinaryExpr.java 100644 0 0 6056 10525225063 27107 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/BinaryExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: BinaryExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
public interface BinaryExpr extends Expr
{
Expr getLHS();
Expr getRHS();
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultAbsoluteLocationPath.java 100644 0 0 10700 10525225063 32424 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultAbsoluteLocationPath.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultAbsoluteLocationPath.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class DefaultAbsoluteLocationPath extends DefaultLocationPath
{
public DefaultAbsoluteLocationPath()
{
}
public String toString()
{
return "[(DefaultAbsoluteLocationPath): " + super.toString() + "]";
}
public boolean isAbsolute()
{
return true;
}
public String getText()
{
return "/" + super.getText();
}
public Object evaluate(Context context) throws JaxenException
{
ContextSupport support = context.getContextSupport();
Navigator nav = support.getNavigator();
Context absContext = new Context( support );
List contextNodes = context.getNodeSet();
if ( contextNodes.isEmpty() )
{
return Collections.EMPTY_LIST;
}
Object firstNode = contextNodes.get( 0 );
Object docNode = nav.getDocumentNode( firstNode );
if ( docNode == null )
{
return Collections.EMPTY_LIST;
}
List list = new ArrayList(1);
list.add( docNode );
absContext.setNodeSet( list );
return super.evaluate( absContext );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultAdditiveExpr.java 100644 0 0 6456 10525225063 30725 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultAdditiveExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultAdditiveExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
abstract class DefaultAdditiveExpr extends DefaultArithExpr
{
public DefaultAdditiveExpr(Expr lhs,
Expr rhs)
{
super( lhs,
rhs );
}
public String toString()
{
return "[(DefaultAdditiveExpr): " + getLHS() + ", " + getRHS() + "]";
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultAllNodeStep.java 100644 0 0 7111 10525225063 30474 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultAllNodeStep.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultAllNodeStep.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.expr.iter.IterableAxis;
public class DefaultAllNodeStep extends DefaultStep
{
public DefaultAllNodeStep(IterableAxis axis)
{
super( axis );
}
public String toString()
{
return "[(DefaultAllNodeStep): " + getAxisName() + "]";
}
public String getText()
{
return getAxisName() + "::node()" + super.getText();
}
public boolean matches(Object node,
ContextSupport contextSupport)
{
return true;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultAndExpr.java 100644 0 0 10103 10525225063 27676 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultAndExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultAndExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import org.xmlpull.v1.builder.xpath.jaxen.function.BooleanFunction;
class DefaultAndExpr extends DefaultLogicalExpr
{
public DefaultAndExpr(Expr lhs,
Expr rhs)
{
super( lhs,
rhs );
}
public String getOperator()
{
return "and";
}
public String toString()
{
return "[(DefaultAndExpr): " + getLHS() + ", " + getRHS() + "]";
}
public Object evaluate(Context context) throws JaxenException
{
Navigator nav = context.getNavigator();
Boolean lhsValue = BooleanFunction.evaluate( getLHS().evaluate( context ), nav );
if ( lhsValue == Boolean.FALSE )
{
return Boolean.FALSE;
}
Boolean rhsValue = BooleanFunction.evaluate( getRHS().evaluate( context ), nav );
if ( rhsValue == Boolean.FALSE )
{
return Boolean.FALSE;
}
return Boolean.TRUE;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultArithExpr.java 100644 0 0 7077 10525225063 30243 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultArithExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultArithExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
abstract class DefaultArithExpr extends DefaultBinaryExpr
{
public DefaultArithExpr(Expr lhs,
Expr rhs)
{
super( lhs,
rhs );
}
public String toString()
{
return "[(DefaultArithExpr): " + getLHS() + ", " + getRHS() + "]";
}
public void assertInteger( Number number ) throws JaxenException
{
if( number.doubleValue() != number.intValue() )
{
throw new JaxenException( number + " is not an integer" );
}
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultBinaryExpr.java 100644 0 0 7765 10525225063 30424 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultBinaryExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultBinaryExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
abstract class DefaultBinaryExpr extends DefaultExpr implements BinaryExpr
{
private Expr lhs;
private Expr rhs;
public DefaultBinaryExpr(Expr lhs,
Expr rhs)
{
this.lhs = lhs;
this.rhs = rhs;
}
public Expr getLHS()
{
return this.lhs;
}
public Expr getRHS()
{
return this.rhs;
}
public void setLHS(Expr lhs)
{
this.lhs = lhs;
}
public void setRHS(Expr rhs)
{
this.rhs = rhs;
}
public abstract String getOperator();
public String getText()
{
Expr lhs = getLHS();
Expr rhs = getRHS();
return "(" + getLHS().getText() + " " + getOperator() + " " + getRHS().getText() + ")";
}
public String toString()
{
return "[(" + getClass().getName() + "): " + getLHS() + ", " + getRHS() + "]";
}
public Expr simplify()
{
setLHS( getLHS().simplify() );
setRHS( getRHS().simplify() );
return this;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultCommentNodeStep.java 100644 0 0 7310 10525225063 31367 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultCommentNodeStep.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultCommentNodeStep.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import org.xmlpull.v1.builder.xpath.jaxen.expr.iter.IterableAxis;
public class DefaultCommentNodeStep extends DefaultStep
{
public DefaultCommentNodeStep(IterableAxis axis)
{
super( axis );
}
public String toString()
{
return "[(DefaultCommentNodeStep): " + getAxis() + "]";
}
public String getText()
{
return getAxisName() + "::comment()";
}
public boolean matches(Object node,
ContextSupport contextSupport)
{
Navigator nav = contextSupport.getNavigator();
return nav.isComment( node );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultDivExpr.java 100644 0 0 7613 10525225063 27712 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultDivExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultDivExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.jaxen.function.NumberFunction;
class DefaultDivExpr extends DefaultMultiplicativeExpr
{
public DefaultDivExpr(Expr lhs,
Expr rhs)
{
super( lhs,
rhs );
}
public String getOperator()
{
return "div";
}
public Object evaluate(Context context) throws JaxenException
{
Number lhsValue = NumberFunction.evaluate( getLHS().evaluate( context ),
context.getNavigator() );
Number rhsValue = NumberFunction.evaluate( getRHS().evaluate( context ),
context.getNavigator() );
double result = lhsValue.doubleValue() / rhsValue.doubleValue();
return new Double( result );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultEqualityExpr.java 100644 0 0 14317 10525225063 31004 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultEqualityExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultEqualityExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import java.util.List;
import java.util.Iterator;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.jaxen.function.StringFunction;
import org.xmlpull.v1.builder.xpath.jaxen.function.BooleanFunction;
import org.xmlpull.v1.builder.xpath.jaxen.function.NumberFunction;
abstract class DefaultEqualityExpr extends DefaultTruthExpr
{
public DefaultEqualityExpr( Expr lhs, Expr rhs )
{
super( lhs, rhs );
}
public String toString()
{
return "[(DefaultEqualityExpr): " + getLHS() + ", " + getRHS() + "]";
}
public Object evaluate( Context context ) throws JaxenException
{
Object lhsValue = getLHS().evaluate( context );
Object rhsValue = getRHS().evaluate( context );
if( lhsValue == null || rhsValue == null )
{
return Boolean.FALSE;
}
Navigator nav = context.getNavigator();
if( bothAreSets( lhsValue, rhsValue ) )
{
return evaluateSetSet( (List) lhsValue, (List) rhsValue, nav );
}
else if ( eitherIsSet( lhsValue, rhsValue ) )
{
if ( isSet( lhsValue ) )
{
return evaluateSetSet( (List) lhsValue, convertToList( rhsValue ), nav );
}
else
{
return evaluateSetSet( convertToList( lhsValue ), (List) rhsValue, nav );
}
}
else
{
return evaluateObjectObject( lhsValue, rhsValue, nav ) ? Boolean.TRUE : Boolean.FALSE;
}
}
private Boolean evaluateSetSet( List lhsSet, List rhsSet, Navigator nav )
{
if( setIsEmpty( lhsSet ) || setIsEmpty( rhsSet ) )
{
return Boolean.FALSE;
}
for( Iterator lhsIterator = lhsSet.iterator(); lhsIterator.hasNext(); )
{
Object lhs = lhsIterator.next();
for( Iterator rhsIterator = rhsSet.iterator(); rhsIterator.hasNext(); )
{
Object rhs = rhsIterator.next();
if( evaluateObjectObject( lhs, rhs, nav ) )
{
return Boolean.TRUE;
}
}
}
return Boolean.FALSE;
}
private boolean evaluateObjectObject( Object lhs, Object rhs, Navigator nav )
{
if( eitherIsBoolean( lhs, rhs ) )
{
return evaluateObjectObject( BooleanFunction.evaluate( lhs, nav ),
BooleanFunction.evaluate( rhs, nav ) );
}
else if( eitherIsNumber( lhs, rhs ) )
{
return evaluateObjectObject( NumberFunction.evaluate( lhs,
nav ),
NumberFunction.evaluate( rhs,
nav ) );
}
else
{
return evaluateObjectObject( StringFunction.evaluate( lhs,
nav ),
StringFunction.evaluate( rhs,
nav ) );
}
}
protected abstract boolean evaluateObjectObject( Object lhs, Object rhs );
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultEqualsExpr.java 100644 0 0 7227 10525225063 30423 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultEqualsExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultEqualsExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.function.NumberFunction;
class DefaultEqualsExpr extends DefaultEqualityExpr
{
public DefaultEqualsExpr( Expr lhs, Expr rhs )
{
super( lhs, rhs );
}
public String getOperator()
{
return "=";
}
public String toString()
{
return "[(DefaultEqualsExpr): " + getLHS() + ", " + getRHS() + "]";
}
protected boolean evaluateObjectObject( Object lhs, Object rhs )
{
if( eitherIsNumber( lhs, rhs ) )
{
if( NumberFunction.isNaN( (Double) lhs ) || NumberFunction.isNaN( (Double) rhs ) )
{
return false;
}
}
return lhs.equals( rhs );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultExpr.java 100644 0 0 7411 10525225063 27243 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.util.SingleObjectIterator;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
public abstract class DefaultExpr implements Expr
{
public Expr simplify()
{
return this;
}
static public Iterator convertToIterator(Object obj)
{
if ( obj instanceof Iterator )
{
return (Iterator) obj;
}
if ( obj instanceof List )
{
return ((List)obj).iterator();
}
return new SingleObjectIterator( obj );
}
static public List convertToList(Object obj)
{
if ( obj instanceof List )
{
return (List) obj;
}
List list = new ArrayList( 1 );
list.add( obj );
return list;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultFilterExpr.java 100644 0 0 13277 10525225063 30440 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultFilterExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultFilterExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import java.util.ArrayList;
import java.util.List;
public class DefaultFilterExpr extends DefaultExpr implements FilterExpr, Predicated
{
private Expr expr;
private PredicateSet predicates;
public DefaultFilterExpr()
{
this.predicates = new PredicateSet();
}
public DefaultFilterExpr(Expr expr)
{
this.expr = expr;
this.predicates = new PredicateSet();
}
public void addPredicate(Predicate predicate)
{
this.predicates.addPredicate( predicate );
}
public List getPredicates()
{
return this.predicates.getPredicates();
}
public PredicateSet getPredicateSet()
{
return this.predicates;
}
public Expr getExpr()
{
return this.expr;
}
public String toString()
{
return "[(DefaultFilterExpr): expr: " + expr + " predicates: " + predicates + " ]";
}
public String getText()
{
String text = "";
if ( this.expr != null )
{
text = this.expr.getText();
}
text += predicates.getText();
return text;
}
public Expr simplify()
{
this.predicates.simplify();
if ( this.expr != null )
{
this.expr = this.expr.simplify();
}
if ( this.predicates.getPredicates().size() == 0 )
{
return getExpr();
}
return this;
}
/** Returns true if the current filter matches at least one of the context nodes
*/
public boolean asBoolean(Context context) throws JaxenException
{
Object results = null;
if ( expr != null )
{
results = expr.evaluate( context );
}
else
{
ArrayList list = new ArrayList(1);
list.addAll( context.getNodeSet() );
results = list;
}
if ( results instanceof Boolean )
{
Boolean b = (Boolean) results;
return b.booleanValue();
}
if ( results instanceof List )
{
return getPredicateSet().evaluateAsBoolean(
(List) results, context.getContextSupport()
);
}
return false;
}
public Object evaluate(Context context) throws JaxenException
{
Object results = getExpr().evaluate( context );
if ( results instanceof List )
{
List newresults = getPredicateSet().evaluatePredicates( (List) results,
context.getContextSupport() );
results = newresults;
}
return results;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultFunctionCallExpr.java 100644 0 0 14567 10525225063 31577 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultFunctionCallExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultFunctionCallExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
class DefaultFunctionCallExpr extends DefaultExpr implements FunctionCallExpr
{
private String prefix;
private String functionName;
private List parameters;
public DefaultFunctionCallExpr(String prefix,
String functionName)
{
this.prefix = prefix;
this.functionName = functionName;
this.parameters = new ArrayList();
}
public void addParameter(Expr parameter)
{
this.parameters.add( parameter );
}
public List getParameters()
{
return this.parameters;
}
public String getPrefix()
{
return this.prefix;
}
public String getFunctionName()
{
return this.functionName;
}
public String getText()
{
StringBuffer buf = new StringBuffer();
String prefix = getPrefix();
if ( prefix != null
&&
! prefix.equals("") )
{
buf.append( prefix );
buf.append( ":" );
}
buf.append( getFunctionName() );
buf.append( "(" );
Iterator paramIter = getParameters().iterator();
Expr eachParam = null;
while ( paramIter.hasNext() )
{
eachParam = (Expr) paramIter.next();
buf.append( eachParam.getText() );
if ( paramIter.hasNext() )
{
buf.append( ", " );
}
}
buf.append( ")" );
return buf.toString();
}
public Expr simplify()
{
List paramExprs = getParameters();
int paramSize = paramExprs.size();
Expr eachParam = null;
List newParams = new ArrayList( paramSize );
for ( int i = 0 ; i < paramSize ; ++i )
{
eachParam = (Expr) paramExprs.get( i );
newParams.add( eachParam.simplify() );
}
this.parameters = newParams;
return this;
}
public String toString()
{
String prefix = getPrefix();
if ( prefix == null )
{
return "[(DefaultFunctionCallExpr): " + getFunctionName() + "(" + getParameters() + ") ]";
}
return "[(DefaultFunctionCallExpr): " + getPrefix() + ":" + getFunctionName() + "(" + getParameters() + ") ]";
}
public Object evaluate(Context context) throws JaxenException
{
String namespaceURI =
context.translateNamespacePrefixToUri( getPrefix() );
Function func = context.getFunction( namespaceURI,
getPrefix(),
getFunctionName() );
List paramExprs = getParameters();
int paramSize = paramExprs.size();
List paramValues = new ArrayList( paramSize );
Expr eachParam = null;
Object eachValue = null;
for ( int i = 0 ; i < paramSize ; ++i )
{
eachParam = (Expr) paramExprs.get( i );
eachValue = eachParam.evaluate( context );
paramValues.add( eachValue );
}
return func.call( context, paramValues );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultGreaterThanEqualExpr.java 100644 0 0 6533 10525225063 32364 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultGreaterThanEqualExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultGreaterThanEqualExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
class DefaultGreaterThanEqualExpr extends DefaultRelationalExpr
{
public DefaultGreaterThanEqualExpr( Expr lhs, Expr rhs )
{
super( lhs, rhs );
}
public String getOperator()
{
return ">=";
}
protected boolean evaluateDoubleDouble( Double lhs, Double rhs )
{
return lhs.compareTo( rhs ) >= 0;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultGreaterThanExpr.java 100644 0 0 6505 10525225063 31373 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultGreaterThanExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultGreaterThanExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
class DefaultGreaterThanExpr extends DefaultRelationalExpr
{
public DefaultGreaterThanExpr( Expr lhs, Expr rhs )
{
super( lhs, rhs );
}
public String getOperator()
{
return ">";
}
protected boolean evaluateDoubleDouble( Double lhs, Double rhs )
{
return lhs.compareTo( rhs ) > 0;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultLessThanEqualExpr.java 100644 0 0 6517 10525225063 31703 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultLessThanEqualExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultLessThanEqualExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
class DefaultLessThanEqualExpr extends DefaultRelationalExpr
{
public DefaultLessThanEqualExpr( Expr lhs, Expr rhs )
{
super( lhs, rhs );
}
public String getOperator()
{
return "<=";
}
protected boolean evaluateDoubleDouble( Double lhs, Double rhs )
{
return lhs.compareTo( rhs ) <= 0;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultLessThanExpr.java 100644 0 0 6465 10525225063 30715 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultLessThanExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultLessThanExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
class DefaultLessThanExpr extends DefaultRelationalExpr
{
public DefaultLessThanExpr( Expr lhs, Expr rhs )
{
super( lhs, rhs );
}
public String getOperator()
{
return "<";
}
protected boolean evaluateDoubleDouble( Double lhs, Double rhs )
{
return lhs.compareTo( rhs ) < 0;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultLiteralExpr.java 100644 0 0 7072 10525225063 30563 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultLiteralExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultLiteralExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
class DefaultLiteralExpr extends DefaultExpr implements LiteralExpr
{
private String literal;
public DefaultLiteralExpr(String literal)
{
this.literal = literal;
}
public String getLiteral()
{
return this.literal;
}
public String toString()
{
return "[(DefaultLiteralExpr): " + getLiteral() + "]";
}
public String getText()
{
return "\"" + getLiteral() + "\"";
}
public Object evaluate(Context context)
{
return getLiteral();
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultLocationPath.java 100644 0 0 16061 10525225063 30733 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultLocationPath.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultLocationPath.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.jaxen.util.IdentityHashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Iterator;
import java.util.Map;
abstract class DefaultLocationPath extends DefaultExpr implements LocationPath
{
private List steps;
private final static Object PRESENT = new Object();
public DefaultLocationPath()
{
this.steps = new LinkedList();
}
public void addStep(Step step)
{
getSteps().add( step );
}
public List getSteps()
{
return this.steps;
}
public Expr simplify()
{
Iterator stepIter = getSteps().iterator();
Step eachStep = null;
while ( stepIter.hasNext() )
{
eachStep = (Step) stepIter.next();
eachStep.simplify();
}
return this;
}
public String getText()
{
StringBuffer buf = new StringBuffer();
Iterator stepIter = getSteps().iterator();
while ( stepIter.hasNext() )
{
buf.append( ((Step)stepIter.next()).getText() );
if ( stepIter.hasNext() )
{
buf.append( "/" );
}
}
return buf.toString();
}
public String toString()
{
StringBuffer buf = new StringBuffer();
Iterator stepIter = getSteps().iterator();
while( stepIter.hasNext() )
{
buf.append( stepIter.next().toString() );
if ( stepIter.hasNext() )
{
buf.append("/");
}
}
return buf.toString();
}
public boolean isAbsolute()
{
return false;
}
public Object evaluate(Context context) throws JaxenException
{
List contextNodeSet = new ArrayList();
Map unique = new IdentityHashMap();
contextNodeSet.addAll( context.getNodeSet() );
Object eachContextNode = null;
Iterator stepIter = getSteps().iterator();
Step eachStep = null;
List newNodeSet = new ArrayList();
int contextSize = 0;
OUTTER:
while ( stepIter.hasNext() )
{
eachStep = (Step) stepIter.next();
contextSize = contextNodeSet.size();
INNER:
for ( int i = 0 ; i < contextSize ; ++i )
{
eachContextNode = contextNodeSet.get( i );
Iterator axisNodeIter = eachStep.axisIterator( eachContextNode,
context.getContextSupport() );
if ( axisNodeIter == null )
{
continue INNER;
}
Object eachAxisNode = null;
List interimSet=new ArrayList();
while ( axisNodeIter.hasNext() )
{
eachAxisNode = axisNodeIter.next();
// System.err.println( "----> " + eachAxisNode + " // " + eachStep.matches( eachAxisNode, context.getContextSupport() ) );
if ( eachStep.matches( eachAxisNode,
context.getContextSupport() ) )
{
if ( ! unique.containsKey( eachAxisNode ) )
{
unique.put( eachAxisNode,
PRESENT );
interimSet.add( eachAxisNode );
}
}
}
List filtered = eachStep.getPredicateSet().evaluatePredicates(interimSet,context.getContextSupport() );
newNodeSet.addAll(filtered);
}
contextNodeSet.clear();
contextNodeSet.addAll( newNodeSet );
newNodeSet.clear();
unique.clear();
}
return contextNodeSet;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultLogicalExpr.java 100644 0 0 6261 10525225063 30540 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultLogicalExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultLogicalExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
abstract class DefaultLogicalExpr extends DefaultTruthExpr
{
public DefaultLogicalExpr(Expr lhs,
Expr rhs)
{
super( lhs,
rhs );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultMinusExpr.java 100644 0 0 7620 10525225063 30261 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultMinusExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultMinusExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.jaxen.function.NumberFunction;
class DefaultMinusExpr extends DefaultAdditiveExpr
{
public DefaultMinusExpr(Expr lhs,
Expr rhs)
{
super( lhs,
rhs );
}
public String getOperator()
{
return "-";
}
public Object evaluate(Context context) throws JaxenException
{
Number lhsValue = NumberFunction.evaluate( getLHS().evaluate( context ),
context.getNavigator() );
Number rhsValue = NumberFunction.evaluate( getRHS().evaluate( context ),
context.getNavigator() );
double result = lhsValue.doubleValue() - rhsValue.doubleValue();
return new Double( result );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultModExpr.java 100644 0 0 7731 10525225063 27710 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultModExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultModExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.jaxen.function.NumberFunction;
class DefaultModExpr extends DefaultMultiplicativeExpr
{
public DefaultModExpr(Expr lhs,
Expr rhs)
{
super( lhs,
rhs );
}
public String getOperator()
{
return "mod";
}
public Object evaluate(Context context) throws JaxenException
{
Number lhsValue = NumberFunction.evaluate( getLHS().evaluate( context ),
context.getNavigator() );
Number rhsValue = NumberFunction.evaluate( getRHS().evaluate( context ),
context.getNavigator() );
assertInteger( lhsValue );
assertInteger( rhsValue );
int result = lhsValue.intValue() % rhsValue.intValue();
return new Double( result );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultMultiplicativeExpr.java 100644 0 0 6522 10525225063 32161 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultMultiplicativeExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultMultiplicativeExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
abstract class DefaultMultiplicativeExpr extends DefaultArithExpr
{
public DefaultMultiplicativeExpr(Expr lhs,
Expr rhs)
{
super( lhs,
rhs );
}
public String toString()
{
return "[(DefaultMultiplicativeExpr): " + getLHS() + ", " + getRHS() + "]";
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultMultiplyExpr.java 100644 0 0 7640 10525225063 31007 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultMultiplyExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultMultiplyExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.jaxen.function.NumberFunction;
class DefaultMultiplyExpr extends DefaultMultiplicativeExpr
{
public DefaultMultiplyExpr(Expr lhs,
Expr rhs)
{
super( lhs,
rhs );
}
public String getOperator()
{
return "*";
}
public Object evaluate(Context context) throws JaxenException
{
Number lhsValue = NumberFunction.evaluate( getLHS().evaluate( context ),
context.getNavigator() );
Number rhsValue = NumberFunction.evaluate( getRHS().evaluate( context ),
context.getNavigator() );
double result = lhsValue.doubleValue() * rhsValue.doubleValue();
return new Double( result );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultNameStep.java 100644 0 0 17770 10525225063 30072 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultNameStep.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultNameStep.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import org.xmlpull.v1.builder.xpath.jaxen.expr.iter.IterableAxis;
/** Expression object that represents any flavor
* of name-test steps within an XPath.
*
*
* This includes simple steps, such as "foo",
* non-default-axis steps, such as "following-sibling::foo"
* or "@foo", and namespace-aware steps, such
* as "foo:bar".
*
*
* @author bob mcwhirter (bob@werken.com)
*/
public class DefaultNameStep extends DefaultStep
{
/** Our prefix, bound through the current Context.
* The empty-string ("") if no prefix was specified.
* Decidedly NOT-NULL, due to SAXPath constraints.
*/
private String prefix;
/** Our local-name.*/
private String localName;
/** Quick flag denoting if the localname was '*' */
private boolean matchesAnyName;
public DefaultNameStep(IterableAxis axis,
String prefix,
String localName)
{
super( axis );
this.prefix = prefix;
this.localName = localName;
this.matchesAnyName = "*".equals( localName );
}
public String getPrefix()
{
return this.prefix;
}
public String getLocalName()
{
return this.localName;
}
public boolean isMatchesAnyName()
{
return matchesAnyName;
}
public String getText()
{
if ( ( getPrefix() != null )
&&
( ! getPrefix().equals("") ) )
{
return getAxisName() + "::" + getPrefix() + ":" + getLocalName() + super.getText();
}
return getAxisName()
+ "::" + getLocalName()
+ super.getText();
}
public String toString()
{
return "[(DefaultNameStep): " + getPrefix() + ":" + getLocalName() + "[" + super.toString() + "]]";
}
public boolean matches(Object node,
ContextSupport contextSupport)
{
//System.err.println( "DefaultNameStep.matches(" + node + ")" );
Navigator nav = contextSupport.getNavigator();
String myPrefix = getPrefix();
String myUri = null;
boolean hasPrefix = ( myPrefix != null ) && (! ( "".equals( myPrefix ) ) );
String nodeUri = null;
String nodeName = null;
if ( nav.isElement( node ) )
{
nodeUri = nav.getElementNamespaceUri( node );
nodeName = nav.getElementName( node );
}
else if ( nav.isAttribute( node ) )
{
nodeUri = nav.getAttributeNamespaceUri( node );
nodeName = nav.getAttributeName( node );
}
else if ( nav.isDocument( node ) )
{
return ( ! hasPrefix ) && matchesAnyName;
}
else if ( nav.isNamespace( node ) )
{
nodeUri = null;
nodeName = nav.getNamespacePrefix( node );
}
else
{
// * will only match elements on most axis
return false;
}
// System.out.println( "Matching nodeURI: " + nodeUri + " name: " + nodeName );
if ( hasPrefix )
{
myUri = contextSupport.translateNamespacePrefixToUri( myPrefix );
}
else if ( matchesAnyName )
{
return true;
}
// If we have a prefix that does not map to no namespace,
// but the node doesn't have *any* namespace-uri, then we fast-fail.
if ( ( myUri != null && !"".equals( myUri ) )
&&
( nodeUri == null || "".equals( nodeUri ) ) )
{
return false;
}
// If we don't have a prefix, but the node does
// have any namespace-uri, then we fast-fail.
if ( ! hasPrefix
&&
( nodeUri != null
&&
! "".equals( nodeUri ) ) )
{
return false;
}
// To fail-fast, we check the equality of
// local-names first. Shorter strings compare
// quicker.
if ( getLocalName().equals( nodeName )
||
matchesAnyName )
{
if ( ! hasPrefix )
{
return true;
}
return matchesNamespaceURIs( myUri,
nodeUri );
}
return false;
}
/** @return true if the two namespace URIs are equal
* Note that we may wish to consider null being equal to ""
*/
protected boolean matchesNamespaceURIs( String u1, String u2 ) {
//System.out.println( "Comparing URI: " + u1 + " against URI: " + u2 );
if ( u1 == u2 ) {
return true;
}
if ( u1 == null )
{
u1 = "";
}
if ( u2 == null )
{
u2 = "";
}
return u1.equals( u2 );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultNotEqualsExpr.java 100644 0 0 7246 10525225063 31105 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultNotEqualsExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultNotEqualsExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.function.NumberFunction;
class DefaultNotEqualsExpr extends DefaultEqualityExpr
{
public DefaultNotEqualsExpr( Expr lhs, Expr rhs )
{
super( lhs, rhs );
}
public String getOperator()
{
return "!=";
}
public String toString()
{
return "[(DefaultNotEqualsExpr): " + getLHS() + ", " + getRHS() + "]";
}
protected boolean evaluateObjectObject( Object lhs, Object rhs )
{
if( eitherIsNumber( lhs, rhs ) )
{
if( NumberFunction.isNaN( (Double) lhs ) || NumberFunction.isNaN( (Double) rhs ) )
{
return true;
}
}
return !lhs.equals( rhs );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultNumberExpr.java 100644 0 0 7050 10525225063 30413 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultNumberExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultNumberExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
class DefaultNumberExpr extends DefaultExpr implements NumberExpr
{
private Number number;
public DefaultNumberExpr(Number number)
{
this.number = number;
}
public Number getNumber()
{
return this.number;
}
public String toString()
{
return "[(DefaultNumberExpr): " + getNumber() + "]";
}
public String getText()
{
return getNumber().toString();
}
public Object evaluate(Context context)
{
return getNumber();
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultOrExpr.java 100644 0 0 10073 10525225063 27562 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultOrExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultOrExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import org.xmlpull.v1.builder.xpath.jaxen.function.BooleanFunction;
class DefaultOrExpr extends DefaultLogicalExpr
{
public DefaultOrExpr(Expr lhs,
Expr rhs)
{
super( lhs,
rhs );
}
public String getOperator()
{
return "or";
}
public String toString()
{
return "[(DefaultOrExpr): " + getLHS() + ", " + getRHS() + "]";
}
public Object evaluate(Context context) throws JaxenException
{
Navigator nav = context.getNavigator();
Boolean lhsValue = BooleanFunction.evaluate( getLHS().evaluate( context ), nav );
if ( lhsValue == Boolean.TRUE )
{
return Boolean.TRUE;
}
Boolean rhsValue = BooleanFunction.evaluate( getRHS().evaluate( context ), nav );
if ( rhsValue == Boolean.TRUE )
{
return Boolean.TRUE;
}
return Boolean.FALSE;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultPathExpr.java 100644 0 0 11760 10525225063 30102 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultPathExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultPathExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
class DefaultPathExpr extends DefaultExpr implements PathExpr
{
private Expr filterExpr;
private LocationPath locationPath;
public DefaultPathExpr(Expr filterExpr,
LocationPath locationPath)
{
this.filterExpr = filterExpr;
this.locationPath = locationPath;
}
public Expr getFilterExpr()
{
return this.filterExpr;
}
public void setFilterExpr(Expr filterExpr)
{
this.filterExpr = filterExpr;
}
public LocationPath getLocationPath()
{
return this.locationPath;
}
public String toString()
{
if ( getLocationPath() != null )
{
return "[(DefaultPathExpr): " + getFilterExpr() + ", " + getLocationPath() + "]";
}
return "[(DefaultPathExpr): " + getFilterExpr() + "]";
}
public String getText()
{
StringBuffer buf = new StringBuffer();
if ( getFilterExpr() != null )
{
buf.append( getFilterExpr().getText() );
}
if ( getLocationPath() != null )
{
buf.append( getLocationPath().getText() );
}
return buf.toString();
}
public Expr simplify()
{
if ( getFilterExpr() != null )
{
setFilterExpr( getFilterExpr().simplify() );
}
if ( getLocationPath() != null )
{
getLocationPath().simplify();
}
if ( getLocationPath() == null )
{
return getFilterExpr();
}
if ( getFilterExpr() == null )
{
return getLocationPath();
}
return this;
}
public Object evaluate(Context context) throws JaxenException
{
Object results = getFilterExpr().evaluate( context );
context.setNodeSet( convertToList( results ) );
return getLocationPath().evaluate( context );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultPlusExpr.java 100644 0 0 7620 10525225063 30111 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultPlusExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultPlusExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.jaxen.function.NumberFunction;
class DefaultPlusExpr extends DefaultAdditiveExpr
{
public DefaultPlusExpr(Expr lhs,
Expr rhs)
{
super( lhs,
rhs );
}
public String getOperator()
{
return "+";
}
public Object evaluate(Context context) throws JaxenException
{
Number lhsValue = NumberFunction.evaluate( getLHS().evaluate( context ),
context.getNavigator() );
Number rhsValue = NumberFunction.evaluate( getRHS().evaluate( context ),
context.getNavigator() );
double result = lhsValue.doubleValue() + rhsValue.doubleValue();
return new Double( result );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultPredicate.java 100644 0 0 7377 10525225063 30240 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultPredicate.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultPredicate.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
class DefaultPredicate implements Predicate
{
private Expr expr;
public DefaultPredicate(Expr expr)
{
setExpr( expr );
}
public Expr getExpr()
{
return this.expr;
}
public void setExpr(Expr expr)
{
this.expr = expr;
}
public String getText()
{
return "[" + getExpr().getText() + "]";
}
public String toString()
{
return "[(DefaultPredicate): " + getExpr() + "]";
}
public void simplify()
{
setExpr( getExpr().simplify() );
}
public Object evaluate(Context context) throws JaxenException
{
return getExpr().evaluate( context );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultPredicated.java 100644 0 0 10546 10525225063 30414 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultPredicated.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultPredicated.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
class DefaultPredicated
{
private List predicates;
protected DefaultPredicated()
{
this.predicates = new ArrayList();
}
public List getPredicates()
{
return this.predicates;
}
public void addPredicate(Predicate predicate)
{
getPredicates().add( predicate );
}
public String getText()
{
StringBuffer buf = new StringBuffer();
Iterator predIter = getPredicates().iterator();
while ( predIter.hasNext() )
{
buf.append( ((Predicate)predIter.next()).getText() );
}
return buf.toString();
}
public String toString()
{
StringBuffer buf = new StringBuffer();
Iterator predIter = getPredicates().iterator();
while( predIter.hasNext() )
{
buf.append( predIter.next().toString() );
if ( predIter.hasNext() )
{
buf.append(", ");
}
}
return buf.toString();
}
public void simplifyAllPredicates()
{
Iterator predIter = getPredicates().iterator();
Predicate eachPred = null;
while ( predIter.hasNext() )
{
eachPred = (Predicate) predIter.next();
eachPred.simplify();
}
}
}
././@LongLink 100644 0 0 155 10525225067 10260 L ustar 0 0 xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultProcessingInstructionNodeStep.java xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultProcessingInstructionNodeS100644 0 0 10117 10525225063 32731 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultProcessingInstructionNodeStep.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultProcessingInstructionNodeStep.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import org.xmlpull.v1.builder.xpath.jaxen.expr.iter.IterableAxis;
public class DefaultProcessingInstructionNodeStep extends DefaultStep
{
private String name;
public DefaultProcessingInstructionNodeStep(IterableAxis axis,
String name)
{
super( axis );
this.name = name;
}
public String getName()
{
return this.name;
}
public boolean matches(Object node,
ContextSupport support)
{
Navigator nav = support.getNavigator();
boolean isPi = nav.isProcessingInstruction( node );
if ( isPi )
{
String name = getName();
if ( name == null || "".equals( name ) )
{
return true;
}
else
{
return name.equals( nav.getProcessingInstructionTarget( node ) );
}
}
return false;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultRelationalExpr.java 100644 0 0 13005 10525225063 31272 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultRelationalExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultRelationalExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import java.util.List;
import java.util.Iterator;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.jaxen.function.NumberFunction;
abstract class DefaultRelationalExpr extends DefaultTruthExpr
{
public DefaultRelationalExpr( Expr lhs, Expr rhs )
{
super( lhs, rhs );
}
public String toString()
{
return "[(DefaultRelationalExpr): " + getLHS() + ", " + getRHS() + "]";
}
public Object evaluate( Context context ) throws JaxenException
{
Object lhsValue = getLHS().evaluate( context );
Object rhsValue = getRHS().evaluate( context );
Navigator nav = context.getNavigator();
if( bothAreSets( lhsValue, rhsValue ) )
{
return evaluateSetSet( (List) lhsValue, (List) rhsValue, nav );
}
if( eitherIsSet( lhsValue, rhsValue ) )
{
if( isSet( lhsValue ) )
{
return evaluateSetSet( (List) lhsValue, convertToList( rhsValue ), nav );
}
else
{
return evaluateSetSet( convertToList( lhsValue ), (List) rhsValue, nav );
}
}
return evaluateObjectObject( lhsValue, rhsValue, nav ) ? Boolean.TRUE : Boolean.FALSE;
}
private Object evaluateSetSet( List lhsSet, List rhsSet, Navigator nav )
{
if( setIsEmpty( lhsSet ) || setIsEmpty( rhsSet ) ) // return false if either is null or empty
{
return Boolean.FALSE;
}
for( Iterator lhsIterator = lhsSet.iterator(); lhsIterator.hasNext(); )
{
Object lhs = lhsIterator.next();
for( Iterator rhsIterator = rhsSet.iterator(); rhsIterator.hasNext(); )
{
Object rhs = rhsIterator.next();
if( evaluateObjectObject( lhs, rhs, nav ) )
{
return Boolean.TRUE;
}
}
}
return Boolean.FALSE;
}
private boolean evaluateObjectObject( Object lhs, Object rhs, Navigator nav )
{
if( lhs == null || rhs == null )
{
return false;
}
Double lhsNum = NumberFunction.evaluate( lhs, nav );
Double rhsNum = NumberFunction.evaluate( rhs, nav );
if( NumberFunction.isNaN( lhsNum ) || NumberFunction.isNaN( rhsNum ) )
{
return false;
}
return evaluateDoubleDouble( lhsNum, rhsNum );
}
protected abstract boolean evaluateDoubleDouble( Double lhs, Double rhs );
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultRelativeLocationPath.java 100644 0 0 6362 10525225063 32412 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultRelativeLocationPath.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultRelativeLocationPath.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
public class DefaultRelativeLocationPath extends DefaultLocationPath
{
public DefaultRelativeLocationPath()
{
}
public String toString()
{
return "[(DefaultRelativeLocationPath): " + super.toString() + "]";
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultStep.java 100644 0 0 11045 10525225063 27256 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultStep.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultStep.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
import org.xmlpull.v1.builder.xpath.jaxen.expr.iter.IterableAxis;
import org.xmlpull.v1.builder.xpath.saxpath.Axis;
import java.util.List;
import java.util.Iterator;
public abstract class DefaultStep implements Step
{
private IterableAxis axis;
private PredicateSet predicates;
public DefaultStep(IterableAxis axis)
{
this.axis = axis;
this.predicates = new PredicateSet();
}
public void addPredicate(Predicate predicate)
{
this.predicates.addPredicate( predicate );
}
public List getPredicates()
{
return this.predicates.getPredicates();
}
public PredicateSet getPredicateSet()
{
return this.predicates;
}
public int getAxis()
{
return this.axis.value();
}
public IterableAxis getIterableAxis()
{
return this.axis;
}
public String getAxisName()
{
return Axis.lookup( getAxis() );
}
public String getText()
{
return this.predicates.getText();
}
public String toString()
{
return getIterableAxis() + " " + super.toString();
}
public void simplify()
{
this.predicates.simplify();
}
public Iterator axisIterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException
{
return getIterableAxis().iterator( contextNode,
support );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultTextNodeStep.java 100644 0 0 7120 10525225063 30710 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultTextNodeStep.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultTextNodeStep.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import org.xmlpull.v1.builder.xpath.jaxen.expr.iter.IterableAxis;
public class DefaultTextNodeStep extends DefaultStep
{
public DefaultTextNodeStep(IterableAxis axis)
{
super( axis );
}
public boolean matches(Object node,
ContextSupport support)
{
Navigator nav = support.getNavigator();
return nav.isText( node );
}
public String getText()
{
return getAxisName() + "::text()" + super.getText();
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultTruthExpr.java 100644 0 0 11502 10525225063 30306 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultTruthExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultTruthExpr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import java.util.List;
abstract class DefaultTruthExpr extends DefaultBinaryExpr
{
public DefaultTruthExpr(Expr lhs,
Expr rhs)
{
super( lhs,
rhs );
}
public String toString()
{
return "[(DefaultTruthExpr): " + getLHS() + ", " + getRHS() + "]";
}
protected boolean bothAreSets(Object lhs,
Object rhs)
{
return ( lhs instanceof List
&&
rhs instanceof List );
}
protected boolean eitherIsSet(Object lhs,
Object rhs)
{
return ( lhs instanceof List
||
rhs instanceof List );
}
protected boolean isSet(Object obj)
{
return ( obj instanceof List );
}
protected boolean setIsEmpty( List set )
{
return (set == null || set.size() == 0);
}
protected boolean eitherIsBoolean(Object lhs,
Object rhs)
{
return ( lhs instanceof Boolean
||
rhs instanceof Boolean );
}
protected boolean bothAreBoolean(Object lhs,
Object rhs)
{
return ( lhs instanceof Boolean
&&
rhs instanceof Boolean );
}
protected boolean eitherIsNumber(Object lhs,
Object rhs)
{
return ( lhs instanceof Number
||
rhs instanceof Number );
}
protected boolean isNumber(Object obj)
{
return ( obj instanceof Number );
}
protected boolean isString(Object obj)
{
return ( obj instanceof String );
}
protected boolean isBoolean(Object obj)
{
return ( obj instanceof Boolean );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultUnaryExpr.java 100644 0 0 7702 10525225063 30265 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultUnaryExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultUnaryExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.jaxen.function.NumberFunction;
class DefaultUnaryExpr extends DefaultExpr implements UnaryExpr
{
private Expr expr;
public DefaultUnaryExpr(Expr expr)
{
this.expr = expr;
}
public Expr getExpr()
{
return this.expr;
}
public String toString()
{
return "[(DefaultUnaryExpr): " + getExpr() + "]";
}
public String getText()
{
return "-(" + getExpr().getText() + ")";
}
public Expr simplify()
{
expr = expr.simplify();
return this;
}
public Object evaluate(Context context) throws JaxenException
{
Number number = NumberFunction.evaluate( getExpr().evaluate( context ),
context.getNavigator() );
return new Double( number.doubleValue() * -1 );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultUnionExpr.java 100644 0 0 10465 10525225063 30277 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultUnionExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultUnionExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
public class DefaultUnionExpr extends DefaultBinaryExpr implements UnionExpr
{
public DefaultUnionExpr(Expr lhs,
Expr rhs)
{
super( lhs,
rhs );
}
public String getOperator()
{
return "|";
}
public String toString()
{
return "[(DefaultUnionExpr): " + getLHS() + ", " + getRHS() + "]";
}
public Object evaluate(Context context) throws JaxenException
{
List results = new ArrayList();
List lhsResults = convertToList( getLHS().evaluate( context ) );
List rhsResults = convertToList( getRHS().evaluate( context ) );
Set unique = new HashSet();
results.addAll( lhsResults );
unique.addAll( lhsResults );
Iterator rhsIter = rhsResults.iterator();
Object each = null;
while ( rhsIter.hasNext() )
{
each = rhsIter.next();
if ( ! unique.contains( each ) )
{
results.add( each );
unique.add( each );
}
}
return results;
}
}
././@LongLink 100644 0 0 145 10525225067 10257 L ustar 0 0 xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultVariableReferenceExpr.java xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultVariableReferenceExpr.java100644 0 0 10773 10525225063 32555 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultVariableReferenceExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultVariableReferenceExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.UnresolvableException;
class DefaultVariableReferenceExpr extends DefaultExpr implements VariableReferenceExpr
{
private String prefix;
private String variableName;
public DefaultVariableReferenceExpr(String prefix,
String variableName)
{
this.prefix = prefix;
this.variableName = variableName;
}
public String getPrefix()
{
return this.prefix;
}
public String getVariableName()
{
return this.variableName;
}
public String toString()
{
String prefix = getPrefix();
if ( prefix == null )
{
return "[(DefaultVariableReferenceExpr): " + getVariableName() + "]";
}
return "[(DefaultVariableReferenceExpr): " + getPrefix() + ":" + getVariableName() + "]";
}
public String getText()
{
String prefix = getPrefix();
if ( prefix == null )
{
return "$" + getVariableName();
}
return "$" + prefix + ":" + getVariableName();
}
public Object evaluate(Context context)
throws UnresolvableException
{
String namespaceURI =
context.translateNamespacePrefixToUri( getPrefix() );
return context.getVariableValue( namespaceURI,
getPrefix(),
getVariableName() );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultXPathExpr.java 100644 0 0 7544 10525225063 30217 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultXPathExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultXPathExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import java.util.List;
public class DefaultXPathExpr implements XPathExpr
{
private Expr rootExpr;
public DefaultXPathExpr(Expr rootExpr)
{
this.rootExpr = rootExpr;
}
public Expr getRootExpr()
{
return this.rootExpr;
}
public void setRootExpr(Expr rootExpr)
{
this.rootExpr = rootExpr;
}
public String toString()
{
return "[(DefaultXPath): " + getRootExpr() + "]";
}
public String getText()
{
return getRootExpr().getText();
}
public void simplify()
{
setRootExpr( getRootExpr().simplify() );
}
public List asList(Context context) throws JaxenException
{
return DefaultExpr.convertToList( getRootExpr().evaluate( context ) );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultXPathFactory.java 100644 0 0 31142 10525225063 30717 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/DefaultXPathFactory.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DefaultXPathFactory.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.jaxen.expr.iter.*;
import org.xmlpull.v1.builder.xpath.saxpath.Axis;
public class DefaultXPathFactory implements XPathFactory
{
public XPathExpr createXPath(Expr rootExpr) throws JaxenException
{
return new DefaultXPathExpr( rootExpr );
}
public PathExpr createPathExpr(FilterExpr filterExpr,
LocationPath locationPath) throws JaxenException
{
return new DefaultPathExpr( filterExpr,
locationPath );
}
public LocationPath createRelativeLocationPath() throws JaxenException
{
return new DefaultRelativeLocationPath();
}
public LocationPath createAbsoluteLocationPath() throws JaxenException
{
return new DefaultAbsoluteLocationPath();
}
public BinaryExpr createOrExpr(Expr lhs,
Expr rhs) throws JaxenException
{
return new DefaultOrExpr( lhs,
rhs );
}
public BinaryExpr createAndExpr(Expr lhs,
Expr rhs) throws JaxenException
{
return new DefaultAndExpr( lhs,
rhs );
}
public BinaryExpr createEqualityExpr(Expr lhs,
Expr rhs,
int equalityOperator) throws JaxenException
{
switch ( equalityOperator )
{
case EQUALS:
{
return new DefaultEqualsExpr( lhs,
rhs );
}
case NOT_EQUALS:
{
return new DefaultNotEqualsExpr( lhs,
rhs );
}
}
throw new JaxenException( "Unhandled operator in createEqualityExpr(): " + equalityOperator );
}
public BinaryExpr createRelationalExpr(Expr lhs,
Expr rhs,
int relationalOperator) throws JaxenException
{
switch ( relationalOperator )
{
case LESS_THAN:
{
return new DefaultLessThanExpr( lhs,
rhs );
}
case GREATER_THAN:
{
return new DefaultGreaterThanExpr( lhs,
rhs );
}
case LESS_THAN_EQUALS:
{
return new DefaultLessThanEqualExpr( lhs,
rhs );
}
case GREATER_THAN_EQUALS:
{
return new DefaultGreaterThanEqualExpr( lhs,
rhs );
}
}
throw new JaxenException( "Unhandled operator in createRelationalExpr(): " + relationalOperator );
}
public BinaryExpr createAdditiveExpr(Expr lhs,
Expr rhs,
int additiveOperator) throws JaxenException
{
switch ( additiveOperator )
{
case ADD:
{
return new DefaultPlusExpr( lhs,
rhs );
}
case SUBTRACT:
{
return new DefaultMinusExpr( lhs,
rhs );
}
}
throw new JaxenException( "Unhandled operator in createAdditiveExpr(): " + additiveOperator );
}
public BinaryExpr createMultiplicativeExpr(Expr lhs,
Expr rhs,
int multiplicativeOperator) throws JaxenException
{
switch ( multiplicativeOperator )
{
case MULTIPLY:
{
return new DefaultMultiplyExpr( lhs,
rhs );
}
case DIV:
{
return new DefaultDivExpr( lhs,
rhs );
}
case MOD:
{
return new DefaultModExpr( lhs,
rhs );
}
}
throw new JaxenException( "Unhandled operator in createMultiplicativeExpr(): " + multiplicativeOperator );
}
public Expr createUnaryExpr(Expr expr,
int unaryOperator) throws JaxenException
{
switch ( unaryOperator )
{
case NEGATIVE:
{
return new DefaultUnaryExpr( expr );
}
}
return expr;
}
public UnionExpr createUnionExpr(Expr lhs,
Expr rhs) throws JaxenException
{
return new DefaultUnionExpr( lhs,
rhs );
}
public FilterExpr createFilterExpr(Expr expr) throws JaxenException
{
return new DefaultFilterExpr( expr );
}
public FunctionCallExpr createFunctionCallExpr(String prefix,
String functionName) throws JaxenException
{
return new DefaultFunctionCallExpr( prefix,
functionName );
}
public NumberExpr createNumberExpr(int number) throws JaxenException
{
// return new DefaultNumberExpr( new Integer(number) );
return new DefaultNumberExpr( new Double(number) );
}
public NumberExpr createNumberExpr(double number) throws JaxenException
{
return new DefaultNumberExpr( new Double(number) );
}
public LiteralExpr createLiteralExpr(String literal) throws JaxenException
{
return new DefaultLiteralExpr( literal );
}
public VariableReferenceExpr createVariableReferenceExpr(String prefix,
String variable) throws JaxenException
{
return new DefaultVariableReferenceExpr( prefix,
variable );
}
public Step createNameStep(int axis,
String prefix,
String localName) throws JaxenException
{
IterableAxis iter = getIterableAxis( axis );
return new DefaultNameStep( iter,
prefix,
localName );
}
public Step createTextNodeStep(int axis) throws JaxenException
{
IterableAxis iter = getIterableAxis( axis );
return new DefaultTextNodeStep( iter );
}
public Step createCommentNodeStep(int axis) throws JaxenException
{
IterableAxis iter = getIterableAxis( axis );
return new DefaultCommentNodeStep( iter );
}
public Step createAllNodeStep(int axis) throws JaxenException
{
IterableAxis iter = getIterableAxis( axis );
return new DefaultAllNodeStep( iter );
}
public Step createProcessingInstructionNodeStep(int axis,
String piName) throws JaxenException
{
IterableAxis iter = getIterableAxis( axis );
return new DefaultProcessingInstructionNodeStep( iter,
piName );
}
public Predicate createPredicate(Expr predicateExpr) throws JaxenException
{
return new DefaultPredicate( predicateExpr );
}
protected IterableAxis getIterableAxis(int axis)
{
IterableAxis iter = null;
switch ( axis )
{
case Axis.CHILD:
{
iter = new IterableChildAxis( axis );
break;
}
case Axis.DESCENDANT:
{
iter = new IterableDescendantAxis( axis );
break;
}
case Axis.PARENT:
{
iter = new IterableParentAxis( axis );
break;
}
case Axis.FOLLOWING_SIBLING:
{
iter = new IterableFollowingSiblingAxis( axis );
break;
}
case Axis.PRECEDING_SIBLING:
{
iter = new IterablePrecedingSiblingAxis( axis );
break;
}
case Axis.FOLLOWING:
{
iter = new IterableFollowingAxis( axis );
break;
}
case Axis.PRECEDING:
{
iter = new IterablePrecedingAxis( axis );
break;
}
case Axis.ATTRIBUTE:
{
iter = new IterableAttributeAxis( axis );
break;
}
case Axis.NAMESPACE:
{
iter = new IterableNamespaceAxis( axis );
break;
}
case Axis.SELF:
{
iter = new IterableSelfAxis( axis );
break;
}
case Axis.DESCENDANT_OR_SELF:
{
iter = new IterableDescendantOrSelfAxis( axis );
break;
}
case Axis.ANCESTOR_OR_SELF:
{
iter = new IterableAncestorOrSelfAxis( axis );
break;
}
case Axis.ANCESTOR:
{
iter = new IterableAncestorAxis( axis );
break;
}
}
return iter;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/Expr.java 100644 0 0 7152 10525225063 25740 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/Expr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: Expr.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import java.io.Serializable;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
public interface Expr extends Serializable
{
String getText();
Expr simplify();
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
/*
List asList(Context context);
Iterator asIterator(Context context);
String asString(Context context);
Boolean asBoolean(Context context);
Number asNumber(Context context);
*/
Object evaluate(Context context) throws JaxenException;
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/FilterExpr.java 100644 0 0 6505 10525225063 27107 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/FilterExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: FilterExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
public interface FilterExpr extends Expr, Predicated
{
/** Evaluates the filter expression on the current context
* and returns true if at least one node matches.
*/
public boolean asBoolean(Context context) throws JaxenException;
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/FunctionCallExpr.java 100644 0 0 6101 10525225063 30233 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/FunctionCallExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: FunctionCallExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
public interface FunctionCallExpr extends Expr
{
void addParameter(Expr parameter);
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/LiteralExpr.java 100644 0 0 6014 10525225063 27251 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/LiteralExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: LiteralExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
public interface LiteralExpr extends Expr
{
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/LocationPath.java 100644 0 0 6226 10525225063 27410 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/LocationPath.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: LocationPath.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import java.util.List;
public interface LocationPath extends Expr
{
void addStep(Step step);
List getSteps();
String getText();
public boolean isAbsolute();
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/NumberExpr.java 100644 0 0 6011 10525225063 27102 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/NumberExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: NumberExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
public interface NumberExpr extends Expr
{
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/PathExpr.java 100644 0 0 6152 10525225063 26554 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/PathExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: PathExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
public interface PathExpr extends Expr
{
Expr getFilterExpr();
void setFilterExpr(Expr filterExpr);
LocationPath getLocationPath();
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/Predicate.java 100644 0 0 6465 10525225063 26730 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/Predicate.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:00 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: Predicate.java,v 1.2 2005/08/11 22:44:00 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import java.io.Serializable;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
public interface Predicate extends Serializable
{
Expr getExpr();
void setExpr(Expr expr);
void simplify();
String getText();
Object evaluate(Context context) throws JaxenException;
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/PredicateSet.java 100644 0 0 21466 10525225063 27422 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/PredicateSet.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: PredicateSet.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.jaxen.function.BooleanFunction;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
class PredicateSet implements Serializable
{
private List predicates;
public PredicateSet()
{
this.predicates = Collections.EMPTY_LIST;
}
public void addPredicate(Predicate predicate)
{
if ( this.predicates == Collections.EMPTY_LIST )
{
this.predicates = new ArrayList();
}
this.predicates.add( predicate );
}
public List getPredicates()
{
return this.predicates;
}
public void simplify()
{
Iterator predIter = this.predicates.iterator();
Predicate eachPred = null;
while ( predIter.hasNext() )
{
eachPred = (Predicate) predIter.next();
eachPred.simplify();
}
}
public String getText()
{
StringBuffer buf = new StringBuffer();
Iterator predIter = this.predicates.iterator();
Predicate eachPred = null;
while ( predIter.hasNext() )
{
eachPred = (Predicate) predIter.next();
buf.append( eachPred.getText() );
}
return buf.toString();
}
// XXXX: Note - this could be *MUCH* more efficient
// currently this creates many redundant collections and should halt
// evaluation on the first matching item.
protected boolean evaluateAsBoolean(List contextNodeSet,
ContextSupport support) throws JaxenException
{
List result = evaluatePredicates( contextNodeSet, support );
return ! result.isEmpty();
}
protected List evaluatePredicates(List contextNodeSet,
ContextSupport support) throws JaxenException
{
// Easy way out (necessary)
if (predicates.size()==0) return contextNodeSet;
List newNodeSet = new ArrayList();
List filterSet = contextNodeSet;
List predicates = getPredicates();
Iterator predIter = predicates.iterator();
Predicate eachPred = null;
Object contextNode = null;
Object predResult = null;
Context predContext = new Context( support );
// Filter the 'filterSet' against all predicates. This has been
// tuned for performance, so there are two separate loops
// In the first run, all nodes matching the first predicate will
// be copied from contextNodeSet to newNodeSet
// In the second loop, newNodeSet is filtered progressively against
// the remaining predicates, eliminating any non-matching nodes
if ( predIter.hasNext() )
{
eachPred = (Predicate) predIter.next();
int filterSize = filterSet.size();
for ( int i = 0 ; i < filterSize ; ++i )
{
contextNode = filterSet.get( i );
List list = new ArrayList( 1 );
list.add( contextNode );
predContext.setNodeSet( list );
predContext.setPosition( i + 1 );
predContext.setSize( filterSize );
predResult = eachPred.evaluate( predContext );
if ( predResult instanceof Number )
{
int proximity = ((Number)predResult).intValue();
if ( proximity == ( i + 1 ) )
{
newNodeSet.add( contextNode );
}
}
else
{
Boolean includes = BooleanFunction.evaluate( predResult, predContext.getNavigator() );
if ( includes.booleanValue() )
{
newNodeSet.add( contextNode );
}
}
}
}
// This will be true if any filtering takes place from here on
boolean nodesFiltered = false;
// Second loop: Filter filterSet until no more predicates are left
filterSet = newNodeSet;
while ( predIter.hasNext() )
{
eachPred = (Predicate) predIter.next();
int filterSize = filterSet.size();
for ( int i = 0 ; i < filterSize ; ++i )
{
contextNode = filterSet.get(i);
// Check if a node has been eliminated already
if (contextNode == null) continue;
List list = new ArrayList( 1 );
list.add( contextNode );
predContext.setNodeSet( list );
predContext.setPosition( i + 1 );
predContext.setSize( filterSize );
predResult = eachPred.evaluate( predContext );
if ( predResult instanceof Number )
{
int proximity = ((Number)predResult).intValue();
if ( proximity != ( i + 1 ) )
{
filterSet.set(i,null);
nodesFiltered = true;
}
}
else
{
Boolean includes = BooleanFunction.evaluate( predResult, predContext.getNavigator() );
if ( !includes.booleanValue() )
{
filterSet.set(i,null);
nodesFiltered = true;
}
}
}
}
// Go through the filtered set and delete any null nodes (if necessary)
if (nodesFiltered)
{
// System.err.println("FILTERING");
Iterator iter=filterSet.iterator();
while (iter.hasNext()) {
Object obj=iter.next();
if (obj==null)
iter.remove();
}
}
return filterSet;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/Predicated.java 100644 0 0 6260 10525225063 27065 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/Predicated.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: Predicated.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import java.io.Serializable;
import java.util.List;
public interface Predicated extends Serializable
{
void addPredicate(Predicate predicate);
List getPredicates();
PredicateSet getPredicateSet();
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/Step.java 100644 0 0 7134 10525225063 25735 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/Step.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: Step.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
import java.util.Iterator;
//public interface Step extends Predicated, Expr
public interface Step extends Predicated
{
boolean matches(Object node,
ContextSupport contextSupport);
String getText();
void simplify();
public int getAxis();
/*
Iterator asIterator(Iterator contextIterator,
ContextSupport support);
*/
Iterator axisIterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException;
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/UnaryExpr.java 100644 0 0 6031 10525225063 26752 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/UnaryExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: UnaryExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
public interface UnaryExpr extends Expr
{
Expr getExpr();
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/UnionExpr.java 100644 0 0 6013 10525225063 26744 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/UnionExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: UnionExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
public interface UnionExpr extends BinaryExpr
{
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/VariableReferenceExpr.java 100644 0 0 6052 10525225063 31223 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/VariableReferenceExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: VariableReferenceExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
public interface VariableReferenceExpr extends Expr
{
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/XPathExpr.java 100644 0 0 6522 10525225063 26705 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/XPathExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: XPathExpr.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import java.io.Serializable;
import java.util.List;
public interface XPathExpr extends Serializable
{
Expr getRootExpr();
void setRootExpr(Expr rootExpr);
String getText();
void simplify();
List asList(Context context) throws JaxenException;
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/XPathFactory.java 100644 0 0 13223 10525225063 27412 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/XPathFactory.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:36 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: XPathFactory.java,v 1.1 2004/06/16 15:55:36 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr;
import org.xmlpull.v1.builder.xpath.jaxen.JaxenException;
import org.xmlpull.v1.builder.xpath.saxpath.Operator;
public interface XPathFactory extends Operator
{
XPathExpr createXPath(Expr rootExpr) throws JaxenException;
PathExpr createPathExpr(FilterExpr filterExpr,
LocationPath locationPath) throws JaxenException;
LocationPath createRelativeLocationPath() throws JaxenException;
LocationPath createAbsoluteLocationPath() throws JaxenException;
BinaryExpr createOrExpr(Expr lhs,
Expr rhs) throws JaxenException;
BinaryExpr createAndExpr(Expr lhs,
Expr rhs) throws JaxenException;
BinaryExpr createEqualityExpr(Expr lhs,
Expr rhs,
int equalityOperator) throws JaxenException;
BinaryExpr createRelationalExpr(Expr lhs,
Expr rhs,
int relationalOperator) throws JaxenException;
BinaryExpr createAdditiveExpr(Expr lhs,
Expr rhs,
int additiveOperator) throws JaxenException;
BinaryExpr createMultiplicativeExpr(Expr lhs,
Expr rhs,
int multiplicativeOperator) throws JaxenException;
Expr createUnaryExpr(Expr expr,
int unaryOperator) throws JaxenException;
UnionExpr createUnionExpr(Expr lhs,
Expr rhs) throws JaxenException;
FilterExpr createFilterExpr(Expr expr) throws JaxenException;
FunctionCallExpr createFunctionCallExpr(String prefix,
String functionName) throws JaxenException;
NumberExpr createNumberExpr(int number) throws JaxenException;
NumberExpr createNumberExpr(double number) throws JaxenException;
LiteralExpr createLiteralExpr(String literal) throws JaxenException;
VariableReferenceExpr createVariableReferenceExpr(String prefix,
String variableName) throws JaxenException;
Step createNameStep(int axis,
String prefix,
String localName) throws JaxenException;
Step createAllNodeStep(int axis) throws JaxenException;
Step createCommentNodeStep(int axis) throws JaxenException;
Step createTextNodeStep(int axis) throws JaxenException;
Step createProcessingInstructionNodeStep(int axis,
String name) throws JaxenException;
Predicate createPredicate(Expr predicateExpr) throws JaxenException;
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableAncestorAxis.java 100644 0 0 6776 10525225063 32053 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableAncestorAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:01 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IterableAncestorAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr.iter;
import java.util.Iterator;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
public class IterableAncestorAxis extends IterableAxis
{
public IterableAncestorAxis(int value)
{
super( value );
}
public Iterator iterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException
{
return support.getNavigator().getAncestorAxisIterator( contextNode );
}
}
././@LongLink 100644 0 0 150 10525225067 10253 L ustar 0 0 xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableAncestorOrSelfAxis.java xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableAncestorOrSelfAxis.j100644 0 0 7034 10525225063 32462 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableAncestorOrSelfAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:01 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IterableAncestorOrSelfAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr.iter;
import java.util.Iterator;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
public class IterableAncestorOrSelfAxis extends IterableAxis
{
public IterableAncestorOrSelfAxis(int value)
{
super( value );
}
public Iterator iterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException
{
return support.getNavigator().getAncestorOrSelfAxisIterator( contextNode );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableAttributeAxis.java 100644 0 0 7003 10525225063 32220 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableAttributeAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:01 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IterableAttributeAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr.iter;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
import java.util.Iterator;
public class IterableAttributeAxis extends IterableAxis
{
public IterableAttributeAxis(int value)
{
super( value );
}
public Iterator iterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException
{
return support.getNavigator().getAttributeAxisIterator( contextNode );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableAxis.java 100644 0 0 7043 10525225063 30340 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:01 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IterableAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr.iter;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
import java.io.Serializable;
import java.util.Iterator;
public abstract class IterableAxis implements Serializable
{
private int value;
public IterableAxis(int axisValue)
{
this.value = axisValue;
}
public int value()
{
return this.value;
}
public abstract Iterator iterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException;
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableChildAxis.java 100644 0 0 6757 10525225063 31317 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableChildAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:01 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IterableChildAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr.iter;
import java.util.Iterator;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
public class IterableChildAxis extends IterableAxis
{
public IterableChildAxis(int value)
{
super( value );
}
public Iterator iterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException
{
return support.getNavigator().getChildAxisIterator( contextNode );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableDescendantAxis.java 100644 0 0 7010 10525225063 32323 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableDescendantAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:01 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IterableDescendantAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr.iter;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
import java.util.Iterator;
public class IterableDescendantAxis extends IterableAxis
{
public IterableDescendantAxis(int value)
{
super( value );
}
public Iterator iterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException
{
return support.getNavigator().getDescendantAxisIterator( contextNode );
}
}
././@LongLink 100644 0 0 152 10525225067 10255 L ustar 0 0 xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableDescendantOrSelfAxis.java xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableDescendantOrSelfAxis100644 0 0 7046 10525225063 32527 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableDescendantOrSelfAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:01 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IterableDescendantOrSelfAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr.iter;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
import java.util.Iterator;
public class IterableDescendantOrSelfAxis extends IterableAxis
{
public IterableDescendantOrSelfAxis(int value)
{
super( value );
}
public Iterator iterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException
{
return support.getNavigator().getDescendantOrSelfAxisIterator( contextNode );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableFollowingAxis.java 100644 0 0 7003 10525225063 32215 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableFollowingAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:01 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IterableFollowingAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr.iter;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
import java.util.Iterator;
public class IterableFollowingAxis extends IterableAxis
{
public IterableFollowingAxis(int value)
{
super( value );
}
public Iterator iterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException
{
return support.getNavigator().getFollowingAxisIterator( contextNode );
}
}
././@LongLink 100644 0 0 152 10525225067 10255 L ustar 0 0 xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableFollowingSiblingAxis.java xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableFollowingSiblingAxis100644 0 0 7046 10525225063 32614 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableFollowingSiblingAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:01 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IterableFollowingSiblingAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr.iter;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
import java.util.Iterator;
public class IterableFollowingSiblingAxis extends IterableAxis
{
public IterableFollowingSiblingAxis(int value)
{
super( value );
}
public Iterator iterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException
{
return support.getNavigator().getFollowingSiblingAxisIterator( contextNode );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableNamespaceAxis.java 100644 0 0 7003 10525225063 32151 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableNamespaceAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:01 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IterableNamespaceAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr.iter;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
import java.util.Iterator;
public class IterableNamespaceAxis extends IterableAxis
{
public IterableNamespaceAxis(int value)
{
super( value );
}
public Iterator iterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException
{
return support.getNavigator().getNamespaceAxisIterator( contextNode );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableParentAxis.java 100644 0 0 6764 10525225063 31523 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableParentAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:01 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IterableParentAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr.iter;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
import java.util.Iterator;
public class IterableParentAxis extends IterableAxis
{
public IterableParentAxis(int value)
{
super( value );
}
public Iterator iterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException
{
return support.getNavigator().getParentAxisIterator( contextNode );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterablePrecedingAxis.java 100644 0 0 7003 10525225063 32155 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterablePrecedingAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:01 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IterablePrecedingAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr.iter;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
import java.util.Iterator;
public class IterablePrecedingAxis extends IterableAxis
{
public IterablePrecedingAxis(int value)
{
super( value );
}
public Iterator iterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException
{
return support.getNavigator().getPrecedingAxisIterator( contextNode );
}
}
././@LongLink 100644 0 0 152 10525225067 10255 L ustar 0 0 xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterablePrecedingSiblingAxis.java xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterablePrecedingSiblingAxis100644 0 0 7046 10525225063 32554 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterablePrecedingSiblingAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:01 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IterablePrecedingSiblingAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr.iter;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
import java.util.Iterator;
public class IterablePrecedingSiblingAxis extends IterableAxis
{
public IterablePrecedingSiblingAxis(int value)
{
super( value );
}
public Iterator iterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException
{
return support.getNavigator().getPrecedingSiblingAxisIterator( contextNode );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableSelfAxis.java 100644 0 0 6752 10525225063 31160 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/expr/iter/IterableSelfAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:01 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IterableSelfAxis.java,v 1.2 2005/08/11 22:44:01 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.expr.iter;
import org.xmlpull.v1.builder.xpath.jaxen.ContextSupport;
import org.xmlpull.v1.builder.xpath.jaxen.UnsupportedAxisException;
import java.util.Iterator;
public class IterableSelfAxis extends IterableAxis
{
public IterableSelfAxis(int value)
{
super( value );
}
public Iterator iterator(Object contextNode,
ContextSupport support) throws UnsupportedAxisException
{
return support.getNavigator().getSelfAxisIterator( contextNode );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/BooleanFunction.java 100644 0 0 13663 10525225063 31002 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/BooleanFunction.java,v 1.2 2005/08/11 22:44:02 aslom Exp $
* $Revision: 1.2 $
* $Date: 2005/08/11 22:44:02 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: BooleanFunction.java,v 1.2 2005/08/11 22:44:02 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import java.util.List;
/**
* 4.3 boolean boolean(object )
*
* @author bob mcwhirter (bob @ werken.com)
*/
public class BooleanFunction implements Function
{
public Object call(Context context,
List args) throws FunctionCallException
{
if ( args.size() == 1 )
{
return evaluate( args.get(0), context.getNavigator() );
}
throw new FunctionCallException("boolean() requires one argument");
}
public static Boolean evaluate(Object obj, Navigator nav)
{
if ( obj instanceof List )
{
List list = (List) obj;
// if it's an empty list, then we have a null node-set -> false
if (list.size() == 0)
{
return Boolean.FALSE;
}
// otherwise, unwrap the list and check the primitive
obj = list.get(0);
}
// now check for primitive types
// otherwise a non-empty nodeset is true
// if it's a Boolean, let it decide
if ( obj instanceof Boolean )
{
return (Boolean) obj;
}
// if it's a Number, != 0 -> true
else if ( obj instanceof Number )
{
double d = ((Number) obj).doubleValue();
if ( d == 0 || d == Double.NaN )
{
return Boolean.FALSE;
}
return Boolean.TRUE;
}
// if it's a String, "" -> false
else if ( obj instanceof String )
{
return ( ((String)obj).length() > 0
? Boolean.TRUE
: Boolean.FALSE );
}
else
{
// assume its a node so that this nodeset is non-empty
// and so its true
return ( obj != null ) ? Boolean.TRUE : Boolean.FALSE;
}
/*
This is the old way to test nodes
- don't think this is correct and its certainly less efficient
else {
// convert to String if it's a special object type
if ( nav.isElement( obj ) )
{
obj = nav.getElementStringValue( obj );
}
else if ( nav.isAttribute( obj ) )
{
obj = nav.getAttributeStringValue( obj );
}
else if ( nav.isText( obj ) )
{
obj = nav.getTextStringValue( obj );
}
else if ( obj instanceof String )
{
return ( ((String)obj).length() > 0
? Boolean.TRUE
: Boolean.FALSE );
}
return Boolean.FALSE;
}
*/
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/CeilingFunction.java 100644 0 0 10003 10525225063 30756 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/CeilingFunction.java,v 1.1 2004/06/16 15:55:39 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:39 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: CeilingFunction.java,v 1.1 2004/06/16 15:55:39 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import java.util.List;
/**
* 4.4 number ceiling(number )
*
* @author bob mcwhirter (bob @ werken.com)
*/
public class CeilingFunction implements Function
{
public Object call(Context context,
List args) throws FunctionCallException
{
if (args.size() == 1)
{
return evaluate( args.get(0),
context.getNavigator() );
}
throw new FunctionCallException("ceiling() requires one argument.");
}
public static Double evaluate(Object obj,
Navigator nav)
{
Number value = NumberFunction.evaluate( obj,
nav );
return new Double( Math.ceil( value.doubleValue() ) );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/ConcatFunction.java 100644 0 0 10314 10525225063 30620 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/ConcatFunction.java,v 1.1 2004/06/16 15:55:39 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:39 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: ConcatFunction.java,v 1.1 2004/06/16 15:55:39 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import java.util.List;
import java.util.Iterator;
/**
* 4.2 string concat(string ,string ,string* )
*
* @author bob mcwhirter (bob@werken.com)
*/
public class ConcatFunction implements Function
{
public Object call(Context context,
List args) throws FunctionCallException
{
if ( args.size() >= 2 )
{
return evaluate( args,
context.getNavigator() );
}
throw new FunctionCallException("concat() requires at least two arguments");
}
public static String evaluate(List list,
Navigator nav)
{
StringBuffer result = new StringBuffer();
Iterator argIter = list.iterator();
while ( argIter.hasNext() )
{
result.append( StringFunction.evaluate( argIter.next(),
nav ) );
}
return result.toString();
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/ContainsFunction.java 100644 0 0 10460 10525225063 31171 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/ContainsFunction.java,v 1.1 2004/06/16 15:55:39 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:39 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: ContainsFunction.java,v 1.1 2004/06/16 15:55:39 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import java.util.List;
/**
* 4.2 boolean contains(string ,string )
*
* @author bob mcwhirter (bob @ werken.com)
*/
public class ContainsFunction implements Function
{
public Object call(Context context,
List args) throws FunctionCallException
{
if (args.size() == 2)
{
return evaluate(args.get(0),
args.get(1),
context.getNavigator() );
}
throw new FunctionCallException("contains() requires two arguments.");
}
public static Boolean evaluate(Object strArg,
Object matchArg,
Navigator nav)
{
String str = StringFunction.evaluate( strArg,
nav );
String match = StringFunction.evaluate( matchArg,
nav );
return ( ( str.indexOf(match) >= 0)
? Boolean.TRUE
: Boolean.FALSE
);
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/CountFunction.java 100644 0 0 7631 10525225063 30471 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/CountFunction.java,v 1.1 2004/06/16 15:55:39 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:39 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: CountFunction.java,v 1.1 2004/06/16 15:55:39 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import java.util.List;
/**
* 4.1 number count(node-set )
*
* @author bob mcwhirter (bob @ werken.com)
*/
public class CountFunction implements Function
{
public Object call(Context context,
List args) throws FunctionCallException
{
if (args.size() == 1)
{
return evaluate( args.get(0) );
}
throw new FunctionCallException( "count() requires one argument." );
}
public static Number evaluate(Object obj)
{
if( obj == null )
{
return new Double( 0 );
}
if (obj instanceof List)
{
return new Double( ((List)obj).size() );
}
return new Double( 1 );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/DocumentFunction.java 100644 0 0 7672 10525225063 31164 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/DocumentFunction.java,v 1.1 2004/06/16 15:55:39 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:39 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: DocumentFunction.java,v 1.1 2004/06/16 15:55:39 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import java.util.List;
public class DocumentFunction implements Function
{
public Object call(Context context,
List args) throws FunctionCallException
{
if (args.size() == 1)
{
Navigator nav = context.getNavigator();
String url = StringFunction.evaluate( args.get( 0 ),
nav );
return evaluate( url,
nav );
}
throw new FunctionCallException( "false() requires no arguments." );
}
public static Object evaluate(String url,
Navigator nav) throws FunctionCallException
{
return nav.getDocument( url );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/FalseFunction.java 100644 0 0 7255 10525225063 30435 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/FalseFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:40 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: FalseFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import java.util.List;
/**
* 4.3 boolean false()
*
* @author bob mcwhirter (bob @ werken.com)
*/
public class FalseFunction implements Function
{
public Object call(Context context,
List args) throws FunctionCallException
{
if (args.size() == 0)
{
return evaluate();
}
throw new FunctionCallException( "false() requires no arguments." );
}
public static Boolean evaluate()
{
return Boolean.FALSE;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/FloorFunction.java 100644 0 0 7772 10525225063 30470 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/FloorFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:40 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: FloorFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import java.util.List;
/**
* 4.4 number floor(number )
*
* @author bob mcwhirter (bob @ werken.com)
*/
public class FloorFunction implements Function
{
public Object call(Context context,
List args) throws FunctionCallException
{
if (args.size() == 1)
{
return evaluate( args.get(0),
context.getNavigator() );
}
throw new FunctionCallException( "floor() requires one argument." );
}
public static Double evaluate(Object obj,
Navigator nav)
{
Number value = NumberFunction.evaluate( obj,
nav );
return new Double( Math.floor( value.doubleValue() ) );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/IdFunction.java 100644 0 0 11463 10525225063 27753 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/IdFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:40 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: IdFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
/**
* 4.1 node-set id(object )
*
* @author Erwin Bolwidt (ejb @ klomp.org)
* @author J\u00e9r\u00f4me N\u00e8gre (jerome.negre @ e-xmlmedia.fr)
*/
public class IdFunction implements Function
{
public Object call (Context context, List args) throws FunctionCallException
{
if ( args.size() == 1 ) {
return evaluate( context.getNodeSet(),
args.get(0), context.getNavigator() );
}
throw new FunctionCallException( "id() requires one argument" );
}
public static List evaluate (List contextNodes, Object arg, Navigator nav)
{
List nodes = new ArrayList();
if (contextNodes.size() == 0)
return nodes;
Object contextNode = contextNodes.get(0);
if (arg instanceof List) {
Iterator iter = ((List)arg).iterator();
while (iter.hasNext()) {
String id = StringFunction.evaluate(iter.next(), nav);
nodes.addAll( evaluate( contextNodes, id, nav ) );
}
} else {
String ids = StringFunction.evaluate(arg, nav);
StringTokenizer tok = new StringTokenizer(ids, " \t\n\r");
while (tok.hasMoreTokens()) {
String id = tok.nextToken();
Object node = nav.getElementById(contextNode, id);
if (node != null) {
nodes.add(node);
}
}
}
return nodes;
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/LastFunction.java 100644 0 0 7325 10525225063 30304 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/LastFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:40 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: LastFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import java.util.List;
/**
* 4.1 number last()
*
* @author bob mcwhirter (bob @ werken.com)
*/
public class LastFunction implements Function
{
public Object call(Context context,
List args) throws FunctionCallException
{
if (args.size() == 0)
{
return evaluate( context );
}
throw new FunctionCallException( "last() requires no arguments." );
}
public static Double evaluate(Context context)
{
return new Double( context.getSize() );
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/LocalNameFunction.java 100644 0 0 11506 10525225063 31250 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/LocalNameFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:40 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: LocalNameFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import java.util.List;
/**
* 4.1 string local-name(node-set? )
*
* @author bob mcwhirter (bob @ werken.com)
*/
public class LocalNameFunction implements Function
{
public Object call(Context context,
List args) throws FunctionCallException
{
if ( args.size() == 0 )
{
return evaluate( context.getNodeSet(),
context.getNavigator() );
}
if ( args.size() == 1 )
{
return evaluate( args,
context.getNavigator() );
}
throw new FunctionCallException( "local-name() requires zero or one argument." );
}
public static String evaluate(List list,
Navigator nav)
{
if ( ! list.isEmpty() )
{
Object first = list.get(0);
if (first instanceof List)
{
return evaluate( (List) first,
nav );
}
else if ( nav.isElement( first ) )
{
return nav.getElementName( first );
}
else if ( nav.isAttribute( first ) )
{
return nav.getAttributeName( first );
}
else if ( nav.isProcessingInstruction( first ) )
{
return nav.getProcessingInstructionTarget( first );
}
else if ( nav.isNamespace( first ) )
{
return nav.getNamespacePrefix( first );
}
}
return "";
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/NameFunction.java 100644 0 0 11456 10525225063 30301 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/NameFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:40 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: NameFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import java.util.List;
/**
* 4.1 string name(node-set? )
*
* @author bob mcwhirter (bob @ werken.com)
*/
public class NameFunction implements Function
{
public Object call(Context context,
List args) throws FunctionCallException
{
if ( args.size() == 0 )
{
return evaluate( context.getNodeSet(),
context.getNavigator() );
}
if ( args.size() == 1 )
{
return evaluate( args,
context.getNavigator() );
}
throw new FunctionCallException( "name() requires zero or one argument." );
}
public static String evaluate(List list,
Navigator nav)
{
if ( ! list.isEmpty() )
{
Object first = list.get(0);
if (first instanceof List)
{
return evaluate( (List) first,
nav );
}
else if ( nav.isElement( first ) )
{
return nav.getElementQName( first );
}
else if ( nav.isAttribute( first ) )
{
return nav.getAttributeQName( first );
}
else if ( nav.isProcessingInstruction( first ) )
{
return nav.getProcessingInstructionTarget( first );
}
else if ( nav.isNamespace( first ) )
{
return nav.getNamespacePrefix( first );
}
}
return "";
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/NamespaceUriFunction.java 100644 0 0 11063 10525225063 31767 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/NamespaceUriFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:40 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: NamespaceUriFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import java.util.List;
/**
* 4.1 string namespace-uri(node-set? )
*
* @author bob mcwhirter (bob @ werken.com)
*/
public class NamespaceUriFunction implements Function
{
public Object call(Context context,
List args) throws FunctionCallException
{
if (args.size() == 0)
{
return evaluate( context.getNodeSet(),
context.getNavigator() );
}
if ( args.size() == 1 )
{
return evaluate( args,
context.getNavigator() );
}
throw new FunctionCallException( "namespace-uri() requires zero or one argument." );
}
public static String evaluate(List list,
Navigator nav)
{
if ( ! list.isEmpty() )
{
Object first = list.get(0);
if ( first instanceof List )
{
return evaluate( (List) first,
nav );
}
else if ( nav.isElement( first ) )
{
return nav.getElementNamespaceUri( first );
}
else if ( nav.isAttribute( first ) )
{
return nav.getAttributeNamespaceUri( first );
}
}
return "";
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/NormalizeSpaceFunction.java 100644 0 0 11061 10525225063 32325 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/NormalizeSpaceFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:40 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: NormalizeSpaceFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import java.util.List;
import java.util.StringTokenizer;
/**
* 4.2 string normalize-space(string )
*
* @author James Strachan (james@metastuff.com)
*/
public class NormalizeSpaceFunction implements Function
{
public Object call(Context context,
List args) throws FunctionCallException
{
if (args.size() >= 1)
{
return evaluate( args.get(0),
context.getNavigator() );
}
throw new FunctionCallException( "normalize-space() requires one argument" );
}
public static String evaluate(Object strArg,
Navigator nav)
{
String str = StringFunction.evaluate( strArg,
nav );
if ( str.length() <= 1 )
{
return str;
}
StringBuffer buffer = new StringBuffer();
boolean first = true;
StringTokenizer tokenizer = new StringTokenizer(str);
while ( tokenizer.hasMoreTokens() )
{
if (first)
{
first = false;
}
else
{
buffer.append(" ");
}
buffer.append(tokenizer.nextToken());
}
return buffer.toString();
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/NotFunction.java 100644 0 0 7643 10525225063 30144 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/NotFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:40 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: NotFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import java.util.List;
/**
* 4.3 boolean not(boolean )
*
* @author bob mcwhirter (bob @ werken.com)
*/
public class NotFunction implements Function
{
public Object call(Context context,
List args) throws FunctionCallException
{
if (args.size() == 1)
{
return evaluate( args.get(0), context.getNavigator() );
}
throw new FunctionCallException( "not() requires one argument." );
}
public static Boolean evaluate(Object obj, Navigator nav)
{
return ( ( BooleanFunction.evaluate( obj, nav ).booleanValue() )
? Boolean.FALSE
: Boolean.TRUE
);
}
}
xpp3-1.1.4c/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/NumberFunction.java 100644 0 0 12121 10525225063 30637 0 ustar aslom ewww 0 0 /*
* $Header: /l/extreme/cvs/codes/XPP3/java/src/java/xpath/org/xmlpull/v1/builder/xpath/jaxen/function/NumberFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
* $Revision: 1.1 $
* $Date: 2004/06/16 15:55:40 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter and
* James Strachan . For more information on the
* Jaxen Project, please see .
*
* $Id: NumberFunction.java,v 1.1 2004/06/16 15:55:40 aslom Exp $
*/
package org.xmlpull.v1.builder.xpath.jaxen.function;
import org.xmlpull.v1.builder.xpath.jaxen.Context;
import org.xmlpull.v1.builder.xpath.jaxen.Function;
import org.xmlpull.v1.builder.xpath.jaxen.FunctionCallException;
import org.xmlpull.v1.builder.xpath.jaxen.Navigator;
import java.util.List;
import java.util.Iterator;
/**
*