use of org.xml.sax.SAXException in project j2objc by google.
the class ProcessorExsltFunction method validate.
/**
* Non-recursive traversal of FunctionElement tree based on TreeWalker to verify that
* there are no literal result elements except within a func:result element and that
* the func:result element does not contain any following siblings except xsl:fallback.
*/
public void validate(ElemTemplateElement elem, StylesheetHandler handler) throws SAXException {
String msg = "";
while (elem != null) {
//System.out.println("elem " + elem);
if (elem instanceof ElemExsltFuncResult && elem.getNextSiblingElem() != null && !(elem.getNextSiblingElem() instanceof ElemFallback)) {
msg = "func:result has an illegal following sibling (only xsl:fallback allowed)";
handler.error(msg, new SAXException(msg));
}
if ((elem instanceof ElemApplyImport || elem instanceof ElemApplyTemplates || elem instanceof ElemAttribute || elem instanceof ElemCallTemplate || elem instanceof ElemComment || elem instanceof ElemCopy || elem instanceof ElemCopyOf || elem instanceof ElemElement || elem instanceof ElemLiteralResult || elem instanceof ElemNumber || elem instanceof ElemPI || elem instanceof ElemText || elem instanceof ElemTextLiteral || elem instanceof ElemValueOf) && !(ancestorIsOk(elem))) {
msg = "misplaced literal result in a func:function container.";
handler.error(msg, new SAXException(msg));
}
ElemTemplateElement nextElem = elem.getFirstChildElem();
while (nextElem == null) {
nextElem = elem.getNextSiblingElem();
if (nextElem == null)
elem = elem.getParentElem();
if (elem == null || elem instanceof ElemExsltFunction)
// ok
return;
}
elem = nextElem;
}
}
use of org.xml.sax.SAXException in project j2objc by google.
the class SerializerUtils method addAttribute.
/**
* Copy an DOM attribute to the created output element, executing
* attribute templates as need be, and processing the xsl:use
* attribute.
*
* @param handler SerializationHandler to which the attributes are added.
* @param attr Attribute node to add to SerializationHandler.
*
* @throws TransformerException
*/
public static void addAttribute(SerializationHandler handler, int attr) throws TransformerException {
TransformerImpl transformer = (TransformerImpl) handler.getTransformer();
DTM dtm = transformer.getXPathContext().getDTM(attr);
if (SerializerUtils.isDefinedNSDecl(handler, attr, dtm))
return;
String ns = dtm.getNamespaceURI(attr);
if (ns == null)
ns = "";
// %OPT% ...can I just store the node handle?
try {
handler.addAttribute(ns, dtm.getLocalName(attr), dtm.getNodeName(attr), "CDATA", dtm.getNodeValue(attr), false);
} catch (SAXException e) {
// do something?
}
}
use of org.xml.sax.SAXException in project j2objc by google.
the class ElemAttribute method constructNode.
/**
* Construct a node in the result tree. This method is overloaded by
* xsl:attribute. At this class level, this method creates an element.
*
* @param nodeName The name of the node, which may be null.
* @param prefix The prefix for the namespace, which may be null.
* @param nodeNamespace The namespace of the node, which may be null.
* @param transformer non-null reference to the the current transform-time state.
* @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
* @param mode reference, which may be null, to the <a href="http://www.w3.org/TR/xslt#modes">current mode</a>.
*
* @throws TransformerException
*/
void constructNode(String nodeName, String prefix, String nodeNamespace, TransformerImpl transformer) throws TransformerException {
if (null != nodeName && nodeName.length() > 0) {
SerializationHandler rhandler = transformer.getSerializationHandler();
// Evaluate the value of this attribute
String val = transformer.transformToString(this);
try {
// Let the result tree handler add the attribute and its String value.
String localName = QName.getLocalPart(nodeName);
if (prefix != null && prefix.length() > 0) {
rhandler.addAttribute(nodeNamespace, localName, nodeName, "CDATA", val, true);
} else {
rhandler.addAttribute("", localName, nodeName, "CDATA", val, true);
}
} catch (SAXException e) {
}
}
}
use of org.xml.sax.SAXException in project j2objc by google.
the class XMLReaderManager method getXMLReader.
/**
* Retrieves a cached XMLReader for this thread, or creates a new
* XMLReader, if the existing reader is in use. When the caller no
* longer needs the reader, it must release it with a call to
* {@link #releaseXMLReader}.
*/
public synchronized XMLReader getXMLReader() throws SAXException {
XMLReader reader;
boolean readerInUse;
if (m_readers == null) {
// When the m_readers.get() method is called for the first time
// on a thread, a new XMLReader will automatically be created.
m_readers = new ThreadLocal();
}
if (m_inUse == null) {
m_inUse = new Hashtable();
}
// If the cached reader for this thread is in use, construct a new
// one; otherwise, return the cached reader.
reader = (XMLReader) m_readers.get();
boolean threadHasReader = (reader != null);
if (!threadHasReader || m_inUse.get(reader) == Boolean.TRUE) {
try {
try {
// According to JAXP 1.2 specification, if a SAXSource
// is created using a SAX InputSource the Transformer or
// TransformerFactory creates a reader via the
// XMLReaderFactory if setXMLReader is not used
reader = XMLReaderFactory.createXMLReader();
} catch (Exception e) {
try {
// the XMLReader from JAXP
if (m_parserFactory == null) {
m_parserFactory = SAXParserFactory.newInstance();
m_parserFactory.setNamespaceAware(true);
}
reader = m_parserFactory.newSAXParser().getXMLReader();
} catch (ParserConfigurationException pce) {
// pass along pce
throw pce;
}
}
try {
reader.setFeature(NAMESPACES_FEATURE, true);
reader.setFeature(NAMESPACE_PREFIXES_FEATURE, false);
} catch (SAXException se) {
// Try to carry on if we've got a parser that
// doesn't know about namespace prefixes.
}
} catch (ParserConfigurationException ex) {
throw new SAXException(ex);
} catch (FactoryConfigurationError ex1) {
throw new SAXException(ex1.toString());
} catch (NoSuchMethodError ex2) {
} catch (AbstractMethodError ame) {
}
// a reader for this thread.
if (!threadHasReader) {
m_readers.set(reader);
m_inUse.put(reader, Boolean.TRUE);
}
} else {
m_inUse.put(reader, Boolean.TRUE);
}
return reader;
}
use of org.xml.sax.SAXException in project j2objc by google.
the class DocumentBuilderTest method testNewDocument.
/**
* javax.xml.parsers.DocumentBuilder#getSchema()
* TBD getSchema() is not supported
*/
/* public void test_getSchema() {
assertNull(db.getSchema());
SchemaFactory sf =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
try {
Schema schema = sf.newSchema();
dbf.setSchema(schema);
assertNotNull(dbf.newDocumentBuilder().getSchema());
} catch (ParserConfigurationException pce) {
fail("Unexpected ParserConfigurationException " + pce.toString());
} catch (SAXException sax) {
fail("Unexpected SAXException " + sax.toString());
}
}
*/
public void testNewDocument() {
Document d;
try {
d = dbf.newDocumentBuilder().newDocument();
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
assertNotNull(d);
assertNull(d.getDoctype());
assertNull(d.getDocumentElement());
assertNull(d.getNamespaceURI());
}
Aggregations