Example usage for javax.xml.parsers ParserConfigurationException ParserConfigurationException

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

Introduction

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

Prototype


public ParserConfigurationException(String msg) 

Source Link

Document

Create a new ParserConfigurationException with the String specified as an error message.

Usage

From source file:com.mingo.parser.xml.dom.DocumentBuilderFactoryCreator.java

/**
 * Creates schema from list of {@link Source} objects.
 *
 * @param sources list of {@link Source}
 * @return immutable in-memory representation of grammar
 * @throws ParserConfigurationException {@link ParserConfigurationException}
 *///from  w  ww .  ja  va 2 s.c  o  m
private static Schema createSchema(List<Source> sources) throws ParserConfigurationException {
    Schema schema;
    try {
        schema = SCHEMA_FACTORY.newSchema(sources.toArray(new Source[0]));
    } catch (SAXException e) {
        throw new ParserConfigurationException(ExceptionUtils.getMessage(e));
    }
    return schema;
}

From source file:org.eclipse.gemini.blueprint.test.provisioning.internal.MavenPackagedArtifactFinder.java

/**
 * Returns the <tt>groupId</tt> setting in a <tt>pom.xml</tt> file.
 * /* w  w w.  j av  a2 s.  c  om*/
 * @return a <tt>pom.xml</tt> <tt>groupId</tt>.
 */
String getGroupIdFromPom(Resource pomXml) {
    try {
        DocumentLoader docLoader = new DefaultDocumentLoader();
        Document document = docLoader.loadDocument(new InputSource(pomXml.getInputStream()), null, null,
                XmlValidationModeDetector.VALIDATION_NONE, false);

        String groupId = DomUtils.getChildElementValueByTagName(document.getDocumentElement(), GROUP_ID_ELEM);
        // no groupId specified, try the parent definition
        if (groupId == null) {
            if (log.isTraceEnabled())
                log.trace("No groupId defined; checking for the parent definition");
            Element parent = DomUtils.getChildElementByTagName(document.getDocumentElement(), "parent");
            if (parent != null)
                return DomUtils.getChildElementValueByTagName(parent, GROUP_ID_ELEM);
        } else {
            return groupId;
        }
    } catch (Exception ex) {
        throw (RuntimeException) new RuntimeException(
                new ParserConfigurationException("error parsing resource=" + pomXml).initCause(ex));
    }

    throw new IllegalArgumentException(
            "no groupId or parent/groupId defined by resource [" + pomXml.getDescription() + "]");

}

From source file:org.eclipse.gemini.blueprint.test.provisioning.internal.LocalFileSystemMavenRepository.java

/**
 * Returns the <code>localRepository</code> settings as indicated by the
 * <code>settings.xml</code> file.
 * /* ww w  .j a v a2s  .  c  o m*/
 * @return local repository as indicated by a Maven settings.xml file
 */
String getMavenSettingsLocalRepository(Resource m2Settings) {
    // no file found, return null to continue the discovery process
    if (!m2Settings.exists())
        return null;

    try {
        DocumentLoader docLoader = new DefaultDocumentLoader();
        Document document = docLoader.loadDocument(new InputSource(m2Settings.getInputStream()), null, null,
                XmlValidationModeDetector.VALIDATION_NONE, false);

        return (DomUtils.getChildElementValueByTagName(document.getDocumentElement(), LOCAL_REPOSITORY_ELEM));
    } catch (Exception ex) {
        throw (RuntimeException) new RuntimeException(
                new ParserConfigurationException("error parsing resource=" + m2Settings).initCause(ex));
    }
}

From source file:de.haber.xmind2latex.XMindToLatexExporter.java

public void convert() throws ParserConfigurationException, SAXException, IOException {
    InputStream is = getxMindSourceAsStream();
    if (is == null) {
        throw new ParserConfigurationException("Call configure() before convert().");
    }/*w  w  w  .j  a va2 s  .c  o m*/
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(is);
    is.close();
    StringBuilder sb = new StringBuilder();

    sb.append(convert(document.getChildNodes()));

    String text = sb.toString();
    save(text);
}

From source file:com.netspective.commons.xml.ParseContext.java

public void init(InputSource inputSource) throws ParserConfigurationException, SAXException {
    this.inputSource = inputSource;
    this.errors = new ArrayList();
    this.warnings = new ArrayList();

    if (inputSource.getSystemId() == null)
        throw new ParserConfigurationException("Please set the system id.");

    SAXParser saxParser = getParserFactory().newSAXParser();
    parser = saxParser.getXMLReader();/*from  w  w  w  . j a va  2 s . c o m*/
}

From source file:de.bayern.gdi.services.Atom.java

private void preLoad() throws MalformedURLException, ParserConfigurationException {
    items = new ArrayList<>();
    String getTitle = "//title";
    this.title = (String) XML.xpath(this.mainDoc, getTitle, XPathConstants.STRING, this.nscontext);
    String getSubtitle = "//subtitle";
    this.subTitle = (String) XML.xpath(this.mainDoc, getSubtitle, XPathConstants.STRING, this.nscontext);
    String getID = "//id";
    this.serviceID = (String) XML.xpath(this.mainDoc, getID, XPathConstants.STRING, this.nscontext);
    String getEntriesQuery = "//entry";
    NodeList entries = (NodeList) XML.xpath(this.mainDoc, getEntriesQuery, XPathConstants.NODESET,
            this.nscontext);
    for (int i = 0; i < entries.getLength(); i++) {
        Node entry = entries.item(i);
        String getEntryTitle = "title";
        Node titleN = (Node) XML.xpath(entry, getEntryTitle, XPathConstants.NODE, this.nscontext);
        String getEntryid = "*[local-name()" + "='spatial_dataset_identifier_code']";
        Node id = (Node) XML.xpath(entry, getEntryid, XPathConstants.NODE, this.nscontext);
        if (id == null) {
            getEntryid = "id";
            id = (Node) XML.xpath(entry, getEntryid, XPathConstants.NODE, this.nscontext);
        }/*w w w. java 2s  .co m*/
        String summaryExpr = "summary";
        Node description = (Node) XML.xpath(entry, summaryExpr, XPathConstants.NODE, this.nscontext);
        String describedByExpr = "link[@rel='alternate']/@href";
        Node describedBy = (Node) XML.xpath(entry, describedByExpr, XPathConstants.NODE, this.nscontext);
        if (describedBy == null) {
            describedByExpr = "link/@href";
            describedBy = (Node) XML.xpath(entry, describedByExpr, XPathConstants.NODE, this.nscontext);
        }
        String borderPolygonExpr = "*[local-name()" + "='polygon']";
        Node borderPolyGonN = (Node) XML.xpath(entry, borderPolygonExpr, XPathConstants.NODE, this.nscontext);
        if (borderPolyGonN == null) {
            borderPolygonExpr = "*[local-name()" + "='box']";
            borderPolyGonN = (Node) XML.xpath(entry, borderPolygonExpr, XPathConstants.NODE, this.nscontext);
        }
        Item it = new Item(new URL(this.serviceURL));
        if (id != null) {
            it.id = id.getTextContent();
        } else {
            throw new ParserConfigurationException("Could not Parse " + "Service. ID not found");
        }
        if (title != null) {
            it.title = titleN.getTextContent();
        } else {
            throw new ParserConfigurationException("Could not Parse " + "Service. Title not found");
        }
        if (description != null) {
            it.description = description.getTextContent();
        } else {
            it.description = it.title;
        }
        if (describedBy != null) {
            it.describedBy = describedBy.getTextContent();
        } else {
            throw new ParserConfigurationException("Could not Parse " + "Service. DescribedBy not found");
        }
        if (entry != null) {
            it.otherCRSs = getCRS(entry);
        } else {
            throw new ParserConfigurationException("Could not Parse " + "Service. Entry not found");
        }
        if (it.otherCRSs != null) {
            it.defaultCRS = it.otherCRSs.get(0);
        } else {
            throw new ParserConfigurationException("Could not Parse " + "Service. CRSs not found");
        }
        it.username = this.username;
        it.password = this.password;

        // XXX: GML, anyone?
        if (borderPolyGonN != null) {
            WKTReader reader = new WKTReader(new GeometryFactory());
            String bboxStr = convertPolygonToWKT(borderPolyGonN.getTextContent());

            Geometry polygon = null;
            try {
                polygon = reader.read(bboxStr);
            } catch (ParseException e) {
                log.log(Level.SEVERE, e.getMessage(), e);
                continue;
            } catch (IllegalArgumentException e) {
                log.log(Level.SEVERE, e.getMessage(), e);
                throw e;
            }

            Envelope env = polygon.getEnvelopeInternal();
            if (env == null || !(polygon instanceof Polygon)) {
                continue;
            }

            it.polygon = (Polygon) polygon;
        } else {
            throw new ParserConfigurationException("Could not Parse " + "Service. Bounding Box not Found");
        }
        items.add(it);
    }
}

From source file:org.jmingo.parser.xml.dom.DocumentBuilderFactoryCreator.java

/**
 * Creates schema from list of {@link Source} objects.
 *
 * @param sources list of {@link Source}
 * @return immutable in-memory representation of grammar
 * @throws ParserConfigurationException {@link ParserConfigurationException}
 *///from   w ww. j  a  v  a  2 s.co m
private static Schema createSchema(List<Source> sources) throws ParserConfigurationException {
    Schema schema;
    try {
        schema = SCHEMA_FACTORY.newSchema(sources.toArray(new Source[sources.size()]));
    } catch (SAXException e) {
        throw new ParserConfigurationException(ExceptionUtils.getMessage(e));
    }
    return schema;
}

From source file:org.springframework.beans.factory.xml.DefaultDocumentLoader.java

/**
 * Create the {@link DocumentBuilderFactory} instance.
 * @param validationMode the type of validation: {@link XmlValidationModeDetector#VALIDATION_DTD DTD}
 * or {@link XmlValidationModeDetector#VALIDATION_XSD XSD})
 * @param namespaceAware whether the returned factory is to provide support for XML namespaces
 * @return the JAXP DocumentBuilderFactory
 * @throws ParserConfigurationException if we failed to build a proper DocumentBuilderFactory
 *///w ww  .  j  a va2 s. c  o  m
protected DocumentBuilderFactory createDocumentBuilderFactory(int validationMode, boolean namespaceAware)
        throws ParserConfigurationException {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(namespaceAware);

    if (validationMode != XmlValidationModeDetector.VALIDATION_NONE) {
        factory.setValidating(true);
        if (validationMode == XmlValidationModeDetector.VALIDATION_XSD) {
            // Enforce namespace aware for XSD...
            factory.setNamespaceAware(true);
            try {
                factory.setAttribute(SCHEMA_LANGUAGE_ATTRIBUTE, XSD_SCHEMA_LANGUAGE);
            } catch (IllegalArgumentException ex) {
                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;
            }
        }
    }

    return factory;
}

From source file:org.staticioc.SpringConfigParser.java

public SpringConfigParser() throws ParserConfigurationException {
    // Init DocumentBuilderFactory
    dbf = DocumentBuilderFactory.newInstance();

    dbf.setNamespaceAware(false);//from  w ww .j  a  v  a 2  s .c o m
    dbf.setValidating(false);
    dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
    dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
    dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
    dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    dbf.setFeature("http://xml.org/sax/features/use-entity-resolver2", false);

    db = dbf.newDocumentBuilder();

    xPathFactory = XPathFactory.newInstance();

    beanContainer = new BeanContainerImpl();

    namespaceParsers = new LinkedList<NamespaceParser>();
    addNamespaceParser(new SpringBeansNameSpaceParser());
    addNamespaceParser(new SpringPNameSpaceParser());

    try {
        final XPath xPathBeans = xPathFactory.newXPath();
        xBeans = xPathBeans.compile(XPATH_BEAN);

        final XPath xPathImports = xPathFactory.newXPath();
        xImports = xPathImports.compile(XPATH_IMPORT);

        final XPath xPathBeanRoot = xPathFactory.newXPath();
        xBeanRoot = xPathBeanRoot.compile(XPATH_BEANS_NODE);
    } catch (XPathExpressionException e) {
        throw new ParserConfigurationException("Error compiling XPaths :" + e.getMessage());
    }
}