Search in sources :

Example 26 with SAXException

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. ");
    }
}
Also used : IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 27 with SAXException

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;
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) IJavaElement(org.eclipse.jdt.core.IJavaElement) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 28 with SAXException

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DefaultRefactoringDescriptor(org.eclipse.ltk.internal.core.refactoring.history.DefaultRefactoringDescriptor) RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) CoreException(org.eclipse.core.runtime.CoreException) SAXParseException(org.xml.sax.SAXParseException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) RefactoringSessionDescriptor(org.eclipse.ltk.core.refactoring.RefactoringSessionDescriptor) SAXException(org.xml.sax.SAXException)

Example 29 with SAXException

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();
}
Also used : SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 30 with SAXException

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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.w3c.dom.Document) DefaultHandler(org.xml.sax.helpers.DefaultHandler) Template(org.eclipse.jface.text.templates.Template) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Collection(java.util.Collection) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashSet(java.util.HashSet)

Aggregations

SAXException (org.xml.sax.SAXException)1084 IOException (java.io.IOException)653 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)387 Document (org.w3c.dom.Document)258 DocumentBuilder (javax.xml.parsers.DocumentBuilder)213 InputSource (org.xml.sax.InputSource)205 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)158 InputStream (java.io.InputStream)141 Element (org.w3c.dom.Element)115 File (java.io.File)109 NodeList (org.w3c.dom.NodeList)106 SAXParseException (org.xml.sax.SAXParseException)104 Node (org.w3c.dom.Node)91 StringReader (java.io.StringReader)83 TransformerException (javax.xml.transform.TransformerException)82 ByteArrayInputStream (java.io.ByteArrayInputStream)81 SAXParser (javax.xml.parsers.SAXParser)76 ArrayList (java.util.ArrayList)71 FileInputStream (java.io.FileInputStream)64 XMLReader (org.xml.sax.XMLReader)56