Methods Summary |
---|
public boolean | getFeature(java.lang.String name)Return the current value of the feature with given name.
NOTE: factory features are not used for XML Serializer.
Boolean value = (Boolean) features.get(name);
return value != null ? value.booleanValue() : false;
|
public boolean | isNamespaceAware()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 getFeature (XmlPullParser.FEATURE_PROCESS_NAMESPACES);
|
public boolean | isValidating()Indicates whether or not the factory is configured to produce parsers
which validate the XML content during parse.
return getFeature (XmlPullParser.FEATURE_VALIDATION);
|
public static org.xmlpull.v1.XmlPullParserFactory | newInstance()Create a new instance of a PullParserFactory that can be used
to create XML pull parsers (see class description for more
details).
return newInstance(null, null);
|
public static org.xmlpull.v1.XmlPullParserFactory | newInstance(java.lang.String classNames, java.lang.Class context)
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+"'";
}
*/
classNames = "org.kxml2.io.KXmlParser,org.kxml2.io.KXmlSerializer";
XmlPullParserFactory factory = null;
final ArrayList parserClasses = new ArrayList();
final ArrayList serializerClasses = new ArrayList();
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.add(candidate);
recognized = true;
}
if (instance instanceof XmlSerializer) {
serializerClasses.add(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 = "org.kxml2.io.kXmlParser,org.kxml2.io.KXmlSerializer";
return factory;
|
public org.xmlpull.v1.XmlPullParser | newPullParser()Creates a new instance of a XML Pull Parser
using the currently configured factory features.
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.get(i);
try {
final XmlPullParser pp = (XmlPullParser) ppClass.newInstance();
for (Iterator iter = features.keySet().iterator(); iter.hasNext(); ) {
final String key = (String) iter.next();
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);
|
public org.xmlpull.v1.XmlSerializer | newSerializer()Creates a new instance of a XML Serializer.
NOTE: factory features are not used for XML Serializer.
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.get(i);
try {
final XmlSerializer ser = (XmlSerializer) ppClass.newInstance();
return ser;
} catch(Exception ex) {
issues.append (ppClass.getName () + ": "+ ex.toString ()+"; ");
}
}
throw new XmlPullParserException ("could not create serializer: "+issues);
|
public void | setFeature(java.lang.String name, boolean state)Set the features to be set when XML Pull Parser is created by this factory.
NOTE: factory features are not used for XML Serializer.
features.put(name, new Boolean(state));
|
public void | setNamespaceAware(boolean awareness)Specifies that the parser produced by this factory will provide
support for XML namespaces.
By default the value of this is set to false.
features.put (XmlPullParser.FEATURE_PROCESS_NAMESPACES, new Boolean (awareness));
|
public void | setValidating(boolean validating)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.
features.put (XmlPullParser.FEATURE_VALIDATION, new Boolean (validating));
|