public AtmosphereConfig parse(AtmosphereConfig config, String filename) throws FileNotFoundException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { return parse(config, factory.newDocumentBuilder().parse(filename)); } catch (SAXException e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } catch (IOException e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } catch (ParserConfigurationException e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } }
Document document = null; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(f); if (sxe.getException() != null) x = sxe.getException(); x.printStackTrace(); throw sxe; } catch (ParserConfigurationException pce) { pce.printStackTrace(); throw pce; } catch (IOException ioe) {
private static DocumentBuilder getParser() { try { // we'd really like to cache those DocumentBuilders, but we can't because: // 1. thread safety. parsers are not thread-safe, so at least // we need one instance per a thread. // 2. parsers are non-reentrant, so now we are looking at having a // pool of parsers. // 3. then the class loading issue. The look-up procedure of // DocumentBuilderFactory.newInstance() depends on context class loader // and system properties, which may change during the execution of JVM. // // so we really have to create a fresh DocumentBuilder every time we need one // - KK DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware( true ); dbf.setValidating( false ); return dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { // this should never happen with a well-behaving JAXP implementation. throw new Error(e.toString()); } }
throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(namespaceAware); factory.setValidating(true); if (validationMode == XmlValidationModeDetector.VALIDATION_XSD) { ParserConfigurationException pcex = new ParserConfigurationException( "Unable to validate using XSD: Your JAXP provider [" + factory + "] does not support XML Schema. Are you running on Java 1.4 with Apache Crimson? " + "Upgrade to Apache Xerces (or Java 1.5) for full XSD support."); pcex.initCause(ex); throw pcex;
public void createFiles(OutputStream fos) throws IOException { try { final ScxmlStateDiagramStandard xmi; xmi = new ScxmlStateDiagramStandard(diagram); xmi.transformerXml(fos); } catch (ParserConfigurationException e) { Log.error(e.toString()); e.printStackTrace(); throw new IOException(e.toString()); } catch (TransformerException e) { Log.error(e.toString()); e.printStackTrace(); throw new IOException(e.toString()); } }
/** * Handle reading of the input (object) from the kettle repository by getting the job-xml from the repository step * attribute string and then re-hydrate the job entry (object) with our already existing read method. * * @param object * @param rep * @param id_step * @param databases * @throws KettleException */ public static void readJobRep( Object object, Repository rep, ObjectId id_step, List<DatabaseMeta> databases ) throws KettleException { try { String jobXML = rep.getJobEntryAttributeString( id_step, "job-xml" ); ByteArrayInputStream bais = new ByteArrayInputStream( jobXML.getBytes() ); Document doc = XMLParserFactoryProducer.createSecureDocBuilderFactory().newDocumentBuilder().parse( bais ); read( object, doc.getDocumentElement() ); } catch ( ParserConfigurationException ex ) { throw new KettleException( ex.getMessage(), ex ); } catch ( SAXException ex ) { throw new KettleException( ex.getMessage(), ex ); } catch ( IOException ex ) { throw new KettleException( ex.getMessage(), ex ); } }
public static String getHello() { try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); DOMImplementation domImpl = docBuilder.getDOMImplementation(); // Root elements. Document doc = domImpl.createDocument(s_namespace, "nc:hello", null); // Client capacity. We are only supporting basic capacity. Element capabilities = doc.createElement("nc:capabilities"); Element capability = doc.createElement("nc:capability"); capability.setTextContent("urn:ietf:params:xml:ns:netconf:base:1.0"); capabilities.appendChild(capability); doc.getDocumentElement().appendChild(capabilities); return serialize(domImpl, doc); } catch (ParserConfigurationException e) { s_logger.error("Error while creating hello message : " + e.getMessage()); return null; } catch (DOMException e) { s_logger.error("Error while creating hello message : " + e.getMessage()); return null; } }
protected void initialize() { try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setNamespaceAware(true); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); _docResponse = docBuilder.parse(new InputSource(new StringReader(_xmlResponse))); if (_docResponse != null) { parse(_docResponse.getDocumentElement()); } } catch (ParserConfigurationException e) { s_logger.error("Error parsing the response : " + e.toString()); } catch (SAXException e) { s_logger.error("Error parsing the response : " + e.toString()); } catch (IOException e) { s_logger.error("Error parsing the response : " + e.toString()); } }
/** * Load profiler data from a file. * */ public static void loadProfilerData(String file, Collection data, Collection datainfo) throws IOException { try { InputStream is = new FileInputStream(file); SAXParser saxp = XMLHelper.getParser(); ProfilerXMLHandler handler = new ProfilerXMLHandler(data, datainfo); saxp.parse( is, handler); is.close(); // Now, these is the kind of codeyour teached warned you for: } catch(SAXException sae) { throw new IOException(sae.getMessage() ); } catch(ParserConfigurationException pce) { throw new IOException(pce.getMessage() ); } } }
DocumentBuilder builder = factory.newDocumentBuilder(); builder.setEntityResolver(secureEntityResolver); Document document = builder.parse(is); result = new DOMSource(document); } catch (ParserConfigurationException e) { if (debug > 0) { log(e.getMessage(), e); log(e.getMessage(), e); if (is != null) { try { is.close(); } catch (IOException e) {
private DOMSource readDOMSource(InputStream body, HttpInputMessage inputMessage) throws IOException { try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setFeature( "http://apache.org/xml/features/disallow-doctype-decl", !isSupportDtd()); documentBuilderFactory.setFeature( DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); if (!isProcessExternalEntities()) { documentBuilder.setEntityResolver(NO_OP_ENTITY_RESOLVER); Document document = documentBuilder.parse(body); return new DOMSource(document); "Could not set feature: " + ex.getMessage(), ex, inputMessage); "Could not parse document: " + ex.getMessage(), ex, inputMessage);
public FilterRunner(IRapidView rapidView, boolean limitLevel){ mLimitLevel = limitLevel; mRapidView = rapidView; try{ mFactory = DocumentBuilderFactory.newInstance(); mBuilder = mFactory.newDocumentBuilder(); mDocument = mBuilder.newDocument(); } catch (ParserConfigurationException e){ e.printStackTrace(); } }
protected void loadXML() throws IOException { try { SAXParserFactory factory = SAXParserFactory.newInstance(); XMLReader xr = factory.newSAXParser().getXMLReader(); rules = new HashMap<String, JSGFRule>(); GrXMLHandler handler = new GrXMLHandler(baseURL, rules, logger); xr.setContentHandler(handler); xr.setErrorHandler(handler); InputStream is = baseURL.openStream(); xr.parse(new InputSource(is)); is.close(); } catch (SAXParseException e) { String msg = "Error while parsing line " + e.getLineNumber() + " of " + baseURL + ": " + e.getMessage(); throw new IOException(msg); } catch (SAXException e) { throw new IOException("Problem with XML: " + e); } catch (ParserConfigurationException e) { throw new IOException(e.getMessage()); } return; }
@Override public Element createElement(String tagName) throws DOMException { if (this.xmlDocument == null) { try { this.xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch (ParserConfigurationException ex) { throw new DOMException(DOMException.INVALID_STATE_ERR, ex.toString()); } } return this.xmlDocument.createElement(tagName); }
(source instanceof DOMSource && ((DOMSource)source).getNode()==null)){ try { DocumentBuilderFactory builderF = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderF.newDocumentBuilder(); String systemID = source.getSystemId(); source = new DOMSource(builder.newDocument()); throw new TransformerException(e.getMessage());
protected void printResponse() { try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); DOMImplementationLS ls = (DOMImplementationLS)docBuilder.getDOMImplementation(); LSSerializer lss = ls.createLSSerializer(); System.out.println(lss.writeToString(_docResponse)); } catch (ParserConfigurationException e) { s_logger.error("Error parsing the repsonse : " + e.toString()); } } }
public DefaultConfiguration(String key) { DocumentBuilder builder = null; try { builder = DBF.newDocumentBuilder(); } catch (ParserConfigurationException e) { e.printStackTrace(); throw new IllegalStateException(e); } Document doc = builder.newDocument(); // create the root element node element = doc.createElement(key); doc.appendChild(element); }
/** * Creates new form YunSuTest */ public YunSuTest() { dbf = DocumentBuilderFactory.newInstance(); try { db = dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { e.printStackTrace(); } initComponents(); }
if (validating) { if (validatingFactory == null) { throw new ParserConfigurationException("No validating parser factory available"); } else if (!validatingFactory.isValidating()) { throw new ParserConfigurationException("factory should be validating but isn't"); builder = validatingFactory.newDocumentBuilder(); assert builder.isValidating(); builder.setErrorHandler(new ErrorHandler() { public void error(SAXParseException e) throws SAXParseException { throw e; builder = factory.newDocumentBuilder();
/** * Use the suitably configured DocumentBuilderFactory to provide * a new instance of DocumentBuilder. Remember that DocumentBuilder is not thread-safe! * @return * @since 3.2.0 */ public static DocumentBuilder getNewDocumentBuilder() { synchronized (documentBuilderFactory) { // see https://community.oracle.com/thread/1626108 for inconclusive discussion about whether a pool would be worthwhile try { return documentBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { // Catch this, since its unlikely to happen log.error(e.getMessage(), e); return null; } } }