nicolaken 02/05/14 13:34:23 Modified: src/scratchpad/src/org/apache/cocoon/transformation/constrained AbstractConstrainedTransformer.java src/scratchpad/src/org/apache/cocoon/transformation Chart2SvgTransformer.java src/scratchpad/webapp/mount/charts/content/static linechart.xml src/scratchpad/webapp/mount/charts/content samples.xml src/scratchpad/webapp/mount/charts sitemap.xmap Log: Tom Klaasen <[EMAIL PROTECTED]> is getting it to work. Revision Changes Path 1.2 +285 -282 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/constrained/AbstractConstrainedTransformer.java Index: AbstractConstrainedTransformer.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/constrained/AbstractConstrainedTransformer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractConstrainedTransformer.java 8 Apr 2002 08:09:16 -0000 1.1 +++ AbstractConstrainedTransformer.java 14 May 2002 20:34:22 -0000 1.2 @@ -1,54 +1,42 @@ /* - - ============================================================================ - 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 modifica- - tion, 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 "Apache Cocoon" 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 (INCLU- - DING, 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 created by - Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - -*/ - + * ============================================================================ + * 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 modifica- + * tion, 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 "Apache Cocoon" 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 (INCLU- + * DING, 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 created by + * Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ package org.apache.cocoon.transformation.constrained; import java.io.IOException; @@ -66,7 +54,7 @@ import org.apache.cocoon.xml.XMLConsumer; import org.apache.cocoon.xml.XMLProducer; import org.apache.cocoon.transformation.*; - +import org.apache.cocoon.environment.SourceResolver; import org.xml.sax.ContentHandler; import org.xml.sax.EntityResolver; @@ -76,243 +64,258 @@ import org.xml.sax.Locator; import org.xml.sax.ext.LexicalHandler; - /** - * This class is an abstract class from which you can extend your Transformer - * and write it in a way similar to AWT & Swing Event Handling. - * Part of this code is from the SQLTransformer of Donald Ball. - * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> + * This class is an abstract class from which you can extend your Transformer + * and write it in a way similar to AWT & Swing Event Handling. Part of this + * code is from the SQLTransformer of Donald Ball. + * + *@author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> + *@created 14 mei 2002 */ public abstract class AbstractConstrainedTransformer - extends AbstractTransformer { + extends AbstractTransformer { - private String my_uri; - private String my_prefix = "unknown"; - private String my_name; - private ArrayList myUriOpenElements = new ArrayList(); - private ArrayList globalOpenElements = new ArrayList(); - private ArrayList globalOpenElementsAttributes = new ArrayList(); - private String lastOpenElementRaw = ""; - private ArrayList registeredListeners = new ArrayList(); - private ArrayList registeredListenerConstraints = new ArrayList(); - private StringBuffer current_value = - new StringBuffer(); - protected XMLConsumer xml_consumer; - protected LexicalHandler lexical_handler; - - - public abstract void init(Parameters parameters); - - public abstract String getUri(); - - public abstract String getName(); - - public final void setup( - EntityResolver resolver, Map objectModel, String source, Parameters parameters) - throws ProcessingException, SAXException, IOException { - - my_uri = getUri(); - getLogger().debug(my_uri); - my_name = getName(); - getLogger().debug(my_name); - init(parameters); - - } - - - public void addEventListener( - ElementEventListener l, XmlTreeConstraint constraint){ - - registeredListeners.add(l); - registeredListenerConstraints.add(constraint); - } - - - public void setDocumentLocator(Locator locator) { - if (super.contentHandler != null) { - super.contentHandler.setDocumentLocator(locator); - } - } - - public void startElement( - String uri, String name, String raw, Attributes attributes) - throws SAXException { - System.out.println("Start"+uri+name+raw+attributes); - - lastOpenElementRaw = raw; - - boolean isMyUri = false; - - if (uri.equals(my_uri)) { - isMyUri = true; - if (getLogger().isDebugEnabled()) - getLogger().debug(raw+" isMyUri!!!"); - myUriOpenElements.add(name); - - current_value.delete(0, current_value.length()); - globalOpenElements.add(name); - globalOpenElementsAttributes.add(attributes); - - ListIterator constraintsIter = - this.registeredListenerConstraints.listIterator(); - - while (constraintsIter.hasNext()) { - if (((XmlTreeConstraint) constraintsIter.next()) - .isAllowed(new Boolean(isMyUri), this.myUriOpenElements, - this.globalOpenElements)) { - return; - } - } - } -else{ - super.startElement(uri, name, raw, attributes); -} - } + private String my_uri; + private String my_prefix = "unknown"; + private String my_name; + private ArrayList myUriOpenElements = new ArrayList(); + private ArrayList globalOpenElements = new ArrayList(); + private ArrayList globalOpenElementsAttributes = new ArrayList(); + private String lastOpenElementRaw = ""; + private ArrayList registeredListeners = new ArrayList(); + private ArrayList registeredListenerConstraints = new ArrayList(); + private StringBuffer current_value = + new StringBuffer(); + public XMLConsumer xml_consumer; + public LexicalHandler lexical_handler; + + + public abstract void init(Parameters parameters); + + + public abstract String getUri(); + + + public abstract String getName(); + + + public final void setup( + SourceResolver resolver, Map objectModel, String source, Parameters parameters) + throws ProcessingException, SAXException, IOException { + + my_uri = getUri(); + getLogger().debug(my_uri); + my_name = getName(); + getLogger().debug(my_name); + init(parameters); + + } + + + public void addEventListener( + ElementEventListener l, XmlTreeConstraint constraint) { + + registeredListeners.add(l); + registeredListenerConstraints.add(constraint); + } + + + public void setDocumentLocator(Locator locator) { + if (super.contentHandler != null) { + super.contentHandler.setDocumentLocator(locator); + } + } + + + public void startElement( + String uri, String name, String raw, Attributes attributes) + throws SAXException { + System.out.println("Start Element " + uri + " " + name + " " + raw + " " + attributes); + + lastOpenElementRaw = raw; + + boolean isMyUri = false; + + if (uri.equals(my_uri)) { + isMyUri = true; + System.out.println(raw + " isMyUri!!!"); + if (getLogger().isDebugEnabled()) { + getLogger().debug(raw + " isMyUri!!!"); + } + myUriOpenElements.add(name); + + current_value.delete(0, current_value.length()); + globalOpenElements.add(name); + globalOpenElementsAttributes.add(attributes); + + ListIterator constraintsIter = + this.registeredListenerConstraints.listIterator(); + + while (constraintsIter.hasNext()) { + if (((XmlTreeConstraint) constraintsIter.next()) + .isAllowed(new Boolean(isMyUri), this.myUriOpenElements, + this.globalOpenElements)) { + return; + } + } + } else { + System.out.println(raw + " is NOT MyUri!!!"); + if (getLogger().isDebugEnabled()) { + getLogger().debug(raw + " is NOT MyUri!!!"); + } + + super.startElement(uri, name, raw, attributes); + } + } + + + public void endElement(String uri, String name, String raw) + throws SAXException { + + try { - public void endElement(String uri, String name, String raw) - throws SAXException { + boolean isMyUri = false; - try { + if (uri.equals(my_uri)) { + isMyUri = true; - boolean isMyUri = false; + ListIterator constraintsIter = + this.registeredListenerConstraints.listIterator(); + XmlTreeConstraint currentConstraint; + boolean isAllowed; + boolean isElementTag = lastOpenElementRaw.equals(raw); - if (uri.equals(my_uri)) { - isMyUri = true; - - ListIterator constraintsIter = - this.registeredListenerConstraints.listIterator(); - XmlTreeConstraint currentConstraint; - boolean isAllowed; - boolean isElementTag = lastOpenElementRaw.equals(raw); - - while (constraintsIter.hasNext()) { - currentConstraint = - (XmlTreeConstraint) constraintsIter.next(); - isAllowed = - currentConstraint.isAllowed(new Boolean(isMyUri), - this.myUriOpenElements, - this.globalOpenElements); - - if (isAllowed) { - - EventListener el = - (EventListener) (registeredListeners - .get(constraintsIter.previousIndex())); - - - if(isElementTag)//it's an element - { - ((ElementEventListener)el).elementValueRecieved( - new ElementValueEvent( - this, name, current_value.toString(), - (Attributes) this.globalOpenElementsAttributes - .get(globalOpenElementsAttributes.size() - - 1))); - } - else {//it's a container - ((ElementEventListener)el).containerElementEnded( - new ContainerElementEndEvent( - this, name)); - } - - - if (uri.equals(my_uri)) { - myUriOpenElements.remove(myUriOpenElements.size() - - 1); - } - - globalOpenElements.remove(globalOpenElements.size() - 1); - globalOpenElementsAttributes - .remove(globalOpenElementsAttributes.size() - 1); - current_value.delete(0, current_value.length()); - - return; - } - } - - if (globalOpenElements.size() > 0) { - globalOpenElements.remove(globalOpenElements.size() - 1); - globalOpenElementsAttributes - .remove(globalOpenElementsAttributes.size() - 1); - - } - - if (uri.equals(my_uri) && (myUriOpenElements.size() > 0)) { - myUriOpenElements.remove(myUriOpenElements.size() - 1); - - } - } -else{ - super.endElement(uri, name, raw); - } - - - current_value.delete(0, current_value.length()); - - } catch (Exception t) { - throw new SAXException("Exception in transformer " - + this.getName() + " with uri " - + this.getUri() - + " while ending element.", t); - } - } - - /***************************************/ - /* Utility methods also for subclasses */ - /***************************************/ - - - public class RipperListener extends ElementEventAdapter { - - public void elementValueRecieved(ElementValueEvent e) { - //do nothing so that element doesn't pass through - } - } - - - public void characters(char ary[], int start, int length) - throws SAXException { - - if (this.globalOpenElements.isEmpty()) { - super.characters(ary, start, length); - } else { - current_value.append(ary, start, length); - } - } - - protected void start(String name, AttributesImpl attr) - throws SAXException { - super.contentHandler.startElement(getUri(), name, name, attr); - attr.clear(); - } - - protected void start(String name) throws SAXException { - super.contentHandler.startElement(getUri(), name, name, - new AttributesImpl()); - } - - protected void end(String name) throws SAXException { - super.contentHandler.endElement(getUri(), name, name); - } - - protected void data(String data) throws SAXException { - - if (data != null) { - super.contentHandler.characters(data.toCharArray(), 0, - data.length()); - } - } - - protected static String getStringValue(Object object) { - - if (object instanceof byte[]) { - return new String((byte[]) object); - } else if (object instanceof char[]) { - return new String((char[]) object); - } else if (object != null) { - return object.toString(); - } else { - return ""; - } - } + while (constraintsIter.hasNext()) { + currentConstraint = + (XmlTreeConstraint) constraintsIter.next(); + isAllowed = + currentConstraint.isAllowed(new Boolean(isMyUri), + this.myUriOpenElements, + this.globalOpenElements); + + if (isAllowed) { + + EventListener el = + (EventListener) (registeredListeners.get(constraintsIter.previousIndex())); + + if (isElementTag) { + //it's an element + + ((ElementEventListener) el).elementValueRecieved( + new ElementValueEvent( + this, name, current_value.toString(), + (Attributes) this.globalOpenElementsAttributes + .get(globalOpenElementsAttributes.size() + - 1))); + } else { + //it's a container + ((ElementEventListener) el).containerElementEnded( + new ContainerElementEndEvent( + this, name)); + } + + if (uri.equals(my_uri)) { + myUriOpenElements.remove(myUriOpenElements.size() + - 1); + } + + globalOpenElements.remove(globalOpenElements.size() - 1); + globalOpenElementsAttributes.remove(globalOpenElementsAttributes.size() - 1); + current_value.delete(0, current_value.length()); + + return; + } + } + + if (globalOpenElements.size() > 0) { + globalOpenElements.remove(globalOpenElements.size() - 1); + globalOpenElementsAttributes.remove(globalOpenElementsAttributes.size() - 1); + + } + + if (uri.equals(my_uri) && (myUriOpenElements.size() > 0)) { + myUriOpenElements.remove(myUriOpenElements.size() - 1); + + } + } else { + super.endElement(uri, name, raw); + } + + current_value.delete(0, current_value.length()); + + } catch (Exception t) { + throw new SAXException("Exception in transformer " + + this.getName() + " with uri " + + this.getUri() + + " while ending element.", t); + } + } + + + /** + * Utility methods also for subclasses + * + *@author Nicola Ken Barozzi + *@created 14 mei 2002 + */ + + public class RipperListener extends ElementEventAdapter { + + public void elementValueRecieved(ElementValueEvent e) { + //do nothing so that element doesn't pass through + } + } + + + public void characters(char ary[], int start, int length) + throws SAXException { + + if (this.globalOpenElements.isEmpty()) { + super.characters(ary, start, length); + } else { + current_value.append(ary, start, length); + } + } + + + public void start(String name, AttributesImpl attr) + throws SAXException { + super.contentHandler.startElement(getUri(), name, name, attr); + attr.clear(); + } + + + public void start(String name) throws SAXException { + super.contentHandler.startElement(getUri(), name, name, + new AttributesImpl()); + } + + + public void end(String name) throws SAXException { + super.contentHandler.endElement(getUri(), name, name); + } + + + public void data(String data) throws SAXException { + + if (data != null) { + super.contentHandler.characters(data.toCharArray(), 0, + data.length()); + } + } + + + public static String getStringValue(Object object) { + + if (object instanceof byte[]) { + return new String((byte[]) object); + } else if (object instanceof char[]) { + return new String((char[]) object); + } else if (object != null) { + return object.toString(); + } else { + return ""; + } + } } + 1.2 +196 -195 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/Chart2SvgTransformer.java Index: Chart2SvgTransformer.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/Chart2SvgTransformer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Chart2SvgTransformer.java 8 Apr 2002 08:09:17 -0000 1.1 +++ Chart2SvgTransformer.java 14 May 2002 20:34:22 -0000 1.2 @@ -1,54 +1,42 @@ /* - - ============================================================================ - 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 modifica- - tion, 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 "Apache Cocoon" 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 (INCLU- - DING, 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 created by - Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - -*/ - + * ============================================================================ + * 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 modifica- + * tion, 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 "Apache Cocoon" 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 (INCLU- + * DING, 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 created by + * Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ package org.apache.cocoon.transformation; import java.io.IOException; @@ -72,207 +60,220 @@ import org.krysalis.wings.*; - /** - * This Transformer transforms XML that describes a chart into an SVG - * representation. - * See Cocoon examples for implicit DTD. + * This Transformer transforms XML that describes a chart into an SVG + * representation. See Cocoon examples for implicit DTD. * - * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> + *@author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> + *@created 14 mei 2002 */ public class Chart2SvgTransformer extends AbstractConstrainedTransformer { - private String originalPrefix = "unknown"; - private boolean minSet = false; - private boolean maxSet = false; - private ChartModel2D cm = new ChartModel2D(); - private String type = ""; - private String title = ""; - private AbstractChart c; - private ColorList cl = new ColorList(); - private double min; - private double max; - private boolean LF3D = false; - private int width = 320; - private int height = 200; + private String originalPrefix = "unknown"; + private boolean minSet = false; + private boolean maxSet = false; + private ChartModel2D cm = new ChartModel2D(); + private String type = ""; + private String title = ""; + private AbstractChart c; + private ColorList cl = new ColorList(); + private double min; + private double max; + private boolean LF3D = false; + private int width = 320; + private int height = 200; + - public String getUri() { - return "http://apache.org/cocoon/chart2svg"; - } + public String getUri() { + return "http://apache.org/cocoon/Chart2Svg"; + } - public String getName() { - return "chart2svg"; - } - public void setup(SourceResolver resolver, Map map, String string, Parameters parameters) - { + public String getName() { + return "Chart2Svg"; + } - } - public void init(Parameters parameters) { + /* + * public void setup(SourceResolver resolver, Map map, String string, Parameters parameters) + * { + * } + */ + public void init(Parameters parameters) { - String[] chartdefStack = { "chartdef" }; + String[] chartdefStack = {"chartdef"}; - addEventListener(new ElementEventAdapter() { + addEventListener( + new ElementEventAdapter() { - public void containerElementEnded(ContainerElementEndEvent e) - throws SAXException { + public void containerElementEnded(ContainerElementEndEvent e) + throws SAXException { - if (minSet) { - cm.setMin(min); - } + if (minSet) { + cm.setMin(min); + } - if (maxSet) { - cm.setMax(max); - } + if (maxSet) { + cm.setMax(max); + } - if (type.trim().equals("bar")) { - c = new BarChart(cm); + if (type.trim().equals("bar")) { + c = new BarChart(cm); - ((BarChart) c).set3DLF(LF3D); - } - else if (type.trim().equals("pie")) { - c = new PieChart(cm); - } - else { - c = new LineChart(cm); - } + ((BarChart) c).set3DLF(LF3D); + } else if (type.trim().equals("pie")) { + c = new PieChart(cm); + } else { + c = new LineChart(cm); + } - c.setTitle(title); - c.setColorList(cl); - c.setSize(width, height); + c.setTitle(title); + c.setColorList(cl); + c.setSize(width, height); - SVGGraphics svg = new SVGGraphics(Chart2SvgTransformer.super.contentHandler, width, - height); - svg.startEvents(); - c.paint(svg); - svg.stopEvents(); + //FIXME (tomK): had to set anti-aliasing to false, because it gave a ClassCastException. + // Probably a bug in krysalis + c.setAntialiasing(false); + SVGGraphics svg = new SVGGraphics(Chart2SvgTransformer.super.contentHandler, width, + height); + svg.startEvents(); + c.paint(svg); + svg.stopEvents(); - } - }, new XmlTreeConstraint(chartdefStack, true)); + } + }, new XmlTreeConstraint(chartdefStack, true)); - String[] typeStack = { "type" }; + String[] typeStack = {"type"}; - addEventListener(new ElementEventAdapter() { + addEventListener( + new ElementEventAdapter() { - public void elementValueRecieved(ElementValueEvent e) { - type = e.getElementValue(); - } - }, new XmlTreeConstraint(typeStack, true)); + public void elementValueRecieved(ElementValueEvent e) { + type = e.getElementValue(); + } + }, new XmlTreeConstraint(typeStack, true)); - String[] titleStack = { "title" }; + String[] titleStack = {"title"}; - addEventListener(new ElementEventAdapter() { + addEventListener( + new ElementEventAdapter() { - public void elementValueRecieved(ElementValueEvent e) { - title = e.getElementValue(); - } - }, new XmlTreeConstraint(titleStack, true)); + public void elementValueRecieved(ElementValueEvent e) { + title = e.getElementValue(); + } + }, new XmlTreeConstraint(titleStack, true)); - String[] LF3dStack = { "LF3d" }; + String[] LF3dStack = {"LF3d"}; - addEventListener(new ElementEventAdapter() { + addEventListener( + new ElementEventAdapter() { - public void elementValueRecieved(ElementValueEvent e) { - LF3D = true; - } - }, new XmlTreeConstraint(LF3dStack, true)); + public void elementValueRecieved(ElementValueEvent e) { + LF3D = true; + } + }, new XmlTreeConstraint(LF3dStack, true)); - String[] colorStack = { "color" }; + String[] colorStack = {"color"}; - addEventListener(new ElementEventAdapter() { + addEventListener( + new ElementEventAdapter() { - public void elementValueRecieved(ElementValueEvent e) { - cl.add(Color.decode(e.getElementValue())); - } - }, new XmlTreeConstraint(colorStack, true)); + public void elementValueRecieved(ElementValueEvent e) { + cl.add(Color.decode(e.getElementValue())); + } + }, new XmlTreeConstraint(colorStack, true)); - String[] widthStack = { "width" }; + String[] widthStack = {"width"}; - addEventListener(new ElementEventAdapter() { + addEventListener( + new ElementEventAdapter() { - public void elementValueRecieved(ElementValueEvent e) { - width = Integer.parseInt(e.getElementValue()); - try - { - Chart2SvgTransformer.this.start("prova"); - Chart2SvgTransformer.this.end("prova"); - Chart2SvgTransformer.this.data("prova data"); - } - catch(Exception exx) - { - System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAA"); - } - } - }, new XmlTreeConstraint(widthStack, true)); + public void elementValueRecieved(ElementValueEvent e) { + width = Integer.parseInt(e.getElementValue()); + try { + /* + * FIXME: Is this used for anything?? Then it should come back ... + * Chart2SvgTransformer.this.start("prova"); + * Chart2SvgTransformer.this.end("prova"); + * Chart2SvgTransformer.this.data("prova data"); + */ + } catch (Exception exx) { + System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAA"); + } + } + }, new XmlTreeConstraint(widthStack, true)); - String[] heightStack = { "height" }; + String[] heightStack = {"height"}; - addEventListener(new ElementEventAdapter() { + addEventListener( + new ElementEventAdapter() { - public void elementValueRecieved(ElementValueEvent e) { - height = Integer.parseInt(e.getElementValue()); - } - }, new XmlTreeConstraint(heightStack, true)); + public void elementValueRecieved(ElementValueEvent e) { + height = Integer.parseInt(e.getElementValue()); + } + }, new XmlTreeConstraint(heightStack, true)); - String[] minStack = { "min" }; + String[] minStack = {"min"}; - addEventListener(new ElementEventAdapter() { + addEventListener( + new ElementEventAdapter() { - public void elementValueRecieved(ElementValueEvent e) { - min = Double.parseDouble(e.getElementValue().trim()); - minSet = true; - } - }, new XmlTreeConstraint(minStack, true)); + public void elementValueRecieved(ElementValueEvent e) { + min = Double.parseDouble(e.getElementValue().trim()); + minSet = true; + } + }, new XmlTreeConstraint(minStack, true)); - String[] maxStack = { "max" }; + String[] maxStack = {"max"}; - addEventListener(new ElementEventAdapter() { + addEventListener( + new ElementEventAdapter() { - public void elementValueRecieved(ElementValueEvent e) { - max = Double.parseDouble(e.getElementValue().trim()); - maxSet = true; - } - }, new XmlTreeConstraint(maxStack, true)); + public void elementValueRecieved(ElementValueEvent e) { + max = Double.parseDouble(e.getElementValue().trim()); + maxSet = true; + } + }, new XmlTreeConstraint(maxStack, true)); - String[] dataStack = { "data" }; + String[] dataStack = {"data"}; - addEventListener(new DataListener(), - new XmlTreeConstraint(dataStack, - false)); - addEventListener(new RipperListener(), - new XmlTreeConstraint(dataStack, - true)); + addEventListener(new DataListener(), + new XmlTreeConstraint(dataStack, + false)); + addEventListener(new RipperListener(), + new XmlTreeConstraint(dataStack, + true)); - String[] appearanceStack = { "appearance" }; + String[] appearanceStack = {"appearance"}; - addEventListener( - new RipperListener(), - new XmlTreeConstraint(appearanceStack, true)); + addEventListener( + new RipperListener(), + new XmlTreeConstraint(appearanceStack, true)); - String[] propertiesStack = { "properties" }; + String[] propertiesStack = {"properties"}; - addEventListener( - new RipperListener(), - new XmlTreeConstraint(propertiesStack, true)); + addEventListener( + new RipperListener(), + new XmlTreeConstraint(propertiesStack, true)); - String[] colorsStack = { "colors" }; + String[] colorsStack = {"colors"}; - addEventListener(new RipperListener(), - new XmlTreeConstraint(colorsStack, - true)); + addEventListener(new RipperListener(), + new XmlTreeConstraint(colorsStack, + true)); - } + } - class DataListener extends ElementEventAdapter { + class DataListener extends ElementEventAdapter { - public void elementValueRecieved(ElementValueEvent e) - throws SAXException { - cm.addToRow(e.getElementName(), - Double.parseDouble(e.getElementValue())); - } - } + public void elementValueRecieved(ElementValueEvent e) + throws SAXException { + cm.addToRow(e.getElementName(), + Double.parseDouble(e.getElementValue())); + } + } } + 1.2 +23 -23 xml-cocoon2/src/scratchpad/webapp/mount/charts/content/static/linechart.xml Index: linechart.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/webapp/mount/charts/content/static/linechart.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- linechart.xml 8 Apr 2002 08:09:16 -0000 1.1 +++ linechart.xml 14 May 2002 20:34:22 -0000 1.2 @@ -1,5 +1,5 @@ <?xml version="1.0"?> -<chart:chartdef xmlns:chart="http://apache.org/cocoon/Chart2Svg"> +<chart:chartdef xmlns:chart="http://apache.org/cocoon/chart2svg"> <chart:appearance> <chart:type>line</chart:type> <chart:title>Cocoon 1 vs Cocoon 2 :)</chart:title> @@ -15,28 +15,28 @@ <chart:max>7</chart:max> </chart:properties> <chart:data> - <result> - <row> - <cocoon1>1</cocoon1> - <cocoon2>3</cocoon2> - <cocoon3>5</cocoon3> - </row> - <row> - <cocoon1>2</cocoon1> - <cocoon2>6</cocoon2> - <cocoon3>3</cocoon3> - </row> - <row> - <cocoon1>2</cocoon1> - <cocoon2>6</cocoon2> - <cocoon3>5</cocoon3> - </row> - <row> - <cocoon1>2</cocoon1> - <cocoon2>6</cocoon2> - <cocoon3>3</cocoon3> - </row> - </result> + <chart:result> + <chart:row> + <chart:cocoon1>1</chart:cocoon1> + <chart:cocoon2>3</chart:cocoon2> + <chart:cocoon3>5</chart:cocoon3> + </chart:row> + <chart:row> + <chart:cocoon1>2</chart:cocoon1> + <chart:cocoon2>6</chart:cocoon2> + <chart:cocoon3>3</chart:cocoon3> + </chart:row> + <chart:row> + <chart:cocoon1>2</chart:cocoon1> + <chart:cocoon2>6</chart:cocoon2> + <chart:cocoon3>5</chart:cocoon3> + </chart:row> + <chart:row> + <chart:cocoon1>2</chart:cocoon1> + <chart:cocoon2>6</chart:cocoon2> + <chart:cocoon3>3</chart:cocoon3> + </chart:row> + </chart:result> </chart:data> </chart:chartdef> 1.2 +2 -2 xml-cocoon2/src/scratchpad/webapp/mount/charts/content/samples.xml Index: samples.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/webapp/mount/charts/content/samples.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- samples.xml 8 Apr 2002 08:09:17 -0000 1.1 +++ samples.xml 14 May 2002 20:34:22 -0000 1.2 @@ -16,7 +16,7 @@ <sample name="Bar Chart 3d style" href="bar3Dchart.svg"> This sample doesn't yet work. Still needs debugging and fixing. It used to work with an early version of Cocoon2 and currently it hasen't been completely adapted. Patches are welcome :-) </sample> - <sample name="Line Chart" href="line.svg"> + <sample name="Line Chart" href="linechart.svg"> This sample doesn't yet work. Still needs debugging and fixing. It used to work with an early version of Cocoon2 and currently it hasen't been completely adapted. Patches are welcome :-) </sample> </group> @@ -28,7 +28,7 @@ <sample name="Bar Chart 3d style" href="bar3Dchart.xml"> This sample doesn't yet work. Still needs debugging and fixing. It used to work with an early version of Cocoon2 and currently it hasen't been completely adapted. Patches are welcome :-) </sample> - <sample name="Line Chart" href="line.xml"> + <sample name="Line Chart" href="linechart.xml"> This sample doesn't yet work. Still needs debugging and fixing. It used to work with an early version of Cocoon2 and currently it hasen't been completely adapted. Patches are welcome :-) </sample> </group> 1.2 +8 -1 xml-cocoon2/src/scratchpad/webapp/mount/charts/sitemap.xmap Index: sitemap.xmap =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/webapp/mount/charts/sitemap.xmap,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- sitemap.xmap 8 Apr 2002 08:09:17 -0000 1.1 +++ sitemap.xmap 14 May 2002 20:34:23 -0000 1.2 @@ -6,7 +6,7 @@ <map:generators default="file"/> <map:transformers default="xslt"> - <map:transformer name="chart2svg" src="org.apache.cocoon.transformation.Chart2SvgTransformer"/> + <map:transformer label="transformed" name="chart2svg" src="org.apache.cocoon.transformation.Chart2SvgTransformer"/> </map:transformers> <map:readers default="resource"/> @@ -22,6 +22,13 @@ <map:matchers default="wildcard"/> <map:selectors default="browser"/> + + <map:views> + <map:view name="transformed" from-label="transformed"> + <map:serialize type="xml"/> + </map:view> + </map:views> + </map:components>
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]