Search in sources :

Example 11 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project head by mifos.

the class TypeParser method parser.

public Files parser(String filename) throws TableTagTypeParserException {
    Files file = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
        // Specify our own schema - this overrides the schemaLocation in the
        // xml file
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "type.xsd");
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setErrorHandler(null);
        Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsStream(filename));
        Node fileNode = document.getFirstChild();
        file = new Files();
        file.setFileName(createFileName(fileNode));
    } catch (ParserConfigurationException pce) {
        throw new TableTagTypeParserException(pce);
    } catch (IOException ioe) {
        throw new TableTagTypeParserException(ioe);
    } catch (SAXParseException saxpe) {
        throw new TableTagTypeParserException(saxpe);
    } catch (SAXException saxe) {
        throw new TableTagTypeParserException(saxe);
    } catch (MifosRuntimeException saxe) {
        throw new TableTagTypeParserException(saxe);
    }
    return file;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) Node(org.w3c.dom.Node) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) TableTagTypeParserException(org.mifos.framework.exceptions.TableTagTypeParserException) SAXException(org.xml.sax.SAXException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 12 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project head by mifos.

the class ChartOfAccountsConfig method load.

/**
     * Factory method which loads the Chart of Accounts configuration from the
     * given filename. Given XML filename will be validated against
     * {@link FilePaths#CHART_OF_ACCOUNTS_SCHEMA}.
     *
     * @param chartOfAccountsXml
     *            a relative path to the Chart of Accounts configuration file.
     */
public static ChartOfAccountsConfig load(String chartOfAccountsXml) throws ConfigurationException {
    ChartOfAccountsConfig instance = null;
    Document document = null;
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder parser = dbf.newDocumentBuilder();
        if (FilePaths.CHART_OF_ACCOUNTS_DEFAULT.equals(chartOfAccountsXml)) {
            // default chart of accounts
            document = parser.parse(MifosResourceUtil.getClassPathResourceAsStream(chartOfAccountsXml));
        } else {
            // custom chart of accounts
            document = parser.parse(MifosResourceUtil.getFile(chartOfAccountsXml));
        }
        // create a SchemaFactory capable of understanding XML schemas
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        // load an XML schema
        ClassPathResource schemaFileResource = new ClassPathResource(FilePaths.CHART_OF_ACCOUNTS_SCHEMA);
        Source schemaFile = null;
        if (schemaFileResource.exists()) {
            InputStream in = ChartOfAccountsConfig.class.getClassLoader().getResourceAsStream(FilePaths.CHART_OF_ACCOUNTS_SCHEMA);
            schemaFile = new StreamSource(in);
        } else {
            schemaFile = new StreamSource(MifosResourceUtil.getFile(FilePaths.CHART_OF_ACCOUNTS_SCHEMA));
        }
        Schema schema = factory.newSchema(schemaFile);
        // create a Validator instance and validate document
        Validator validator = schema.newValidator();
        validator.validate(new DOMSource(document));
    } catch (IOException e) {
        throw new ConfigurationException(e);
    } catch (SAXException e) {
        throw new ConfigurationException(e);
    } catch (ParserConfigurationException e) {
        throw new ConfigurationException(e);
    }
    instance = new ChartOfAccountsConfig();
    instance.coaDocument = document;
    return instance;
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Schema(javax.xml.validation.Schema) IOException(java.io.IOException) Document(org.w3c.dom.Document) ClassPathResource(org.springframework.core.io.ClassPathResource) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Validator(javax.xml.validation.Validator)

Example 13 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project head by mifos.

the class StateXMLParser method loadMapFromXml.

public Map<StateEntity, List<StateEntity>> loadMapFromXml(String filename, String configurationName) {
    Map<StateEntity, List<StateEntity>> transitionMap = new HashMap<StateEntity, List<StateEntity>>();
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
        // Specify our own schema - this overrides the schemaLocation in the
        // xml file
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "StateMachine.xsd");
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setErrorHandler(null);
        Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsStream(filename));
        Node mapToprocess = null;
        /*
             * String configurationName = ""; if
             * (stateConfiguration=="configuration1") configurationName = "1";
             * else configurationName = "2";
             */
        NodeList configMaps = document.getElementsByTagName("stateConfiguration");
        for (int m = 0; m < configMaps.getLength(); m++) {
            Node stateConfiguration = configMaps.item(m);
            if (configurationName.equals(stateConfiguration.getAttributes().getNamedItem("configurationName").getNodeValue())) {
                mapToprocess = stateConfiguration;
            }
        }
        // NodeList stateList = firstChild.getChildNodes();
        NodeList stateList = mapToprocess.getChildNodes();
        for (int i = 0; i < stateList.getLength(); i++) {
            // each state has state id and possiblestates as childern
            Node state = stateList.item(i);
            // iterate for each child of state
            NodeList stateInfoList = state.getChildNodes();
            StateEntity currentState = null;
            List<StateEntity> currntPossibleStates = new ArrayList<StateEntity>();
            for (int j = 0; j < stateInfoList.getLength(); j++) {
                Node info = stateInfoList.item(j);
                if ("stateid".equals(info.getLocalName())) {
                    Element ele = (Element) info;
                    currentState = new StateEntity(Short.valueOf(((Text) ele.getFirstChild()).getData()));
                }
                if ("possiblestates".equals(info.getLocalName())) {
                    // get all the childern
                    NodeList allStates = info.getChildNodes();
                    currntPossibleStates = new ArrayList<StateEntity>();
                    for (int k = 0; k < allStates.getLength(); k++) {
                        Node infoState = allStates.item(k);
                        NodeList eachPossiblechild = infoState.getChildNodes();
                        for (int l = 0; l < eachPossiblechild.getLength(); l++) {
                            Node eachPossiblechildelement = eachPossiblechild.item(l);
                            if ("stateid".equals(eachPossiblechildelement.getLocalName())) {
                                Element element = (Element) eachPossiblechildelement;
                                Short possibleTrantionId = Short.valueOf(((Text) element.getFirstChild()).getData());
                                currntPossibleStates.add(new StateEntity(possibleTrantionId));
                            }
                        }
                    }
                }
            }
            if (currentState != null) {
                transitionMap.put(currentState, currntPossibleStates);
            }
        }
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (SAXParseException e) {
        throw new RuntimeException(e);
    } catch (SAXException e) {
        throw new RuntimeException(e);
    }
    return transitionMap;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) HashMap(java.util.HashMap) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.w3c.dom.Document) StateEntity(org.mifos.application.master.business.StateEntity) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 14 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project head by mifos.

the class XMLParser method parser.

public ColumnPropertyMapping parser() throws SystemException {
    Document document = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        document = builder.parse(MifosResourceUtil.getClassPathResourceAsStream("org/mifos/framework/util/resources/audit/ColumnMapping.xml"));
        getColumnPropertyMapping(document);
    } catch (ParserConfigurationException e) {
        throw new SystemException(e);
    } catch (IOException e) {
        throw new SystemException(e);
    } catch (SAXParseException e) {
        throw new SystemException(e);
    } catch (SAXException e) {
        throw new SystemException(e);
    }
    return columnPropertyMapping;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) SystemException(org.mifos.framework.exceptions.SystemException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 15 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project OpenGrok by OpenGrok.

the class SubversionRepository method setDirectoryName.

@Override
public void setDirectoryName(String directoryName) {
    super.setDirectoryName(directoryName);
    if (isWorking()) {
        // set to true if we manage to find the root directory
        Boolean rootFound = Boolean.FALSE;
        List<String> cmd = new ArrayList<>();
        cmd.add(RepoCommand);
        cmd.add("info");
        cmd.add("--xml");
        File directory = new File(getDirectoryName());
        Executor executor = new Executor(cmd, directory);
        if (executor.exec() == 0) {
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document document = builder.parse(executor.getOutputStream());
                String url = getValue(document.getElementsByTagName("url").item(0));
                if (url == null) {
                    LOGGER.log(Level.WARNING, "svn info did not contain an URL for [{0}]. Assuming remote repository.", directoryName);
                    setRemote(true);
                } else {
                    if (!url.startsWith("file")) {
                        setRemote(true);
                    }
                }
                String root = getValue(document.getElementsByTagName("root").item(0));
                if (url != null && root != null) {
                    reposPath = url.substring(root.length());
                    rootFound = Boolean.TRUE;
                }
            } catch (SAXException saxe) {
                LOGGER.log(Level.WARNING, "Parser error parsing svn output", saxe);
            } catch (ParserConfigurationException pce) {
                LOGGER.log(Level.WARNING, "Parser configuration error parsing svn output", pce);
            } catch (IOException ioe) {
                LOGGER.log(Level.WARNING, "IOException reading from svn process", ioe);
            }
        } else {
            LOGGER.log(Level.WARNING, "Failed to execute svn info for [{0}]. Repository disabled.", directoryName);
        }
        setWorking(rootFound);
    }
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ArrayList(java.util.ArrayList) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) File(java.io.File) SAXException(org.xml.sax.SAXException)

Aggregations

ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1435 SAXException (org.xml.sax.SAXException)1039 IOException (java.io.IOException)951 Document (org.w3c.dom.Document)751 DocumentBuilder (javax.xml.parsers.DocumentBuilder)687 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)622 Element (org.w3c.dom.Element)389 InputSource (org.xml.sax.InputSource)260 NodeList (org.w3c.dom.NodeList)248 Node (org.w3c.dom.Node)225 SAXParser (javax.xml.parsers.SAXParser)185 File (java.io.File)171 InputStream (java.io.InputStream)170 TransformerException (javax.xml.transform.TransformerException)167 SAXParserFactory (javax.xml.parsers.SAXParserFactory)144 ByteArrayInputStream (java.io.ByteArrayInputStream)141 StringReader (java.io.StringReader)127 ArrayList (java.util.ArrayList)122 DOMSource (javax.xml.transform.dom.DOMSource)114 StreamResult (javax.xml.transform.stream.StreamResult)98