use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class XMLAttributes method remove.
@Override
public Object remove(Collection.Key k) throws PageException {
String key = k.getString();
Node rtn = null;
if (!caseSensitive) {
int len = nodeMap.getLength();
String nn;
for (int i = len - 1; i >= 0; i--) {
nn = nodeMap.item(i).getNodeName();
if (key.equalsIgnoreCase(nn))
rtn = nodeMap.removeNamedItem(nn);
}
} else
rtn = nodeMap.removeNamedItem(toName(key));
if (rtn != null)
return rtn.getNodeValue();
throw new ExpressionException("can't remove element with name [" + key + "], element doesn't exist");
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class XMLCaster method toCommentArray.
/**
* casts a value to a XML Comment Array
* @param doc XML Document
* @param o Object to cast
* @return XML Comment Array
* @throws PageException
*/
public static Comment[] toCommentArray(Document doc, Object o) throws PageException {
// Node[]
if (o instanceof Node[]) {
Node[] nodes = (Node[]) o;
if (_isAllOfSameType(nodes, Node.COMMENT_NODE))
return (Comment[]) nodes;
Comment[] comments = new Comment[nodes.length];
for (int i = 0; i < nodes.length; i++) {
comments[i] = toComment(doc, nodes[i]);
}
return comments;
} else // Collection
if (o instanceof Collection) {
Collection coll = (Collection) o;
Iterator<Object> it = coll.valueIterator();
List<Comment> comments = new ArrayList<Comment>();
while (it.hasNext()) {
comments.add(toComment(doc, it.next()));
}
return comments.toArray(new Comment[comments.size()]);
}
// Node Map and List
Node[] nodes = _toNodeArray(doc, o);
if (nodes != null)
return toCommentArray(doc, nodes);
// Single Text Node
try {
return new Comment[] { toComment(doc, o) };
} catch (ExpressionException e) {
throw new XMLException("can't cast Object of type " + Caster.toClassName(o) + " to a XML Comment Array");
}
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class XMLCaster method toAttrArray.
/**
* casts a value to a XML Attr Array
* @param doc XML Document
* @param o Object to cast
* @return XML Attr Array
* @throws PageException
*/
public static Attr[] toAttrArray(Document doc, Object o) throws PageException {
// Node[]
if (o instanceof Node[]) {
Node[] nodes = (Node[]) o;
if (_isAllOfSameType(nodes, Node.ATTRIBUTE_NODE))
return (Attr[]) nodes;
Attr[] attres = new Attr[nodes.length];
for (int i = 0; i < nodes.length; i++) {
attres[i] = toAttr(doc, nodes[i]);
}
return attres;
} else // Collection
if (o instanceof Collection) {
Collection coll = (Collection) o;
Iterator<Entry<Key, Object>> it = coll.entryIterator();
Entry<Key, Object> e;
List<Attr> attres = new ArrayList<Attr>();
Attr attr;
Collection.Key k;
while (it.hasNext()) {
e = it.next();
k = e.getKey();
attr = doc.createAttribute(Decision.isNumber(k.getString()) ? "attribute-" + k.getString() : k.getString());
attr.setValue(Caster.toString(e.getValue()));
attres.add(attr);
}
return attres.toArray(new Attr[attres.size()]);
}
// Node Map and List
Node[] nodes = _toNodeArray(doc, o);
if (nodes != null)
return toAttrArray(doc, nodes);
// Single Text Node
try {
return new Attr[] { toAttr(doc, o) };
} catch (ExpressionException e) {
throw new XMLException("can't cast Object of type " + Caster.toClassName(o) + " to a XML Attributes Array");
}
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class XMLNodeList method insert.
@Override
public boolean insert(int index, Object value) throws PageException {
// check min Index
if (index < 1)
throw new ExpressionException("invalid index [" + index + "] to insert a child node, valid indexes start at 1");
Node[] nodes = getChildNodesAsArray();
// if index Greater len append
if (index > nodes.length) {
append(value);
return true;
}
// remove all children
clear();
// set all children before new Element
for (int i = 1; i < index; i++) {
append(nodes[i - 1]);
}
// set new Element
append(XMLCaster.toNode(doc, value, true));
// set all after new Element
for (int i = index; i <= nodes.length; i++) {
append(nodes[i - 1]);
}
return true;
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class XMLNodeList method setE.
@Override
public Object setE(int index, Object value) throws PageException {
// check min Index
if (index < 1)
throw new ExpressionException("invalid index [" + index + "] to set a child node, valid indexes start at 1");
Node[] nodes = getChildNodesAsArray();
// if index Greater len append
if (index > nodes.length)
return append(value);
// remove all children
clear();
// set all children before new Element
for (int i = 1; i < index; i++) {
append(nodes[i - 1]);
}
// set new Element
append(XMLCaster.toNode(doc, value, true));
// set all after new Element
for (int i = index; i < nodes.length; i++) {
append(nodes[i]);
}
return value;
}
Aggregations