/** * Given a namespace, get the corrisponding prefix from the current * namespace support context. * * @param prefix The prefix to look up, which may be an empty string ("") for the default Namespace. * * @return The associated Namespace URI, or null if the prefix * is undeclared in this context. */ public String getNamespaceForPrefix(String prefix) { return this.getNamespaceSupport().getURI(prefix); }
/** * Given a namespace, get the corrisponding prefix from the current * namespace support context. * * @param prefix The prefix to look up, which may be an empty string ("") for the default Namespace. * * @return The associated Namespace URI, or null if the prefix * is undeclared in this context. */ public String getNamespaceForPrefix(String prefix) { return this.getNamespaceSupport().getURI(prefix); }
while (allPrefixes.hasMoreElements()) { String prefix = (String) allPrefixes.nextElement(); if (uri.equals(getURI(prefix))) { prefixes.add(prefix);
/** * Copy the namespace declarations from the NamespaceSupport object. * Take care to call resolveInheritedNamespaceDecls. * after all namespace declarations have been added. * * @param nsSupport non-null reference to NamespaceSupport from * the ContentHandler. * @param excludeXSLDecl true if XSLT namespaces should be ignored. * * @throws TransformerException */ public void setPrefixes(NamespaceSupport nsSupport, boolean excludeXSLDecl) throws TransformerException { Enumeration decls = nsSupport.getDeclaredPrefixes(); while (decls.hasMoreElements()) { String prefix = (String) decls.nextElement(); if (null == m_declaredPrefixes) m_declaredPrefixes = new ArrayList(); String uri = nsSupport.getURI(prefix); if (excludeXSLDecl && uri.equals(Constants.S_XSLNAMESPACEURL)) continue; // System.out.println("setPrefixes - "+prefix+", "+uri); XMLNSDecl decl = new XMLNSDecl(prefix, uri, false); m_declaredPrefixes.add(decl); } }
/** * Copy the namespace declarations from the NamespaceSupport object. * Take care to call resolveInheritedNamespaceDecls. * after all namespace declarations have been added. * * @param nsSupport non-null reference to NamespaceSupport from * the ContentHandler. * @param excludeXSLDecl true if XSLT namespaces should be ignored. * * @throws TransformerException */ public void setPrefixes(NamespaceSupport nsSupport, boolean excludeXSLDecl) throws TransformerException { Enumeration decls = nsSupport.getDeclaredPrefixes(); while (decls.hasMoreElements()) { String prefix = (String) decls.nextElement(); if (null == m_declaredPrefixes) m_declaredPrefixes = new ArrayList(); String uri = nsSupport.getURI(prefix); if (excludeXSLDecl && uri.equals(Constants.S_XSLNAMESPACEURL)) continue; // System.out.println("setPrefixes - "+prefix+", "+uri); XMLNSDecl decl = new XMLNSDecl(prefix, uri, false); m_declaredPrefixes.add(decl); } }
public void scan( Element e) throws SAXException { setCurrentLocation( e ); receiver.setDocumentLocator(locator); receiver.startDocument(); NamespaceSupport nss = new NamespaceSupport(); buildNamespaceSupport( nss, e.getParentNode() ); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); receiver.startPrefixMapping( prefix, nss.getURI(prefix) ); } visit(e); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); receiver.endPrefixMapping( prefix ); } setCurrentLocation( e ); receiver.endDocument(); }
@Test public void testMultiple() throws Exception { NamespaceSupport ctx = parser.parse( "xmlns(foo=http://bar), xmlns(ex=http://example.com),xmlns(gs=http://geoserver.org)"); assertEquals("http://bar", ctx.getURI("foo")); assertEquals("http://example.com", ctx.getURI("ex")); assertEquals("http://geoserver.org", ctx.getURI("gs")); }
@Test public void testWfs20Syntax() throws Exception { NamespaceKvpParser parser = new NamespaceKvpParser("namespaces", true); NamespaceSupport ctx = parser.parse( "xmlns(http://bar), xmlns(ex,http://example.com),xmlns(gs,http://geoserver.org)"); assertEquals("http://bar", ctx.getURI("")); assertEquals("http://example.com", ctx.getURI("ex")); assertEquals("http://geoserver.org", ctx.getURI("gs")); } }
@Test public void testSingle() throws Exception { NamespaceSupport ctx = parser.parse("xmlns(foo=http://bar)"); assertEquals("http://bar", ctx.getURI("foo")); }
@Test public void testDefaultNamespace() throws Exception { NamespaceSupport ctx = parser.parse("xmlns(http://default.namespace.com)"); assertEquals("http://default.namespace.com", ctx.getURI(XMLConstants.DEFAULT_NS_PREFIX)); }
public String getNamespaceURI(String prefix) { return namespaceSupport.getURI(prefix); }
/** * Creates a qualified name from a string by parsing out the colon as the prefix / local * separator. * * @param name The possibly qualified name. * @param namespaces The namespace prefix uri mappings. */ public static QName qName(String name, NamespaceSupport namespaces) { int dot = name.indexOf(':'); if (dot > -1) { String[] split = name.split(":"); String prefix = split[0]; String local = split[1]; return new QName(namespaces.getURI(prefix), local, prefix); } return new QName(name); }
String findGMLPrefix(Encoder encoder) { NamespaceSupport ns = encoder.getNamespaces(); Enumeration<String> p = ns.getPrefixes(); while (p.hasMoreElements()) { String prefix = p.nextElement(); String uri = ns.getURI(prefix); if (uri.startsWith(GML.NAMESPACE)) { return prefix; } } return "gml"; }
private static void addNamespaces(NamespaceSupport ns, JXPathContext context) { Enumeration<String> prefixes = ns.getPrefixes(); while (prefixes.hasMoreElements()) { String prefix = prefixes.nextElement(); String uri = ns.getURI(prefix); context.registerNamespace(prefix, uri); } }
/** * Utility method to copy namespace declarations from "sub" translators into this ns * support... */ protected void addNamespaceDeclarations(TranslatorSupport trans) { NamespaceSupport additional = trans.getNamespaceSupport(); java.util.Enumeration declared = additional.getDeclaredPrefixes(); while (declared.hasMoreElements()) { String prefix1 = declared.nextElement().toString(); nsSupport.declarePrefix(prefix1, additional.getURI(prefix1)); } }
public AppSchemaFeatureTypeRegistry(NamespaceSupport namespaces) { super( new ComplexFeatureTypeFactoryImpl(), new GmlFeatureTypeRegistryConfiguration( namespaces == null ? null : namespaces.getURI("gml"))); } }
public void set(Object object, String xpath, Object value, Class target) throws IllegalAttributeException { if (object instanceof FeatureType) { throw new IllegalAttributeException(null, "feature type is immutable"); } JXPathContext context = JXPathContext.newContext(object); Enumeration declaredPrefixes = namespaces.getDeclaredPrefixes(); while (declaredPrefixes.hasMoreElements()) { String prefix = (String) declaredPrefixes.nextElement(); String uri = namespaces.getURI(prefix); context.registerNamespace(prefix, uri); } context.setValue(xpath, value); assert value == context.getValue(xpath); } }
public GML3Delegate(Encoder encoder) { this.gmlPrefix = findGMLPrefix(encoder); String gmlURI = encoder.getNamespaces().getURI(gmlPrefix); this.gmlUri = gmlURI != null ? gmlURI : GML.NAMESPACE; this.featureMembers = FEATURE_MEMBERS.derive(gmlPrefix, gmlURI); this.featureMember = FEATURE_MEMBER.derive(gmlPrefix, gmlURI); this.srsSyntax = (SrsSyntax) encoder.getContext().getComponentInstanceOfType(SrsSyntax.class); this.numDecimals = getNumDecimals(encoder.getConfiguration()); this.padWithZeros = getPadWithZeros(encoder.getConfiguration()); this.decimalEncoding = getForceDecimalEncoding(encoder.getConfiguration()); this.encodeMeasures = getEncodecoordinatesMeasures(encoder.getConfiguration()); this.encodeSeparateMember = encoder.getConfiguration().hasProperty(GMLConfiguration.ENCODE_FEATURE_MEMBER); }