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;
}
}
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;
}
}
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;
}
}
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();
}
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"));
}
}
Aggregations