tkormann 01/11/09 09:12:02
Modified: sources/org/apache/batik/css CSSOMStyleDeclaration.java
CSSOMStyleRule.java
sources/org/apache/batik/css/parser Parser.java
sources/org/apache/batik/css/value AbstractValueFactory.java
Added: sources/org/apache/batik/css/parser ExtendedParser.java
Log:
parse<CSS stuffs> methods now uses java.lang.String instead of
new InputSource(StringReader()). We also check if the CSS parser is an
ExtendedParser to still be compliant with SAC (Simple API for CSS).
10%-25% build phase speed improved
Revision Changes Path
1.3 +28 -5
xml-batik/sources/org/apache/batik/css/CSSOMStyleDeclaration.java
Index: CSSOMStyleDeclaration.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/css/CSSOMStyleDeclaration.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CSSOMStyleDeclaration.java 2001/02/05 09:55:30 1.2
+++ CSSOMStyleDeclaration.java 2001/11/09 17:12:02 1.3
@@ -10,17 +10,24 @@
import java.io.Reader;
import java.io.StringReader;
+
import org.apache.batik.css.event.CSSStyleDeclarationChangeListener;
import org.apache.batik.css.event.CSSStyleDeclarationChangeSupport;
import org.apache.batik.css.event.CSSValueChangeListener;
+
+import org.apache.batik.css.parser.ExtendedParser;
+
import org.apache.batik.css.value.ValueFactory;
import org.apache.batik.css.value.ValueFactoryMap;
+
import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.DocumentHandler;
import org.w3c.css.sac.InputSource;
import org.w3c.css.sac.LexicalUnit;
import org.w3c.css.sac.Parser;
+
import org.w3c.dom.DOMException;
+
import org.w3c.dom.css.CSSRule;
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.css.CSSValue;
@@ -30,7 +37,7 @@
* interface.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: CSSOMStyleDeclaration.java,v 1.2 2001/02/05 09:55:30 hillion Exp $
+ * @version $Id: CSSOMStyleDeclaration.java,v 1.3 2001/11/09 17:12:02 tkormann Exp $
*/
public class CSSOMStyleDeclaration
implements CSSStyleDeclaration,
@@ -78,11 +85,17 @@
protected CSSStyleDeclarationChangeSupport declarationChangeSupport;
/**
+ * Indicates whether or not the CSS parser supports methods with String.
+ */
+ protected boolean isExtendedParser;
+
+ /**
* Creates a new CSSStyleDeclaration object.
*/
public CSSOMStyleDeclaration() {
try {
parser = CSSDocumentHandler.createParser();
+ isExtendedParser = (parser instanceof ExtendedParser);
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
@@ -93,6 +106,7 @@
*/
public CSSOMStyleDeclaration(CSSRule r, Parser p) {
parser = p;
+ isExtendedParser = (parser instanceof ExtendedParser);
parentRule = r;
}
@@ -208,9 +222,13 @@
oldProperties = new PropertyMap(properties);
properties = new PropertyMap();
try {
- Reader r = new StringReader(cssText);
parser.setDocumentHandler(handler);
- parser.parseStyleDeclaration(new InputSource(r));
+ if (isExtendedParser) {
+ ((ExtendedParser)parser).parseStyleDeclaration(cssText);
+ } else {
+ Reader r = new StringReader(cssText);
+ parser.parseStyleDeclaration(new InputSource(r));
+ }
} catch (DOMException e) {
properties = pm;
oldProperties = null;
@@ -320,8 +338,13 @@
try {
ValueFactory f;
f = factories.get(propertyName.toLowerCase().intern());
- InputSource is = new InputSource(new StringReader(value));
- LexicalUnit lu = parser.parsePropertyValue(is);
+ LexicalUnit lu;
+ if (isExtendedParser) {
+ lu = ((ExtendedParser)parser).parsePropertyValue(value);
+ } else {
+ InputSource is = new InputSource(new StringReader(value));
+ lu = parser.parsePropertyValue(is);
+ }
f.createCSSValue(lu, this, prio);
} catch (Exception e) {
e.printStackTrace();
1.4 +20 -3 xml-batik/sources/org/apache/batik/css/CSSOMStyleRule.java
Index: CSSOMStyleRule.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/CSSOMStyleRule.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CSSOMStyleRule.java 2001/10/18 12:30:22 1.3
+++ CSSOMStyleRule.java 2001/11/09 17:12:02 1.4
@@ -12,19 +12,26 @@
import java.net.URL;
import org.apache.batik.css.value.ValueFactory;
+
import org.apache.batik.css.event.CSSStyleDeclarationChangeEvent;
import org.apache.batik.css.event.CSSStyleDeclarationChangeListener;
import org.apache.batik.css.event.CSSStyleRuleChangeListener;
import org.apache.batik.css.event.CSSStyleRuleChangeSupport;
import org.apache.batik.css.event.CSSPropertyChangeEvent;
+
+import org.apache.batik.css.parser.ExtendedParser;
+
import org.apache.batik.css.value.ValueFactoryMap;
+
import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.DocumentHandler;
import org.w3c.css.sac.InputSource;
import org.w3c.css.sac.LexicalUnit;
import org.w3c.css.sac.Parser;
import org.w3c.css.sac.SelectorList;
+
import org.w3c.dom.DOMException;
+
import org.w3c.dom.css.CSSRule;
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.css.CSSStyleRule;
@@ -34,7 +41,7 @@
* This class implements the {@link org.w3c.dom.css.CSSStyleRule} interface.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: CSSOMStyleRule.java,v 1.3 2001/10/18 12:30:22 hillion Exp $
+ * @version $Id: CSSOMStyleRule.java,v 1.4 2001/11/09 17:12:02 tkormann Exp $
*/
public class CSSOMStyleRule
extends AbstractCSSRule
@@ -74,6 +81,11 @@
* The base URI.
*/
protected URL baseURI;
+
+ /**
+ * Indicates whether or not the CSS parser supports methods with String.
+ */
+ protected boolean isExtendedParser;
/**
* Creates a new rule set.
@@ -84,6 +96,7 @@
ValueFactoryMap m) {
super(ss, pr);
parser = p;
+ isExtendedParser = (parser instanceof ExtendedParser);
factories = m;
style = new CSSOMStyleDeclaration(this, p);
style.setValueFactoryMap(m);
@@ -135,11 +148,15 @@
style.addCSSStyleDeclarationChangeListener(this);
style.fireCSSStyleDeclarationChangeStart();
- InputSource is = new InputSource(new StringReader(cssText));
parser.setSelectorFactory(SELECTOR_FACTORY);
parser.setConditionFactory(CONDITION_FACTORY);
parser.setDocumentHandler(ruleHandler);
- parser.parseRule(is);
+ if (isExtendedParser) {
+ ((ExtendedParser)parser).parseRule(cssText);
+ } else {
+ InputSource is = new InputSource(new StringReader(cssText));
+ parser.parseRule(is);
+ }
} catch (DOMException e) {
style.fireCSSStyleDeclarationChangeCancel();
fireCSSStyleRuleChangeCancel();
1.16 +97 -5 xml-batik/sources/org/apache/batik/css/parser/Parser.java
Index: Parser.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/parser/Parser.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Parser.java 2001/11/08 23:02:43 1.15
+++ Parser.java 2001/11/09 17:12:02 1.16
@@ -43,11 +43,9 @@
* This class implements the {@link org.w3c.css.sac.Parser} interface.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: Parser.java,v 1.15 2001/11/08 23:02:43 deweese Exp $
+ * @version $Id: Parser.java,v 1.16 2001/11/09 17:12:02 tkormann Exp $
*/
-public class Parser
- implements org.w3c.css.sac.Parser,
- Localizable {
+public class Parser implements ExtendedParser, Localizable {
/**
* The CSS to Java encoding table.
@@ -300,7 +298,16 @@
*/
public void parseStyleDeclaration(InputSource source)
throws CSSException, IOException {
+
scanner = new Scanner(characterStream(source, null));
+ parseStyleDeclarationInternal();
+ }
+
+ /**
+ * Parses a style declaration using the current scanner.
+ */
+ protected void parseStyleDeclarationInternal()
+ throws CSSException, IOException {
nextIgnoreSpaces();
try {
parseStyleDeclaration(false);
@@ -314,8 +321,16 @@
/**
* <b>SAC</b>: Implements {@link org.w3c.css.sac.Parser#parseRule(InputSource)}.
*/
- public void parseRule(InputSource source) throws CSSException, IOException {
+ public void parseRule(InputSource source)
+ throws CSSException, IOException {
scanner = new Scanner(characterStream(source, null));
+ parseRuleInternal();
+ }
+
+ /**
+ * Parses a rule using the current scanner.
+ */
+ protected void parseRuleInternal() throws CSSException, IOException {
nextIgnoreSpaces();
parseRule();
scanner = null;
@@ -327,6 +342,14 @@
public SelectorList parseSelectors(InputSource source)
throws CSSException, IOException {
scanner = new Scanner(characterStream(source, null));
+ return parseSelectorsInternal();
+ }
+
+ /**
+ * Parses selectors using the current scanner.
+ */
+ protected SelectorList parseSelectorsInternal()
+ throws CSSException, IOException {
nextIgnoreSpaces();
SelectorList ret = parseSelectorList();
scanner = null;
@@ -340,6 +363,14 @@
public LexicalUnit parsePropertyValue(InputSource source)
throws CSSException, IOException {
scanner = new Scanner(characterStream(source, null));
+ return parsePropertyValueInternal();
+ }
+
+ /**
+ * Parses property value using the current scanner.
+ */
+ protected LexicalUnit parsePropertyValueInternal()
+ throws CSSException, IOException {
nextIgnoreSpaces();
LexicalUnit exp = null;
@@ -366,6 +397,14 @@
public boolean parsePriority(InputSource source)
throws CSSException, IOException {
scanner = new Scanner(characterStream(source, null));
+ return parsePriorityInternal();
+ }
+
+ /**
+ * Parses the priority using the current scanner.
+ */
+ protected boolean parsePriorityInternal()
+ throws CSSException, IOException {
nextIgnoreSpaces();
scanner = null;
@@ -1687,5 +1726,58 @@
documentURI,
scanner.getLine(),
scanner.getColumn());
+ }
+
+ // -----------------------------------------------------------------------
+ // Extended methods
+ // -----------------------------------------------------------------------
+
+ /**
+ * Implements {@link
+ * org.apache.batik.css.parser.ExtendedParser#parseStyleDeclaration(String)}.
+ */
+ public void parseStyleDeclaration(String source)
+ throws CSSException, IOException {
+ scanner = new Scanner(source);
+ parseStyleDeclarationInternal();
+ }
+
+ /**
+ * Implements {@link
+ * org.apache.batik.css.parser.ExtendedParser#parseRule(String)}.
+ */
+ public void parseRule(String source) throws CSSException, IOException {
+ scanner = new Scanner(source);
+ parseRuleInternal();
+ }
+
+ /**
+ * Implements {@link
+ * org.apache.batik.css.parser.ExtendedParser#parseSelectors(String)}.
+ */
+ public SelectorList parseSelectors(String source)
+ throws CSSException, IOException {
+ scanner = new Scanner(source);
+ return parseSelectorsInternal();
+ }
+
+ /**
+ * Implements {@link
+ * org.apache.batik.css.parser.ExtendedParser#parsePropertyValue(String)}.
+ */
+ public LexicalUnit parsePropertyValue(String source)
+ throws CSSException, IOException {
+ scanner = new Scanner(source);
+ return parsePropertyValueInternal();
+ }
+
+ /**
+ * Implements {@link
+ * org.apache.batik.css.parser.ExtendedParser#parsePriority(String)}.
+ */
+ public boolean parsePriority(String source)
+ throws CSSException, IOException {
+ scanner = new Scanner(source);
+ return parsePriorityInternal();
}
}
1.1
xml-batik/sources/org/apache/batik/css/parser/ExtendedParser.java
Index: ExtendedParser.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.css.parser;
import java.io.IOException;
import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.LexicalUnit;
import org.w3c.css.sac.SelectorList;
/**
* This class implements the {@link org.w3c.css.sac.Parser} interface plus a
* set of custom methods.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
* @version $Id: ExtendedParser.java,v 1.1 2001/11/09 17:12:02 tkormann Exp $
*/
public interface ExtendedParser extends org.w3c.css.sac.Parser {
/**
* Parse a CSS style declaration (without '{' and '}').
*
* @param styleValue The declaration.
* @exception CSSException Any CSS exception, possibly
* wrapping another exception.
* @exception java.io.IOException An IO exception from the parser,
* possibly from a byte stream or character stream
* supplied by the application.
*/
void parseStyleDeclaration(String source)
throws CSSException, IOException;
/**
* Parse a CSS rule.
*
* @exception CSSException Any CSS exception, possibly
* wrapping another exception.
* @exception java.io.IOException An IO exception from the parser,
* possibly from a byte stream or character stream
* supplied by the application.
*/
void parseRule(String source) throws CSSException, IOException;
/**
* Parse a comma separated list of selectors.
*
*
* @exception CSSException Any CSS exception, possibly
* wrapping another exception.
* @exception java.io.IOException An IO exception from the parser,
* possibly from a byte stream or character stream
* supplied by the application.
*/
SelectorList parseSelectors(String source)
throws CSSException, IOException;
/**
* Parse a CSS property value.
*
*
* @exception CSSException Any CSS exception, possibly
* wrapping another exception.
* @exception java.io.IOException An IO exception from the parser,
* possibly from a byte stream or character stream
* supplied by the application.
*/
LexicalUnit parsePropertyValue(String source)
throws CSSException, IOException;
/**
* Parse a CSS priority value (e.g. "!important").
*
*
* @exception CSSException Any CSS exception, possibly
* wrapping another exception.
* @exception java.io.IOException An IO exception from the parser,
* possibly from a byte stream or character stream
* supplied by the application.
*/
boolean parsePriority(String source)
throws CSSException, IOException;
}
1.7 +17 -3
xml-batik/sources/org/apache/batik/css/value/AbstractValueFactory.java
Index: AbstractValueFactory.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/css/value/AbstractValueFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractValueFactory.java 2001/10/19 06:45:50 1.6
+++ AbstractValueFactory.java 2001/11/09 17:12:02 1.7
@@ -15,6 +15,8 @@
import org.apache.batik.css.CSSOMStyleDeclaration;
import org.apache.batik.css.CSSOMValue;
+import org.apache.batik.css.parser.ExtendedParser;
+
import org.w3c.css.sac.InputSource;
import org.w3c.css.sac.LexicalUnit;
import org.w3c.css.sac.Parser;
@@ -25,7 +27,7 @@
* This class provides a base implementation for every value factories.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: AbstractValueFactory.java,v 1.6 2001/10/19 06:45:50 hillion Exp $
+ * @version $Id: AbstractValueFactory.java,v 1.7 2001/11/09 17:12:02 tkormann Exp $
*/
public abstract class AbstractValueFactory
implements ValueFactory,
@@ -37,11 +39,17 @@
protected Parser parser;
/**
+ * Indicates whether or not the CSS parser supports methods with String.
+ */
+ protected boolean isExtendedParser;
+
+ /**
* To creates a new ValueFactory object.
* @param p The CSS parser used to parse the CSS texts.
*/
protected AbstractValueFactory(Parser p) {
parser = p;
+ isExtendedParser = (parser instanceof ExtendedParser);
}
/**
@@ -56,6 +64,7 @@
*/
public void setParser(Parser p) {
parser = p;
+ isExtendedParser = (parser instanceof ExtendedParser);
}
/**
@@ -64,8 +73,13 @@
*/
public ImmutableValue createValue(String text) throws DOMException {
try {
- InputSource is = new InputSource(new StringReader(text));
- LexicalUnit lu = parser.parsePropertyValue(is);
+ LexicalUnit lu;
+ if (isExtendedParser) {
+ lu = ((ExtendedParser)parser).parsePropertyValue(text);
+ } else {
+ InputSource is = new InputSource(new StringReader(text));
+ lu = parser.parsePropertyValue(is);
+ }
return createValue(lu);
} catch (IOException e) {
// Should never happen
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]