use of org.xml.sax.SAXParseException in project jackrabbit by apache.
the class ConfigurationParser method parseXML.
/**
* Parses the given XML document and returns the DOM root element.
* A custom entity resolver is used to make the included configuration
* file DTD available using the specified public identifiers.
*
* @see ConfigurationEntityResolver
* @param xml xml document
* @param validate whether the XML should be validated
* @return root element
* @throws ConfigurationException if the configuration document could
* not be read or parsed
*/
protected Element parseXML(InputSource xml, boolean validate) throws ConfigurationException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(validate);
DocumentBuilder builder = factory.newDocumentBuilder();
if (validate) {
builder.setErrorHandler(getErrorHandler());
}
builder.setEntityResolver(getEntityResolver());
Document document = builder.parse(xml);
return postParseModificationHook(document).getDocumentElement();
} catch (ParserConfigurationException e) {
throw new ConfigurationException("Unable to create configuration XML parser", e);
} catch (SAXParseException e) {
throw new ConfigurationException("Configuration file syntax error. (Line: " + e.getLineNumber() + " Column: " + e.getColumnNumber() + ")", e);
} catch (SAXException e) {
throw new ConfigurationException("Configuration file syntax error. ", e);
} catch (IOException e) {
throw new ConfigurationException("Configuration file could not be read.", e);
}
}
use of org.xml.sax.SAXParseException in project jackrabbit by apache.
the class DefaultLoginModuleTest method parseXML.
private static Element parseXML(InputSource xml, boolean validate) throws ConfigurationException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(validate);
DocumentBuilder builder = factory.newDocumentBuilder();
if (validate) {
builder.setErrorHandler(new ConfigurationErrorHandler());
}
builder.setEntityResolver(ConfigurationEntityResolver.INSTANCE);
Document document = builder.parse(xml);
return document.getDocumentElement();
} catch (ParserConfigurationException e) {
throw new ConfigurationException("Unable to create configuration XML parser", e);
} catch (SAXParseException e) {
throw new ConfigurationException("Configuration file syntax error. (Line: " + e.getLineNumber() + " Column: " + e.getColumnNumber() + ")", e);
} catch (SAXException e) {
throw new ConfigurationException("Configuration file syntax error. ", e);
} catch (IOException e) {
throw new ConfigurationException("Configuration file could not be read.", e);
}
}
use of org.xml.sax.SAXParseException in project karaf by apache.
the class FeatureDeploymentListener method parse.
protected Document parse(File artifact) throws Exception {
if (dbf == null) {
dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
}
DocumentBuilder db = dbf.newDocumentBuilder();
db.setErrorHandler(new ErrorHandler() {
public void warning(SAXParseException exception) throws SAXException {
}
public void error(SAXParseException exception) throws SAXException {
}
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
});
return db.parse(artifact);
}
use of org.xml.sax.SAXParseException in project karaf by apache.
the class FeatureDetector method parse.
/**
* Parse a features XML.
*
* @param artifact the features XML to parse.
* @return the parsed document.
* @throws Exception in case of parsing failure.
*/
private Document parse(File artifact) throws Exception {
DocumentBuilder db = dbf.newDocumentBuilder();
db.setErrorHandler(new ErrorHandler() {
public void warning(SAXParseException exception) throws SAXException {
}
public void error(SAXParseException exception) throws SAXException {
}
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
});
return db.parse(artifact);
}
use of org.xml.sax.SAXParseException in project jena by apache.
the class XMLLiteralType method isValid.
/**
* Test whether the given string is a legal lexical form
* of this datatype.
*/
@Override
public boolean isValid(final String lexicalForm) {
/*
* To check the lexical form we construct
* a dummy RDF/XML document and parse it with
* ARP. ARP performs an exclusive canonicalization,
* the dummy document has exactly one triple.
* If the lexicalForm is valid then the resulting
* literal found by ARP is unchanged.
* All other scenarios are either impossible
* or occur because the lexical form is invalid.
*/
final boolean[] status = new boolean[] { false, false, false };
// status[0] true on error or other reason to know that this is not well-formed
// status[1] true once first triple found
// status[2] the result (good if status[1] and not status[0]).
ARP arp = new ARP();
arp.getHandlers().setErrorHandler(new ErrorHandler() {
@Override
public void fatalError(SAXParseException e) {
status[0] = true;
}
@Override
public void error(SAXParseException e) {
status[0] = true;
}
@Override
public void warning(SAXParseException e) {
status[0] = true;
}
});
arp.getHandlers().setStatementHandler(new StatementHandler() {
@Override
public void statement(AResource a, AResource b, ALiteral l) {
/* this method is invoked exactly once
* while parsing the dummy document.
* The l argument is in exclusive canonical XML and
* corresponds to where the lexical form has been
* in the dummy document. The lexical form is valid
* iff it is unchanged.
*/
if (status[1] || !l.isWellFormedXML()) {
status[0] = true;
}
//throw new BrokenException("plain literal in XMLLiteral code.");
status[1] = true;
status[2] = l.toString().equals(lexicalForm);
}
@Override
public void statement(AResource a, AResource b, AResource l) {
status[0] = true;
//throw new BrokenException("resource valued RDF/XML in XMLLiteral code.");
}
});
try {
arp.load(new StringReader("<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n" + "<rdf:Description><rdf:value rdf:parseType='Literal'>" + lexicalForm + "</rdf:value>\n" + "</rdf:Description></rdf:RDF>"));
} catch (IOException ioe) {
throw new BrokenException(ioe);
} catch (SAXException s) {
return false;
}
return (!status[0]) && status[1] && status[2];
}
Aggregations