List of usage examples for javax.xml.parsers SAXParserFactory newInstance
public static SAXParserFactory newInstance()
From source file:eionet.gdem.conversion.excel.ExcelProcessor.java
/** * Converts XML string to OutputStream/* w w w .ja va2s.c o m*/ * @param sIn Input string * @param sOut OutputStream * @throws GDEMException In case an error occurs. */ public void makeExcel(String sIn, OutputStream sOut) throws GDEMException { if (sIn == null) { return; } if (sOut == null) { return; } try { ExcelConversionHandlerIF excel = ExcelUtils.getExcelConversionHandler(); //excel.setFileName(sOut); ExcelXMLHandler handler = new ExcelXMLHandler(excel); SAXParserFactory spfact = SAXParserFactory.newInstance(); SAXParser parser = spfact.newSAXParser(); XMLReader reader = parser.getXMLReader(); spfact.setValidating(true); reader.setContentHandler(handler); reader.parse(sIn); excel.writeToFile(sOut); } catch (Exception e) { throw new GDEMException("Error generating Excel file: " + e.toString(), e); } return; }
From source file:Main.java
private static XMLReader makeXMLReader() throws ParserConfigurationException, SAXException { final SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true);//ww w .j av a2 s . co m final XMLReader reader = factory.newSAXParser().getXMLReader(); return reader; }
From source file:com.xhsoft.framework.common.init.ConfigLoad.java
/** * <p>Description:?xmlString?</p> * @param strFilePath /* w ww . j a v a 2 s .com*/ * @return String * @author wenzhi * @version 1.0 */ public void parser(String strFilePath) { try { /**??*/ InputStream stream = this.getClass().getResourceAsStream(strFilePath); if (stream == null) { log.warn(strFilePath + " not found"); } /**SAXParser??*/ SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser saxParser = spf.newSAXParser(); saxParser.parse(stream, this); /** ??*/ this.loadConfig(this.configMap); } catch (Exception ex) { log.error(" " + strFilePath + " ! ?."); ex.printStackTrace(); } }
From source file:net.lightbody.bmp.proxy.jetty.xml.XmlParser.java
/** * Construct/* w w w . j a v a2s .com*/ */ public XmlParser() { try { SAXParserFactory factory = SAXParserFactory.newInstance(); boolean notValidating = Boolean.getBoolean("net.lightbody.bmp.proxy.jetty.xml.XmlParser.NotValidating"); factory.setValidating(!notValidating); _parser = factory.newSAXParser(); try { if (!notValidating) _parser.getXMLReader().setFeature("http://apache.org/xml/features/validation/schema", true); } catch (Exception e) { log.warn("Schema validation may not be supported"); log.debug("", e); notValidating = true; } _parser.getXMLReader().setFeature("http://xml.org/sax/features/validation", !notValidating); _parser.getXMLReader().setFeature("http://xml.org/sax/features/namespaces", !notValidating); _parser.getXMLReader().setFeature("http://xml.org/sax/features/namespace-prefixes", !notValidating); } catch (Exception e) { log.warn(LogSupport.EXCEPTION, e); throw new Error(e.toString()); } }
From source file:com.tyndalehouse.step.tools.modules.ConvertXmlToOSISModule.java
private void convertToXml(final String moduleName, final File osisSource) throws Exception { LOGGER.debug("Reading [{}]", moduleName); SAXParserFactory spf = SAXParserFactory.newInstance(); final SAXParser saxParser = spf.newSAXParser(); final ExtractHeaderInformationSax header = new ExtractHeaderInformationSax(); saxParser.parse(osisSource, header); LOGGER.debug(//ww w. j av a 2 s . co m "title:[{}], description:[{}], copyright:[{}], license:[{}], language:[{}], versification:[{}]", header.getTitle(), header.getDescription(), header.getCopyright(), header.getLicense(), header.getLanguage(), header.getVersification()); String sanitizedModuleName = moduleName.replace("-", "").toLowerCase(); File outputDirectory = new File(BASE_OUTPUT, sanitizedModuleName); outputDirectory.mkdirs(); BASE_ERRORS.mkdirs(); // // LOGGER.debug("Converting [{}] to OSIS Module", sanitizedModuleName); // Process p = Runtime.getRuntime().exec(String.format("osis2mod %s %s -z -v %s", outputDirectory.getAbsolutePath(), osisSource.getAbsolutePath(), header.getVersification())); // LOGGER.debug("Conversion of [{}] finished.", sanitizedModuleName); // outputErrors(p, moduleName); // p.waitFor(); outputConfFile(header, sanitizedModuleName, FileUtils.sizeOfDirectory(outputDirectory)); }
From source file:com.spoledge.util.xml.XMLValidator.java
private void init(Schema schema) { spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); spf.setSchema(schema); }
From source file:com.openbravo.pos.printer.TicketParser.java
public void printTicket(Reader in) throws TicketPrinterException { try {//from w ww . j a v a 2s . c o m if (m_sp == null) { SAXParserFactory spf = SAXParserFactory.newInstance(); m_sp = spf.newSAXParser(); } m_sp.parse(new InputSource(in), this); } catch (ParserConfigurationException ePC) { throw new TicketPrinterException(LocalRes.getIntString("exception.parserconfig"), ePC); } catch (SAXException eSAX) { throw new TicketPrinterException(LocalRes.getIntString("exception.xmlfile"), eSAX); } catch (IOException eIO) { throw new TicketPrinterException(LocalRes.getIntString("exception.iofile"), eIO); } }
From source file:io.dataapps.chlorine.finder.DefaultFinderProvider.java
DefaultFinderProvider(InputStream in, final boolean ignoreEnabledFlag) { try {/*from w w w . j a va2s.c o m*/ SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); DefaultHandler handler = new DefaultHandler() { boolean bName = false; boolean bPattern = false; boolean bClass = false; boolean bEnabled = false; boolean bFlags = false; String name = ""; String pattern = ""; String className = ""; String strFlags = ""; int flags = RegexFinder.DEFAULT_FLAGS; String strEnabled = ""; boolean enabled = true; public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equalsIgnoreCase("NAME")) { bName = true; } else if (qName.equalsIgnoreCase("PATTERN")) { bPattern = true; } else if (qName.equalsIgnoreCase("CLASS")) { bClass = true; } else if (qName.equalsIgnoreCase("FLAGS")) { bFlags = true; } else if (qName.equalsIgnoreCase("ENABLED")) { bEnabled = true; } } public void endElement(String uri, String localName, String qName) throws SAXException { if (qName.equalsIgnoreCase("NAME")) { bName = false; name = name.trim(); } else if (qName.equalsIgnoreCase("PATTERN")) { bPattern = false; pattern = pattern.trim(); } else if (qName.equalsIgnoreCase("CLASS")) { bClass = false; className = className.trim(); } else if (qName.equalsIgnoreCase("FLAGS")) { bFlags = false; flags = Integer.parseInt(strFlags.trim()); } else if (qName.equalsIgnoreCase("ENABLED")) { bEnabled = false; enabled = Boolean.parseBoolean(strEnabled.trim()); } else if (qName.equalsIgnoreCase("FINDER")) { if (ignoreEnabledFlag || enabled) { if (!className.isEmpty()) { try { Class<?> klass = Thread.currentThread().getContextClassLoader() .loadClass(className); finders.add((Finder) klass.newInstance()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { LOG.error(e); } } else if (flags != RegexFinder.DEFAULT_FLAGS) { finders.add(new RegexFinder(name, pattern, flags)); } else { finders.add(new RegexFinder(name, pattern)); } } name = ""; pattern = ""; className = ""; flags = RegexFinder.DEFAULT_FLAGS; strFlags = ""; enabled = true; strEnabled = ""; } } public void characters(char ch[], int start, int length) throws SAXException { if (bName) { name += new String(ch, start, length); } else if (bPattern) { pattern += new String(ch, start, length); } else if (bClass) { className += new String(ch, start, length); } else if (bEnabled) { strEnabled += new String(ch, start, length); } else if (bFlags) { strFlags += new String(ch, start, length); } } }; saxParser.parse(in, handler); } catch (Exception e) { LOG.error(e); } }
From source file:me.crime.loader.DataBaseLoader.java
public DataBaseLoader() { classMap_.put("ciras.db.Crime", Crime.class.getName()); classMap_.put("ciras.db.Address", Address.class.getName()); classMap_.put("ciras.db.Arrested", Arrested.class.getName()); classMap_.put("ciras.db.URCCatagories", URCCatagories.class.getName()); classMap_.put("ciras.db.GeoPoint", GeoPoint.class.getName()); try {//from ww w . ja v a 2 s .c o m SAXParserFactory factory = SAXParserFactory.newInstance(); parser_ = factory.newSAXParser(); } catch (ParserConfigurationException e) { DataBaseLoader.log_.error(e); } catch (SAXException e) { DataBaseLoader.log_.error(e); } }
From source file:com.zyz.mobile.book.UserBookData.java
/** * open the info xml file. create one if it cannot be found *///from w w w .java2 s .c om public boolean parse() { try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader reader = sp.getXMLReader(); reader.setContentHandler(this); reader.parse(new InputSource(new FileReader(mInfoFile))); } catch (Exception e) { // constructor doesn't check for validity of the file // catch all exceptions here Log.e(TAG, "Failed to parse xml file?"); return false; } return true; }