Example usage for org.eclipse.jdt.internal.core.util Messages file_badFormat

List of usage examples for org.eclipse.jdt.internal.core.util Messages file_badFormat

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.util Messages file_badFormat.

Prototype

String file_badFormat

To view the source code for org.eclipse.jdt.internal.core.util Messages file_badFormat.

Click Source Link

Usage

From source file:io.sarl.eclipse.util.JavaClasspathParser.java

License:Apache License

/**
 * Reads and decode an XML classpath string. Returns a two-dimensional array, where the number of elements in the row is fixed to 2. The first
 * element is an array of raw classpath entries and the second element is an array of referenced entries that may have been stored by the client
 * earlier. See {@link IJavaProject#getReferencedClasspathEntries()} for more details.
 *
 * @param projectName// ww  w.  j  a  v  a  2s  .  co  m
 *            - the name of project containing the .classpath file
 * @param projectRootAbsoluteFullPath
 *            - the path to project containing the .classpath file
 * @param xmlClasspath
 *            - path to the XML
 * @param unknownElements
 *            - map of unknow elements
 * @return the set of CLasspath ENtries extracted from the .classpath
 * @throws IOException
 *             - exception during parsing of .classpath
 * @throws ClasspathEntry.AssertionFailedException
 *             - exception during parsing of .classpath
 */
@SuppressWarnings("checkstyle:npathcomplexity")
public static IClasspathEntry[][] decodeClasspath(String projectName, IPath projectRootAbsoluteFullPath,
        String xmlClasspath, Map<IPath, UnknownXmlElements> unknownElements)
        throws IOException, ClasspathEntry.AssertionFailedException {

    final List<IClasspathEntry> paths = new ArrayList<>();
    IClasspathEntry defaultOutput = null;
    final Element cpElement;

    try (StringReader reader = new StringReader(xmlClasspath);) {
        final DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        cpElement = parser.parse(new InputSource(reader)).getDocumentElement();
    } catch (SAXException e) {
        throw new IOException(Messages.file_badFormat);
    } catch (ParserConfigurationException e) {
        throw new IOException(Messages.file_badFormat);
    }

    if (!cpElement.getNodeName().equalsIgnoreCase("classpath")) { //$NON-NLS-1$
        throw new IOException(Messages.file_badFormat);
    }
    NodeList list = cpElement.getElementsByTagName(ClasspathEntry.TAG_CLASSPATHENTRY);
    int length = list.getLength();

    for (int i = 0; i < length; ++i) {
        final Node node = list.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            final IClasspathEntry entry = elementDecode((Element) node, projectName,
                    projectRootAbsoluteFullPath, unknownElements);
            if (entry != null) {
                if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
                    // separate output
                    defaultOutput = entry;
                } else {
                    paths.add(entry);
                }
            }
        }
    }
    final int pathSize = paths.size();
    final IClasspathEntry[][] entries = new IClasspathEntry[2][];
    entries[0] = new IClasspathEntry[pathSize + (defaultOutput == null ? 0 : 1)];
    paths.toArray(entries[0]);
    if (defaultOutput != null) {
        // ensure output is last item
        entries[0][pathSize] = defaultOutput;
    }
    paths.clear();
    list = cpElement.getElementsByTagName(ClasspathEntry.TAG_REFERENCED_ENTRY);
    length = list.getLength();

    for (int i = 0; i < length; ++i) {
        final Node node = list.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            final IClasspathEntry entry = elementDecode((Element) node, projectName,
                    projectRootAbsoluteFullPath, unknownElements);
            if (entry != null) {
                paths.add(entry);
            }
        }
    }
    entries[1] = new IClasspathEntry[paths.size()];
    paths.toArray(entries[1]);

    return entries;
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * Reads and decode an XML classpath string. Returns a two-dimensional array, where the number of elements in the row is fixed to 2.
 * The first element is an array of raw classpath entries and the second element is an array of referenced entries that may have been stored
 * by the client earlier. See {@link IJavaProject#getReferencedClasspathEntries()} for more details. 
 * //from   w  w  w  .  jav a  2s  .c  om
 */
public IClasspathEntry[][] decodeClasspath(String xmlClasspath, Map unknownElements)
        throws IOException, ClasspathEntry.AssertionFailedException {

    ArrayList paths = new ArrayList();
    IClasspathEntry defaultOutput = null;
    StringReader reader = new StringReader(xmlClasspath);
    Element cpElement;
    try {
        DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        cpElement = parser.parse(new InputSource(reader)).getDocumentElement();
    } catch (SAXException e) {
        throw new IOException(Messages.file_badFormat);
    } catch (ParserConfigurationException e) {
        throw new IOException(Messages.file_badFormat);
    } finally {
        reader.close();
    }

    if (!cpElement.getNodeName().equalsIgnoreCase("classpath")) { //$NON-NLS-1$
        throw new IOException(Messages.file_badFormat);
    }
    NodeList list = cpElement.getElementsByTagName(ClasspathEntry.TAG_CLASSPATHENTRY);
    int length = list.getLength();

    for (int i = 0; i < length; ++i) {
        Node node = list.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            IClasspathEntry entry = ClasspathEntry.elementDecode((Element) node, this, unknownElements);
            if (entry != null) {
                if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
                    defaultOutput = entry; // separate output
                } else {
                    paths.add(entry);
                }
            }
        }
    }
    int pathSize = paths.size();
    IClasspathEntry[][] entries = new IClasspathEntry[2][];
    entries[0] = new IClasspathEntry[pathSize + (defaultOutput == null ? 0 : 1)];
    paths.toArray(entries[0]);
    if (defaultOutput != null)
        entries[0][pathSize] = defaultOutput; // ensure output is last item

    paths.clear();
    list = cpElement.getElementsByTagName(ClasspathEntry.TAG_REFERENCED_ENTRY);
    length = list.getLength();

    for (int i = 0; i < length; ++i) {
        Node node = list.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            IClasspathEntry entry = ClasspathEntry.elementDecode((Element) node, this, unknownElements);
            if (entry != null) {
                paths.add(entry);
            }
        }
    }
    entries[1] = new IClasspathEntry[paths.size()];
    paths.toArray(entries[1]);

    return entries;
}