private String getURI() { if(prefix==-1) return ""; else return nsContext.getNamespaceURI(prefix); }
private String makeUniquePrefix() { String prefix; prefix = new StringBuilder(5).append("ns").append(size).toString(); while(getNamespaceURI(prefix)!=null) { prefix += '_'; // under a rare circumstance there might be existing 'nsNNN', so rename them } return prefix; }
public void beginStartTag(int prefix, String localName) throws IOException, XMLStreamException { next.beginStartTag(prefix, localName); this.nsUri = nsContext.getNamespaceURI(prefix); this.localName = localName; }
public void attribute(int prefix, String localName, String value) throws IOException, XMLStreamException { if(prefix==-1) out.writeAttribute(localName,value); else out.writeAttribute( nsContext.getPrefix(prefix), nsContext.getNamespaceURI(prefix), localName, value); }
public void beginStartTag(int prefix, String localName) { elementNsUri = nsContext.getNamespaceURI(prefix); elementLocalName = localName; elementQName = getQName(prefix,localName); atts.clear(); }
public void attribute(int prefix, String localName, String value) { String qname; String nsUri; if(prefix==-1) { nsUri = ""; qname = localName; } else { nsUri = nsContext.getNamespaceURI(prefix); String p = nsContext.getPrefix(prefix); if(p.length()==0) // this is more likely a bug in the application code (NamespacePrefixMapper implementation) // this only happens when it tries to assign "" prefix to a non-"" URI, // which is by itself violation of namespace rec. But let's just be safe. // See http://forums.java.net/jive/thread.jspa?messageID=212598#212598 qname = localName; else qname = p +':'+localName; } atts.addAttribute( nsUri, localName, qname, "CDATA", value ); }
public void endTag(int prefix, String localName) throws IOException, SAXException, XMLStreamException { out.add( ef.createEndElement( nsContext.getPrefix(prefix), nsContext.getNamespaceURI(prefix), localName)); }
public void endTag(int prefix, String localName) throws SAXException { out.endElement( nsContext.getNamespaceURI(prefix), localName, getQName(prefix, localName) ); NamespaceContextImpl.Element ns = nsContext.getCurrent(); if(ns!=null) { int sz = ns.count(); for( int i=sz-1; i>=0; i-- ) { String p = ns.getPrefix(i); String uri = ns.getNsUri(i); if(uri.length()==0 && ns.getBase()==1) continue; // no point in definint xmlns='' on the root out.endPrefixMapping(p); } } }
public void beginStartTag(int prefix, String localName) throws IOException, XMLStreamException { out.writeStartElement( nsContext.getPrefix(prefix), localName, nsContext.getNamespaceURI(prefix)); NamespaceContextImpl.Element nse = nsContext.getCurrent(); if(nse.count()>0) { for( int i=nse.count()-1; i>=0; i-- ) { String uri = nse.getNsUri(i); if(uri.length()==0 && nse.getBase()==1) continue; // no point in definint xmlns='' on the root out.writeNamespace(nse.getPrefix(i),uri); } } }
public void attribute(int prefix, String localName, String value) throws IOException, XMLStreamException { Attribute att; if(prefix==-1) att = ef.createAttribute(localName,value); else att = ef.createAttribute( nsContext.getPrefix(prefix), nsContext.getNamespaceURI(prefix), localName, value); out.add(att); }
/** * Writes a single namespace declaration for the specified prefix. */ protected final void writeNsDecl(int prefixIndex) throws IOException { String p = nsContext.getPrefix(prefixIndex); if(p.length()==0) { if(nsContext.getCurrent().isRootElement() && nsContext.getNamespaceURI(prefixIndex).length()==0) return; // no point in declaring xmlns="" on the root element write(XMLNS_EQUALS); } else { Encoded e = prefixes[prefixIndex]; write(XMLNS_COLON); write(e.buf,0,e.len-1); // skip the trailing ':' write(EQUALS); } doText(nsContext.getNamespaceURI(prefixIndex),true); write('\"'); }
@Override public void attribute(int prefix, String localName, String value) throws IOException { fiout.writeLowLevelStartAttributes(); boolean isIndexed; if (prefix == -1) isIndexed = fiout.writeLowLevelAttribute("", "", localName); else isIndexed = fiout.writeLowLevelAttribute( nsContext.getPrefix(prefix), nsContext.getNamespaceURI(prefix), localName); if (!isIndexed) tables.incrementMaxIndexValue(); fiout.writeLowLevelAttributeValue(value); } }
public void beginStartTag(int prefix, String localName) throws IOException, XMLStreamException { out.add( ef.createStartElement( nsContext.getPrefix(prefix), nsContext.getNamespaceURI(prefix), localName)); NamespaceContextImpl.Element nse = nsContext.getCurrent(); if(nse.count()>0) { for( int i=nse.count()-1; i>=0; i-- ) { String uri = nse.getNsUri(i); if(uri.length()==0 && nse.getBase()==1) continue; // no point in definint xmlns='' on the root out.add(ef.createNamespace(nse.getPrefix(i),uri)); } } }
@Override public void attribute(Name name, String value) throws IOException { fiout.writeLowLevelStartAttributes(); final int qNameIndex = tables.attributeIndexes[name.qNameIndex] - tables.indexOffset; if (qNameIndex >= 0) { fiout.writeLowLevelAttributeIndexed(qNameIndex); } else { tables.attributeIndexes[name.qNameIndex] = fiout.getNextAttributeIndex() + tables.indexOffset; final int namespaceURIId = name.nsUriIndex; if (namespaceURIId == -1) { writeLiteral(EncodingConstants.ATTRIBUTE_LITERAL_QNAME_FLAG, name, "", ""); } else { final int prefix = nsUriIndex2prefixIndex[namespaceURIId]; writeLiteral(EncodingConstants.ATTRIBUTE_LITERAL_QNAME_FLAG, name, nsContext.getPrefix(prefix), nsContext.getNamespaceURI(prefix)); } } fiout.writeLowLevelAttributeValue(value); }
@Override public void beginStartTag(Name name) throws IOException { fiout.writeLowLevelTerminationAndMark(); if (nsContext.getCurrent().count() == 0) { final int qNameIndex = tables.elementIndexes[name.qNameIndex] - tables.indexOffset; final int prefixIndex = nsUriIndex2prefixIndex[name.nsUriIndex]; if (qNameIndex >= 0 && tables.elementIndexPrefixes[name.qNameIndex] == prefixIndex) { fiout.writeLowLevelStartElementIndexed(EncodingConstants.ELEMENT, qNameIndex); } else { tables.elementIndexes[name.qNameIndex] = fiout.getNextElementIndex() + tables.indexOffset; tables.elementIndexPrefixes[name.qNameIndex] = prefixIndex; writeLiteral(EncodingConstants.ELEMENT | EncodingConstants.ELEMENT_LITERAL_QNAME_FLAG, name, nsContext.getPrefix(prefixIndex), nsContext.getNamespaceURI(prefixIndex)); } } else { beginStartTagWithNamespaces(name); } }
public void beginStartTagWithNamespaces(Name name) throws IOException { final NamespaceContextImpl.Element nse = nsContext.getCurrent(); fiout.writeLowLevelStartNamespaces(); for (int i = nse.count() - 1; i >= 0; i--) { final String uri = nse.getNsUri(i); if (uri.length() == 0 && nse.getBase() == 1) continue; // no point in definint xmlns='' on the root fiout.writeLowLevelNamespace(nse.getPrefix(i), uri); } fiout.writeLowLevelEndNamespaces(); final int qNameIndex = tables.elementIndexes[name.qNameIndex] - tables.indexOffset; final int prefixIndex = nsUriIndex2prefixIndex[name.nsUriIndex]; if (qNameIndex >= 0 && tables.elementIndexPrefixes[name.qNameIndex] == prefixIndex) { fiout.writeLowLevelStartElementIndexed(0, qNameIndex); } else { tables.elementIndexes[name.qNameIndex] = fiout.getNextElementIndex() + tables.indexOffset; tables.elementIndexPrefixes[name.qNameIndex] = prefixIndex; writeLiteral(EncodingConstants.ELEMENT_LITERAL_QNAME_FLAG, name, nsContext.getPrefix(prefixIndex), nsContext.getNamespaceURI(prefixIndex)); } }
@Override public void beginStartTag(int prefix, String localName) throws IOException { fiout.writeLowLevelTerminationAndMark(); int type = EncodingConstants.ELEMENT; if (nsContext.getCurrent().count() > 0) { final NamespaceContextImpl.Element nse = nsContext.getCurrent(); fiout.writeLowLevelStartNamespaces(); for (int i = nse.count() - 1; i >= 0; i--) { final String uri = nse.getNsUri(i); if (uri.length() == 0 && nse.getBase() == 1) continue; // no point in definint xmlns='' on the root fiout.writeLowLevelNamespace(nse.getPrefix(i), uri); } fiout.writeLowLevelEndNamespaces(); type= 0; } final boolean isIndexed = fiout.writeLowLevelStartElement( type, nsContext.getPrefix(prefix), localName, nsContext.getNamespaceURI(prefix)); if (!isIndexed) tables.incrementMaxIndexValue(); }
public void beginStartTag(int prefix, String localName) throws IOException, XMLStreamException { next.beginStartTag(prefix, localName); this.nsUri = nsContext.getNamespaceURI(prefix); this.localName = localName; }
public void endTag(int prefix, String localName) throws IOException, SAXException, XMLStreamException { out.add( ef.createEndElement( nsContext.getPrefix(prefix), nsContext.getNamespaceURI(prefix), localName)); }
public void attribute(int prefix, String localName, String value) throws IOException, XMLStreamException { Attribute att; if(prefix==-1) att = ef.createAttribute(localName,value); else att = ef.createAttribute( nsContext.getPrefix(prefix), nsContext.getNamespaceURI(prefix), localName, value); out.add(att); }