Refine search
/** * Recursively visit ancestors and build up {@link NamespaceSupport} oject. */ private void buildNamespaceSupport(NamespaceSupport nss, Node node) { if(node==null || node.getNodeType()!=Node.ELEMENT_NODE) return; buildNamespaceSupport( nss, node.getParentNode() ); nss.pushContext(); NamedNodeMap atts = node.getAttributes(); for( int i=0; i<atts.getLength(); i++ ) { Attr a = (Attr)atts.item(i); if( "xmlns".equals(a.getPrefix()) ) { nss.declarePrefix( a.getLocalName(), a.getValue() ); continue; } if( "xmlns".equals(a.getName()) ) { nss.declarePrefix( "", a.getValue() ); continue; } } }
/** * 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(); }
Enumeration allPrefixes = getPrefixes(); while (allPrefixes.hasMoreElements()) { String prefix = (String) allPrefixes.nextElement(); if (uri.equals(getURI(prefix))) { prefixes.add(prefix);
contentHandler.endElement("", "", qName.intern()); contentHandler.endElement(names[0], names[1], names[2]); Enumeration prefixes = nsSupport.getDeclaredPrefixes(); while (prefixes.hasMoreElements()) { String prefix = (String)prefixes.nextElement(); contentHandler.endPrefixMapping(prefix); nsSupport.popContext();
if (namespaces.getPrefix(XS.NAMESPACE) == null) { namespaces.declarePrefix("xs", XS.NAMESPACE); serializer.startDocument(); for (Enumeration e = namespaces.getPrefixes(); e.hasMoreElements(); ) { String prefix = (String) e.nextElement(); String uri = namespaces.getURI(prefix); serializer.startPrefixMapping(prefix, uri); if (namespaces.getPrefix(ns) != null) { continue; serializer.startPrefixMapping(pre != null ? pre : "", ns); serializer.endPrefixMapping(pre != null ? pre : ""); namespaces.declarePrefix((pre != null) ? pre : "", ns); if (namespaces.getURI("") == null) { namespaces.declarePrefix("", schema.getTargetNamespace()); new QName(e.getTargetNamespace(), e.getName()), context); serializer.startPrefixMapping("xsi", XSDUtil.SCHEMA_INSTANCE_URI_2001); serializer.endPrefixMapping("xsi"); namespaces.declarePrefix("xsi", XSDUtil.SCHEMA_INSTANCE_URI_2001);
@SuppressWarnings("unchecked") private List<String> getPrefixes(NamespaceSupport ctx) { Enumeration<String> prefixes = ctx.getPrefixes(); List<String> l = new ArrayList<String>(); while (prefixes.hasMoreElements()) { l.add(prefixes.nextElement()); } return l; }
java.util.Enumeration e = ns.getPrefixes(); while (e.hasMoreElements()) { String prefix = e.nextElement().toString(); atts.addAttribute(XMLNS_NAMESPACE, null, xmlns, "CDATA", ns.getURI(prefix)); String defaultNS = ns.getURI(""); handler.startDocument(); translator.encode(object); handler.endDocument();
private static NamespaceSupport getNameSpaces(Node node) { NamespaceSupport namespaces = new NamespaceSupport(); while (node != null) { NamedNodeMap atts = node.getAttributes(); if (atts != null) { for (int i = 0; i < atts.getLength(); i++) { Node att = atts.item(i); if (att.getNamespaceURI() != null && att.getNamespaceURI().equals("http://www.w3.org/2000/xmlns/") && namespaces.getURI(att.getLocalName()) == null) { namespaces.declarePrefix(att.getLocalName(), att.getNodeValue()); } } } node = node.getParentNode(); } return namespaces; }
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (QueryExpressionText.getLocalPart().equals(localName)) { // root element result = Wfs20Factory.eINSTANCE.createQueryExpressionTextType(); result.setLanguage(attributes.getValue("language")); if (attributes.getValue("isPrivate") != null) { String isPrivate = attributes.getValue("isPrivate"); result.setIsPrivate("true".equalsIgnoreCase(isPrivate) || "1".equals(isPrivate)); } result.setReturnFeatureTypes(new ArrayList<QName>()); for (String returnType : attributes.getValue("returnFeatureTypes").split(" +")) { QName typeName = null; String[] split = returnType.split(":"); if (split.length == 1) { typeName = new QName(split[0]); } else { String prefix = split[0]; typeName = new QName(namespaceContext.getURI(prefix), split[1], prefix); } result.getReturnFeatureTypes().add(typeName); } } else { super.startElement(uri, localName, qName, attributes); } }
public String getQName(int index) { Node n = atts.item(index); if (namespaces != null) { String uri = n.getNamespaceURI(); String prefix = (uri != null) ? namespaces.getPrefix(uri) : null; if (prefix != null) { return prefix + ":" + n.getLocalName(); } } return n.getLocalName() != null ? n.getLocalName() : n.getNodeName(); }
QName lastStepQName = lastStep.getName(); Name lastStepName; if (lastStepQName.getPrefix() != null && lastStepQName.getPrefix().length() > 0 && (lastStepQName.getNamespaceURI() == null || lastStepQName.getNamespaceURI().length() == 0)) { String prefix = lastStepQName.getPrefix(); String uri = namespaceSupport.getURI(prefix); lastStepName = Types.typeName(uri, lastStepQName.getLocalPart()); } else {
/** * Tests a location path of the form <code>"foo/bar/@baz"</code> gets built as a {@link * StepList} of attribute names <code>"foo/bar/baz"</code> (i.e. no distinction between what's a * "property" and what's an (xml) "attribute". * * @throws Exception */ @Test public void testStepsWithXmlAttribute() throws Exception { FeatureType complexType = ComplexTestData.createExample01MultiValuedComplexProperty( new UniqueNameFeatureTypeFactoryImpl()); Name name = complexType.getName(); AttributeDescriptor descriptor = new AttributeDescriptorImpl(complexType, name, 0, Integer.MAX_VALUE, true, null); QName rootQName = new QName(name.getNamespaceURI(), name.getLocalPart()); NamespaceSupport namespaces = new NamespaceSupport(); namespaces.declarePrefix("wq", name.getNamespaceURI()); namespaces.declarePrefix("xlink", XLINK.NAMESPACE); StepList steps = XPathUtil.steps(descriptor, "wq_plus/measurement[2]/@xlink:href", namespaces); assertNotNull(steps); assertEquals(steps.toString(), 2, steps.size()); XPathUtil.Step step1 = new XPathUtil.Step(new QName(rootQName.getNamespaceURI(), "measurement"), 2, false); XPathUtil.Step step2 = new XPathUtil.Step(XLINK.HREF, 1, true); assertEquals(step1, steps.get(0)); assertEquals(step2, steps.get(1)); }
String[] split = local.split(":"); local = split[1]; uri = namespaces.getURI(split[0]); } else { uri = null; uri = (uri != null) ? uri : namespaces.getURI(""); qName = namespaces.getPrefix(uri) + ":" + qName; serializer.startElement(uri, local, qName, atts); String data = XMLUtils.removeXMLInvalidChars(((Text) node).getData()); char[] ch = data.toCharArray(); serializer.characters(ch, 0, ch.length); QName childName = new QName(child.getNamespaceURI(), child.getNodeName()); XSDElementDeclaration childDecl = declaration != null this.namespaces.pushContext(); this.namespaces.declarePrefix("", uri);
private QualifiedName getFeatureQualifiedName(QName featureName) { String featureNamespaceURI = featureName.getNamespaceURI(); String featureLocalName = featureName.getLocalPart(); String featurePrefix = namespaces.getPrefix(featureNamespaceURI); QualifiedName featureQualifiedName = QualifiedName.build(featureNamespaceURI, featureLocalName, featurePrefix); return featureQualifiedName; }
public void testEncodeFeatureWithNullValues() throws Exception { SimpleFeatureType type = buildTestFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); builder.add("theName"); builder.add("theDescription"); builder.add(GML3MockData.point()); builder.add(null); builder.add(null); SimpleFeature feature = builder.buildFeature("fid.1"); TestConfiguration configuration = new TestConfiguration(); Encoder encoder = new Encoder(configuration); Document dom = encoder.encodeAsDOM(feature, TEST.TestFeature); NodeList countList = dom.getElementsByTagName("test:count"); Node count = countList.item(0); assertEquals("true", count.getAttributes().getNamedItem("xs:nil").getTextContent()); NodeList dateList = dom.getElementsByTagName("test:date"); Node date = dateList.item(0); assertEquals("true", date.getAttributes().getNamedItem("xs:nil").getTextContent()); // now force the XSD prefix encoder = new Encoder(configuration); encoder.getNamespaces().declarePrefix("xsd", "http://www.w3.org/2001/XMLSchema"); dom = encoder.encodeAsDOM(feature, TEST.TestFeature); countList = dom.getElementsByTagName("test:count"); count = countList.item(0); assertEquals("true", count.getAttributes().getNamedItem("xsd:nil").getTextContent()); dateList = dom.getElementsByTagName("test:date"); date = dateList.item(0); assertEquals("true", date.getAttributes().getNamedItem("xsd:nil").getTextContent()); }
public void endElement(String uri, String localName, String qName) throws SAXException { //pop the last handler off of the stack ElementHandler handler = (ElementHandler) handlers.pop(); //create a qName object from the string QName qualifiedName = new QName(uri, localName); handler.endElement(qualifiedName); endElementInternal(handler); //pop namespace context namespaces.popContext(); }
public static QName toQName(Name featurePath, NamespaceSupport ns) { if (featurePath == null) { return null; } String namespace = featurePath.getNamespaceURI(); String localName = featurePath.getLocalPart(); QName qName; if (null == namespace) { qName = new QName(localName); } else { if (ns != null) { String prefix = ns.getPrefix(namespace); if (prefix != null) { qName = new QName(namespace, localName, prefix); return qName; } } qName = new QName(namespace, localName); } return qName; }
/** * 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); }
NamespaceSupport namespaces = new NamespaceSupport(); QName rootQName = new QName(name.getNamespaceURI(), name.getLocalPart(), ""); assertEquals(rootQName, step.getName()); namespaces.declarePrefix(prefix, name.getNamespaceURI()); rootQName = new QName(name.getNamespaceURI(), name.getLocalPart(), prefix); assertEquals(rootQName, step.getName());