Search in sources :

Example 56 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project tdi-studio-se by Talend.

the class ComplexSAXLooper method parse.

/**
     * Parse the XML file. Buffer the result in LoopEntry.
     * 
     * @param is InputStream
     */
public void parse(java.io.InputStream is, String charset) {
    this.charset = charset;
    Reader reader = null;
    try {
        DefaultHandler hd = null;
        SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
        if (rootPath == null || rootPath.equals("")) {
            hd = newHandler();
        } else {
            hd = newHandler2();
        }
        saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", hd);
        // routines.system.UnicodeReader.java is used to ignore the BOM of the source file.
        reader = new UnicodeReader(is, this.charset);
        org.xml.sax.InputSource inSource = new org.xml.sax.InputSource(reader);
        saxParser.parse(inSource, hd);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : UnicodeReader(org.talend.xml.sax.io.UnicodeReader) Reader(java.io.Reader) SAXParser(javax.xml.parsers.SAXParser) UnicodeReader(org.talend.xml.sax.io.UnicodeReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException)

Example 57 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project tdi-studio-se by Talend.

the class MetadataExportXmlCommandExt method execute.

/*
     * (non-Java)
     * 
     * @see org.talend.commons.ui.command.CommonCommand#execute()
     */
@Override
public void execute() {
    try {
        if (file != null) {
            file.createNewFile();
            if (extendedTableModel != null) {
                IMetadataTable currentTable = extendedTableModel.getMetadataTable();
                // get all the columns from the table
                if (currentTable != null) {
                    MetadataSchemaExt ext = new MetadataSchemaExt(extendedTableModel.getRowGenUI().getFunctionManager());
                    ext.saveColumnsToFile(file, currentTable);
                }
            }
        }
    } catch (IOException e) {
        ExceptionHandler.process(e);
    } catch (ParserConfigurationException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 58 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project mustangproject by ZUGFeRD.

the class ZUGFeRDImporter method parse.

public void parse() {
    DocumentBuilderFactory factory = null;
    DocumentBuilder builder = null;
    Document document = null;
    if (!extracted) {
        throw new RuntimeException("extract() or extractLowLevel() must be used before parsing.");
    }
    factory = DocumentBuilderFactory.newInstance();
    //otherwise we can not act namespace independend, i.e. use document.getElementsByTagNameNS("*",...
    factory.setNamespaceAware(true);
    try {
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException ex3) {
        // TODO Auto-generated catch block
        ex3.printStackTrace();
    }
    try {
        InputStream bais = new ByteArrayInputStream(rawXML);
        document = builder.parse(bais);
    } catch (SAXException ex1) {
        ex1.printStackTrace();
    } catch (IOException ex2) {
        ex2.printStackTrace();
    }
    NodeList ndList;
    // rootNode = document.getDocumentElement();
    // ApplicableSupplyChainTradeSettlement
    ndList = document.getDocumentElement().getElementsByTagNameNS("*", //$NON-NLS-1$
    "PaymentReference");
    for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
        Node booking = ndList.item(bookingIndex);
        // if there is a attribute in the tag number:value
        setForeignReference(booking.getTextContent());
    }
    /*
		ndList = document
				.getElementsByTagName("GermanBankleitzahlID"); //$NON-NLS-1$

		for (int bookingIndex = 0; bookingIndex < ndList
				.getLength(); bookingIndex++) {
			Node booking = ndList.item(bookingIndex);
			// if there is a attribute in the tag number:value
			setBIC(booking.getTextContent());

		}

		ndList = document.getElementsByTagName("ProprietaryID"); //$NON-NLS-1$

		for (int bookingIndex = 0; bookingIndex < ndList
				.getLength(); bookingIndex++) {
			Node booking = ndList.item(bookingIndex);
			// if there is a attribute in the tag number:value
			setIBAN(booking.getTextContent());

		}
			<ram:PayeePartyCreditorFinancialAccount>
					<ram:IBANID>DE1234</ram:IBANID>
				</ram:PayeePartyCreditorFinancialAccount>
				<ram:PayeeSpecifiedCreditorFinancialInstitution>
					<ram:BICID>DE5656565</ram:BICID>
					<ram:Name>Commerzbank</ram:Name>
				</ram:PayeeSpecifiedCreditorFinancialInstitution>

*/
    //$NON-NLS-1$
    ndList = document.getElementsByTagNameNS("*", "PayeePartyCreditorFinancialAccount");
    for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
        Node booking = ndList.item(bookingIndex);
        // there are many "name" elements, so get the one below
        // SellerTradeParty
        NodeList bookingDetails = booking.getChildNodes();
        for (int detailIndex = 0; detailIndex < bookingDetails.getLength(); detailIndex++) {
            Node detail = bookingDetails.item(detailIndex);
            if ((detail.getLocalName() != null) && (detail.getLocalName().equals("IBANID"))) {
                //$NON-NLS-1$
                setIBAN(detail.getTextContent());
            }
        }
    }
    //$NON-NLS-1$
    ndList = document.getElementsByTagNameNS("*", "PayeeSpecifiedCreditorFinancialInstitution");
    for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
        Node booking = ndList.item(bookingIndex);
        // there are many "name" elements, so get the one below
        // SellerTradeParty
        NodeList bookingDetails = booking.getChildNodes();
        for (int detailIndex = 0; detailIndex < bookingDetails.getLength(); detailIndex++) {
            Node detail = bookingDetails.item(detailIndex);
            if ((detail.getLocalName() != null) && (detail.getLocalName().equals("BICID"))) {
                //$NON-NLS-1$
                setBIC(detail.getTextContent());
            }
            if ((detail.getLocalName() != null) && (detail.getLocalName().equals("Name"))) {
                //$NON-NLS-1$
                setBankName(detail.getTextContent());
            }
        }
    }
    //
    //$NON-NLS-1$
    ndList = document.getElementsByTagNameNS("*", "SellerTradeParty");
    for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
        Node booking = ndList.item(bookingIndex);
        // there are many "name" elements, so get the one below
        // SellerTradeParty
        NodeList bookingDetails = booking.getChildNodes();
        for (int detailIndex = 0; detailIndex < bookingDetails.getLength(); detailIndex++) {
            Node detail = bookingDetails.item(detailIndex);
            if ((detail.getLocalName() != null) && (detail.getLocalName().equals("Name"))) {
                //$NON-NLS-1$
                setHolder(detail.getTextContent());
            }
        }
    }
    //$NON-NLS-1$
    ndList = document.getElementsByTagNameNS("*", "DuePayableAmount");
    for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
        Node booking = ndList.item(bookingIndex);
        // if there is a attribute in the tag number:value
        amountFound = true;
        setAmount(booking.getTextContent());
    }
    if (!amountFound) {
        /* there is apparently no requirement to mention DuePayableAmount,,
			 * if it's not there, check for GrandTotalAmount
			 */
        //$NON-NLS-1$
        ndList = document.getElementsByTagNameNS("*", "GrandTotalAmount");
        for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
            Node booking = ndList.item(bookingIndex);
            // if there is a attribute in the tag number:value
            amountFound = true;
            setAmount(booking.getTextContent());
        }
    }
    //$NON-NLS-1$
    ndList = document.getElementsByTagNameNS("*", "SpecifiedTradePaymentTerms");
    for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
        Node booking = ndList.item(bookingIndex);
        // there are many "name" elements, so get the one below
        // SellerTradeParty
        NodeList bookingDetails = booking.getChildNodes();
        for (int detailIndex = 0; detailIndex < bookingDetails.getLength(); detailIndex++) {
            Node detail = bookingDetails.item(detailIndex);
            if ((detail.getLocalName() != null) && (detail.getLocalName().equals("DueDateDateTime"))) {
                //$NON-NLS-1$
                setDueDate(detail.getTextContent().trim());
            }
        }
    }
    parsed = true;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) PDEmbeddedFilesNameTreeNode(org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 59 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project zm-mailbox by Zimbra.

the class W3cDomUtil method getDom4jSAXParserWhichUsesSecureProcessing.

public static SAXParser getDom4jSAXParserWhichUsesSecureProcessing() throws XmlParseException {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setXIncludeAware(false);
    factory.setValidating(false);
    try {
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
    } catch (SAXNotRecognizedException | SAXNotSupportedException | ParserConfigurationException ex) {
        ZimbraLog.misc.error("Problem setting up SAXParser which supports secure XML processing", ex);
        throw XmlParseException.PARSE_ERROR();
    }
    try {
        return factory.newSAXParser();
    } catch (ParserConfigurationException | SAXException e) {
        ZimbraLog.misc.error("Problem setting up SAXParser", e);
        throw XmlParseException.PARSE_ERROR();
    }
}
Also used : SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 60 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project robo4j by Robo4J.

the class XmlConfigurationFactory method fromXml.

public static Configuration fromXml(String xml) throws ConfigurationFactoryException {
    DefaultConfiguration config = new DefaultConfiguration();
    SAXParser saxParser;
    try {
        saxParser = SAXParserFactory.newInstance().newSAXParser();
        saxParser.parse(new ByteArrayInputStream(xml.getBytes(Constants.DEFAULT_ENCODING)), new ConfigurationHandler(config));
    } catch (ParserConfigurationException | SAXException | IOException e) {
        throw new ConfigurationFactoryException("Could not parse the configuration", e);
    }
    return config;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1353 SAXException (org.xml.sax.SAXException)975 IOException (java.io.IOException)891 Document (org.w3c.dom.Document)710 DocumentBuilder (javax.xml.parsers.DocumentBuilder)631 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)569 Element (org.w3c.dom.Element)372 InputSource (org.xml.sax.InputSource)246 NodeList (org.w3c.dom.NodeList)226 Node (org.w3c.dom.Node)210 SAXParser (javax.xml.parsers.SAXParser)175 TransformerException (javax.xml.transform.TransformerException)163 File (java.io.File)162 InputStream (java.io.InputStream)158 SAXParserFactory (javax.xml.parsers.SAXParserFactory)137 ByteArrayInputStream (java.io.ByteArrayInputStream)129 StringReader (java.io.StringReader)117 ArrayList (java.util.ArrayList)115 DOMSource (javax.xml.transform.dom.DOMSource)109 StreamResult (javax.xml.transform.stream.StreamResult)93