Search in sources :

Example 21 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project jmonkeyengine by jMonkeyEngine.

the class SceneMaterialLoader method load.

public MaterialList load(AssetManager assetManager, String folderName, InputStream in) throws IOException {
    try {
        this.assetManager = assetManager;
        this.folderName = folderName;
        reset();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XMLReader xr = factory.newSAXParser().getXMLReader();
        xr.setContentHandler(this);
        xr.setErrorHandler(this);
        InputStreamReader r = null;
        try {
            r = new InputStreamReader(in);
            xr.parse(new InputSource(r));
        } finally {
            if (r != null) {
                r.close();
            }
        }
        return materialList;
    } catch (SAXException ex) {
        IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
        ioEx.initCause(ex);
        throw ioEx;
    } catch (ParserConfigurationException ex) {
        IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
        ioEx.initCause(ex);
        throw ioEx;
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 22 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project che by eclipse.

the class Launching method restoreLibraryInfo.

/**
     * Restores library information for VMs
     */
private static void restoreLibraryInfo() {
    fgLibraryInfoMap = new HashMap<String, LibraryInfo>(10);
    IPath libPath = getDefault().getStateLocation();
    //$NON-NLS-1$
    libPath = libPath.append("libraryInfos.xml");
    File file = libPath.toFile();
    if (file.exists()) {
        try {
            InputStream stream = new BufferedInputStream(new FileInputStream(file));
            DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            parser.setErrorHandler(new DefaultHandler());
            Element root = parser.parse(new InputSource(stream)).getDocumentElement();
            if (!root.getNodeName().equals("libraryInfos")) {
                //$NON-NLS-1$
                return;
            }
            NodeList list = root.getChildNodes();
            int length = list.getLength();
            for (int i = 0; i < length; ++i) {
                Node node = list.item(i);
                short type = node.getNodeType();
                if (type == Node.ELEMENT_NODE) {
                    Element element = (Element) node;
                    String nodeName = element.getNodeName();
                    if (nodeName.equalsIgnoreCase("libraryInfo")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        String version = element.getAttribute("version");
                        //$NON-NLS-1$
                        String location = element.getAttribute("home");
                        //$NON-NLS-1$
                        String[] bootpath = getPathsFromXML(element, "bootpath");
                        //$NON-NLS-1$
                        String[] extDirs = getPathsFromXML(element, "extensionDirs");
                        //$NON-NLS-1$
                        String[] endDirs = getPathsFromXML(element, "endorsedDirs");
                        if (location != null) {
                            LibraryInfo info = new LibraryInfo(version, bootpath, extDirs, endDirs);
                            fgLibraryInfoMap.put(location, info);
                        }
                    }
                }
            }
        } catch (IOException | SAXException | ParserConfigurationException e) {
            log(e);
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) IPath(org.eclipse.core.runtime.IPath) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException) BufferedInputStream(java.io.BufferedInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 23 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project che by eclipse.

the class Launching method readInstallInfo.

/**
     * Reads the file of saved time stamps and populates the {@link #fgInstallTimeMap}.
     * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=266651 for more information
     *
     * @since 3.7
     */
private static void readInstallInfo() {
    fgInstallTimeMap = new HashMap<String, Long>();
    IPath libPath = getDefault().getStateLocation();
    //$NON-NLS-1$
    libPath = libPath.append(".install.xml");
    File file = libPath.toFile();
    if (file.exists()) {
        try {
            InputStream stream = new BufferedInputStream(new FileInputStream(file));
            DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            parser.setErrorHandler(new DefaultHandler());
            Element root = parser.parse(new InputSource(stream)).getDocumentElement();
            if (root.getNodeName().equalsIgnoreCase("dirs")) {
                //$NON-NLS-1$
                NodeList nodes = root.getChildNodes();
                Node node = null;
                Element element = null;
                for (int i = 0; i < nodes.getLength(); i++) {
                    node = nodes.item(i);
                    if (node.getNodeType() == Node.ELEMENT_NODE) {
                        element = (Element) node;
                        if (element.getNodeName().equalsIgnoreCase("entry")) {
                            //$NON-NLS-1$
                            //$NON-NLS-1$
                            String loc = element.getAttribute("loc");
                            //$NON-NLS-1$
                            String stamp = element.getAttribute("stamp");
                            try {
                                Long l = new Long(stamp);
                                fgInstallTimeMap.put(loc, l);
                            } catch (NumberFormatException nfe) {
                            //do nothing
                            }
                        }
                    }
                }
            }
        } catch (IOException e) {
            log(e);
        } catch (ParserConfigurationException e) {
            log(e);
        } catch (SAXException e) {
            log(e);
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) IPath(org.eclipse.core.runtime.IPath) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException) BufferedInputStream(java.io.BufferedInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 24 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project AndEngine by nicolasgramlich.

the class LevelLoader method loadLevelFromStream.

public void loadLevelFromStream(final InputStream pInputStream) throws IOException {
    try {
        final SAXParserFactory spf = SAXParserFactory.newInstance();
        final SAXParser sp = spf.newSAXParser();
        final XMLReader xr = sp.getXMLReader();
        this.onBeforeLoadLevel();
        final LevelParser levelParser = new LevelParser(this.mDefaultEntityLoader, this.mEntityLoaders);
        xr.setContentHandler(levelParser);
        xr.parse(new InputSource(new BufferedInputStream(pInputStream)));
        this.onAfterLoadLevel();
    } catch (final SAXException se) {
        Debug.e(se);
    /* Doesn't happen. */
    } catch (final ParserConfigurationException pe) {
        Debug.e(pe);
    /* Doesn't happen. */
    } finally {
        StreamUtils.close(pInputStream);
    }
}
Also used : InputSource(org.xml.sax.InputSource) BufferedInputStream(java.io.BufferedInputStream) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 25 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project AndEngine by nicolasgramlich.

the class TexturePackLoader method load.

public TexturePack load(final InputStream pInputStream, final String pAssetBasePath) throws TexturePackParseException {
    try {
        final SAXParserFactory spf = SAXParserFactory.newInstance();
        final SAXParser sp = spf.newSAXParser();
        final XMLReader xr = sp.getXMLReader();
        final TexturePackParser texturePackParser = new TexturePackParser(this.mAssetManager, pAssetBasePath, this.mTextureManager);
        xr.setContentHandler(texturePackParser);
        xr.parse(new InputSource(new BufferedInputStream(pInputStream)));
        return texturePackParser.getTexturePack();
    } catch (final SAXException e) {
        throw new TexturePackParseException(e);
    } catch (final ParserConfigurationException pe) {
        /* Doesn't happen. */
        return null;
    } catch (final IOException e) {
        throw new TexturePackParseException(e);
    } finally {
        StreamUtils.close(pInputStream);
    }
}
Also used : InputSource(org.xml.sax.InputSource) BufferedInputStream(java.io.BufferedInputStream) SAXParser(javax.xml.parsers.SAXParser) TexturePackParseException(org.andengine.util.texturepack.exception.TexturePackParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) 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