Example usage for javax.xml.parsers ParserConfigurationException getMessage

List of usage examples for javax.xml.parsers ParserConfigurationException getMessage

Introduction

In this page you can find the example usage for javax.xml.parsers ParserConfigurationException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.ikon.util.FormUtils.java

/**
 * Parse PropertyGroups.xml definitions//  w  ww. j a  va  2s.c  om
 * 
 * @return A Map with all the forms and its form elements.
 */
public static synchronized Map<PropertyGroup, List<FormElement>> parsePropertyGroupsForms(String pgForm)
        throws IOException, ParseException {
    log.debug("parsePropertyGroupsForms({})", pgForm);

    if (pGroups == null) {
        pGroups = new HashMap<PropertyGroup, List<FormElement>>();
        FileInputStream fis = null;

        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            dbf.setValidating(true);
            ErrorHandler handler = new ErrorHandler();
            // EntityResolver resolver = new LocalResolver(Config.DTD_BASE);
            DocumentBuilder db = dbf.newDocumentBuilder();
            db.setErrorHandler(handler);
            db.setEntityResolver(resolver);
            fis = new FileInputStream(pgForm);

            if (fis != null) {
                Document doc = db.parse(fis);
                doc.getDocumentElement().normalize();
                NodeList nlForm = doc.getElementsByTagName("property-group");

                for (int i = 0; i < nlForm.getLength(); i++) {
                    Node nForm = nlForm.item(i);

                    if (nForm.getNodeType() == Node.ELEMENT_NODE) {
                        PropertyGroup pg = new PropertyGroup();

                        Node item = nForm.getAttributes().getNamedItem("label");
                        if (item != null)
                            pg.setLabel(item.getNodeValue());
                        item = nForm.getAttributes().getNamedItem("name");
                        if (item != null)
                            pg.setName(item.getNodeValue());
                        item = nForm.getAttributes().getNamedItem("visible");
                        if (item != null)
                            pg.setVisible(Boolean.valueOf(item.getNodeValue()));
                        item = nForm.getAttributes().getNamedItem("readonly");
                        if (item != null)
                            pg.setReadonly(Boolean.valueOf(item.getNodeValue()));

                        NodeList nlField = nForm.getChildNodes();
                        List<FormElement> fe = parseField(nlField);
                        pGroups.put(pg, fe);
                    }
                }
            }
        } catch (ParserConfigurationException e) {
            throw new ParseException(e.getMessage());
        } catch (SAXException e) {
            throw new ParseException(e.getMessage());
        } catch (IOException e) {
            throw e;
        } finally {
            IOUtils.closeQuietly(fis);
        }
    }

    log.debug("parsePropertyGroupsForms: {}", pGroups);
    return clonedPropertyGroups();
}

From source file:com.openkm.util.FormUtils.java

/**
 * Parse params.xml definitions/*from   ww w  .j  ava2s.c  om*/
 * 
 * @return A List parameter elements.
 */
public static List<FormElement> parseReportParameters(InputStream is) throws ParseException {
    log.debug("parseReportParameters({})", is);
    long begin = System.currentTimeMillis();
    List<FormElement> params = new ArrayList<FormElement>();

    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(true);
        ErrorHandler handler = new ErrorHandler();
        // EntityResolver resolver = new LocalResolver(Config.DTD_BASE);
        DocumentBuilder db = dbf.newDocumentBuilder();
        db.setErrorHandler(handler);
        db.setEntityResolver(resolver);

        if (is != null) {
            Document doc = db.parse(is);
            doc.getDocumentElement().normalize();
            NodeList nlForm = doc.getElementsByTagName("report-parameters");

            for (int i = 0; i < nlForm.getLength(); i++) {
                Node nForm = nlForm.item(i);

                if (nForm.getNodeType() == Node.ELEMENT_NODE) {
                    NodeList nlField = nForm.getChildNodes();
                    params = parseField(nlField);
                }
            }
        }
    } catch (ParserConfigurationException e) {
        throw new ParseException(e.getMessage(), e);
    } catch (SAXException e) {
        throw new ParseException(e.getMessage(), e);
    } catch (IOException e) {
        throw new ParseException(e.getMessage(), e);
    }

    log.trace("parseReportParameters.Time: {}", System.currentTimeMillis() - begin);
    log.debug("parseReportParameters: {}", params);
    return params;
}

From source file:com.syrup.storage.xml.XmlFactory.java

/**
 * Returns a <code>Document</code> object representing a ???
 * //from   w  w  w .j  a  va2  s . co  m
 * @param mockServices List of services to convert into an xml document
  * @return <code>Document</code> object representing a cXML order request
 */
public Document getAsDocument(IStorage store) {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);

        DocumentBuilder docBuilder = factory.newDocumentBuilder();
        Document document = docBuilder.newDocument();

        XmlFileConfigurationGenerator xmlGeneratorSupport = new XmlFileConfigurationGenerator();

        Element xmlRootElement = xmlGeneratorSupport.getElement(document, store);
        document.appendChild(xmlRootElement);

        return document;
    } catch (ParserConfigurationException pce) {
        System.out.println(":" + pce.getMessage());

        return null;
    }
}

From source file:com.openkm.util.FormUtils.java

/**
 * Parse form.xml definitions/*  ww w.  j  a v a2  s .com*/
 * 
 * @return A Map with all the forms and its form elements.
 */
public static Map<String, List<FormElement>> parseWorkflowForms(InputStream is) throws ParseException {
    log.debug("parseWorkflowForms({})", is);
    long begin = System.currentTimeMillis();
    Map<String, List<FormElement>> forms = new HashMap<String, List<FormElement>>();

    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(true);
        ErrorHandler handler = new ErrorHandler();
        // EntityResolver resolver = new LocalResolver(Config.DTD_BASE);
        DocumentBuilder db = dbf.newDocumentBuilder();
        db.setErrorHandler(handler);
        db.setEntityResolver(resolver);

        if (is != null) {
            Document doc = db.parse(is);
            doc.getDocumentElement().normalize();
            NodeList nlForm = doc.getElementsByTagName("workflow-form");

            for (int i = 0; i < nlForm.getLength(); i++) {
                Node nForm = nlForm.item(i);

                if (nForm.getNodeType() == Node.ELEMENT_NODE) {
                    String taskName = nForm.getAttributes().getNamedItem("task").getNodeValue();
                    NodeList nlField = nForm.getChildNodes();
                    List<FormElement> fe = parseField(nlField);
                    forms.put(taskName, fe);
                }
            }
        }
    } catch (ParserConfigurationException e) {
        throw new ParseException(e.getMessage(), e);
    } catch (SAXException e) {
        throw new ParseException(e.getMessage(), e);
    } catch (IOException e) {
        throw new ParseException(e.getMessage(), e);
    }

    log.trace("parseWorkflowForms.Time: {}", System.currentTimeMillis() - begin);
    log.debug("parseWorkflowForms: {}", forms);
    return forms;
}

From source file:com.openkm.util.FormUtils.java

/**
 * Parse PropertyGroups.xml definitions/*from ww w.ja  v  a 2  s  .  com*/
 * 
 * @param pgDefFile Path to file where is the Property Groups definition.
 * @return A Map with all the forms and its form elements.
 */
public static synchronized Map<PropertyGroup, List<FormElement>> parsePropertyGroupsForms(String pgDefFile)
        throws IOException, ParseException {
    log.debug("parsePropertyGroupsForms({})", pgDefFile);

    if (pGroups == null) {
        long begin = System.currentTimeMillis();
        pGroups = new HashMap<PropertyGroup, List<FormElement>>();
        FileInputStream fis = null;

        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            dbf.setValidating(true);
            ErrorHandler handler = new ErrorHandler();
            // EntityResolver resolver = new LocalResolver(Config.DTD_BASE);
            DocumentBuilder db = dbf.newDocumentBuilder();
            db.setErrorHandler(handler);
            db.setEntityResolver(resolver);
            fis = new FileInputStream(pgDefFile);

            if (fis != null) {
                Document doc = db.parse(fis);
                doc.getDocumentElement().normalize();
                NodeList nlForm = doc.getElementsByTagName("property-group");

                for (int i = 0; i < nlForm.getLength(); i++) {
                    Node nForm = nlForm.item(i);

                    if (nForm.getNodeType() == Node.ELEMENT_NODE) {
                        PropertyGroup pg = new PropertyGroup();

                        Node item = nForm.getAttributes().getNamedItem("label");
                        if (item != null)
                            pg.setLabel(item.getNodeValue());
                        item = nForm.getAttributes().getNamedItem("name");
                        if (item != null)
                            pg.setName(item.getNodeValue());
                        item = nForm.getAttributes().getNamedItem("visible");
                        if (item != null)
                            pg.setVisible(Boolean.valueOf(item.getNodeValue()));
                        item = nForm.getAttributes().getNamedItem("readonly");
                        if (item != null)
                            pg.setReadonly(Boolean.valueOf(item.getNodeValue()));

                        NodeList nlField = nForm.getChildNodes();
                        List<FormElement> fe = parseField(nlField);
                        pGroups.put(pg, fe);
                    }
                }
            }
        } catch (ParserConfigurationException e) {
            throw new ParseException(e.getMessage());
        } catch (SAXException e) {
            throw new ParseException(e.getMessage());
        } catch (IOException e) {
            throw e;
        } finally {
            IOUtils.closeQuietly(fis);
        }

        log.trace("parsePropertyGroupsForms.Time: {}", System.currentTimeMillis() - begin);
    }

    log.debug("parsePropertyGroupsForms: {}", pGroups);
    return clonedPropertyGroups();
}

From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java

public static ArrayList<SAnnotationMapping> getSAnnotationMappingsFromFile(MMAX2ExporterProperties props) {
    ArrayList<SAnnotationMapping> mappings = new ArrayList<SAnnotationMapping>();

    if (props.getSAnnotationMappingsFilePath() != null) {
        DocumentBuilder documentBuilder;
        try {/*from  w  w w.  j  a  va 2 s.c  om*/
            documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            throw new PepperModuleException(e.getMessage(), e);
        }

        File configurationFile = new File(props.getSAnnotationMappingsFilePath());
        NodeList nodes = null;
        try {
            nodes = documentBuilder.parse(configurationFile).getDocumentElement().getChildNodes();
        } catch (SAXException e) {
            throw new PepperModuleException(e.getMessage(), e);
        } catch (IOException e) {
            throw new PepperModuleException(e.getMessage(), e);
        }

        for (int i = 0; i < nodes.getLength(); i++) {
            Node xmlNode = nodes.item(i);
            if (xmlNode.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }

            String nodeName = xmlNode.getNodeName();
            if (nodeName.equals(MAPPING_NODE_NAME)) {
                Node mapping_infos = null;
                Node condition_infos = null;

                NodeList sub_nodes = xmlNode.getChildNodes();
                for (int j = 0; j < sub_nodes.getLength(); j++) {
                    Node sub_xmlNode = sub_nodes.item(j);
                    if (sub_xmlNode.getNodeType() != Node.ELEMENT_NODE) {
                        continue;
                    }

                    String sub_nodeName = sub_xmlNode.getNodeName();
                    if (sub_nodeName.equals(MAPPING_INFOS_NODE_NAME)) {
                        if (mapping_infos == null) {
                            mapping_infos = sub_xmlNode;
                        } else {
                            throw new PepperModuleException(
                                    "More than one mapping infos defined on SAnnotation Mapping '" + xmlNode
                                            + "'");
                        }
                    } else if (sub_nodeName.equals(CONDITION_NODE_NAME)) {
                        if (condition_infos == null) {
                            condition_infos = sub_xmlNode;
                        } else {
                            throw new PepperModuleException(
                                    "More than one match condition defined on SAnnotation Mapping '" + xmlNode
                                            + "'");
                        }
                    } else {
                        throw new PepperModuleException("Unknown type of Node '" + sub_xmlNode + "' with name '"
                                + sub_nodeName + "' on SAnnotation Mapping '" + xmlNode + "'");
                    }
                }

                NamedNodeMap mapping_attributes = mapping_infos.getAttributes();
                Node associatedSchemeNameAttribute = mapping_attributes.getNamedItem(SANN_MAPPING_ASS_SCHEME);
                if (associatedSchemeNameAttribute == null) {
                    throw new PepperModuleException("associated scheme name '" + SANN_MAPPING_ASS_SCHEME
                            + "' on SAnnotation Mapping infos Node '" + mapping_infos + "' is not defined...");
                }
                String associatedSchemeName = associatedSchemeNameAttribute.getNodeValue();
                mapping_attributes.removeNamedItem(SANN_MAPPING_ASS_SCHEME);

                Node associatedAttributeNameAttribute = mapping_attributes.getNamedItem(SANN_MAPPING_ASS_ATTR);
                if (associatedAttributeNameAttribute == null) {
                    throw new PepperModuleException("associated attribute name '" + SANN_MAPPING_ASS_ATTR
                            + "' on SAnnotation Mapping infos Node  '" + mapping_infos + "' is not defined...");
                }
                String associatedAttributeName = associatedAttributeNameAttribute.getNodeValue();
                mapping_attributes.removeNamedItem(SANN_MAPPING_ASS_ATTR);

                SAnnotationMatchCondition condition = parseSAnnotationMatchCondition(condition_infos);

                if (mapping_attributes.getLength() != 0) {
                    ArrayList<String> unknownAttributes = new ArrayList<String>();
                    for (int j = 0; j < mapping_attributes.getLength(); j++) {
                        unknownAttributes.add(mapping_attributes.item(j).getNodeName());
                    }
                    throw new PepperModuleException(
                            "Unknown attributes '" + StringUtils.join(unknownAttributes, ",")
                                    + "' on SAnnotation Mapping infos Node  '" + mapping_infos + "'");
                }

                mappings.add(new SAnnotationMapping(condition, associatedSchemeName, associatedAttributeName));
            } else if (xmlNode.getNodeType() == Node.ELEMENT_NODE) {
                throw new PepperModuleException("Unknown type of Node among Mapping nodes '" + xmlNode
                        + "' with name '" + nodeName + "'");
            }
        }
    }
    return mappings;
}

From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java

public static ArrayList<SRelationMapping> getSRelationMappingsFromFile(MMAX2ExporterProperties props) {
    ArrayList<SRelationMapping> mappings = new ArrayList<SRelationMapping>();

    if (props.getSRelationMappingsFilePath() != null) {
        DocumentBuilder documentBuilder;
        try {//from  w w w.  java 2  s.  c  o m
            documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            throw new PepperModuleException(e.getMessage(), e);
        }

        File configurationFile = new File(props.getSRelationMappingsFilePath());
        NodeList nodes = null;
        try {
            nodes = documentBuilder.parse(configurationFile).getDocumentElement().getChildNodes();
        } catch (SAXException e) {
            throw new PepperModuleException(e.getMessage(), e);
        } catch (IOException e) {
            throw new PepperModuleException(e.getMessage(), e);
        }

        for (int i = 0; i < nodes.getLength(); i++) {
            Node xmlNode = nodes.item(i);
            if (xmlNode.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }

            String nodeName = xmlNode.getNodeName();
            if (nodeName.equals(MAPPING_NODE_NAME)) {
                Node mapping_infos = null;
                Node condition_infos = null;

                NodeList sub_nodes = xmlNode.getChildNodes();
                for (int j = 0; j < sub_nodes.getLength(); j++) {
                    Node sub_xmlNode = sub_nodes.item(j);
                    if (sub_xmlNode.getNodeType() != Node.ELEMENT_NODE) {
                        continue;
                    }

                    String sub_nodeName = sub_xmlNode.getNodeName();
                    if (sub_nodeName.equals(MAPPING_INFOS_NODE_NAME)) {
                        if (mapping_infos == null) {
                            mapping_infos = sub_xmlNode;
                        } else {
                            throw new PepperModuleException(
                                    "More than one mapping infos defined on SRelation Mapping '" + xmlNode
                                            + "'");
                        }
                    } else if (sub_nodeName.equals(CONDITION_NODE_NAME)) {
                        if (condition_infos == null) {
                            condition_infos = sub_xmlNode;
                        } else {
                            throw new PepperModuleException(
                                    "More than one match condition defined on SRelation Mapping '" + xmlNode
                                            + "'");
                        }
                    } else if (!sub_nodeName.equals("")) {
                        throw new PepperModuleException("Unknown type of Node '" + sub_xmlNode + "' with name '"
                                + sub_nodeName + "' on SRelation Mapping '" + xmlNode + "'");
                    }
                }
                NamedNodeMap mapping_attributes = mapping_infos.getAttributes();

                Node sourceDestSchemeNode = mapping_attributes.getNamedItem(SREL_MAPP_SOURCE_SCHEME_NAME);
                if (sourceDestSchemeNode == null) {
                    throw new PepperModuleException("Source destination scheme '" + SREL_MAPP_SOURCE_SCHEME_NAME
                            + "' on SRelation Mapping infos Node '" + mapping_infos + "' is not defined...");
                }
                mapping_attributes.removeNamedItem(SREL_MAPP_SOURCE_SCHEME_NAME);
                String sourceSchemeName = sourceDestSchemeNode.getNodeValue();

                Node targetDestSchemeNode = mapping_attributes.getNamedItem(SREL_MAPP_TARGET_SCHEME_NAME);
                if (targetDestSchemeNode == null) {
                    throw new PepperModuleException("Target destination scheme '" + SREL_MAPP_TARGET_SCHEME_NAME
                            + "' on SRelation Mapping infos Node '" + mapping_infos + "' is not defined...");
                }
                mapping_attributes.removeNamedItem(SREL_MAPP_TARGET_SCHEME_NAME);
                String targetSchemeName = targetDestSchemeNode.getNodeValue();

                Node destAttrNode = mapping_attributes.getNamedItem(SREL_MAPP_POINTER_ATTR_NAME);
                if (destAttrNode == null) {
                    throw new PepperModuleException("Source attribute '" + SREL_MAPP_POINTER_ATTR_NAME
                            + "' on SRelation Mapping infos Node '" + mapping_infos + "' is not defined...");
                }
                mapping_attributes.removeNamedItem(SREL_MAPP_POINTER_ATTR_NAME);
                String attrName = destAttrNode.getNodeValue();

                SRelationMatchCondition condition = parseSRelationMatchCondition(condition_infos);
                if (mapping_attributes.getLength() != 0) {
                    ArrayList<String> unknownAttributes = new ArrayList<String>();
                    for (int j = 0; j < mapping_attributes.getLength(); j++) {
                        unknownAttributes.add(mapping_attributes.item(j).getNodeName());
                    }
                    throw new PepperModuleException(
                            "Unknown attributes '" + StringUtils.join(unknownAttributes, ",")
                                    + "' on SRelation Mapping infos Node '" + mapping_infos + "'");
                }

                mappings.add(new SRelationMapping(condition, sourceSchemeName, targetSchemeName, attrName));
            } else {
                throw new PepperModuleException("Unknown type of Node among Mapping nodes '" + xmlNode
                        + "' with name '" + nodeName + "'");
            }
        }
    }

    return mappings;
}

From source file:dk.ciid.android.infobooth.xml.XMLParser.java

/**
 * Getting XML DOM element//from   ww w.j a  v  a2  s .  co m
 * @param XML string
 * */
public Document getDomElement(String xml) {
    Document doc = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {

        DocumentBuilder db = dbf.newDocumentBuilder();

        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(xml));
        doc = db.parse(is);

    } catch (ParserConfigurationException e) {
        Log.e("Error: ", e.getMessage());
        return null;
    } catch (SAXException e) {
        Log.e("Error: ", e.getMessage());
        return null;
    } catch (IOException e) {
        Log.e("Error: ", e.getMessage());
        return null;
    }

    return doc;
}

From source file:com.l2jfree.gameserver.script.ScriptDocument.java

public ScriptDocument(String name, InputStream input) {
    if (input == null)
        return;//from   ww  w .  j a v a2s  .  c  o  m
    _name = name;

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        _document = builder.parse(input);
    } catch (SAXException sxe) {
        // Error generated during parsing)
        _log.error("Invalid document " + name + ". Error = " + sxe.getMessage(), sxe);
    } catch (ParserConfigurationException pce) {
        // Parser with specified options can't be built
        _log.error(pce.getMessage(), pce);
    } catch (IOException ioe) {
        // I/O error
        _log.error(ioe.getMessage(), ioe);
    }
}

From source file:com.jereksel.rommanager.XMLParser.java

/**
 * Getting XML DOM element/*from  w  ww. ja va2 s.  c  o m*/
 *
 * @param XML string
 */
public Document getDomElement(String xml) {
    Document doc;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {

        DocumentBuilder db = dbf.newDocumentBuilder();

        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(xml));
        doc = db.parse(is);

    } catch (ParserConfigurationException e) {
        Log.e("Error: ", e.getMessage());
        return null;
    } catch (SAXException e) {
        Log.e("Error: ", e.getMessage());
        return null;
    } catch (IOException e) {
        Log.e("Error: ", e.getMessage());
        return null;
    }

    return doc;
}