use of javax.xml.parsers.ParserConfigurationException in project AndEngine by nicolasgramlich.
the class AnimationPackLoader method load.
public AnimationPack load(final InputStream pInputStream, final String pAssetBasePath) throws AnimationPackParseException {
try {
final SAXParserFactory spf = SAXParserFactory.newInstance();
final SAXParser sp = spf.newSAXParser();
final XMLReader xr = sp.getXMLReader();
final AnimationPackParser animationPackParser = new AnimationPackParser(this.mAssetManager, pAssetBasePath, this.mTextureManager);
xr.setContentHandler(animationPackParser);
xr.parse(new InputSource(new BufferedInputStream(pInputStream)));
return animationPackParser.getAnimationPack();
} catch (final SAXException e) {
throw new AnimationPackParseException(e);
} catch (final ParserConfigurationException pe) {
/* Doesn't happen. */
return null;
} catch (final IOException e) {
throw new AnimationPackParseException(e);
} finally {
StreamUtils.close(pInputStream);
}
}
use of javax.xml.parsers.ParserConfigurationException in project che by eclipse.
the class JavaProject method decodeClasspathEntry.
public IClasspathEntry decodeClasspathEntry(String encodedEntry) {
try {
if (encodedEntry == null)
return null;
StringReader reader = new StringReader(encodedEntry);
Element node;
try {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
node = parser.parse(new InputSource(reader)).getDocumentElement();
} catch (SAXException e) {
return null;
} catch (ParserConfigurationException e) {
return null;
} finally {
reader.close();
}
if (!node.getNodeName().equalsIgnoreCase(ClasspathEntry.TAG_CLASSPATHENTRY) || node.getNodeType() != Node.ELEMENT_NODE) {
return null;
}
return ClasspathEntry.elementDecode(node, this, null);
} catch (IOException e) {
// bad format
return null;
}
}
use of javax.xml.parsers.ParserConfigurationException in project che by eclipse.
the class RefactoringSessionReader method readSession.
/**
* Reads a refactoring history descriptor from the specified input object.
*
* @param source
* the input source
* @return a corresponding refactoring history descriptor, or
* <code>null</code>
* @throws CoreException
* if an error occurs while reading form the input source
*/
public RefactoringSessionDescriptor readSession(final InputSource source) throws CoreException {
fSessionFound = false;
try {
//$NON-NLS-1$
source.setSystemId("/");
createParser(SAXParserFactory.newInstance()).parse(source, this);
if (!fSessionFound)
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.REFACTORING_HISTORY_FORMAT_ERROR, RefactoringCoreMessages.RefactoringSessionReader_no_session, null));
if (fRefactoringDescriptors != null) {
if (//$NON-NLS-1$
fVersion == null || "".equals(fVersion))
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.MISSING_REFACTORING_HISTORY_VERSION, RefactoringCoreMessages.RefactoringSessionReader_missing_version_information, null));
if (!IRefactoringSerializationConstants.CURRENT_VERSION.equals(fVersion))
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.UNSUPPORTED_REFACTORING_HISTORY_VERSION, RefactoringCoreMessages.RefactoringSessionReader_unsupported_version_information, null));
return new RefactoringSessionDescriptor((RefactoringDescriptor[]) fRefactoringDescriptors.toArray(new RefactoringDescriptor[fRefactoringDescriptors.size()]), fVersion, fComment);
}
} catch (IOException exception) {
throwCoreException(exception, exception.getLocalizedMessage());
} catch (ParserConfigurationException exception) {
throwCoreException(exception, exception.getLocalizedMessage());
} catch (SAXParseException exception) {
String message = Messages.format(RefactoringCoreMessages.RefactoringSessionReader_invalid_contents_at, new Object[] { Integer.toString(exception.getLineNumber()), Integer.toString(exception.getColumnNumber()) });
throwCoreException(exception, message);
} catch (SAXException exception) {
throwCoreException(exception, exception.getLocalizedMessage());
} finally {
fRefactoringDescriptors = null;
fVersion = null;
fComment = null;
fLocator = null;
}
return null;
}
use of javax.xml.parsers.ParserConfigurationException in project cogtool by cogtool.
the class ObjectPersister method load.
// registerForPersistence
/**
* Load an Object from a file. This method assumes that all error checking
* and prompting/correction for the validity of the file has already
* been completed.
*
* @param src the File location of the saved Object
* @return a new instantiated Object
* @throws java.io.IOException if any file operation fails or the SAX XML
* parser fails
*/
public Object load(File src) throws IOException {
// See if an object is already loaded for the given file
String canonicalFileName = src.getCanonicalPath();
PersistInfo info = getInfoByName(canonicalFileName);
if (info != null) {
return info.obj;
}
// Attempt to create a file of 3x size in the temp directory
// to hold the expanded XML serialization.
File sizeCheckFile = File.createTempFile(tmpFilePrefix, ".size", tmpDir);
try {
checkDiskSpace(sizeCheckFile, 3 * src.length(), "Not enough temp space on disk to open file: " + src);
} finally {
sizeCheckFile.delete();
}
// If we're here, no exception was thrown; create checkpoint directory
File chkptFile = createTempDirectory();
// Open file as ZipFile and decompress
ZipFile zip = null;
try {
zip = new ZipFile(src);
// Unzip the file to the checkpoint directory
ZipUtil.unzip(zip, chkptFile);
} catch (ZipException ex) {
IOException newE = new IOException("load encountered zip compression error");
newE.initCause(ex);
throw newE;
} finally {
if (zip != null) {
zip.close();
}
}
// Load object from the expanded XML serialization
ObjectLoader l = new ObjectLoader();
Object obj = null;
Reader reader = null;
try {
reader = new InputStreamReader(new FileInputStream(new File(chkptFile, PERSIST_FILE)), "UTF-8");
Collection<?> objSet = l.load(new InputSource(reader), null);
// There should be only one top-level object
Iterator<?> objs = objSet.iterator();
if (objs.hasNext()) {
obj = objs.next();
}
// Register this file for future lookup, both by object
// and by file name
info = new PersistInfo(obj, chkptFile, src);
objInfos.put(obj, info);
fileInfos.put(canonicalFileName, info);
} catch (ParserConfigurationException e) {
IOException newE = new IOException("load encountered parser error");
newE.initCause(e);
throw newE;
} catch (SAXException e) {
IOException newE = new IOException("load encountered SAX error");
newE.initCause(e);
throw newE;
} finally {
if (reader != null) {
reader.close();
}
}
return obj;
}
use of javax.xml.parsers.ParserConfigurationException in project openhab1-addons by openhab.
the class OWServerBinding method getVariable.
String getVariable(String response, String romId, String name) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Get the DOM Builder
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
logger.error("Error parsing OWServer XML response " + e.getMessage());
}
// Load and Parse the XML document
// document contains the complete XML as a Tree.
Document document = null;
try {
InputSource is = new InputSource(new StringReader(response));
document = builder.parse(is);
} catch (SAXException e) {
logger.error("Error reading OWServer XML response " + e.getMessage());
} catch (IOException e) {
logger.error("Error reading OWServer XML response " + e.getMessage());
}
// Iterating through the nodes and extracting the data.
NodeList nodeList = document.getDocumentElement().getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeName().startsWith("owd_")) {
boolean romMatch = false;
NodeList childNodes = node.getChildNodes();
for (int j = 0; j < childNodes.getLength(); j++) {
Node cNode = childNodes.item(j);
// Identifying the child tag of employee encountered.
if (cNode instanceof Element) {
String content = cNode.getLastChild().getTextContent().trim();
if (cNode.getNodeName().equals("ROMId") & content.equals(romId)) {
romMatch = true;
}
String nname = cNode.getNodeName();
if (nname.equals(name) & romMatch == true) {
return content;
}
}
}
}
}
return null;
}
Aggregations