/* package */ String serialize() throws IOException { ByteArrayOutputStream s = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(s, "UTF8"); // $NON-NLS-1$ XMLWriter xmlWriter = new XMLWriter( writer, null /*use the workspace line delimiter*/, true /*print XML version*/); HashMap library = new HashMap(); library.put(TAG_VERSION, String.valueOf(CURRENT_VERSION)); library.put(TAG_SYSTEMLIBRARY, String.valueOf(this.isSystemLibrary)); xmlWriter.printTag(TAG_USERLIBRARY, library, true, true, false); for (int i = 0; i < this.entries.length; ++i) { ClasspathEntry cpEntry = (ClasspathEntry) this.entries[i]; HashMap archive = new HashMap(); archive.put(TAG_PATH, cpEntry.getPath().toString()); IPath sourceAttach = cpEntry.getSourceAttachmentPath(); if (sourceAttach != null) archive.put(TAG_SOURCEATTACHMENT, sourceAttach); IPath sourceAttachRoot = cpEntry.getSourceAttachmentRootPath(); if (sourceAttachRoot != null) archive.put(TAG_SOURCEATTACHMENTROOT, sourceAttachRoot); boolean hasExtraAttributes = cpEntry.extraAttributes != null && cpEntry.extraAttributes.length != 0; boolean hasRestrictions = cpEntry.getAccessRuleSet() != null; // access rule set is null if no access rules xmlWriter.printTag( TAG_ARCHIVE, archive, true, true, !(hasExtraAttributes || hasRestrictions)); // write extra attributes if necessary if (hasExtraAttributes) { cpEntry.encodeExtraAttributes(xmlWriter, true, true); } // write extra attributes and restriction if necessary if (hasRestrictions) { cpEntry.encodeAccessRules(xmlWriter, true, true); } // write archive end tag if necessary if (hasExtraAttributes || hasRestrictions) { xmlWriter.endTag(TAG_ARCHIVE, true /*insert tab*/, true /*insert new line*/); } } xmlWriter.endTag(TAG_USERLIBRARY, true /*insert tab*/, true /*insert new line*/); writer.flush(); writer.close(); return s.toString("UTF8"); // $NON-NLS-1$ }