Xupdate - comment

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Xupdate - comment

Oliver Charlet
Hi there,

I', done with the Rename tag, but I am stuck with the comment tag. I see
it in connection with the Attribute tag, which should work very similar.
But in the Attribute statement code I don't see the part, that actually
does the manipulation. Can somebody give me a hint about how that tag works?
Rename tag is attached.
:olli

--
-----------------------
oliver charlet
software development

11-041 Olsztyn, Poland

[hidden email]
-----------------------


/**
 *  Copyright (C) 2004 Orbeon, Inc.
 *
 *  This program is free software; you can redistribute it and/or modify it under the terms of the
 *  GNU Lesser General Public License as published by the Free Software Foundation; either version
 *  2.1 of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU Lesser General Public License for more details.
 *
 *  The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
 */
package org.orbeon.oxf.transformer.xupdate.statement;

import java.util.Collections;
import java.util.Iterator;

import javax.xml.transform.URIResolver;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Node;
import org.jaxen.NamespaceContext;
import org.orbeon.oxf.common.ValidationException;
import org.orbeon.oxf.transformer.xupdate.DocumentContext;
import org.orbeon.oxf.transformer.xupdate.Statement;
import org.orbeon.oxf.transformer.xupdate.VariableContextImpl;
import org.orbeon.oxf.xml.dom4j.Dom4jUtils;
import org.orbeon.oxf.xml.dom4j.LocationData;

/**
 * Implements the xupdate "rename" command.
 *
 * @author oliver charlet - [hidden email]
 *
 */
public class Rename extends Statement {
    private String select;
    private NamespaceContext namespaceContext;
    private Statement[] statements;

    public Rename(LocationData locationData, String select, NamespaceContext namespaceContext, Statement[] statements) {
        super(locationData);
        this.select = select;
        this.namespaceContext = namespaceContext;
        this.statements = statements;
    }

    public Object execute(URIResolver uriResolver, Object context, VariableContextImpl variableContext, DocumentContext documentContext) {
        for (Iterator i = Utils.evaluateToList(uriResolver, context, variableContext, getLocationData(), select, namespaceContext, documentContext).iterator(); i.hasNext();) {
            Object node = i.next();
            Object toInsert = Utils.execute(uriResolver, node, variableContext, documentContext, statements);
            if (!(toInsert instanceof String)) {
                throw new ValidationException("the content of the rename tag must be text (#PCDATA)", getLocationData());
            }
            if (node instanceof Element) {
            ((Element)node).setName(toInsert.toString());
            } else if (node instanceof Document) {
                throw new ValidationException("A document node cannot be renamed", getLocationData());
            } else if (node instanceof Attribute) {
            ((Attribute)node).setName(toInsert.toString());
            } else if (node instanceof org.dom4j.Text) {
                throw new ValidationException("A text node cannot be renamed", getLocationData());
            } else {
                throw new ValidationException("Cannot rename a " + node.getClass().getName(), getLocationData());
            }
        }
        return Collections.EMPTY_LIST;
    }
}


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Xupdate - comment

Alessandro  Vernet
Administrator
Olivier,

The goal of the comment statement is to create an XML comment, right?
At this point, the pipeline API is based solely the SAX ContentHandler
which does not support comments. To support comments, we would need to
extend the API to use the SAX LexicalHandler in addition to the
ContentHandler. So for now, you can just implement the XUpdate comment
statement as no-op that ignores its content, which should be simple
enough :).

Alex

On 11/29/05, Oliver Charlet <[hidden email]> wrote:

> Hi there,
>
> I', done with the Rename tag, but I am stuck with the comment tag. I see
> it in connection with the Attribute tag, which should work very similar.
> But in the Attribute statement code I don't see the part, that actually
> does the manipulation. Can somebody give me a hint about how that tag works?
> Rename tag is attached.
> :olli
>
> --
> -----------------------
> oliver charlet
> software development
>
> 11-041 Olsztyn, Poland
>
> [hidden email]
> -----------------------
>
>
>
> /**
>  *  Copyright (C) 2004 Orbeon, Inc.
>  *
>  *  This program is free software; you can redistribute it and/or modify it under the terms of the
>  *  GNU Lesser General Public License as published by the Free Software Foundation; either version
>  *  2.1 of the License, or (at your option) any later version.
>  *
>  *  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
>  *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>  *  See the GNU Lesser General Public License for more details.
>  *
>  *  The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
>  */
> package org.orbeon.oxf.transformer.xupdate.statement;
>
> import java.util.Collections;
> import java.util.Iterator;
>
> import javax.xml.transform.URIResolver;
>
> import org.dom4j.Attribute;
> import org.dom4j.Document;
> import org.dom4j.Element;
> import org.dom4j.Node;
> import org.jaxen.NamespaceContext;
> import org.orbeon.oxf.common.ValidationException;
> import org.orbeon.oxf.transformer.xupdate.DocumentContext;
> import org.orbeon.oxf.transformer.xupdate.Statement;
> import org.orbeon.oxf.transformer.xupdate.VariableContextImpl;
> import org.orbeon.oxf.xml.dom4j.Dom4jUtils;
> import org.orbeon.oxf.xml.dom4j.LocationData;
>
> /**
>  * Implements the xupdate "rename" command.
>  *
>  * @author oliver charlet - [hidden email]
>  *
>  */
> public class Rename extends Statement {
>     private String select;
>     private NamespaceContext namespaceContext;
>     private Statement[] statements;
>
>     public Rename(LocationData locationData, String select, NamespaceContext namespaceContext, Statement[] statements) {
>         super(locationData);
>         this.select = select;
>         this.namespaceContext = namespaceContext;
>         this.statements = statements;
>     }
>
>     public Object execute(URIResolver uriResolver, Object context, VariableContextImpl variableContext, DocumentContext documentContext) {
>         for (Iterator i = Utils.evaluateToList(uriResolver, context, variableContext, getLocationData(), select, namespaceContext, documentContext).iterator(); i.hasNext();) {
>             Object node = i.next();
>             Object toInsert = Utils.execute(uriResolver, node, variableContext, documentContext, statements);
>             if (!(toInsert instanceof String)) {
>                 throw new ValidationException("the content of the rename tag must be text (#PCDATA)", getLocationData());
>             }
>             if (node instanceof Element) {
>                         ((Element)node).setName(toInsert.toString());
>             } else if (node instanceof Document) {
>                 throw new ValidationException("A document node cannot be renamed", getLocationData());
>             } else if (node instanceof Attribute) {
>                         ((Attribute)node).setName(toInsert.toString());
>             } else if (node instanceof org.dom4j.Text) {
>                 throw new ValidationException("A text node cannot be renamed", getLocationData());
>             } else {
>                 throw new ValidationException("Cannot rename a " + node.getClass().getName(), getLocationData());
>             }
>         }
>         return Collections.EMPTY_LIST;
>     }
> }
>
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
>
>
>

--
Blog (XML, Web apps, Open Source): http://www.orbeon.com/blog/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet