Class TransformerBase.TranslatorSupport

    • Method Detail

      • abort

        public void abort()
        Description copied from interface: Translator
        Abort any translating activity. This is needed as some translators iterate internally on a data structure. The abort method should silently fail or succeed based upon the state of a translation.
        Specified by:
        abort in interface Translator
      • mark

        protected void mark()
        Set a mark() to which we can later "roll back" writes. After a call to mark(), the Translator stores pending write operations in memory until commit() is called. The pending writes can be discarded with the reset() method.

        Typically, one would use marks in conjunction with an exception handler:

           void encodeFoo(Foo f) {
             try {
               mark();
               element(foo.riskyMethod());
               element(foo.dangerousMethod());
               commit();
             } catch (BadThingHappened disaster) {
                 mitigate(disaster);
                 reset();
             }
           }
         
        Throws:
        IllegalStateException - if a mark is already set
      • reset

        protected void reset()
        Discard pending write operations after a mark() has been set.

        This method is safe to call even if no mark is set - so it returns to a "known good" state as far as marks are concerned.

        See Also:
        mark()
      • commit

        protected void commit()
        Commit pending write operations. After setting a mark, this method will commit the pending writes.
        Throws:
        IllegalStateException - if no mark is set
        See Also:
        mark()
      • addNamespaceDeclarations

        protected void addNamespaceDeclarations​(TransformerBase.TranslatorSupport trans)
        Utility method to copy namespace declarations from "sub" translators into this ns support...
      • createAttributes

        protected AttributesImpl createAttributes​(String[] nameValuePairs)
        Utility method for creating attributes from an array of name value pairs.

        The nameValuePairs array should be of the form:

        {name1,value1,name2,value2,...,nameN,valueN}
        Parameters:
        nameValuePairs - The attribute names/values.
      • element

        protected void element​(String element,
                               String content)
      • elementSafe

        protected void elementSafe​(String element,
                                   String content)
        Will only issue the provided element if content is non empty
      • start

        protected void start​(String element)
      • chars

        protected void chars​(String text)
      • end

        protected void end​(String element)
      • cdata

        protected void cdata​(String cdata)
      • comment

        protected void comment​(String comment)
      • getDefaultNamespace

        public String getDefaultNamespace()
        Description copied from interface: Translator
        Get the default URI used by this Translator for encoding. Optional.
        Specified by:
        getDefaultNamespace in interface Translator
      • getDefaultPrefix

        public String getDefaultPrefix()
        Description copied from interface: Translator
        Get the default prefix used by this Translator for encoding. Optional.
        Specified by:
        getDefaultPrefix in interface Translator
      • getNamespaceSupport

        public NamespaceSupport getNamespaceSupport()
        Description copied from interface: Translator
        Obtain the namespace prefixes and URIs to be included in the output document.
        Specified by:
        getNamespaceSupport in interface Translator
        Returns:
        An instance of NamespaceSupport.