You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2006/08/25 22:17:31 UTC
svn commit: r436925 - in /incubator/abdera/java/trunk:
core/src/main/java/org/apache/abdera/filter/
core/src/main/java/org/apache/abdera/parser/
core/src/main/java/org/apache/abdera/util/filter/
parser/src/main/java/org/apache/abdera/parser/stax/
Author: jmsnell
Date: Fri Aug 25 13:17:29 2006
New Revision: 436925
URL: http://svn.apache.org/viewvc?rev=436925&view=rev
Log:
Move the various setIgnoreFoo/getIgnoreFoo methods to the parse filter mechanism instead of
parser options. Provide a abstract parse filter impl that handles the methods. Remove the
setIgnoreDoctype/getIgnoreDoctype methods. Because of the bugs in the Stax parsers DTD
handling, we're always ignore DTDs.
Added:
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractParseFilter.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/NonOpParseFilter.java
Modified:
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractListParseFilter.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/CompoundParseFilter.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/SafeContentWhiteListParseFilter.java
incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java?rev=436925&r1=436924&r2=436925&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java Fri Aug 25 13:17:29 2006
@@ -39,4 +39,24 @@
*/
public boolean acceptable(QName qname, QName attribute);
+ /**
+ * Return true if the parser should ignore comments
+ */
+ boolean getIgnoreComments();
+
+ /**
+ * Return true if the parser should ignore insignificant whitespace
+ */
+ boolean getIgnoreWhitespace();
+
+ /**
+ * Return true if the parser should ignore processing instructions
+ */
+ boolean getIgnoreProcessingInstructions();
+
+ void setIgnoreComments(boolean ignore);
+
+ void setIgnoreWhitespace(boolean ignore);
+
+ void setIgnoreProcessingInstructions(boolean ignore);
}
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java?rev=436925&r1=436924&r2=436925&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java Fri Aug 25 13:17:29 2006
@@ -80,16 +80,17 @@
*/
void setTextFilter(TextFilter textFilter);
+ /**
+ * Returns true if the parser should attempt to automatically detect the
+ * character encoding from the stream
+ */
boolean getAutodetectCharset();
+ /**
+ * If true, the parser will attempt to automatically detect the character
+ * encoding from the stream by checking for the byte order mark or checking
+ * the XML prolog.
+ */
void setAutodetectCharset(boolean detect);
- void setIgnoreDoctype(boolean ignore);
- void setIgnoreComments(boolean ignore);
- void setIgnoreWhitespace(boolean ignore);
- void setIgnoreProcessingInstructions(boolean ignore);
- boolean getIgnoreDoctype();
- boolean getIgnoreComments();
- boolean getIgnoreWhitespace();
- boolean getIgnoreProcessingInstructions();
}
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractListParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractListParseFilter.java?rev=436925&r1=436924&r2=436925&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractListParseFilter.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractListParseFilter.java Fri Aug 25 13:17:29 2006
@@ -32,6 +32,7 @@
* method.
*/
public abstract class AbstractListParseFilter
+ extends AbstractParseFilter
implements Cloneable, ListParseFilter {
private List<QName> qnames = null;
Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractParseFilter.java?rev=436925&view=auto
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractParseFilter.java (added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractParseFilter.java Fri Aug 25 13:17:29 2006
@@ -0,0 +1,66 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.util.filter;
+
+import org.apache.abdera.filter.ParseFilter;
+
+public abstract class AbstractParseFilter
+ implements ParseFilter {
+
+ protected byte flags = 0;
+
+ public void setIgnoreComments(boolean ignore) {
+ if (getIgnoreComments()) {
+ if (!ignore) flags ^= 1;
+ } else {
+ if (ignore) flags |= 1;
+ }
+ }
+
+ public void setIgnoreWhitespace(boolean ignore) {
+ if (getIgnoreWhitespace()) {
+ if (!ignore) flags ^= 2;
+ } else {
+ if (ignore) flags |= 2;
+ }
+ }
+
+ public void setIgnoreProcessingInstructions(boolean ignore) {
+ if (getIgnoreProcessingInstructions()) {
+ if (!ignore) flags ^= 4;
+ } else {
+ if (ignore) flags |= 4;
+ }
+ }
+
+ public boolean getIgnoreComments() {
+ return (flags & 1) == 1;
+ }
+
+ public boolean getIgnoreProcessingInstructions() {
+ return (flags & 4) == 4;
+ }
+
+ public boolean getIgnoreWhitespace() {
+ return (flags & 2) == 2;
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+}
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/CompoundParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/CompoundParseFilter.java?rev=436925&r1=436924&r2=436925&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/CompoundParseFilter.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/CompoundParseFilter.java Fri Aug 25 13:17:29 2006
@@ -37,6 +37,7 @@
* </pre>
*/
public class CompoundParseFilter
+ extends AbstractParseFilter
implements ParseFilter {
public enum Condition {
Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/NonOpParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/NonOpParseFilter.java?rev=436925&view=auto
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/NonOpParseFilter.java (added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/NonOpParseFilter.java Fri Aug 25 13:17:29 2006
@@ -0,0 +1,33 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.util.filter;
+
+import javax.xml.namespace.QName;
+
+public class NonOpParseFilter
+ extends AbstractParseFilter {
+
+ public boolean acceptable(QName qname) {
+ return true;
+ }
+
+ public boolean acceptable(QName qname, QName attribute) {
+ return true;
+ }
+
+}
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/SafeContentWhiteListParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/SafeContentWhiteListParseFilter.java?rev=436925&r1=436924&r2=436925&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/SafeContentWhiteListParseFilter.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/SafeContentWhiteListParseFilter.java Fri Aug 25 13:17:29 2006
@@ -23,6 +23,7 @@
import org.apache.abdera.util.Constants;
public class SafeContentWhiteListParseFilter
+ extends AbstractParseFilter
implements ParseFilter {
private static enum xhtml_elements {
Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java?rev=436925&r1=436924&r2=436925&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java (original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java Fri Aug 25 13:17:29 2006
@@ -52,7 +52,10 @@
private ParserOptions parserOptions = null;
private int depth = 0;
private int depthInSkipElement = 0;
-
+ private boolean ignoreWhitespace = false;
+ private boolean ignoreComments = false;
+ private boolean ignorePI = false;
+
public FOMBuilder(
FOMFactory factory,
XMLStreamReader parser,
@@ -61,6 +64,14 @@
this.document = (OMDocument) factory.newDocument();
this.parserOptions = parserOptions;
this.fomfactory = factory;
+ if (parserOptions != null) {
+ ParseFilter parseFilter = parserOptions.getParseFilter();
+ if (parseFilter != null) {
+ ignoreWhitespace = parseFilter.getIgnoreWhitespace();
+ ignoreComments = parseFilter.getIgnoreComments();
+ ignorePI = parseFilter.getIgnoreProcessingInstructions();
+ }
+ }
}
public ParserOptions getParserOptions() {
@@ -128,8 +139,11 @@
private OMNode applyTextFilter(int type) {
if (parserOptions != null) {
- if (parser.isWhiteSpace() && parserOptions.getIgnoreWhitespace()) return createOMText("",type);
TextFilter filter = parserOptions.getTextFilter();
+ ParseFilter parseFilter = parserOptions.getParseFilter();
+ if (parseFilter != null) {
+ if (parser.isWhiteSpace() && parseFilter.getIgnoreWhitespace()) return createOMText("",type);
+ }
if (filter != null) {
String value = parser.getText();
if (!lastNode.isComplete())
@@ -212,12 +226,11 @@
((OMContainerEx) this.document).setComplete(true);
break;
case XMLStreamConstants.SPACE:
- if (!parserOptions.getIgnoreWhitespace())
+ if (!ignoreWhitespace)
lastNode = createOMText(XMLStreamConstants.SPACE);
break;
case XMLStreamConstants.COMMENT:
- if (!parserOptions.getIgnoreComments())
- createComment();
+ if (!ignoreComments) createComment();
break;
case XMLStreamConstants.DTD:
// Current StAX cursor model implementations inconsistently handle DTDs.
@@ -236,8 +249,7 @@
// createDTD();
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
- if (!parserOptions.getIgnoreProcessingInstructions())
- createPI();
+ if (!ignorePI) createPI();
break;
case XMLStreamConstants.ENTITY_REFERENCE:
lastNode = createOMText(XMLStreamConstants.ENTITY_REFERENCE);