List of usage examples for javax.xml.parsers SAXParserFactory setNamespaceAware
public void setNamespaceAware(boolean awareness)
From source file:org.iterx.miru.handler.XmlHandlerMappingParser.java
public void parse(Resource resource) throws IOException { try {//from w w w. j a v a2 s.co 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 www. j av a 2s . c om * * @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.jbpm.jpdl.internal.convert.Jpdl3ConverterParser.java
private static SAXParserFactory createSaxParserFactory() { SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating(true); saxParserFactory.setNamespaceAware(true); return saxParserFactory; }
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. ja va2 s.com*/ 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 ww w.j a va 2 s .co 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); spf.setXIncludeAware(true);/*from w ww. java 2 s . c o m*/ 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); 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; }
From source file:org.kalypsodeegree_impl.io.sax.test.TriangulatedSurfaceContentHandlerTest.java
private GM_TriangulatedSurface readTriangles(final InputSource is) throws IOException, ParserConfigurationException, SAXException { final SAXParserFactory saxFac = SAXParserFactory.newInstance(); saxFac.setNamespaceAware(true); final SAXParser saxParser = saxFac.newSAXParser(); // make namespace-prefixes visible to content handler // used to allow necessary schemas from gml document final XMLReader reader = saxParser.getXMLReader(); reader.setFeature("http://xml.org/sax/features/namespace-prefixes", Boolean.TRUE); //$NON-NLS-1$ final GM_TriangulatedSurface[] result = new GM_TriangulatedSurface[1]; final UnmarshallResultEater resultEater = new UnmarshallResultEater() { @Override/*w w w . jav a 2 s . com*/ public void unmarshallSuccesful(final Object value) { assertTrue(value instanceof GM_TriangulatedSurface); result[0] = (GM_TriangulatedSurface) value; } }; final TriangulatedSurfaceContentHandler contentHandler = new TriangulatedSurfaceContentHandler(reader, resultEater); reader.setContentHandler(contentHandler); reader.parse(is); return result[0]; }
From source file:org.kitodo.production.plugin.opac.pica.GetOpac.java
private OpacResponseHandler parseOpacResponse(String opacResponse) throws IOException, SAXException, ParserConfigurationException { opacResponse = opacResponse.replace("&amp;", "&").replace("&quot;", """) .replace("&lt;", "<").replace("&gt;", ">"); XMLReader parser = null;/*w w w. j av a 2 s . c o m*/ OpacResponseHandler ids = new OpacResponseHandler(); /* Use Java 1.4 methods to create default parser. */ SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); parser = factory.newSAXParser().getXMLReader(); parser.setContentHandler(ids); parser.parse(new InputSource(new StringReader(opacResponse))); return ids; }
From source file:org.kuali.kra.test.OjbRepositoryMappingTest.java
/** * This method verifies the tables for a repository file * @throws SQLException//from w w w.j a va 2 s. com * @throws ParserConfigurationException * @throws SAXException * @throws IOException * @throws ClassNotFoundException */ private void verifyTableForRepository(String repositoryFilePath) throws SQLException, ParserConfigurationException, SAXException, IOException, ClassNotFoundException { //loading the driver class so that DriverManager can find it Class.forName(dsDriver); final Connection conn = DriverManager.getConnection(dsUrl, dsUser, dsPass); final DefaultHandler handler = new TableValidationHandler(conn); LOG.debug(String.format("Starting XML validation")); final InputStream repositoryStream = getFileResource(repositoryFilePath).getInputStream(); LOG.debug(String.format("Found repository url %s\n", repositoryFilePath)); final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating(true); saxParserFactory.setNamespaceAware(false); final SAXParser parser = saxParserFactory.newSAXParser(); try { parser.parse(repositoryStream, handler); } finally { try { conn.close(); } catch (Exception e) { } } }