public void registerNamespacesInto(Element element) { for (PluginNamespace namespace : xsdsFor.values()) { element.addNamespaceDeclaration(Namespace.getNamespace(namespace.prefix, namespace.uri)); } }
private Document createEmptyCruiseConfigDocument() { Element root = new Element("cruise"); Namespace xsiNamespace = Namespace.getNamespace("xsi", XML_NS); root.addNamespaceDeclaration(xsiNamespace); registry.registerNamespacesInto(root); root.setAttribute("noNamespaceSchemaLocation", "cruise-config.xsd", xsiNamespace); String xsds = registry.xsds(); if (!xsds.isEmpty()) { root.setAttribute("schemaLocation", xsds, xsiNamespace); } root.setAttribute("schemaVersion", Integer.toString(GoConstants.CONFIG_SCHEMA_VERSION)); return new Document(root); }
@Test public void registerAllConfigTagImplementationsProvidedByPlugins() throws MalformedURLException { BundleContext execCtx = PluginTestUtil.bundleCtxWithHeaders(DataStructureUtils.m(PluginNamespace.XSD_NAMESPACE_PREFIX, "exec", PluginNamespace.XSD_NAMESPACE_URI, "uri-exec")); PluggableViewModelFactory<PluginExec> factory = mock(PluggableViewModelFactory.class); ConfigTypeExtension exec = new TestTaskConfigTypeExtension<>(PluginExec.class, factory); ConfigurationExtension execTag = new ConfigurationExtension<>( new PluginNamespace(execCtx, new URL("file:///exec")), exec); BundleContext antCtx = PluginTestUtil.bundleCtxWithHeaders(DataStructureUtils.m(PluginNamespace.XSD_NAMESPACE_PREFIX, "ant", PluginNamespace.XSD_NAMESPACE_URI, "uri-ant")); ConfigTypeExtension ant = new TestTaskConfigTypeExtension<>(PluginAnt.class, mock(PluggableViewModelFactory.class)); ConfigurationExtension antTag = new ConfigurationExtension<>( new PluginNamespace(antCtx, new URL("file:///ant")), ant); when(pluginExtns.configTagImplementations()).thenReturn(Arrays.asList(execTag, antTag)); ConfigElementImplementationRegistry registry = new ConfigElementImplementationRegistry(pluginExtns); assertThat(registry.xsds(), containsString("uri-exec file:/exec")); assertThat(registry.xsds(), containsString("uri-ant file:/ant")); List<Class<? extends Task>> implementationTypes = registry.implementersOf(Task.class); assertThat(implementationTypes.contains(PluginExec.class), is(true)); assertThat(implementationTypes.contains(PluginAnt.class), is(true)); Element mock = mock(Element.class); registry.registerNamespacesInto(mock); verify(mock).addNamespaceDeclaration(Namespace.getNamespace("exec", "uri-exec")); verify(mock).addNamespaceDeclaration(Namespace.getNamespace("ant", "uri-ant")); }
@Override public void addNamespaceDeclaration(Element parent, Namespace additional) { parent.addNamespaceDeclaration(additional); }
/** * This will take the supplied <code>{@link Element}</code> and transfer its * namespaces to the global namespace storage. * * @param element * <code>Element</code> to read namespaces from. */ private void transferNamespaces(final Element element) { for (final Namespace ns : declaredNamespaces) { if (ns != element.getNamespace()) { element.addNamespaceDeclaration(ns); } } declaredNamespaces.clear(); }
/** * Read an Element off the ObjectInputStream. * * @see #writeObject(ObjectOutputStream) * @param in where to read the Element from. * @throws IOException if there is a reading problem. * @throws ClassNotFoundException when a class cannot be found */ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); content = new ContentList(this); int nss = in.readInt(); while (--nss >= 0) { addNamespaceDeclaration((Namespace)in.readObject()); } int ats = in.readInt(); while (--ats >= 0) { setAttribute((Attribute)in.readObject()); } int cs = in.readInt(); while (--cs >= 0) { addContent((Content)in.readObject()); } }
private static final Element processElement(final JDOMFactory factory, final StartElement event) { final QName qname = event.getName(); final Element element = factory.element(qname.getLocalPart(), Namespace.getNamespace(qname.getPrefix(), qname.getNamespaceURI())); // Handle attributes for (final Iterator<?> it = event.getAttributes(); it.hasNext(); ) { final javax.xml.stream.events.Attribute att = (javax.xml.stream.events.Attribute)it.next(); final QName aqname = att.getName(); final Namespace attNs = Namespace.getNamespace(aqname.getPrefix(), aqname.getNamespaceURI()); factory.setAttribute(element, factory.attribute( aqname.getLocalPart(), att.getValue(), AttributeType.getAttributeType(att.getDTDType()), attNs)); } for (final Iterator<?> it = event.getNamespaces(); it.hasNext();) { final javax.xml.stream.events.Namespace ns = (javax.xml.stream.events.Namespace)it.next(); element.addNamespaceDeclaration(Namespace.getNamespace( ns.getPrefix(), ns.getNamespaceURI())); } return element; }
private static final Element processElement(final JDOMFactory factory, final XMLStreamReader reader) { final Element element = factory.element(reader.getLocalName(), Namespace.getNamespace(reader.getPrefix(), reader.getNamespaceURI())); // Handle attributes for (int i=0, len=reader.getAttributeCount(); i<len; i++) { factory.setAttribute(element, factory.attribute( reader.getAttributeLocalName(i), reader.getAttributeValue(i), AttributeType.getAttributeType(reader.getAttributeType(i)), Namespace.getNamespace(reader.getAttributePrefix(i), reader.getAttributeNamespace(i)))); } // Handle Namespaces for (int i = 0, len = reader.getNamespaceCount(); i < len; i++) { element.addNamespaceDeclaration(Namespace.getNamespace( reader.getNamespacePrefix(i), reader.getNamespaceURI(i))); } return element; }
protected void generateModuleNamespaceDefs(final Element root) { for (final Namespace allModuleNamespace : allModuleNamespaces) { root.addNamespaceDeclaration(allModuleNamespace); } }
public Element getParametersRootElement(List<Parameter> params) { Element root = getParameters(params); root.addNamespaceDeclaration(UWS.NS); root.addNamespaceDeclaration(UWS.XLINK_NS); root.setAttribute(JobAttribute.VERSION.getAttributeName(), UWS.XSD_VERSION); return root; }
protected Element createRootElement(final Channel channel) { final Element root = new Element("RDF", getRDFNamespace()); root.addNamespaceDeclaration(getFeedNamespace()); root.addNamespaceDeclaration(getRDFNamespace()); root.addNamespaceDeclaration(getContentNamespace()); generateModuleNamespaceDefs(root); return root; }
@Override public void startRecord(final String identifier) { assert !isClosed(); currentElement = createElement(rootTagName); for (Namespace namespace : namespaces.values()) { currentElement.addNamespaceDeclaration(namespace); } document = new Document(currentElement); }
private void writeOneEntry( InvDataset ds, OutputStream out, StringBuffer mess) throws IOException { Element rootElem = new Element("DIF", defNS); Document doc = new Document(rootElem); writeDataset( ds, rootElem, mess); rootElem.addNamespaceDeclaration(defNS); rootElem.addNamespaceDeclaration(XMLEntityResolver.xsiNS); rootElem.setAttribute("schemaLocation", defNS.getURI()+" "+schemaLocation, XMLEntityResolver.xsiNS); // Output the document, use standard formatter XMLOutputter fmt = new XMLOutputter( Format.getPrettyFormat()); fmt.output( doc, out); }
private void writeOneEntry( InvDataset ds, OutputStream out, StringBuilder mess) throws IOException { Element rootElem = new Element("DIF", defNS); Document doc = new Document(rootElem); writeDataset( ds, rootElem, mess); rootElem.addNamespaceDeclaration(defNS); rootElem.addNamespaceDeclaration(XMLEntityResolver.xsiNS); rootElem.setAttribute("schemaLocation", defNS.getURI()+" "+schemaLocation, XMLEntityResolver.xsiNS); // Output the document, use standard formatter XMLOutputter fmt = new XMLOutputter( Format.getPrettyFormat()); fmt.output( doc, out); }
protected Element createRootElement(final Feed feed) { final Element root = new Element("feed", getFeedNamespace()); root.addNamespaceDeclaration(getFeedNamespace()); // Attribute version = new Attribute("version", getVersion()); // root.setAttribute(version); final String xmlBase = feed.getXmlBase(); if (xmlBase != null) { root.setAttribute("base", xmlBase, Namespace.XML_NAMESPACE); } generateModuleNamespaceDefs(root); return root; }
protected Element createRootElement(final Feed feed) { final Element root = new Element("feed", getFeedNamespace()); root.addNamespaceDeclaration(getFeedNamespace()); // Attribute version = new Attribute("version", getVersion()); // root.setAttribute(version); final String xmlBase = feed.getXmlBase(); if (xmlBase != null) { root.setAttribute("base", xmlBase, Namespace.XML_NAMESPACE); } generateModuleNamespaceDefs(root); return root; }
@Override protected Element createRootElement(final Channel channel) { final Element root = new Element("rss", getFeedNamespace()); final Attribute version = new Attribute("version", getVersion()); root.setAttribute(version); root.addNamespaceDeclaration(getContentNamespace()); generateModuleNamespaceDefs(root); return root; }
protected Element createRootElement(final Feed feed) { final Element root = new Element("feed", getFeedNamespace()); root.addNamespaceDeclaration(getFeedNamespace()); final Attribute version = new Attribute("version", getVersion()); root.setAttribute(version); generateModuleNamespaceDefs(root); return root; }
private void writeOneItem( InvDataset ds, OutputStream out) throws IOException { Element rootElem = new Element("itemRecord", defNS); Document doc = new Document(rootElem); writeDataset( ds, rootElem); rootElem.addNamespaceDeclaration(XMLEntityResolver.xsiNS); // rootElem.setAttribute("schemaLocation", schemaLocationLocal, XMLEntityResolver.xsiNS); rootElem.setAttribute("schemaLocation", defNS.getURI()+" "+schemaLocation, XMLEntityResolver.xsiNS); // Output the document, use standard formatter //XMLOutputter fmt = new XMLOutputter(" ", true); XMLOutputter fmt = new XMLOutputter( Format.getPrettyFormat()); fmt.output( doc, out); }
private void writeOneItem( InvDataset ds, OutputStream out) throws IOException { Element rootElem = new Element("dc", defNS); Document doc = new Document(rootElem); writeDataset( ds, rootElem); rootElem.addNamespaceDeclaration(XMLEntityResolver.xsiNS); // rootElem.setAttribute("schemaLocation", schemaLocation, XMLEntityResolver.xsiNS); rootElem.setAttribute("schemaLocation", defNS.getURI()+" "+schemaLocation, XMLEntityResolver.xsiNS); // Output the document, use standard formatter //XMLOutputter fmt = new XMLOutputter(" ", true); XMLOutputter fmt = new XMLOutputter( Format.getPrettyFormat()); fmt.output( doc, out); }