Example usage for org.eclipse.jdt.internal.core ClasspathEntry TAG_CLASSPATH

List of usage examples for org.eclipse.jdt.internal.core ClasspathEntry TAG_CLASSPATH

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core ClasspathEntry TAG_CLASSPATH.

Prototype

String TAG_CLASSPATH

To view the source code for org.eclipse.jdt.internal.core ClasspathEntry TAG_CLASSPATH.

Click Source Link

Usage

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

License:Open Source License

/**
 * Returns the XML String encoding of the class path.
 *///from w  w  w. jav  a  2s . c o  m
protected String encodeClasspath(IClasspathEntry[] classpath, IClasspathEntry[] referencedEntries,
        IPath outputLocation, boolean indent, Map unknownElements) throws JavaModelException {
    try {
        ByteArrayOutputStream s = new ByteArrayOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(s, "UTF8"); //$NON-NLS-1$
        XMLWriter xmlWriter = new XMLWriter(writer, this, true/*print XML version*/);

        xmlWriter.startTag(ClasspathEntry.TAG_CLASSPATH, indent);
        for (int i = 0; i < classpath.length; ++i) {
            ((ClasspathEntry) classpath[i]).elementEncode(xmlWriter, this.project.getFullPath(), indent, true,
                    unknownElements, false);
        }

        if (outputLocation != null) {
            outputLocation = outputLocation.removeFirstSegments(1);
            outputLocation = outputLocation.makeRelative();
            HashMap parameters = new HashMap();
            parameters.put(ClasspathEntry.TAG_KIND, ClasspathEntry.kindToString(ClasspathEntry.K_OUTPUT));
            parameters.put(ClasspathEntry.TAG_PATH, String.valueOf(outputLocation));
            xmlWriter.printTag(ClasspathEntry.TAG_CLASSPATHENTRY, parameters, indent, true, true);
        }

        if (referencedEntries != null) {
            for (int i = 0; i < referencedEntries.length; ++i) {
                ((ClasspathEntry) referencedEntries[i]).elementEncode(xmlWriter, this.project.getFullPath(),
                        indent, true, unknownElements, true);
            }
        }

        xmlWriter.endTag(ClasspathEntry.TAG_CLASSPATH, indent, true/*insert new line*/);
        writer.flush();
        writer.close();
        return s.toString("UTF8");//$NON-NLS-1$
    } catch (IOException e) {
        throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION);
    }
}