001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.xslt.mapper.view;
020:
021: import org.netbeans.modules.xml.xpath.XPathExpression;
022: import org.netbeans.modules.xslt.model.Attribute;
023: import org.netbeans.modules.xslt.model.CopyOf;
024: import org.netbeans.modules.xslt.model.Element;
025: import org.netbeans.modules.xslt.model.ForEach;
026: import org.netbeans.modules.xslt.model.If;
027: import org.netbeans.modules.xslt.model.LiteralResultElement;
028: import org.netbeans.modules.xslt.model.SequenceConstructor;
029: import org.netbeans.modules.xslt.model.ValueOf;
030: import org.netbeans.modules.xslt.model.When;
031: import org.netbeans.modules.xslt.model.XslComponent;
032: import org.netbeans.modules.xslt.model.XslComponentFactory;
033: import org.netbeans.modules.xslt.model.XslVisitorAdapter;
034:
035: /**
036: * Visitor to extract or update xpath expressions stored in different types of
037: * XSL elements
038: *
039: */
040: public class SetExpressionVisitor extends XslVisitorAdapter {
041:
042: private XPathExpression expression;
043:
044: public SetExpressionVisitor(XPathExpression expression) {
045: this .expression = expression;
046:
047: }
048:
049: public String getExpressionString() {
050: return (expression != null) ? expression.getExpressionString()
051: : "";
052: }
053:
054: public void visit(ValueOf vof) {
055: vof.setSelect(getExpressionString());
056: }
057:
058: public void visit(If iff) {
059: iff.setTest(getExpressionString());
060: }
061:
062: public void visit(CopyOf cof) {
063: cof.setSelect(getExpressionString());
064: }
065:
066: public void visit(Attribute attribute) {
067: handleElementOrAttribute(attribute);
068: }
069:
070: public void visit(Element element) {
071: handleElementOrAttribute(element);
072:
073: }
074:
075: public void visit(LiteralResultElement element) {
076: handleElementOrAttribute(element);
077: }
078:
079: private void handleElementOrAttribute(XslComponent component) {
080: ValueOf vof = GetExpressionVisitor
081: .isValueOfContainer(component);
082: if (vof == null) {
083: XslComponentFactory factory = component.getModel()
084: .getFactory();
085: vof = factory.createValueOf();
086: ((SequenceConstructor) component).appendSequenceChild(vof);
087:
088: }
089: vof.setSelect(getExpressionString());
090:
091: }
092:
093: public void visit(ForEach forEach) {
094: forEach.setSelect(getExpressionString());
095:
096: }
097:
098: public void visit(When when) {
099: when.setTest(getExpressionString());
100:
101: }
102:
103: }
|