286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2002-2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A/*
286N/A * $Id: DOMWSFilter.java,v 1.2.4.1 2005/09/06 06:14:31 pvedula Exp $
286N/A */
286N/Apackage com.sun.org.apache.xalan.internal.xsltc.dom;
286N/A
286N/Aimport com.sun.org.apache.xalan.internal.xsltc.DOM;
286N/Aimport com.sun.org.apache.xalan.internal.xsltc.DOMEnhancedForDTM;
286N/Aimport com.sun.org.apache.xalan.internal.xsltc.StripFilter;
286N/Aimport com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
286N/Aimport com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;
286N/Aimport com.sun.org.apache.xml.internal.dtm.DTM;
286N/Aimport com.sun.org.apache.xml.internal.dtm.DTMWSFilter;
286N/A
286N/A/**
286N/A * A wrapper class that adapts the
286N/A * {@link com.sun.org.apache.xml.internal.dtm.DTMWSFilter DTMWSFilter} interface to the XSLTC
286N/A * DOM {@link com.sun.org.apache.xalan.internal.xsltc.StripFilter StripFilter} interface.
286N/A */
286N/Apublic class DOMWSFilter implements DTMWSFilter {
286N/A
286N/A private AbstractTranslet m_translet;
286N/A private StripFilter m_filter;
286N/A
286N/A // The Hashtable for DTM to mapping array
286N/A private Hashtable m_mappings;
286N/A
286N/A // Cache the DTM and mapping that are used last time
286N/A private DTM m_currentDTM;
286N/A private short[] m_currentMapping;
286N/A
286N/A /**
286N/A * Construct an adapter connecting the <code>DTMWSFilter</code> interface
286N/A * to the <code>StripFilter</code> interface.
286N/A *
286N/A * @param translet A translet that also implements the StripFilter
286N/A * interface.
286N/A *
286N/A * @see com.sun.org.apache.xml.internal.dtm.DTMWSFilter
286N/A * @see com.sun.org.apache.xalan.internal.xsltc.StripFilter
286N/A */
286N/A public DOMWSFilter(AbstractTranslet translet) {
286N/A m_translet = translet;
286N/A m_mappings = new Hashtable();
286N/A
286N/A if (translet instanceof StripFilter) {
286N/A m_filter = (StripFilter) translet;
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Test whether whitespace-only text nodes are visible in the logical
286N/A * view of <code>DTM</code>. Normally, this function
286N/A * will be called by the implementation of <code>DTM</code>;
286N/A * it is not normally called directly from
286N/A * user code.
286N/A *
286N/A * @param node int handle of the node.
286N/A * @param dtm the DTM that owns this node
286N/A * @return one of <code>NOTSTRIP</code>, <code>STRIP</code> or
286N/A * <code>INHERIT</code>.
286N/A */
286N/A public short getShouldStripSpace(int node, DTM dtm) {
286N/A if (m_filter != null && dtm instanceof DOM) {
286N/A DOM dom = (DOM)dtm;
286N/A int type = 0;
286N/A
286N/A if (dtm instanceof DOMEnhancedForDTM) {
286N/A DOMEnhancedForDTM mappableDOM = (DOMEnhancedForDTM)dtm;
286N/A
286N/A short[] mapping;
286N/A if (dtm == m_currentDTM) {
286N/A mapping = m_currentMapping;
286N/A }
286N/A else {
286N/A mapping = (short[])m_mappings.get(dtm);
286N/A if (mapping == null) {
286N/A mapping = mappableDOM.getMapping(
286N/A m_translet.getNamesArray(),
286N/A m_translet.getUrisArray(),
286N/A m_translet.getTypesArray());
286N/A m_mappings.put(dtm, mapping);
286N/A m_currentDTM = dtm;
286N/A m_currentMapping = mapping;
286N/A }
286N/A }
286N/A
286N/A int expType = mappableDOM.getExpandedTypeID(node);
286N/A
286N/A // %OPT% The mapping array does not have information about all the
286N/A // exptypes. However it does contain enough information about all names
286N/A // in the translet's namesArray. If the expType does not fall into the
286N/A // range of the mapping array, it means that the expType is not for one
286N/A // of the recognized names. In this case we can just set the type to -1.
286N/A if (expType >= 0 && expType < mapping.length)
286N/A type = mapping[expType];
286N/A else
286N/A type = -1;
286N/A
286N/A }
286N/A else {
286N/A return INHERIT;
286N/A }
286N/A
286N/A if (m_filter.stripSpace(dom, node, type)) {
286N/A return STRIP;
286N/A } else {
286N/A return NOTSTRIP;
286N/A }
286N/A } else {
286N/A return NOTSTRIP;
286N/A }
286N/A }
286N/A}