Example usage for org.eclipse.jdt.internal.core XMLWriter XMLWriter

List of usage examples for org.eclipse.jdt.internal.core XMLWriter XMLWriter

Introduction

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

Prototype

public XMLWriter(Writer writer, IJavaProject project, boolean printXmlVersion) 

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.
 *//* ww w.jav  a  2  s. 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);
    }
}

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

License:Open Source License

public String encodeClasspathEntry(IClasspathEntry classpathEntry) {
    try {/*from  w w  w.java 2  s .  com*/
        ByteArrayOutputStream s = new ByteArrayOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(s, "UTF8"); //$NON-NLS-1$
        XMLWriter xmlWriter = new XMLWriter(writer, this, false/*don't print XML version*/);

        ((ClasspathEntry) classpathEntry).elementEncode(xmlWriter, this.project.getFullPath(), true/*indent*/,
                true/*insert new line*/, null/*not interested in unknown elements*/,
                (classpathEntry.getReferencingEntry() != null));

        writer.flush();
        writer.close();
        return s.toString("UTF8");//$NON-NLS-1$
    } catch (IOException e) {
        return null; // never happens since all is done in memory
    }
}