Search in sources :

Example 91 with SAXException

use of org.xml.sax.SAXException in project tdi-studio-se by Talend.

the class ExportProjectSettings method saveProjectSettings.

public void saveProjectSettings() {
    if (path == null) {
        return;
    }
    File xmlFile = new File(path);
    org.talend.core.model.properties.Project project = pro.getEmfProject();
    try {
        final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
        DocumentBuilder analyseur = fabrique.newDocumentBuilder();
        analyseur.setErrorHandler(new ErrorHandler() {

            @Override
            public void error(final SAXParseException exception) throws SAXException {
                throw exception;
            }

            @Override
            public void fatalError(final SAXParseException exception) throws SAXException {
                throw exception;
            }

            @Override
            public void warning(final SAXParseException exception) throws SAXException {
                throw exception;
            }
        });
        Document document = analyseur.newDocument();
        //$NON-NLS-1$
        Element root = document.createElement("exportParameters");
        createVersionAttr(document, root);
        document.appendChild(root);
        // status
        List technicals = project.getTechnicalStatus();
        //$NON-NLS-1$
        createStatus(technicals, document, root, "technicalStatus");
        List documentation = project.getDocumentationStatus();
        //$NON-NLS-1$
        createStatus(documentation, document, root, "documentationStatus");
        // security
        //$NON-NLS-1$
        Element security = document.createElement("exportParameter");
        root.appendChild(security);
        //$NON-NLS-1$
        Attr typeAttr = document.createAttribute("type");
        //$NON-NLS-1$
        typeAttr.setNodeValue("security");
        security.setAttributeNode(typeAttr);
        //$NON-NLS-1$
        Attr name = document.createAttribute("name");
        //$NON-NLS-1$
        name.setNodeValue("hidePassword");
        security.setAttributeNode(name);
        security.setTextContent(String.valueOf(project.isHidePassword()));
        // stats and logs
        if (project.getStatAndLogsSettings() != null) {
            List statAndLogs = project.getStatAndLogsSettings().getParameters().getElementParameter();
            //$NON-NLS-1$
            saveParameters(document, root, statAndLogs, "statAndLogs");
        }
        // implicit context
        if (project.getImplicitContextSettings() != null) {
            List implicit = project.getImplicitContextSettings().getParameters().getElementParameter();
            //$NON-NLS-1$
            saveParameters(document, root, implicit, "implicitContext");
        }
        // palette
        List componentSettings = project.getComponentsSettings();
        savePalette(document, root, componentSettings);
        saveDocumentByEncoding(document, xmlFile);
    } catch (ParserConfigurationException e) {
        ExceptionHandler.process(e);
    } catch (IOException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 92 with SAXException

use of org.xml.sax.SAXException in project tdi-studio-se by Talend.

the class WsdlTokenManager method getValueFromXML.

private String getValueFromXML(String inputXML, String xPathQuery) throws XPathExpressionException, ParserConfigurationException, SAXException, IOException {
    DocumentBuilder builder;
    try {
        builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document = builder.parse(new ByteArrayInputStream(inputXML.getBytes()));
        XPath xpath = XPathFactory.newInstance().newXPath();
        String expression = xPathQuery;
        Node cipherValue = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);
        return cipherValue == null ? null : cipherValue.getTextContent();
    } catch (XPathExpressionException e) {
        logger.error(e.getMessage());
        throw e;
    } catch (ParserConfigurationException e) {
        logger.error(e.getMessage());
        throw e;
    } catch (SAXException e) {
        logger.error(e.getMessage());
        throw e;
    } catch (IOException e) {
        logger.error(e.getMessage());
        throw e;
    }
}
Also used : XPath(javax.xml.xpath.XPath) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 93 with SAXException

use of org.xml.sax.SAXException 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 94 with SAXException

use of org.xml.sax.SAXException in project tdi-studio-se by Talend.

the class Rfh2AreaParser method parse.

public RFH2Area parse(String stringToParse) {
    SAXParser parser;
    try {
        parser = SAXParserFactory.newInstance().newSAXParser();
    } catch (Exception e) {
        throw new RuntimeException("Failed to create XML parser, can not parse RFH2 areas", e);
    }
    SaxHandler handler = new SaxHandler();
    try {
        parser.parse(new InputSource(new StringReader(stringToParse)), handler);
    } catch (SAXException e) {
        throw new RuntimeException("Invalid RFH2 header", e);
    } catch (IOException e) {
        throw new RuntimeException("Invalid RFH2 header", e);
    }
    return handler.getArea();
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 95 with SAXException

use of org.xml.sax.SAXException 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)

Aggregations

SAXException (org.xml.sax.SAXException)2465 IOException (java.io.IOException)1622 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1049 Document (org.w3c.dom.Document)682 DocumentBuilder (javax.xml.parsers.DocumentBuilder)537 InputSource (org.xml.sax.InputSource)518 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)415 InputStream (java.io.InputStream)317 Element (org.w3c.dom.Element)311 NodeList (org.w3c.dom.NodeList)292 File (java.io.File)274 Node (org.w3c.dom.Node)247 ByteArrayInputStream (java.io.ByteArrayInputStream)235 StringReader (java.io.StringReader)224 SAXParser (javax.xml.parsers.SAXParser)209 SAXParseException (org.xml.sax.SAXParseException)196 TransformerException (javax.xml.transform.TransformerException)180 ArrayList (java.util.ArrayList)169 SAXParserFactory (javax.xml.parsers.SAXParserFactory)159 XMLReader (org.xml.sax.XMLReader)151