Search in sources :

Example 91 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class XMLAttributes method get.

@Override
public Object get(Collection.Key key) throws ExpressionException {
    Node rtn = nodeMap.getNamedItem(key.getString());
    if (rtn != null)
        return rtn.getNodeValue();
    Collection.Key[] keys = keys();
    for (int i = 0; i < keys.length; i++) {
        if (key.equalsIgnoreCase(keys[i]))
            return nodeMap.getNamedItem(keys[i].getString()).getNodeValue();
    }
    throw new ExpressionException("No Attribute " + key.getString() + " defined for tag", "attributes are [" + ListUtil.arrayToList(keys, ", ") + "]");
}
Also used : Node(org.w3c.dom.Node) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 92 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class XMLCaster method toTextArray.

/**
 * casts a value to a XML Text Array
 * @param doc XML Document
 * @param o Object to cast
 * @return XML Text Array
 * @throws PageException
 */
public static Text[] toTextArray(Document doc, Object o) throws PageException {
    // Node[]
    if (o instanceof Node[]) {
        Node[] nodes = (Node[]) o;
        if (_isAllOfSameType(nodes, Node.TEXT_NODE))
            return (Text[]) nodes;
        Text[] textes = new Text[nodes.length];
        for (int i = 0; i < nodes.length; i++) {
            textes[i] = toText(doc, nodes[i]);
        }
        return textes;
    } else // Collection
    if (o instanceof Collection) {
        Collection coll = (Collection) o;
        Iterator<Object> it = coll.valueIterator();
        List<Text> textes = new ArrayList<Text>();
        while (it.hasNext()) {
            textes.add(toText(doc, it.next()));
        }
        return textes.toArray(new Text[textes.size()]);
    }
    // Node Map and List
    Node[] nodes = _toNodeArray(doc, o);
    if (nodes != null)
        return toTextArray(doc, nodes);
    // Single Text Node
    try {
        return new Text[] { toText(doc, o) };
    } catch (ExpressionException e) {
        throw new XMLException("can't cast Object of type " + Caster.toClassName(o) + " to a XML Text Array");
    }
}
Also used : XMLException(lucee.runtime.exp.XMLException) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) Collection(lucee.runtime.type.Collection) Text(org.w3c.dom.Text) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 93 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class XMLCaster method toElementArray.

/**
 * casts a value to a XML Element Array
 * @param doc XML Document
 * @param o Object to cast
 * @return XML Comment Array
 * @throws PageException
 */
public static Element[] toElementArray(Document doc, Object o) throws PageException {
    // Node[]
    if (o instanceof Node[]) {
        Node[] nodes = (Node[]) o;
        if (_isAllOfSameType(nodes, Node.ELEMENT_NODE))
            return (Element[]) nodes;
        Element[] elements = new Element[nodes.length];
        for (int i = 0; i < nodes.length; i++) {
            elements[i] = toElement(doc, nodes[i]);
        }
        return elements;
    } else // Collection
    if (o instanceof Collection) {
        Collection coll = (Collection) o;
        Iterator<Object> it = coll.valueIterator();
        List<Element> elements = new ArrayList<Element>();
        while (it.hasNext()) {
            elements.add(toElement(doc, it.next()));
        }
        return elements.toArray(new Element[elements.size()]);
    }
    // Node Map and List
    Node[] nodes = _toNodeArray(doc, o);
    if (nodes != null)
        return toElementArray(doc, nodes);
    // Single Text Node
    try {
        return new Element[] { toElement(doc, o) };
    } catch (ExpressionException e) {
        throw new XMLException("can't cast Object of type " + Caster.toClassName(o) + " to a XML Element Array");
    }
}
Also used : XMLException(lucee.runtime.exp.XMLException) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Iterator(java.util.Iterator) Collection(lucee.runtime.type.Collection) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 94 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class QueryImpl method rename.

public synchronized void rename(Collection.Key columnName, Collection.Key newColumnName) throws ExpressionException {
    int index = getIndexFromKey(columnName);
    if (index == -1)
        throw new ExpressionException("invalid column name definitions");
    columnNames[index] = newColumnName;
    columns[index].setKey(newColumnName);
}
Also used : ExpressionException(lucee.runtime.exp.ExpressionException)

Example 95 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class UDFAddProperty method callWithNamedValues.

@Override
public Object callWithNamedValues(PageContext pageContext, Struct values, boolean doIncludePath) throws PageException {
    UDFUtil.argumentCollection(values, getFunctionArguments());
    // struct
    if (this.arguments.length == 2) {
        Key keyName = arguments[0].getName();
        Key valueName = arguments[1].getName();
        Object key = values.get(keyName, null);
        Object value = values.get(valueName, null);
        if (key == null)
            throw new ExpressionException("The parameter " + keyName + " to function " + getFunctionName() + " is required but was not passed in.");
        if (value == null)
            throw new ExpressionException("The parameter " + valueName + " to function " + getFunctionName() + " is required but was not passed in.");
        return _call(pageContext, key, value);
    } else // array
    if (this.arguments.length == 1) {
        Key valueName = arguments[0].getName();
        Object value = values.get(valueName, null);
        if (value == null) {
            Key[] keys = CollectionUtil.keys(values);
            if (keys.length == 1) {
                value = values.get(keys[0]);
            } else
                throw new ExpressionException("The parameter " + valueName + " to function " + getFunctionName() + " is required but was not passed in.");
        }
        return _call(pageContext, null, value);
    }
    // never reached
    return component;
}
Also used : Key(lucee.runtime.type.Collection.Key) ExpressionException(lucee.runtime.exp.ExpressionException)

Aggregations

ExpressionException (lucee.runtime.exp.ExpressionException)136 Element (org.w3c.dom.Element)24 Key (lucee.runtime.type.Collection.Key)15 SecurityException (lucee.runtime.exp.SecurityException)13 ArrayList (java.util.ArrayList)12 Struct (lucee.runtime.type.Struct)12 List (java.util.List)11 Collection (lucee.runtime.type.Collection)11 Entry (java.util.Map.Entry)10 Node (org.w3c.dom.Node)10 Resource (lucee.commons.io.res.Resource)9 Iterator (java.util.Iterator)8 PageException (lucee.runtime.exp.PageException)8 Map (java.util.Map)7 CasterException (lucee.runtime.exp.CasterException)7 NodeList (org.w3c.dom.NodeList)7 PageContextImpl (lucee.runtime.PageContextImpl)6 PageSource (lucee.runtime.PageSource)5 Casting (lucee.runtime.interpreter.ref.cast.Casting)5 ArrayImpl (lucee.runtime.type.ArrayImpl)5