List of usage examples for javax.xml.parsers SAXParserFactory newSAXParser
public abstract SAXParser newSAXParser() throws ParserConfigurationException, SAXException;
From source file:org.iterx.miru.dispatcher.handler.factory.XmlHandlerChainParser.java
public void parse(StreamSource source) throws IOException { try {/*from w ww . j a va2s.c o m*/ SAXParserFactory factory; SAXParser parser; factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(true); parser = factory.newSAXParser(); parser.parse(source.getInputStream(), this); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { if (LOGGER.isErrorEnabled()) LOGGER.error(e); throw new IOException("Invalid xml stream [" + source + "]. " + e.getMessage()); } }
From source file:org.iterx.miru.handler.XmlHandlerMappingParser.java
public void parse(Resource resource) throws IOException { try {/*w w w .jav a2 s. c o m*/ SAXParserFactory factory; SAXParser parser; factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(true); parser = factory.newSAXParser(); parser.parse(resource.getInputStream(), this); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new IOException("Invalid xml stream: " + e.getMessage()); } }
From source file:org.jajuk.base.Collection.java
/** * Parse collection.xml file and put all collection information into memory * * @param file /*from ww w.j a v a2 s . c o m*/ * * @throws SAXException the SAX exception * @throws ParserConfigurationException the parser configuration exception * @throws JajukException the jajuk exception * @throws IOException Signals that an I/O exception has occurred. */ public static void load(File file) throws SAXException, ParserConfigurationException, JajukException, IOException { // If we load the regular collection.xml file, try to recover it from previous crash java.io.File regularFile = SessionService.getConfFileByPath(Const.FILE_COLLECTION); if (file.equals(regularFile)) { UtilSystem.recoverFileIfRequired(regularFile); } Log.debug("Loading: " + file.getName()); if (!file.exists()) { throw new JajukException(5, file.toString()); } lTime = System.currentTimeMillis(); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setValidating(false); spf.setNamespaceAware(false); // See http://xerces.apache.org/xerces-j/features.html for details spf.setFeature("http://xml.org/sax/features/external-general-entities", false); spf.setFeature("http://xml.org/sax/features/string-interning", true); SAXParser saxParser = spf.newSAXParser(); saxParser.parse(file.toURI().toURL().toString(), getInstance()); }
From source file:org.jamwiki.utils.XMLTopicFactory.java
/** * *//*from w w w . jav a 2 s. co m*/ public String importWikiXml(File file) throws Exception { //read ini params from file // TODO read all params from JAMWiki properties //importProps = Environment.loadProperties(PROPERTY_FILE_NAME); //For big file parsing System.setProperty("entityExpansionLimit", "1000000"); // Use an instance of ourselves as the SAX event handler // DefaultHandler handler = new XMLPageFactory(); // Use the default (non-validating) parser SAXParserFactory factory = SAXParserFactory.newInstance(); try { // Parse the input file SAXParser saxParser = factory.newSAXParser(); saxParser.parse(file, this); } catch (Throwable t) { logger.severe("Error by importing " + ((XMLTopicFactory) this).pageName, t); throw new Exception("Error by import: " + t.getMessage(), t); } return this.processedTopicName; }
From source file:org.jlibrary.core.search.extraction.XMLExtractor.java
public XMLExtractor() throws ExtractionException { try {/*w w w. jav a2s . c om*/ SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating(false); SAXParser saxParser = saxParserFactory.newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); xmlReader.setFeature("http://xml.org/sax/features/validation", false); xmlReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); parser = new XMLParser(xmlReader); } catch (Exception e) { throw new ExtractionException(e); } }
From source file:org.kalypso.gmlschema.types.SimpleDOMTypeHandler.java
@Override public void marshal(final Object value, final XMLReader reader, final URL context, final String gmlVersion) throws SAXException { try {// www .j a va2s .co m final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final DocumentBuilder builder = factory.newDocumentBuilder(); final Document document = builder.newDocument(); final Node node = internalMarshall(value, document, context); // value is encoded in xml in document object final StringWriter writer = new StringWriter(); XMLHelper.writeDOM(node, "UTF-8", writer); //$NON-NLS-1$ IOUtils.closeQuietly(writer); // value is encoded in string final String xmlString = writer.toString(); final InputSource input = new InputSource(new StringReader(xmlString)); final SAXParserFactory saxFac = SAXParserFactory.newInstance(); saxFac.setNamespaceAware(true); final SAXParser saxParser = saxFac.newSAXParser(); final XMLReader xmlReader = saxParser.getXMLReader(); xmlReader.setContentHandler(reader.getContentHandler()); xmlReader.parse(input); } catch (final SAXException saxe) { throw saxe; } catch (final Exception e) { throw new SAXException(e); } }
From source file:org.kalypso.mapserver.utils.MapFileUtilities.java
/** * This function loads a map file from XML. * * @param inputStream//from w ww . j av a 2s . c o m * The input stream. * @return The contents of the map file. */ public static Map loadFromXML(final InputStream inputStream) throws JAXBException, SAXException, ParserConfigurationException, IOException { /* Create the unmarshaller. */ final Unmarshaller unmarshaller = JC.createUnmarshaller(); /* Get the sax parser factory. */ final SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); spf.setXIncludeAware(true); /* Get the xml reader. */ final XMLReader xr = spf.newSAXParser().getXMLReader(); xr.setContentHandler(unmarshaller.getUnmarshallerHandler()); xr.parse(new InputSource(inputStream)); return (Map) unmarshaller.getUnmarshallerHandler().getResult(); }
From source file:org.kalypso.ogc.gml.GisTemplateHelper.java
public static final Gismapview loadGisMapView(final InputSource is) throws JAXBException, SAXException, ParserConfigurationException, IOException { final Unmarshaller unmarshaller = TemplateUtilities.createGismapviewUnmarshaller(); // XInclude awareness final SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true);/*w ww . j ava 2s . c o m*/ spf.setXIncludeAware(true); final XMLReader xr = spf.newSAXParser().getXMLReader(); xr.setContentHandler(unmarshaller.getUnmarshallerHandler()); xr.parse(is); return (Gismapview) unmarshaller.getUnmarshallerHandler().getResult(); }
From source file:org.kalypso.ogc.gml.serialize.GmlSerializer.java
private static XMLReader createXMLReader() throws ParserConfigurationException, SAXException { final SAXParserFactory saxFac = SAXParserFactory.newInstance(); saxFac.setNamespaceAware(true);/*from ww w . ja v a 2 s .c o m*/ final SAXParser saxParser = saxFac.newSAXParser(); // make namespace-prefixes visible to content handler // used to allow necessary schemas from gml document final XMLReader xmlReader = saxParser.getXMLReader(); xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", Boolean.TRUE); //$NON-NLS-1$ return xmlReader; }