FileDocCategorySizeDatePackage
DOMWSFilter.javaAPI DocJava SE 6 API4846Tue Jun 10 00:22:32 BST 2008com.sun.org.apache.xalan.internal.xsltc.dom

DOMWSFilter

public class DOMWSFilter extends Object implements DTMWSFilter
A wrapper class that adapts the {@link com.sun.org.apache.xml.internal.dtm.DTMWSFilter DTMWSFilter} interface to the XSLTC DOM {@link com.sun.org.apache.xalan.internal.xsltc.StripFilter StripFilter} interface.

Fields Summary
private AbstractTranslet
m_translet
private StripFilter
m_filter
private com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable
m_mappings
private DTM
m_currentDTM
private short[]
m_currentMapping
Constructors Summary
public DOMWSFilter(AbstractTranslet translet)
Construct an adapter connecting the DTMWSFilter interface to the StripFilter interface.

param
translet A translet that also implements the StripFilter interface.
see
com.sun.org.apache.xml.internal.dtm.DTMWSFilter
see
com.sun.org.apache.xalan.internal.xsltc.StripFilter

        m_translet = translet;
        m_mappings = new Hashtable();

        if (translet instanceof StripFilter) {
            m_filter = (StripFilter) translet;
        }
    
Methods Summary
public shortgetShouldStripSpace(int node, com.sun.org.apache.xml.internal.dtm.DTM dtm)
Test whether whitespace-only text nodes are visible in the logical view of DTM. Normally, this function will be called by the implementation of DTM; it is not normally called directly from user code.

param
node int handle of the node.
param
dtm the DTM that owns this node
return
one of NOTSTRIP, STRIP or INHERIT.

        if (m_filter != null && dtm instanceof DOM) {
            DOM dom = (DOM)dtm;
            int type = 0;

            if (dtm instanceof DOMEnhancedForDTM) {
                DOMEnhancedForDTM mappableDOM = (DOMEnhancedForDTM)dtm;
                
                short[] mapping;
                if (dtm == m_currentDTM) {
                    mapping = m_currentMapping;
                }
                else {  
                    mapping = (short[])m_mappings.get(dtm);
                    if (mapping == null) {
                        mapping = mappableDOM.getMapping(
                                     m_translet.getNamesArray(),
                                     m_translet.getUrisArray(),
                                     m_translet.getTypesArray());
                        m_mappings.put(dtm, mapping);
                        m_currentDTM = dtm;
                        m_currentMapping = mapping;
                    }
                }
                
                int expType = mappableDOM.getExpandedTypeID(node);
                
                // %OPT% The mapping array does not have information about all the
                // exptypes. However it does contain enough information about all names
                // in the translet's namesArray. If the expType does not fall into the
                // range of the mapping array, it means that the expType is not for one
                // of the recognized names. In this case we can just set the type to -1.
                if (expType >= 0 && expType < mapping.length)
                  type = mapping[expType];
                else
                  type = -1;
                
            } 
            else {
                return INHERIT;
            }

            if (m_filter.stripSpace(dom, node, type)) {
                return STRIP;
            } else {
                return NOTSTRIP;
            }
        } else {
            return NOTSTRIP;
        }