@Override public void beginStartTag(int prefix, String localName) throws IOException { indentStartTag(); super.beginStartTag(prefix, localName); }
@Override public void endDocument(boolean fragment) throws IOException, SAXException, XMLStreamException { write('\n'); super.endDocument(fragment); } }
@Override public void endTag(Name name) throws IOException { indentEndTag(); super.endTag(name); }
public void beginStartTag(int prefix, String localName) throws IOException { closeStartTag(); int base= pushNsDecls(); write('<'); writeName(prefix,localName); writeNsDecls(base); }
public void text(String value, boolean needSP) throws IOException { closeStartTag(); if(needSP) write(' '); doText(value,false); }
public void text(Pcdata value, boolean needSP) throws IOException { closeStartTag(); if(needSP) write(' '); value.writeTo(this); }
@Override public void text(Pcdata value, boolean needSP) throws IOException { seenText = true; super.text(value, needSP); }
public XmlOutput createWriter( OutputStream os, String encoding ) throws JAXBException { // UTF8XmlOutput does buffering on its own, and // otherwise createWriter(Writer) inserts a buffering, // so no point in doing a buffering here. if(encoding.equals("UTF-8")) { Encoded[] table = context.getUTF8NameTable(); final UTF8XmlOutput out; CharacterEscapeHandler ceh = createEscapeHandler(encoding); if(isFormattedOutput()) out = new IndentingUTF8XmlOutput(os, indent, table, ceh); else { if(c14nSupport) out = new C14nXmlOutput(os, table, context.c14nSupport, ceh); else out = new UTF8XmlOutput(os, table, ceh); } if(header!=null) out.setHeader(header); return out; } try { return createWriter( new OutputStreamWriter(os,getJavaEncoding(encoding)), encoding ); } catch( UnsupportedEncodingException e ) { throw new MarshalException( Messages.UNSUPPORTED_ENCODING.format(encoding), e ); } }
/** * 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('\"'); }
/** * Writes the given byte[] as base64 encoded binary to the output. * * <p> * Being defined on this class allows this method to access the buffer directly, * which translates to a better performance. */ public void text(byte[] data, int dataLen) throws IOException { closeStartTag(); int start = 0; while(dataLen>0) { // how many bytes (in data) can we write without overflowing the buffer? int batchSize = Math.min(((octetBuffer.length-octetBufferIndex)/4)*3,dataLen); // write the batch octetBufferIndex = DatatypeConverterImpl._printBase64Binary(data,start,batchSize,octetBuffer,octetBufferIndex); if(batchSize<dataLen) flushBuffer(); start += batchSize; dataLen -= batchSize; } }
@Override public void endStartTag() throws IOException { if(otherAttributes.isEmpty()) { if(len!=0) { // sort is expensive even for size 0 array, // so it's worth checking len==0 if(!namedAttributesAreOrdered) Arrays.sort(staticAttributes,0,len); // this is the common case for( int i=0; i<len; i++ ) staticAttributes[i].write(); len = 0; } } else { // this is the exceptional case // sort all the attributes, not just the other attributes for( int i=0; i<len; i++ ) otherAttributes.add(staticAttributes[i].toDynamicAttribute()); len = 0; Collections.sort(otherAttributes); // write them all int size = otherAttributes.size(); for( int i=0; i<size; i++ ) { DynamicAttribute a = otherAttributes.get(i); super.attribute(a.prefix,a.localName,a.value); } otherAttributes.clear(); } super.endStartTag(); }
out.setHeader(header); return out;
@Override public void beginStartTag(Name name) throws IOException { closeStartTag(); int base = pushNsDecls(); write('<'); writeName(name); writeNsDecls(base); }
public void text(String value, boolean needSP) throws IOException { closeStartTag(); if(needSP) write(' '); doText(value,false); }
public final void text(int value) throws IOException { closeStartTag(); /* * TODO * Change to use the octet buffer directly */ // max is -2147483648 and 11 digits boolean minus = (value<0); textBuffer.ensureSize(11); byte[] buf = textBuffer.buf; int idx = 11; do { int r = value%10; if(r<0) r = -r; buf[--idx] = (byte)('0'|r); // really measn 0x30+r but 0<=r<10, so bit-OR would do. value /= 10; } while(value!=0); if(minus) buf[--idx] = (byte)'-'; write(buf,idx,11-idx); }
@Override public void text(String value, boolean needSP) throws IOException { seenText = true; super.text(value, needSP); }