use of org.xml.sax.SAXParseException in project hadoop by apache.
the class OfflineEditsXmlLoader method loadEdits.
/**
* Loads edits file, uses visitor to process all elements
*/
@Override
public void loadEdits() throws IOException {
try {
XMLReader xr = XMLReaderFactory.createXMLReader();
xr.setContentHandler(this);
xr.setErrorHandler(this);
xr.setDTDHandler(null);
xr.parse(new InputSource(fileReader));
visitor.close(null);
} catch (SAXParseException e) {
System.out.println("XML parsing error: " + "\n" + "Line: " + e.getLineNumber() + "\n" + "URI: " + e.getSystemId() + "\n" + "Message: " + e.getMessage());
visitor.close(e);
throw new IOException(e.toString());
} catch (SAXException e) {
visitor.close(e);
throw new IOException(e.toString());
} catch (RuntimeException e) {
visitor.close(e);
throw e;
} finally {
fileReader.close();
}
}
use of org.xml.sax.SAXParseException 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 org.xml.sax.SAXParseException in project che by eclipse.
the class RefactoringSessionReader method startElement.
/**
* {@inheritDoc}
*/
public void startElement(final String uri, final String localName, final String qualifiedName, final Attributes attributes) throws SAXException {
if (IRefactoringSerializationConstants.ELEMENT_REFACTORING.equals(qualifiedName)) {
final int length = attributes.getLength();
final Map map = new HashMap(length);
//$NON-NLS-1$
String id = "";
//$NON-NLS-1$
String stamp = "";
//$NON-NLS-1$
String description = "";
String comment = null;
//$NON-NLS-1$
String flags = "0";
String project = null;
for (int index = 0; index < length; index++) {
final String name = attributes.getQName(index);
final String value = attributes.getValue(index);
if (IRefactoringSerializationConstants.ATTRIBUTE_ID.equals(name)) {
id = value;
} else if (IRefactoringSerializationConstants.ATTRIBUTE_STAMP.equals(name)) {
stamp = value;
} else if (IRefactoringSerializationConstants.ATTRIBUTE_DESCRIPTION.equals(name)) {
description = value;
} else if (IRefactoringSerializationConstants.ATTRIBUTE_FLAGS.equals(name)) {
flags = value;
} else if (IRefactoringSerializationConstants.ATTRIBUTE_COMMENT.equals(name)) {
if (//$NON-NLS-1$
!"".equals(value))
comment = value;
} else if (IRefactoringSerializationConstants.ATTRIBUTE_PROJECT.equals(name)) {
project = value;
} else if (!"".equals(name)) {
//$NON-NLS-1$
map.put(name, value);
}
}
int flag = 0;
try {
flag = Integer.parseInt(flags);
} catch (NumberFormatException exception) {
// Do nothing
}
RefactoringDescriptor descriptor = null;
if (fCreateDefaultDescriptors) {
descriptor = new DefaultRefactoringDescriptor(id, project, description, comment, map, flag);
} else {
if (fProject != null && project == null) {
// override project from file if fProject != null
project = fProject;
}
try {
descriptor = RefactoringContributionManager.getInstance().createDescriptor(id, project, description, comment, map, flag);
} catch (RuntimeException e) {
throw new SAXParseException(RefactoringCoreMessages.RefactoringSessionReader_invalid_values_in_xml, fLocator, e) {
private static final long serialVersionUID = 1L;
public Throwable getCause() {
// support proper 1.4-style exception chaining
return getException();
}
};
}
}
try {
descriptor.setTimeStamp(Long.valueOf(stamp).longValue());
} catch (NumberFormatException exception) {
// Do nothing
}
if (fRefactoringDescriptors == null)
fRefactoringDescriptors = new ArrayList();
fRefactoringDescriptors.add(descriptor);
} else if (IRefactoringSerializationConstants.ELEMENT_SESSION.equals(qualifiedName)) {
fSessionFound = true;
final String version = attributes.getValue(IRefactoringSerializationConstants.ATTRIBUTE_VERSION);
if (//$NON-NLS-1$
version != null && !"".equals(version))
fVersion = version;
fComment = attributes.getValue(IRefactoringSerializationConstants.ATTRIBUTE_COMMENT);
}
}
use of org.xml.sax.SAXParseException in project jphp by jphp-compiler.
the class WrapXmlProcessor method __construct.
@Signature
public void __construct(final Environment env) throws ParserConfigurationException, TransformerConfigurationException {
transformerFactory = TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
builderFactory = DocumentBuilderFactory.newInstance();
builder = builderFactory.newDocumentBuilder();
builder.setErrorHandler(new ErrorHandler() {
@Override
public void warning(SAXParseException exception) throws SAXException {
if (onWarning != null) {
onWarning.callAny(new JavaException(env, exception));
}
}
@Override
public void error(SAXParseException exception) throws SAXException {
if (onError != null) {
onError.callAny(new JavaException(env, exception));
}
}
@Override
public void fatalError(SAXParseException exception) throws SAXException {
if (onFatalError != null) {
onFatalError.callAny(new JavaException(env, exception));
} else {
throw exception;
}
}
});
}
use of org.xml.sax.SAXParseException in project XobotOS by xamarin.
the class Properties method loadFromXML.
/**
* Loads the properties from an {@code InputStream} containing the
* properties in XML form. The XML document must begin with (and conform to)
* following DOCTYPE:
*
* <pre>
* <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
* </pre>
*
* Also the content of the XML data must satisfy the DTD but the xml is not
* validated against it. The DTD is not loaded from the SYSTEM ID. After
* this method returns the InputStream is not closed.
*
* @param in the InputStream containing the XML document.
* @throws IOException in case an error occurs during a read operation.
* @throws InvalidPropertiesFormatException if the XML data is not a valid
* properties file.
*/
public synchronized void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException {
if (in == null) {
throw new NullPointerException();
}
if (builder == null) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new Error(e);
}
builder.setErrorHandler(new ErrorHandler() {
public void warning(SAXParseException e) throws SAXException {
throw e;
}
public void error(SAXParseException e) throws SAXException {
throw e;
}
public void fatalError(SAXParseException e) throws SAXException {
throw e;
}
});
builder.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
if (systemId.equals(PROP_DTD_NAME)) {
InputSource result = new InputSource(new StringReader(PROP_DTD));
result.setSystemId(PROP_DTD_NAME);
return result;
}
throw new SAXException("Invalid DOCTYPE declaration: " + systemId);
}
});
}
try {
Document doc = builder.parse(in);
NodeList entries = doc.getElementsByTagName("entry");
if (entries == null) {
return;
}
int entriesListLength = entries.getLength();
for (int i = 0; i < entriesListLength; i++) {
Element entry = (Element) entries.item(i);
String key = entry.getAttribute("key");
String value = entry.getTextContent();
/*
* key != null & value != null but key or(and) value can be
* empty String
*/
put(key, value);
}
} catch (IOException e) {
throw e;
} catch (SAXException e) {
throw new InvalidPropertiesFormatException(e);
}
}
Aggregations