Search in sources :

Example 91 with SAXParserFactory

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

the class MeshLoader method load.

public Object load(AssetInfo info) throws IOException {
    try {
        key = info.getKey();
        meshName = key.getName();
        folderName = key.getFolder();
        String ext = key.getExtension();
        meshName = meshName.substring(0, meshName.length() - ext.length() - 1);
        if (folderName != null && folderName.length() > 0) {
            meshName = meshName.substring(folderName.length());
        }
        assetManager = info.getManager();
        if (key instanceof OgreMeshKey) {
            // OgreMeshKey is being used, try getting the material list
            // from it
            OgreMeshKey meshKey = (OgreMeshKey) key;
            materialList = meshKey.getMaterialList();
            String materialName = meshKey.getMaterialName();
            // Material list not set but material name is available
            if (materialList == null && materialName != null) {
                OgreMaterialKey materialKey = new OgreMaterialKey(folderName + materialName + ".material");
                try {
                    materialList = (MaterialList) assetManager.loadAsset(materialKey);
                } catch (AssetNotFoundException e) {
                    logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[] { materialKey, key });
                }
            }
        } else {
            // Make sure to reset it to null so that previous state
            // doesn't leak onto this one
            materialList = null;
        }
        // default method.
        if (materialList == null) {
            OgreMaterialKey materialKey = new OgreMaterialKey(folderName + meshName + ".material");
            try {
                materialList = (MaterialList) assetManager.loadAsset(materialKey);
            } catch (AssetNotFoundException e) {
                logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[] { materialKey, key });
            }
        }
        // Added by larynx 25.06.2011
        // Android needs the namespace aware flag set to true                 
        // Kirill 30.06.2011
        // Now, hack is applied for both desktop and android to avoid
        // checking with JmeSystem.
        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(info.openStream());
            xr.parse(new InputSource(r));
        } finally {
            if (r != null) {
                r.close();
            }
        }
        return compileModel();
    } catch (SAXException ex) {
        IOException ioEx = new IOException("Error while parsing Ogre3D mesh.xml");
        ioEx.initCause(ex);
        throw ioEx;
    } catch (ParserConfigurationException ex) {
        IOException ioEx = new IOException("Error while parsing Ogre3D mesh.xml");
        ioEx.initCause(ex);
        throw ioEx;
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) OgreMaterialKey(com.jme3.scene.plugins.ogre.matext.OgreMaterialKey) 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 92 with SAXParserFactory

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

the class SceneLoader method load.

public Object load(AssetInfo info) throws IOException {
    try {
        key = info.getKey();
        assetManager = info.getManager();
        sceneName = key.getName();
        String ext = key.getExtension();
        folderName = key.getFolder();
        sceneName = sceneName.substring(0, sceneName.length() - ext.length() - 1);
        reset();
        // == Run 1st pass over XML file to determine material list ==
        materialList = materialLoader.load(assetManager, folderName, info.openStream());
        if (materialList == null || materialList.isEmpty()) {
            // NOTE: No materials were found by searching the externals section.
            // Try finding a similarly named material file in the same folder.
            // (Backward compatibility only!)
            OgreMaterialKey materialKey = new OgreMaterialKey(sceneName + ".material");
            try {
                materialList = (MaterialList) assetManager.loadAsset(materialKey);
            } catch (AssetNotFoundException ex) {
                logger.log(Level.WARNING, "Cannot locate {0} for scene {1}", new Object[] { materialKey, key });
                materialList = null;
            }
        }
        // == Run 2nd pass to load entities and other objects ==
        // Added by larynx 25.06.2011
        // Android needs the namespace aware flag set to true 
        // Kirill 30.06.2011
        // Now, hack is applied for both desktop and android to avoid
        // checking with JmeSystem.
        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(info.openStream());
            xr.parse(new InputSource(r));
        } finally {
            if (r != null) {
                r.close();
            }
        }
        return root;
    } 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) OgreMaterialKey(com.jme3.scene.plugins.ogre.matext.OgreMaterialKey) 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 93 with SAXParserFactory

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

the class SkeletonLoader method load.

public Object load(InputStream in) throws IOException {
    try {
        // Added by larynx 25.06.2011
        // Android needs the namespace aware flag set to true 
        // Kirill 30.06.2011
        // Now, hack is applied for both desktop and android to avoid
        // checking with JmeSystem.
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XMLReader xr = factory.newSAXParser().getXMLReader();
        xr.setContentHandler(this);
        xr.setErrorHandler(this);
        InputStreamReader r = new InputStreamReader(in);
        xr.parse(new InputSource(r));
        if (animations == null) {
            animations = new ArrayList<Animation>();
        }
        AnimData data = new AnimData(skeleton, animations);
        skeleton = null;
        animations = null;
        return data;
    } catch (SAXException ex) {
        IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
        ioEx.initCause(ex);
        fullReset();
        throw ioEx;
    } catch (ParserConfigurationException ex) {
        IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
        ioEx.initCause(ex);
        fullReset();
        throw ioEx;
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) Animation(com.jme3.animation.Animation) 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 94 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project translationstudio8 by heartsome.

the class XlsxRowReader method readCells.

private void readCells(InputStream sheetInputStream, ReadOnlySharedStringsTable sharedStringsTable, IProgressMonitor monitor) throws ParserConfigurationException, SAXException, IOException {
    InputSource sheetSource = new InputSource(sheetInputStream);
    SAXParserFactory saxFactory = SAXParserFactory.newInstance();
    SAXParser saxParser = saxFactory.newSAXParser();
    XMLReader sheetParser = saxParser.getXMLReader();
    ContentHandler handler = new XSSFHander(sharedStringsTable, monitor);
    sheetParser.setContentHandler(handler);
    sheetParser.parse(sheetSource);
    rowsHandler.handleRows(rowCache);
    rowCache.clear();
}
Also used : InputSource(org.xml.sax.InputSource) SAXParser(javax.xml.parsers.SAXParser) XMLReader(org.xml.sax.XMLReader) ContentHandler(org.xml.sax.ContentHandler) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 95 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project translationstudio8 by heartsome.

the class XSLTransformationDialog method transform.

/**
	 * 转换文件
	 * @param strSourcePath
	 *            源文件路径
	 * @param strXSLPath
	 *            XSL 文件路径
	 * @param strTargetPath
	 *            转变文件路径
	 * @throws Exception
	 *             ;
	 */
private void transform(String strSourcePath, String strXSLPath, String strTargetPath) throws Exception {
    TransformerFactory tfactory = TransformerFactory.newInstance();
    String catalogPath = PluginUtil.getCataloguePath();
    if (tfactory.getFeature(SAXSource.FEATURE)) {
        // Standard way of creating an XMLReader in JAXP 1.1.
        SAXParserFactory pfactory = SAXParserFactory.newInstance();
        // Very important!
        pfactory.setNamespaceAware(true);
        // Turn on validation.
        // pfactory.setValidating(true);
        // Get an XMLReader.
        XMLReader reader = pfactory.newSAXParser().getXMLReader();
        reader.setEntityResolver(new Catalogue(catalogPath));
        // Instantiate an error handler (see the Handler inner class below)
        // that will report any
        // errors or warnings that occur as the XMLReader is parsing the XML
        // input.
        reader.setErrorHandler(new HSErrorHandler());
        // Standard way of creating a transformer from a URL.
        Transformer t = tfactory.newTransformer(new StreamSource(strXSLPath));
        // Specify a SAXSource that takes both an XMLReader and a URL.
        SAXSource source = new SAXSource(reader, new InputSource(strSourcePath));
        // Transform to a file.
        t.transform(source, new StreamResult(strTargetPath));
    } else {
        //$NON-NLS-1$
        throw new Exception(Messages.getString("dialog.XSLTransformationDialog.msg6"));
    }
}
Also used : Catalogue(net.heartsome.xml.Catalogue) HSErrorHandler(net.heartsome.xml.HSErrorHandler) InputSource(org.xml.sax.InputSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) SAXSource(javax.xml.transform.sax.SAXSource) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

SAXParserFactory (javax.xml.parsers.SAXParserFactory)183 SAXParser (javax.xml.parsers.SAXParser)141 InputSource (org.xml.sax.InputSource)76 SAXException (org.xml.sax.SAXException)75 IOException (java.io.IOException)62 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)53 XMLReader (org.xml.sax.XMLReader)37 DefaultHandler (org.xml.sax.helpers.DefaultHandler)27 InputStream (java.io.InputStream)22 File (java.io.File)21 SAXSource (javax.xml.transform.sax.SAXSource)21 ByteArrayInputStream (java.io.ByteArrayInputStream)16 StringReader (java.io.StringReader)15 Unmarshaller (javax.xml.bind.Unmarshaller)13 Attributes (org.xml.sax.Attributes)13 JAXBContext (javax.xml.bind.JAXBContext)12 SAXParseException (org.xml.sax.SAXParseException)10 InputStreamReader (java.io.InputStreamReader)9 ArrayList (java.util.ArrayList)9 ValidationEvent (javax.xml.bind.ValidationEvent)9