You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by zo...@apache.org on 2002/09/14 04:33:59 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/dom DOMImpl.java
zongaro 2002/09/13 19:33:59
Modified: java/src/org/apache/xalan/xsltc/dom Tag: XSLTC_DTM
DOMImpl.java
Log:
Fixed problem in which xsl:strip-space was having no effect when input came
from DOMSource. Also, fixed up some problems with indentation.
Revision Changes Path
No revision
No revision
1.68.2.6 +143 -128 xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java
Index: DOMImpl.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java,v
retrieving revision 1.68.2.5
retrieving revision 1.68.2.6
diff -u -r1.68.2.5 -r1.68.2.6
--- DOMImpl.java 12 Sep 2002 16:07:35 -0000 1.68.2.5
+++ DOMImpl.java 14 Sep 2002 02:33:58 -0000 1.68.2.6
@@ -95,14 +95,15 @@
import javax.xml.transform.dom.DOMSource;
-public final class DOMImpl extends DOM2DTM implements DOM, Externalizable
+public final class DOMImpl extends DOM2DTM implements DOM, Externalizable
{
// empty String for null attribute values
private final static String EMPTYSTRING = "";
// empty iterator to be returned when there are no children
- private final static DTMAxisIterator EMPTYITERATOR = new DTMAxisIteratorBase() {
+ private final static DTMAxisIterator EMPTYITERATOR =
+ new DTMAxisIteratorBase() {
public DTMAxisIterator reset() { return this; }
public DTMAxisIterator setStartNode(int node) { return this; }
public int next() { return DTM.NULL; }
@@ -143,6 +144,8 @@
// Tracks which textnodes are whitespaces and which are not
private BitArray _whitespace; // takes xml:space into acc.
+ // Tracks which bits in _whitespace are valid
+ private BitArray _checkedForWhitespace;
// Tracks which textnodes are not escaped
private BitArray _dontEscape = null;
@@ -295,7 +298,8 @@
int anode, nsnode;
final org.apache.xml.dtm.ref.DTMDefaultBaseIterators.AncestorIterator
ancestors =
- new org.apache.xml.dtm.ref.DTMDefaultBaseIterators.AncestorIterator();
+ new org.apache.xml.dtm.ref.DTMDefaultBaseIterators
+ .AncestorIterator();
if (isElement(node)) {
ancestors.includeSelf();
@@ -317,7 +321,8 @@
}
// TODO: Internationalization?
- throw new TransletException("Namespace prefix '" + prefix + "' is undeclared.");
+ throw new TransletException("Namespace prefix '" + prefix +
+ "' is undeclared.");
}
/**
@@ -415,9 +420,8 @@
* Create an org.w3c.dom.NodeList from a node iterator
* The iterator most be started before this method is called
*/
- public NodeList makeNodeList(DTMIterator iter)
- {
- return new DTMNodeList(iter);
+ public NodeList makeNodeList(DTMIterator iter) {
+ return new DTMNodeList(iter);
}
/**
@@ -551,135 +555,146 @@
* whitespace text nodes. The iterator needs to be a supplied
* with a filter that tells it what nodes are WS text.
*/
- private final class StrippingIterator extends InternalAxisIteratorBase //NodeIteratorBase
- {
+ private final class StrippingIterator extends InternalAxisIteratorBase {
- private static final int USE_PREDICATE = 0;
- private static final int STRIP_SPACE = 1;
- private static final int PRESERVE_SPACE = 2;
-
- private StripFilter _filter = null;
- private short[] _mapping = null;
- private final DTMAxisIterator _source;
- private boolean _children = false;
- private int _action = USE_PREDICATE;
- private int _last = -1;
-
- public StrippingIterator(DTMAxisIterator source,
- short[] mapping,
- StripFilter filter)
- {
+ private static final int USE_PREDICATE = 0;
+ private static final int STRIP_SPACE = 1;
+ private static final int PRESERVE_SPACE = 2;
+
+ private StripFilter _filter = null;
+ private short[] _mapping = null;
+ private final DTMAxisIterator _source;
+ private boolean _children = false;
+ private int _action = USE_PREDICATE;
+ private int _last = -1;
+
+ public StrippingIterator(DTMAxisIterator source, short[] mapping,
+ StripFilter filter) {
+ _filter = filter;
+ _mapping = mapping;
+ _source = source;
+
+ if (_source instanceof ChildrenIterator
+ || _source instanceof TypedChildrenIterator) {
+ _children = true;
+ }
+ }
- _filter = filter;
- _mapping = mapping;
- _source = source;
+ public DTMAxisIterator setStartNode(int node) {
+ if (_children){
+ if (_filter.stripSpace((DOM)DOMImpl.this, node,
+ _mapping[getType(node)])) {
+ _action = STRIP_SPACE;
+ } else {
+ _action = PRESERVE_SPACE;
+ }
+ }
- if (_source instanceof ChildrenIterator ||
- _source instanceof TypedChildrenIterator)
- {
- _children = true;
- }
- }
+ _source.setStartNode(node);
+ return this;
+ }
+
+ public int next() {
+ int node;
+ while ((node = _source.next()) != END) {
+ switch(_action) {
+ case STRIP_SPACE:
+ if (isWhitespace(node)) {
+ continue;
+ }
+ // fall through...
+ case PRESERVE_SPACE:
+ return returnNode(node);
+ case USE_PREDICATE:
+ default:
+ if (isWhitespace(node)
+ && _filter.stripSpace((DOM)DOMImpl.this, node,
+ _mapping[getType(getParent(node))])) {
+ continue;
+ }
+ return returnNode(node);
+ }
+ }
+ return END;
+ }
- public DTMAxisIterator setStartNode(int node)
- {
- if (_children)
- {
- if (_filter.stripSpace((DOM)DOMImpl.this, node,
- _mapping[getType(node)]))
- _action = STRIP_SPACE;
- else
- _action = PRESERVE_SPACE;
- }
- _source.setStartNode(node);
- //return resetPosition();
- return(this);
- }
-
- public int next()
- {
- int node;
- while ((node = _source.next()) != END)
- {
- switch(_action)
- {
- case STRIP_SPACE:
- if (_whitespace.getBit(getNodeIdent(node))) continue;
- // fall through...
- case PRESERVE_SPACE:
- return returnNode(node);
- case USE_PREDICATE:
- default:
- if (_whitespace.getBit(getNodeIdent(node)) &&
- _filter.stripSpace((DOM)DOMImpl.this, node,
- _mapping[getType(getParent(node))]))
- continue;
- return returnNode(node);
- }
- }
- return END;
- }
+ public void setRestartable(boolean isRestartable) {
+ _isRestartable = isRestartable;
+ _source.setRestartable(isRestartable);
+ }
- public void setRestartable(boolean isRestartable) {
- _isRestartable = isRestartable;
- _source.setRestartable(isRestartable);
- }
-
+ public DTMAxisIterator reset() {
+ _source.reset();
+ return this;
+ }
- public DTMAxisIterator reset()
- {
- _source.reset();
- return this;
- }
+ public void setMark() {
+ _source.setMark();
+ }
- public void setMark()
- {
- _source.setMark();
- }
+ public void gotoMark() {
+ _source.gotoMark();
+ }
- public void gotoMark()
- {
- _source.gotoMark();
- }
+ public int getLast() {
+ // Return chached value (if we have it)
+ if (_last != -1) {
+ return _last;
+ }
- public int getLast()
- {
- // Return chached value (if we have it)
- if (_last != -1) return _last;
+ int count = getPosition();
+ int node;
- int count = getPosition();
- int node;
+ _source.setMark();
+ while ((node = _source.next()) != END) {
+ switch(_action) {
+ case STRIP_SPACE:
+ if (isWhitespace(node)) {
+ continue;
+ }
+ // fall through...
+ case PRESERVE_SPACE:
+ count++;
+ break;
+ case USE_PREDICATE:
+ default:
+ if (isWhitespace(node)
+ && _filter.stripSpace((DOM)DOMImpl.this, node,
+ _mapping[getType(getParent(node))])) {
+ continue;
+ } else {
+ count++;
+ }
+ }
+ }
+ _source.gotoMark();
+ _last = count;
+ return count;
+ }
+
+ private boolean isWhitespace(int node) {
+ final int nodeIdent = getNodeIdent(node);
+
+ // Is this the first time we've visited this node? If so, check
+ // whether it's whitespace.
+ if (!_checkedForWhitespace.getBit(nodeIdent)) {
+ _checkedForWhitespace.setBit(nodeIdent);
+ final int nodeType = getNodeType(node);
+ if ((nodeType == DTM.TEXT_NODE
+ || nodeType == DTM.CDATA_SECTION_NODE)
+ && DOMImpl.this.isWhitespace(node)) {
+ _whitespace.setBit(nodeIdent);
+ return true;
+ }
+ return false;
+ }
- _source.setMark();
- while ((node = _source.next()) != END)
- {
- switch(_action)
- {
- case STRIP_SPACE:
- if (_whitespace.getBit(getNodeIdent(node)))
- continue;
- // fall through...
- case PRESERVE_SPACE:
- count++;
- break;
- case USE_PREDICATE:
- default:
- if (_whitespace.getBit(getNodeIdent(node)) &&
- _filter.stripSpace((DOM)DOMImpl.this, node,
- _mapping[getType(getParent(node))]))
- continue;
- else
- count++;
- }
- }
- _source.gotoMark();
- _last = count;
- return(count);
- }
+ return _whitespace.getBit(nodeIdent);
+ }
-} // end of StrippingIterator
+ } // end of StrippingIterator
public DTMAxisIterator strippingIterator(DTMAxisIterator iterator,
short[] mapping,
@@ -1251,10 +1266,11 @@
*/
public void initSize(int size)
{
- _offsetOrChild = new int[size];
- _lengthOrAttr = new int[size];
- _text = new char[size * 10];
- _whitespace = new BitArray(size);
+ _offsetOrChild = new int[size];
+ _lengthOrAttr = new int[size];
+ _text = new char[size * 10];
+ _whitespace = new BitArray(size);
+ _checkedForWhitespace = new BitArray(size);
}
/**
@@ -2749,5 +2765,4 @@
}
} // end of DOMBuilder
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org