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, ", ") + "]");
}
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");
}
}
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");
}
}
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);
}
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;
}
Aggregations