deweese 2003/08/10 11:03:16 Modified: . .classpath build.xml samples/tests/spec/scripting security2.jar sources/org/apache/batik/css/engine CSSEngine.java sources/org/apache/batik/dom/svg SVGStylableElement.java sources/org/apache/batik/swing/svg JSVGComponent.java xdocs faq.xml Added: lib LICENSE.xerces_2_5_0.txt xerces_2_5_0.jar Removed: lib LICENSE.xerces_2_3_0.txt xerces_2_3_0.jar Log: 1) Switch to Xerces 2.5.0 to resove performance issue with attributes with large value fields (think data protocol images in xlink:href). 2) Few minor improvements to the handling of URL's in CSS. 3) Some documentation improvements/additions. Revision Changes Path 1.2 +1 -1 xml-batik/.classpath Index: .classpath =================================================================== RCS file: /home/cvs/xml-batik/.classpath,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- .classpath 9 Aug 2003 16:58:44 -0000 1.1 +++ .classpath 10 Aug 2003 18:03:15 -0000 1.2 @@ -7,7 +7,7 @@ <classpathentry kind="src" path="test-sources"/> <classpathentry kind="lib" path="lib/js.jar"/> <classpathentry kind="lib" path="lib/pdf-transcoder.jar"/> - <classpathentry kind="lib" path="lib/xerces_2_3_0.jar"/> + <classpathentry kind="lib" path="lib/xerces_2_5_0.jar"/> <classpathentry kind="lib" path="lib/xml-apis.jar"/> <classpathentry kind="src" path="resources"/> <classpathentry kind="src" path="test-resources"/> 1.139 +2 -2 xml-batik/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/xml-batik/build.xml,v retrieving revision 1.138 retrieving revision 1.139 diff -u -r1.138 -r1.139 --- build.xml 16 Jul 2003 00:46:49 -0000 1.138 +++ build.xml 10 Aug 2003 18:03:15 -0000 1.139 @@ -456,7 +456,7 @@ including the XML parser --> <target name="bean" depends="compile, prepare-build"> <mkdir dir="${build}/tmp"/> - <unjar src="lib/xerces_2_3_0.jar" dest="${build}/tmp"/> + <unjar src="lib/xerces_2_5_0.jar" dest="${build}/tmp"/> <jar jarfile="${build}/lib/${project}-bean.jar" manifest="${src}/${project}-bean.mf"> <manifest> 1.1 xml-batik/lib/LICENSE.xerces_2_5_0.txt Index: LICENSE.xerces_2_5_0.txt =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xerces" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 1999, International * Business Machines, Inc., http://www.ibm.com. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ 1.1 xml-batik/lib/xerces_2_5_0.jar <<Binary file>> 1.5 +39 -29 xml-batik/samples/tests/spec/scripting/security2.jar <<Binary file>> 1.30 +100 -87 xml-batik/sources/org/apache/batik/css/engine/CSSEngine.java Index: CSSEngine.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/engine/CSSEngine.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- CSSEngine.java 9 Aug 2003 16:58:41 -0000 1.29 +++ CSSEngine.java 10 Aug 2003 18:03:16 -0000 1.30 @@ -707,84 +707,87 @@ } element = elt; - + try { // Apply the non-CSS presentational hints to the result. - if (nonCSSPresentationalHints != null) { - NamedNodeMap attrs = elt.getAttributes(); - int len = attrs.getLength(); - for (int i = 0; i < len; i++) { - Node attr = attrs.item(i); - String an = attr.getNodeName(); - if (nonCSSPresentationalHints.contains(an)) { + if (nonCSSPresentationalHints != null) { + NamedNodeMap attrs = elt.getAttributes(); + int len = attrs.getLength(); + for (int i = 0; i < len; i++) { + Node attr = attrs.item(i); + String an = attr.getNodeName(); + if (nonCSSPresentationalHints.contains(an)) { + try { + LexicalUnit lu; + int idx = getPropertyIndex(an); + lu = parser.parsePropertyValue + (attr.getNodeValue()); + ValueManager vm = valueManagers[idx]; + Value v = vm.createValue(lu, this); + putAuthorProperty(result, idx, v, false, + StyleMap.NON_CSS_ORIGIN); + } catch (Exception e) { + String m = e.getMessage(); + if (m == null) m = ""; + String u = ((documentURI == null)?"<unknown>": + documentURI.toString()); + String s = Messages.formatMessage + ("property.syntax.error.at", + new Object[] { u, an, attr.getNodeValue(),m}); + throw new DOMException(DOMException.SYNTAX_ERR, s); + } + } + } + } + + // Apply the document style-sheets to the result. + List snodes = getStyleSheetNodes(); + int slen = snodes.size(); + if (slen > 0) { + List rules = new ArrayList(); + for (int i = 0; i < slen; i++) { + CSSStyleSheetNode ssn = (CSSStyleSheetNode)snodes.get(i); + StyleSheet ss = ssn.getCSSStyleSheet(); + if (ss != null && + (!ss.isAlternate() || + ss.getTitle() == null || + ss.getTitle().equals(alternateStyleSheet)) && + mediaMatch(ss.getMedia())) { + addMatchingRules(rules, ss, elt, pseudo); + } + } + addRules(elt, pseudo, result, rules, StyleMap.AUTHOR_ORIGIN); + } + + // Apply the inline style to the result. + if (styleLocalName != null) { + String style = elt.getAttributeNS(styleNamespaceURI, + styleLocalName); + if (style.length() > 0) { try { - LexicalUnit lu; - int idx = getPropertyIndex(an); - lu = parser.parsePropertyValue(attr.getNodeValue()); - ValueManager vm = valueManagers[idx]; - Value v = vm.createValue(lu, this); - putAuthorProperty(result, idx, v, false, - StyleMap.NON_CSS_ORIGIN); + parser.setSelectorFactory(CSSSelectorFactory.INSTANCE); + parser.setConditionFactory(cssConditionFactory); + styleDeclarationDocumentHandler.styleMap = result; + parser.setDocumentHandler + (styleDeclarationDocumentHandler); + parser.parseStyleDeclaration(style); + styleDeclarationDocumentHandler.styleMap = null; } catch (Exception e) { String m = e.getMessage(); if (m == null) m = ""; String u = ((documentURI == null)?"<unknown>": documentURI.toString()); String s = Messages.formatMessage - ("property.syntax.error.at", - new Object[] { u, an, attr.getNodeValue(),m}); + ("style.syntax.error.at", + new Object[] { u, styleLocalName, style, m}); throw new DOMException(DOMException.SYNTAX_ERR, s); } } } + } finally { + element = null; + cssBaseURI = null; } - // Apply the document style-sheets to the result. - List snodes = getStyleSheetNodes(); - int slen = snodes.size(); - if (slen > 0) { - List rules = new ArrayList(); - for (int i = 0; i < slen; i++) { - CSSStyleSheetNode ssn = (CSSStyleSheetNode)snodes.get(i); - StyleSheet ss = ssn.getCSSStyleSheet(); - if (ss != null && - (!ss.isAlternate() || - ss.getTitle() == null || - ss.getTitle().equals(alternateStyleSheet)) && - mediaMatch(ss.getMedia())) { - addMatchingRules(rules, ss, elt, pseudo); - } - } - addRules(elt, pseudo, result, rules, StyleMap.AUTHOR_ORIGIN); - } - - // Apply the inline style to the result. - if (styleLocalName != null) { - String style = elt.getAttributeNS(styleNamespaceURI, - styleLocalName); - if (style.length() > 0) { - try { - parser.setSelectorFactory(CSSSelectorFactory.INSTANCE); - parser.setConditionFactory(cssConditionFactory); - styleDeclarationDocumentHandler.styleMap = result; - parser.setDocumentHandler(styleDeclarationDocumentHandler); - parser.parseStyleDeclaration(style); - styleDeclarationDocumentHandler.styleMap = null; - } catch (Exception e) { - String m = e.getMessage(); - if (m == null) m = ""; - String u = ((documentURI == null)?"<unknown>": - documentURI.toString()); - String s = Messages.formatMessage - ("style.syntax.error.at", - new Object[] { u, styleLocalName, style, m}); - throw new DOMException(DOMException.SYNTAX_ERR, s); - } - } - } - - element = null; - cssBaseURI = null; - return result; } @@ -905,7 +908,8 @@ } /** - * Parses and creates a property value. + * Parses and creates a property value from elt. + * @param elt The element property is from. * @param prop The property name. * @param value The property value. */ @@ -929,6 +933,7 @@ throw new DOMException(DOMException.SYNTAX_ERR, s); } finally { element = null; + cssBaseURI = null; } } @@ -937,15 +942,15 @@ * Parses and creates a style declaration. * @param value The style declaration text. */ - public StyleDeclaration parseStyleDeclaration(String value) { + public StyleDeclaration parseStyleDeclaration(CSSStylableElement elt, + String value) { try { parser.setSelectorFactory(CSSSelectorFactory.INSTANCE); parser.setConditionFactory(cssConditionFactory); - cssBaseURI = documentURI; + element = elt; styleDeclarationBuilder.styleDeclaration = new StyleDeclaration(); parser.setDocumentHandler(styleDeclarationBuilder); parser.parseStyleDeclaration(value); - cssBaseURI = null; return styleDeclarationBuilder.styleDeclaration; } catch (Exception e) { String m = e.getMessage(); @@ -955,6 +960,9 @@ String s = Messages.formatMessage ("syntax.error.at", new Object[] { u, m }); throw new DOMException(DOMException.SYNTAX_ERR, s); + } finally { + element = null; + cssBaseURI = null; } } @@ -1093,22 +1101,25 @@ throws IOException { parser.setSelectorFactory(CSSSelectorFactory.INSTANCE); parser.setConditionFactory(cssConditionFactory); - cssBaseURI = uri; - styleSheetDocumentHandler.styleSheet = ss; - parser.setDocumentHandler(styleSheetDocumentHandler); - parser.parseStyleSheet(is); - cssBaseURI = null; + try { + cssBaseURI = uri; + styleSheetDocumentHandler.styleSheet = ss; + parser.setDocumentHandler(styleSheetDocumentHandler); + parser.parseStyleSheet(is); - // Load the imported sheets. - int len = ss.getSize(); - for (int i = 0; i < len; i++) { - Rule r = ss.getRule(i); - if (r.getType() != ImportRule.TYPE) { - // @import rules must be the first rules. - break; + // Load the imported sheets. + int len = ss.getSize(); + for (int i = 0; i < len; i++) { + Rule r = ss.getRule(i); + if (r.getType() != ImportRule.TYPE) { + // @import rules must be the first rules. + break; + } + ImportRule ir = (ImportRule)r; + parseStyleSheet(ir, ir.getURI()); } - ImportRule ir = (ImportRule)r; - parseStyleSheet(ir, ir.getURI()); + } finally { + cssBaseURI = null; } } @@ -1715,9 +1726,10 @@ ("style.syntax.error.at", new Object[] { u, styleLocalName, decl, m }); throw new DOMException(DOMException.SYNTAX_ERR, s); + } finally { + element = null; + cssBaseURI = null; } - element = null; - cssBaseURI = null; } // Fall through @@ -2040,9 +2052,10 @@ ("property.syntax.error.at", new Object[] { u, property, evt.getNewValue(), m }); throw new DOMException(DOMException.SYNTAX_ERR, s); + } finally { + element = null; + cssBaseURI = null; } - element = null; - cssBaseURI = null; break; case MutationEvent.REMOVAL: 1.10 +20 -19 xml-batik/sources/org/apache/batik/dom/svg/SVGStylableElement.java Index: SVGStylableElement.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/svg/SVGStylableElement.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- SVGStylableElement.java 8 Aug 2003 11:39:00 -0000 1.9 +++ SVGStylableElement.java 10 Aug 2003 18:03:16 -0000 1.10 @@ -562,7 +562,8 @@ setModificationHandler(this); declaration = cssEngine.parseStyleDeclaration - (getAttributeNS(null, SVG_STYLE_ATTRIBUTE)); + (SVGStylableElement.this, + getAttributeNS(null, SVG_STYLE_ATTRIBUTE)); } // ValueProvider //////////////////////////////////////// @@ -621,7 +622,8 @@ */ public void attrAdded(Attr node, String newv) { if (!mutate) { - declaration = cssEngine.parseStyleDeclaration(newv); + declaration = cssEngine.parseStyleDeclaration + (SVGStylableElement.this, newv); } } @@ -630,7 +632,8 @@ */ public void attrModified(Attr node, String oldv, String newv) { if (!mutate) { - declaration = cssEngine.parseStyleDeclaration(newv); + declaration = cssEngine.parseStyleDeclaration + (SVGStylableElement.this, newv); } } @@ -650,7 +653,8 @@ * Called when the value text has changed. */ public void textChanged(String text) throws DOMException { - declaration = cssEngine.parseStyleDeclaration(text); + declaration = cssEngine.parseStyleDeclaration + (SVGStylableElement.this, text); mutate = true; setAttributeNS(null, SVG_STYLE_ATTRIBUTE, text); mutate = false; @@ -678,22 +682,19 @@ */ public void propertyChanged(String name, String value, String prio) throws DOMException { - int idx = cssEngine.getPropertyIndex(name); - for (int i = 0; i < declaration.size(); i++) { - if (idx == declaration.getIndex(i)) { - Value v = cssEngine.parsePropertyValue - (SVGStylableElement.this, name, value); - declaration.put(i, v, idx, prio.length() > 0); - mutate = true; - setAttributeNS(null, SVG_STYLE_ATTRIBUTE, - declaration.toString(cssEngine)); - mutate = false; - return; - } - } Value v = cssEngine.parsePropertyValue (SVGStylableElement.this, name, value); - declaration.append(v, idx, prio.length() > 0); + + int i = 0; + int idx = cssEngine.getPropertyIndex(name); + for (; i < declaration.size(); i++) { + if (idx == declaration.getIndex(i)) + break; + } + if (i < declaration.size()) + declaration.put(i, v, idx, prio.length() > 0); + else + declaration.append(v, idx, prio.length() > 0); mutate = true; setAttributeNS(null, SVG_STYLE_ATTRIBUTE, declaration.toString(cssEngine)); 1.79 +13 -2 xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java Index: JSVGComponent.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java,v retrieving revision 1.78 retrieving revision 1.79 diff -u -r1.78 -r1.79 --- JSVGComponent.java 9 Aug 2003 16:58:45 -0000 1.78 +++ JSVGComponent.java 10 Aug 2003 18:03:16 -0000 1.79 @@ -403,7 +403,9 @@ /** * Sets the document state. The given value must be one of - * AUTODETECT, ALWAYS_DYNAMIC or ALWAYS_STATIC. + * AUTODETECT, ALWAYS_DYNAMIC or ALWAYS_STATIC. This only + * effects the loading of subsequent documents, it has no + * effect on the currently loaded document. */ public void setDocumentState(int state) { documentState = state; @@ -415,6 +417,15 @@ * notifed when the rendering completes by registering a * GVTTreeRendererListener with the component and waiting for the * <tt>gvtRenderingCompleted</tt> event. + * + * An UpdateManager is only created for Dynamic documents. By + * default the Canvas attempts to autodetect dynamic documents by + * looking for script elements and/or event attributes in the + * document, if it does not find these it assumes the document is + * static. Callers of this method will almost certainly want to + * call setDocumentState(ALWAYS_DYNAMIC) before loading the document + * (with setURI, setDocument, setSVGDocument etc.) so that an + * UpdateManager is always created (even for apparently static documents). */ public UpdateManager getUpdateManager() { if (svgLoadEventDispatcher != null) { 1.37 +46 -29 xml-batik/xdocs/faq.xml Index: faq.xml =================================================================== RCS file: /home/cvs/xml-batik/xdocs/faq.xml,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- faq.xml 10 Jul 2003 08:28:30 -0000 1.36 +++ faq.xml 10 Aug 2003 18:03:16 -0000 1.37 @@ -563,9 +563,9 @@ Batik detects this by looking for script elements but when you modify the document from Java it can't tell. So call JSVGCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC) before - loading the document.</p> + loading the document (with setURI, setDocument, setSVGDocument etc.).</p> <p>The second common reason is that the changes aren't made in - The UpdateManager's thread. You can run code in the UpdateManager's + the UpdateManager's thread. You can run code in the UpdateManager's thread with the following: </p> <code>UpdateManager um = JSVGCanvas.getUpdateManager();</code> @@ -577,41 +577,58 @@ </p> </answer> </faq> - + <faq> + <question>When I change the document in Java it only updates if I + move the mouse over the canvas?</question> + <answer> + <p>The most common causes for this, is that the changes are not made in + the UpdateManager's thread. See previous FAQ for example code to + run code in the Update Manager's thread. Moving the mouse works + because it delivers the mouse move events in the update thread, + and after a runnable completes in the Update Manager's thread it + checks if the canvas needs repainting.</p> + </answer> + </faq> <faq> - <question>When I modify create new SVG elements or modify some + <question>When I create new SVG elements or modify some SVG attributes through the DOM API, from ECMA Script, - nothing happens, changes are not rendered? What is going on?</question> + nothing happens, the changes are not rendered, why not?</question> <answer> <p>A common problem is that script contain the wrong DOM calls to create elements or modify attributes. </p> <p>SVG elements need to be - created in the SVG namespace. For example, to create a <code><rect></code> - element, you should use <code>document.createElementNS(svgNS, "rect")</code>, - (where <code>svgNS</code> is equals to <code>"http://www.w3.org/2000/svg"</code>), + created in the SVG namespace. For example, to create a + <code><rect></code> element, you should use + <code>document.createElementNS(svgNS, "rect")</code>, (where + <code>svgNS</code> is equals to <code>"http://www.w3.org/2000/svg"</code>), which appropriately creates the <code><rect></code> element in the - SVG namespace. A call to <code>document.createElement("rect")</code> creates - an element with the tag <code>rect</code> but which does not belong to the - SVG namespace. As such, it is ignored by Batik.</p> - <p>Most SVG attributes belong to what is called the 'per element type partition - namespace' (see the <link href="http://www.w3.org/TR/REC-xml-names">Namespaces in + SVG namespace. A call to <code>document.createElement("rect")</code> + creates an element with the tag <code>rect</code> but which does not + belong to the SVG namespace. As such, it is ignored by Batik.</p> + <p>Most SVG attributes belong to what is called the 'per element type + partition namespace' (see the + <link href="http://www.w3.org/TR/REC-xml-names">Namespaces in XML</link> specification). The appropriate way to set attributes on an SVG element is a call to <code>setAttributeNS</code> with a namespace - value of <code>null</code>, for example: <code>elt.setAttributeNS(null, "width", "40")</code>. - In the Batik SVG DOM implementation, you can also use a call to <code>setAttribute</code> and - you can write <code>elt.setAttribute("width", "40")</code>. However, it is important - to know that some implementations make a difference between <code>setAttribute(x, y)</code> - and <code>setAttributeNS(null, x, y)</code>, so it is a better practice to use - <code>setAttributeNS</code> which is the only guaranteed interoperable way of - setting attributes in a namespace aware DOM implementation.</p> + value of <code>null</code>, for example: <code>elt.setAttributeNS(null, + "width", "40")</code>. In the Batik SVG DOM implementation, you can + also use a call to <code>setAttribute</code> and you can write + <code>elt.setAttribute("width", "40")</code>. However, it is important + to know that some implementations make a difference between + <code>setAttribute(x, y)</code> and + <code>setAttributeNS(null, x, y)</code>, so it is a better practice to use + <code>setAttributeNS</code> which is the only guaranteed interoperable + way of setting attributes in a namespace aware DOM implementation.</p> <p>Finally, for attributes which belong to a specific namespace, like the the href attribute on the <code><image></code> element, you have to - use the <code>setAttributeNS</code> method with the XLink namespace. For example, - assuming <code>img</code> references an <code><image></code> DOM <code>Element</code>, - you can modify the href as follows: <code>img.setAttributeNS(xlinkNS, "xlink:href", "myImage.jpg")</code> - where <code>xlinkNS</code> is equal to <code>"http://www.w3.org/1999/xlink"</code></p> + use the <code>setAttributeNS</code> method with the XLink namespace. + For example, assuming <code>img</code> references an + <code><image></code> DOM <code>Element</code>, you can modify the + href as follows: <code>img.setAttributeNS(xlinkNS, "xlink:href", + "myImage.jpg")</code> where <code>xlinkNS</code> is equal to + <code>"http://www.w3.org/1999/xlink"</code></p> </answer> </faq> @@ -620,10 +637,10 @@ it is null, why?</question> <answer> <p>The JSVGCanvs is highly asynchronous so when you call - setURI or setDocument they return essentially immediately. - Behind the scenes the Canvas sets up the rendering tree and - does a first rendering after running 'onload' scripts. Only - after this first rendering does the UpdateManger become + setURI, setDocument or setSVGDocument they return essentially + immediately. Behind the scenes the Canvas creates the rendering + tree and does a first rendering after running 'onload' scripts. + Only after this first rendering does the UpdateManger become available. </p> </answer>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]