openTags.push( new ElementLevel( name, namespaces ) ); } else { final String nsPrefix = namespaces.getPrefix( namespaceUri ); openTags.push( new ElementLevel( namespaceUri, null, name, namespaces ) ); } else { w.write( nsPrefix ); w.write( ":" ); w.write( name ); openTags.push( new ElementLevel( namespaceUri, nsPrefix, name, namespaces ) );
final String namespaceUri = entry.getNamespace(); if ( ( isAlwaysAddNamespace() == false ) && ObjectUtilities.equal( currentElement.getNamespace(), namespaceUri ) ) { writer.write( name ); return;
/** * Copies all currently declared namespaces of the given XmlWriterSupport instance as new implied namespaces into this * instance. * * @param writerSupport the Xml-writer from where to copy the declared namespaces. */ public void copyNamespaces( final XmlWriterSupport writerSupport ) { if ( openTags.isEmpty() == false ) { throw new IllegalStateException( "Cannot modify the implied namespaces in the middle of the processing" ); } if ( impliedNamespaces == null ) { impliedNamespaces = new HashMap(); } if ( writerSupport.openTags.isEmpty() == false ) { final ElementLevel parent = (ElementLevel) writerSupport.openTags.peek(); impliedNamespaces.putAll( parent.getNamespaces().getNamespaces() ); } if ( writerSupport.impliedNamespaces != null ) { impliedNamespaces.putAll( writerSupport.impliedNamespaces ); } }
/** * Indent the line. Called for proper indenting in various places. * * @param writer the writer which should receive the indentention. * @throws java.io.IOException if writing the stream failed. */ public void indentForClose( final Writer writer ) throws IOException { if ( openTags.isEmpty() ) { for ( int i = 0; i < additionalIndent; i++ ) { writer.write( indentString ); } return; } final ElementLevel level = (ElementLevel) openTags.peek(); if ( getTagDescription().hasCData( level.getNamespace(), level.getTagName() ) == false ) { doEndOfLine( writer ); for ( int i = 1; i < openTags.size(); i++ ) { writer.write( indentString ); } for ( int i = 0; i < additionalIndent; i++ ) { writer.write( indentString ); } } }
/** * Indent the line. Called for proper indenting in various places. * * @param writer the writer which should receive the indentention. * @throws java.io.IOException if writing the stream failed. */ public void indent( final Writer writer ) throws IOException { if ( openTags.isEmpty() ) { for ( int i = 0; i < additionalIndent; i++ ) { writer.write( indentString ); } return; } final ElementLevel level = (ElementLevel) openTags.peek(); if ( getTagDescription().hasCData( level.getNamespace(), level.getTagName() ) == false ) { doEndOfLine( writer ); for ( int i = 0; i < openTags.size(); i++ ) { writer.write( indentString ); } for ( int i = 0; i < additionalIndent; i++ ) { writer.write( indentString ); } } }
/** * Writes a closing XML tag. * * @param w the writer. * @throws java.io.IOException if there is an I/O problem. */ public void writeCloseTag( final Writer w ) throws IOException { indentForClose( w ); final ElementLevel level = (ElementLevel) openTags.pop(); setLineEmpty( false ); w.write( "</" ); final String prefix = level.getPrefix(); if ( prefix != null ) { w.write( prefix ); w.write( ":" ); w.write( level.getTagName() ); } else { w.write( level.getTagName() ); } w.write( ">" ); doEndOfLine( w ); }
/** * Conditionally writes an end-of-line character. The End-Of-Line is only written, if the tag description indicates * that the currently open element does not expect any CDATA inside. Writing a newline for CDATA-elements may have * sideeffects. * * @param w the writer. * @throws java.io.IOException if there is an I/O problem. */ private void doEndOfLine( final Writer w ) throws IOException { if ( openTags.isEmpty() ) { if ( isWriteFinalLinebreak() ) { writeNewLine( w ); } } else { final ElementLevel level = (ElementLevel) openTags.peek(); if ( getTagDescription().hasCData( level.getNamespace(), level.getTagName() ) == false ) { writeNewLine( w ); } } }
/** * Writes a comment into the generated xml file. * * @param writer the writer. * @param comment the comment text * @throws IOException if there is a problem writing to the character stream. */ public void writeComment( final Writer writer, final String comment ) throws IOException { if ( openTags.isEmpty() == false ) { final ElementLevel level = (ElementLevel) openTags.peek(); if ( getTagDescription().hasCData( level.getNamespace(), level.getTagName() ) == false ) { indent( writer ); } } setLineEmpty( false ); writer.write( "<!-- " ); writeTextNormalized( writer, comment, false ); writer.write( " -->" ); doEndOfLine( writer ); }
/** * Returns all namespaces as properties-collection. This reflects the currently defined namespaces, therefore calls to * writeOpenTag(..) might cause this method to return different collections. * * @return the defined namespaces. */ public Properties getNamespaces() { final Properties namespaces = new Properties(); if ( openTags.isEmpty() ) { if ( impliedNamespaces != null ) { //noinspection UseOfPropertiesAsHashtable namespaces.putAll( impliedNamespaces ); } return namespaces; } final ElementLevel parent = (ElementLevel) openTags.peek(); //noinspection UseOfPropertiesAsHashtable namespaces.putAll( parent.getNamespaces().getNamespaces() ); return namespaces; }
/** * Checks, whether the given URI is defined as valid namespace. * * @param uri the uri of the namespace. * @return true, if there's a namespace defined, false otherwise. */ public boolean isNamespaceDefined( final String uri ) { if ( impliedNamespaces != null ) { if ( impliedNamespaces.containsKey( uri ) ) { return true; } } if ( openTags.isEmpty() ) { return false; } final ElementLevel parent = (ElementLevel) openTags.peek(); return parent.getNamespaces().isNamespaceDefined( uri ); }
/** * Checks, whether the given namespace prefix is defined. * * @param prefix the namespace prefix. * @return true, if the prefix is defined, false otherwise. */ public boolean isNamespacePrefixDefined( final String prefix ) { if ( impliedNamespaces != null ) { if ( impliedNamespaces.containsValue( prefix ) ) { return true; } } if ( openTags.isEmpty() ) { return false; } final ElementLevel parent = (ElementLevel) openTags.peek(); return parent.getNamespaces().isPrefixDefined( prefix ); }
/** * Computes the current collection of defined namespaces. * * @return the namespaces declared at this writing position. */ protected DeclaredNamespaces computeNamespaces() { if ( openTags.isEmpty() ) { final DeclaredNamespaces namespaces = new DeclaredNamespaces(); if ( impliedNamespaces != null ) { return namespaces.add( impliedNamespaces ); } return namespaces; } final ElementLevel parent = (ElementLevel) openTags.peek(); return parent.getNamespaces(); }