List of usage examples for org.xml.sax XMLReader setProperty
public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException;
From source file:org.xwiki.portlet.view.HTMLStreamFilter.java
/** * {@inheritDoc}//from w w w . j a va 2s.c o m * * @see StreamFilter#filter(Reader, Writer) */ public void filter(Reader reader, Writer writer) { try { XMLReader xmlReader = XMLReaderFactory.createXMLReader("org.cyberneko.html.parsers.SAXParser"); xmlReader.setFeature("http://cyberneko.org/html/features/balance-tags/document-fragment", true); xmlReader.setProperty("http://cyberneko.org/html/properties/names/elems", "match"); xmlReader.setProperty("http://cyberneko.org/html/properties/names/attrs", "no-change"); XMLReader parent = xmlReader; for (XMLFilter filter : filters) { filter.setParent(parent); parent = filter; } XHTMLWriter xhtmlWriter = new XHTMLWriter(writer); xhtmlWriter.setParent(parent); xhtmlWriter.parse(new InputSource(reader)); } catch (Exception e) { LOG.error("Failed to rewrite servlet HTML.", e); } }
From source file:org.yawlfoundation.yawl.unmarshal.YawlXMLSpecificationValidator.java
/** * Sets the checker up for a run./*from ww w.j a va2 s.co m*/ * @param version the version of the schema * @return a reader configured to do the checking. * @throws SAXException */ private XMLReader setUpChecker(String version) throws SAXException { XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); if (YSpecification.isValidVersion(version)) { parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", getSchemaLocation(version)); } else { throw new RuntimeException("Version [" + version + "] is not valid version."); } parser.setContentHandler(this); parser.setErrorHandler(this); parser.setFeature("http://xml.org/sax/features/validation", true); parser.setFeature("http://apache.org/xml/features/validation/schema", true); parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true); return parser; }
From source file:xbird.xquery.dm.instance.DocumentTableModel.java
private static final XMLReader getXMLReader(final DocumentTableBuilder handler, final boolean parseAsHtml, final boolean resolveEntity) { final XMLReader myReader; try {/* w ww . j a v a 2s . co m*/ if (parseAsHtml) { Class clazz = ClassResolver.get(HTML_PARSER_CLASS); assert (clazz != null); myReader = ObjectUtils.<XMLReader>instantiate(clazz); } else { final SAXParserFactory factory; if (hasSunXerces) { factory = ObjectUtils .instantiate("com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl", null); } else { factory = SAXParserFactory.newInstance(); } factory.setNamespaceAware(true); SAXParser parser = factory.newSAXParser(); myReader = parser.getXMLReader(); } } catch (Exception e) { throw new XQRTException("Creating SAX XMLReader failed", e); } // setup handlers (requires saxHandler) myReader.setContentHandler(handler); try { myReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler); myReader.setFeature("http://xml.org/sax/features/validation", true); // Validate the document and report validity errors. if (!parseAsHtml) { myReader.setFeature("http://apache.org/xml/features/validation/dynamic", true); // The parser will validate the document only if a grammar is specified. myReader.setFeature("http://apache.org/xml/features/validation/schema", true); // Turn on XML Schema validation by inserting an XML Schema validator into the pipeline. } } catch (Exception e) { throw new XQRTException("Configuaring SAX XMLReader failed.", e); } // setup entity resolver if (resolveEntity) { org.apache.xml.resolver.CatalogManager catalog = org.apache.xml.resolver.CatalogManager .getStaticManager(); catalog.setIgnoreMissingProperties(true); catalog.setPreferPublic(true); catalog.setUseStaticCatalog(false); EntityResolver resolver = new org.apache.xml.resolver.tools.CatalogResolver(catalog); myReader.setEntityResolver(resolver); } return myReader; }