public void registerNamespacesInto(Element element) { for (PluginNamespace namespace : xsdsFor.values()) { element.addNamespaceDeclaration(Namespace.getNamespace(namespace.prefix, namespace.uri)); } }
public Namespace getPluginNamespace() { return Namespace.getNamespace(getPluginNamespacePrefix(), getPluginNamespaceUri()); }
private static Namespace namespaceFor(ConfigTag annotation) { return Namespace.getNamespace(annotation.namespacePrefix(), annotation.namespaceURI()); }
private static Namespace namespaceFor(AttributeAwareConfigTag annotation) { return Namespace.getNamespace(annotation.namespacePrefix(), annotation.namespaceURI()); }
private Element child(Element e, ConfigTag tag) { return e.getChild(tag.value(), Namespace.getNamespace(tag.namespacePrefix(), tag.namespaceURI())); }
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 shouldAddPluginNamespaceToPassedInElement() throws MalformedURLException { ConfigElementImplementationRegistry registry = new ConfigElementImplementationRegistry(pluginExtns); registry.xsdFor(PluginTestUtil.bundleCtxWithHeaders(m(PluginNamespace.XSD_NAMESPACE_PREFIX, "something", PluginNamespace.XSD_NAMESPACE_URI, "uri")), new File("file:///tmp/foo").toURI().toURL()); registry.xsdFor(PluginTestUtil.bundleCtxWithHeaders(m(PluginNamespace.XSD_NAMESPACE_PREFIX, "second", PluginNamespace.XSD_NAMESPACE_URI, "uri-1")), new File("file:///tmp/foo1").toURI().toURL()); Element foo = new Element("foo"); registry.registerNamespacesInto(foo); assertThat(foo.getNamespace("something"), is(Namespace.getNamespace("something", "uri"))); assertThat(foo.getNamespace("second"), is(Namespace.getNamespace("second", "uri-1"))); }
@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")); }
/** * This will retrieve (if in existence) or create (if not) a * <code>Namespace</code> for the supplied URI, and make it usable * as a default namespace, as no prefix is supplied. * This method is thread-safe. * * @param uri <code>String</code> URI of new <code>Namespace</code>. * @return <code>Namespace</code> - ready to use namespace. */ public static Namespace getNamespace(final String uri) { return getNamespace(NS_PREFIX_DEFAULT, uri); }
/** * Creates a new element with the supplied (local) name and a namespace * given by a URI. The element will be put into the unprefixed (default) * namespace. * * @param name name of the element * @param uri namespace URI for the element * @throws IllegalNameException if the given name is illegal as an element * name or the given URI is illegal as a * namespace URI */ public Element(final String name, final String uri) { this(name, Namespace.getNamespace(NS_PREFIX_DEFAULT, uri)); }
private Object readResolve() { return Namespace.getNamespace(pprefix, puri); }
/** * Creates a new element with the supplied (local) name and a namespace * given by the supplied prefix and URI combination. * * @param name local name of the element * @param prefix namespace prefix * @param uri namespace URI for the element * @throws IllegalNameException if the given name is illegal as an element * name, the given prefix is illegal as a * namespace prefix, or the given URI is * illegal as a namespace URI */ public Element(final String name, final String prefix, final String uri) { this(name, Namespace.getNamespace(prefix, uri)); }
/** * This will add the prefix mapping to the JDOM <code>Document</code> * object. * * @param prefix * <code>String</code> namespace prefix. * @param uri * <code>String</code> namespace URI. */ @Override public void startPrefixMapping(final String prefix, final String uri) throws SAXException { if (suppress) return; final Namespace ns = Namespace.getNamespace(prefix, uri); declaredNamespaces.add(ns); }
@Override public Element element(final int line, final int col, final String name, String uri) { return element(name, Namespace.getNamespace("", uri)); }
@Override public Element element(final int line, final int col, final String name, String prefix, String uri) { return element(name, Namespace.getNamespace(prefix, uri)); }
/** * Adds a namespace definition (prefix and URI) to the list of * namespaces known of this XPath expression. * <p> * <strong>Note</strong>: In XPath, there is no such thing as a * 'default namespace'. The empty prefix <b>always</b> resolves * to the empty namespace URI.</p> * * @param prefix the namespace prefix. * @param uri the namespace URI. * * @throws IllegalNameException if the prefix or uri are null or * empty strings or if they contain * illegal characters. */ public void addNamespace(String prefix, String uri) { addNamespace(Namespace.getNamespace(prefix, uri)); }
/** * Define a Namespace to be available for the XPath expression. If a * Namespace with the same prefix was previously defined then the prefix * will be re-defined. * * @param prefix * The namespace prefix to define. * @param uri * The namespace URI to define. * @return true if the Namespace prefix was newly defined, false if the * prefix was previously defined and has now been redefined. */ public boolean setNamespace(String prefix, String uri) { if (prefix == null) { throw new NullPointerException("Null prefix"); } if (uri == null) { throw new NullPointerException("Null URI"); } return setNamespace(Namespace.getNamespace(prefix, uri)); }
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; }
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; }
@Override public Object getVariableValue(String namespaceURI, String prefix, String localName) throws UnresolvableException { if (namespaceURI == null) { namespaceURI = ""; } if (prefix == null) { prefix = ""; } try { if ("".equals(namespaceURI)) { namespaceURI = getNamespace(prefix).getURI(); } return getVariable(localName, Namespace.getNamespace(namespaceURI)); } catch (IllegalArgumentException e) { throw new UnresolvableException("Unable to resolve variable " + localName + " in namespace '" + namespaceURI + "' to a vaulue."); } }