private static void toXml(XmlWriter w, Resource resource) throws IOException { w.element(RepositoryParser.RESOURCE) .attribute(Resource.ID, resource.getId()) .attribute(Resource.SYMBOLIC_NAME, resource.getSymbolicName()) .attribute(Resource.PRESENTATION_NAME, resource.getPresentationName()) .attribute(Resource.URI, getRelativeUri(resource, Resource.URI)) .attribute(Resource.VERSION, resource.getVersion().toString()); w.textElement(Resource.DESCRIPTION, resource.getProperties().get(Resource.DESCRIPTION)) .textElement(Resource.SIZE, resource.getProperties().get(Resource.SIZE)) .textElement( Resource.DOCUMENTATION_URI, getRelativeUri(resource, Resource.DOCUMENTATION_URI)) .textElement(Resource.SOURCE_URI, getRelativeUri(resource, Resource.SOURCE_URI)) .textElement(Resource.JAVADOC_URI, getRelativeUri(resource, Resource.JAVADOC_URI)) .textElement(Resource.LICENSE_URI, getRelativeUri(resource, Resource.LICENSE_URI)); String[] categories = resource.getCategories(); for (int i = 0; categories != null && i < categories.length; i++) { w.element(RepositoryParser.CATEGORY).attribute(RepositoryParser.ID, categories[i]).end(); } Capability[] capabilities = resource.getCapabilities(); for (int i = 0; capabilities != null && i < capabilities.length; i++) { toXml(w, capabilities[i]); } Requirement[] requirements = resource.getRequirements(); for (int i = 0; requirements != null && i < requirements.length; i++) { toXml(w, requirements[i]); } w.end(); }
private static void toXml(XmlWriter w, Capability capability) throws IOException { w.element(RepositoryParser.CAPABILITY).attribute(RepositoryParser.NAME, capability.getName()); Property[] props = capability.getProperties(); for (int j = 0; props != null && j < props.length; j++) { toXml(w, props[j]); } w.end(); }
public void testSimpleXml() { OutputStream byteOut = new ByteArrayOutputStream(); XmlWriter writer = new XmlWriter(byteOut); writer.start("templates"); writer.start("template"); writer.addAttribute("name", "reset"); writer.end(); writer.end(); String xml = "<templates>" + NL + " <template name=\"reset\"/>" + NL + "</templates>" + NL; assertEquals(xml, byteOut.toString()); }
private static void toXml(XmlWriter w, Repository repository) throws IOException { SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmss.SSS"); w.element(RepositoryParser.REPOSITORY) .attribute(RepositoryParser.NAME, repository.getName()) .attribute( RepositoryParser.LASTMODIFIED, format.format(new Date(repository.getLastModified()))); if (repository instanceof RepositoryImpl) { Referral[] referrals = ((RepositoryImpl) repository).getReferrals(); for (int i = 0; referrals != null && i < referrals.length; i++) { w.element(RepositoryParser.REFERRAL) .attribute(RepositoryParser.DEPTH, new Integer(referrals[i].getDepth())) .attribute(RepositoryParser.URL, referrals[i].getUrl()) .end(); } } Resource[] resources = repository.getResources(); for (int i = 0; resources != null && i < resources.length; i++) { toXml(w, resources[i]); } w.end(); }