use of org.xml.sax.EntityResolver in project j2objc by google.
the class XMLFilterImplTest method testGetSetEntityResolver.
public void testGetSetEntityResolver() {
EntityResolver resolver = new MockResolver();
parent.setEntityResolver(resolver);
assertEquals(resolver, parent.getEntityResolver());
parent.setEntityResolver(null);
assertEquals(null, parent.getEntityResolver());
}
use of org.xml.sax.EntityResolver in project jangaroo-tools by CoreMedia.
the class ExmlValidator method setupSAXParser.
private SAXParser setupSAXParser() throws IOException {
try {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
ExmlSchemaResolver exmlSchemaResolver = new ExmlSchemaResolver();
schemaFactory.setResourceResolver(exmlSchemaResolver);
List<Source> schemas = new ArrayList<Source>();
schemas.add(new StreamSource(getClass().getResourceAsStream(Exmlc.EXML_SCHEMA_LOCATION), "exml"));
schemas.add(new StreamSource(getClass().getResourceAsStream(Exmlc.EXML_UNTYPED_SCHEMA_LOCATION), "untyped"));
Collection<ExmlSchemaSource> exmlSchemaSources = exmlSchemaSourceByNamespace.values();
for (ExmlSchemaSource exmlSchemaSource : exmlSchemaSources) {
schemas.add(exmlSchemaSource.newStreamSource());
}
Schema exmlSchema = schemaFactory.newSchema(schemas.toArray(new Source[schemas.size()]));
final SAXParserFactory saxFactory = SAXParserFactory.newInstance();
saxFactory.setNamespaceAware(true);
saxFactory.setSchema(exmlSchema);
SAXParser saxParser = saxFactory.newSAXParser();
saxParser.getXMLReader().setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
// To change body of implemented methods use File | Settings | File Templates.
return null;
}
});
return saxParser;
} catch (ParserConfigurationException e) {
throw new IllegalStateException("A default dom builder should be provided.", e);
} catch (SAXParseException e) {
// SAX parser error while parsing EXML schemas: log only, will cause error or warning, depending on configuration:
logSAXParseException(null, e, true);
return null;
} catch (SAXException e) {
throw new IllegalStateException("SAX parser does not support validation.", e);
}
}
use of org.xml.sax.EntityResolver in project tomcat by apache.
the class Digester method getXMLReader.
/**
* Return the XMLReader to be used for parsing the input document.
*
* FIX ME: there is a bug in JAXP/XERCES that prevent the use of a
* parser that contains a schema with a DTD.
* @return the XML reader
* @exception SAXException if no XMLReader can be instantiated
*/
public XMLReader getXMLReader() throws SAXException {
if (reader == null) {
reader = getParser().getXMLReader();
}
reader.setDTDHandler(this);
reader.setContentHandler(this);
EntityResolver entityResolver = getEntityResolver();
if (entityResolver == null) {
entityResolver = this;
}
// Wrap the resolver so we can perform ${...} property replacement
if (entityResolver instanceof EntityResolver2) {
entityResolver = new EntityResolver2Wrapper((EntityResolver2) entityResolver, source, classLoader);
} else {
entityResolver = new EntityResolverWrapper(entityResolver, source, classLoader);
}
reader.setEntityResolver(entityResolver);
reader.setProperty("http://xml.org/sax/properties/lexical-handler", this);
reader.setErrorHandler(this);
return reader;
}
use of org.xml.sax.EntityResolver in project tinker by Tencent.
the class JavaXmlUtil method getDocumentBuilder.
/**
* get document builder
*
* @return DocumentBuilder
*/
private static DocumentBuilder getDocumentBuilder() {
DocumentBuilder documentBuilder = null;
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
try {
documentBuilder = documentBuilderFactory.newDocumentBuilder();
// Block any external content resolving actions since we don't need them and a report
// says these actions may cause security problems.
documentBuilder.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
return new InputSource();
}
});
} catch (Exception e) {
throw new JavaXmlUtilException(e);
}
return documentBuilder;
}
use of org.xml.sax.EntityResolver in project tinker by Tencent.
the class AndroidParser method parse.
private void parse() throws ParserException {
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
Document document;
try {
DocumentBuilder builder = builderFactory.newDocumentBuilder();
// Block any external content resolving actions since we don't need them and a report
// says these actions may cause security problems.
builder.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
return new InputSource();
}
});
document = builder.parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));
Node manifestNode = document.getElementsByTagName("manifest").item(0);
NodeList nodes = manifestNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
String nodeName = node.getNodeName();
if (nodeName.equals("application")) {
NodeList children = node.getChildNodes();
for (int j = 0; j < children.getLength(); j++) {
Node child = children.item(j);
String childName = child.getNodeName();
switch(childName) {
case "service":
services.add(getAndroidComponent(child, TYPE_SERVICE));
break;
case "activity":
activities.add(getAndroidComponent(child, TYPE_ACTIVITY));
break;
case "receiver":
receivers.add(getAndroidComponent(child, TYPE_BROADCAST_RECEIVER));
break;
case "provider":
providers.add(getAndroidComponent(child, TYPE_CONTENT_PROVIDER));
break;
case "meta-data":
NamedNodeMap attributes = child.getAttributes();
metaDatas.put(getAttribute(attributes, "android:name"), getAttribute(attributes, "android:value"));
break;
default:
break;
}
}
}
}
} catch (Exception e) {
throw new ParserException("Error parsing AndroidManifest.xml", e);
}
}
Aggregations