use of org.xml.sax.SAXException in project darkFunction-Editor by darkFunction.
the class JarvWriter method close.
public void close() throws IOException {
try {
verifierHandler.endDocument();
super.close();
} catch (SAXException se) {
throw new IOException("Need to wrap the SAX exception in end document. ");
}
}
use of org.xml.sax.SAXException 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 org.xml.sax.SAXException 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.SAXException in project che by eclipse.
the class CheCodeFormatterOptions method getCheDefaultSettings.
private Map<String, String> getCheDefaultSettings() {
SAXParserFactory factory = SAXParserFactory.newInstance();
XMLParser parserXML = new XMLParser();
try {
SAXParser parser = factory.newSAXParser();
parser.parse(getClass().getResourceAsStream(DEFAULT_CODESTYLE), parserXML);
} catch (ParserConfigurationException | SAXException | IOException e) {
LOG.error("It is not possible to parse file " + DEFAULT_CODESTYLE, e);
}
return parserXML.getSettings();
}
use of org.xml.sax.SAXException in project che by eclipse.
the class TemplateReaderWriter method read.
/**
* Reads templates from an <code>InputSource</code> and adds them to the templates.
*
* @param source the input source
* @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur
* @param singleId the template id to extract, or <code>null</code> to read in all templates
* @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
* @throws IOException if reading from the stream fails
*/
private TemplatePersistenceData[] read(InputSource source, ResourceBundle bundle, String singleId) throws IOException {
try {
Collection templates = new ArrayList();
Set ids = new HashSet();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
parser.setErrorHandler(new DefaultHandler());
Document document = parser.parse(source);
NodeList elements = document.getElementsByTagName(TEMPLATE_ELEMENT);
int count = elements.getLength();
for (int i = 0; i != count; i++) {
Node node = elements.item(i);
NamedNodeMap attributes = node.getAttributes();
if (attributes == null)
continue;
String id = getStringValue(attributes, ID_ATTRIBUTE, null);
if (id != null && ids.contains(id))
//$NON-NLS-1$
throw new IOException(TemplatePersistenceMessages.getString("TemplateReaderWriter.duplicate.id"));
if (singleId != null && !singleId.equals(id))
continue;
boolean deleted = getBooleanValue(attributes, DELETED_ATTRIBUTE, false);
String name = getStringValue(attributes, NAME_ATTRIBUTE);
name = translateString(name, bundle);
//$NON-NLS-1$
String description = getStringValue(attributes, DESCRIPTION_ATTRIBUTE, "");
description = translateString(description, bundle);
String context = getStringValue(attributes, CONTEXT_ATTRIBUTE);
if (name == null || context == null)
//$NON-NLS-1$
throw new IOException(TemplatePersistenceMessages.getString("TemplateReaderWriter.error.missing_attribute"));
boolean enabled = getBooleanValue(attributes, ENABLED_ATTRIBUTE, true);
boolean autoInsertable = getBooleanValue(attributes, AUTO_INSERTABLE_ATTRIBUTE, true);
StringBuffer buffer = new StringBuffer();
NodeList children = node.getChildNodes();
for (int j = 0; j != children.getLength(); j++) {
String value = children.item(j).getNodeValue();
if (value != null)
buffer.append(value);
}
String pattern = buffer.toString();
pattern = translateString(pattern, bundle);
Template template = new Template(name, description, context, pattern, autoInsertable);
TemplatePersistenceData data = new TemplatePersistenceData(template, enabled, id);
data.setDeleted(deleted);
templates.add(data);
if (singleId != null && singleId.equals(id))
break;
}
return (TemplatePersistenceData[]) templates.toArray(new TemplatePersistenceData[templates.size()]);
} catch (ParserConfigurationException e) {
Assert.isTrue(false);
} catch (SAXException e) {
//$NON-NLS-1$
throw (IOException) new IOException("Could not read template file").initCause(e);
}
// dummy
return null;
}
Aggregations