use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class FnTokenize method tokenize.
/**
* Tokenize operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:tokenize operation.
*/
public static ResultSequence tokenize(Collection args) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
ResultBuffer rs = new ResultBuffer();
// get args
Iterator argiter = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argiter.next();
String str1 = "";
if (!arg1.empty()) {
str1 = ((XSString) arg1.first()).value();
}
ResultSequence arg2 = (ResultSequence) argiter.next();
String pattern = ((XSString) arg2.first()).value();
String flags = null;
if (argiter.hasNext()) {
ResultSequence flagRS = null;
flagRS = (ResultSequence) argiter.next();
flags = flagRS.first().getStringValue();
if (validflags.indexOf(flags) == -1 && flags.length() > 0) {
throw DynamicError.regex_flags_error(null);
}
}
try {
ArrayList ret = tokenize(pattern, flags, str1);
for (Iterator retIter = ret.iterator(); retIter.hasNext(); ) {
rs.add(new XSString((String) retIter.next()));
}
} catch (PatternSyntaxException err) {
throw DynamicError.regex_error(null);
}
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class OpExcept method op_except.
/**
* Op-Except operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of operation.
*/
public static ResultSequence op_except(Collection args) throws DynamicError {
ResultBuffer rs = new ResultBuffer();
// convert arguments
Collection cargs = Function.convert_arguments(args, expected_args());
// get arguments
Iterator iter = cargs.iterator();
ResultSequence one = (ResultSequence) iter.next();
ResultSequence two = (ResultSequence) iter.next();
// XXX lame
for (Iterator i = one.iterator(); i.hasNext(); ) {
NodeType node = (NodeType) i.next();
boolean found = false;
// death
for (Iterator j = two.iterator(); j.hasNext(); ) {
NodeType node2 = (NodeType) j.next();
if (node.node_value() == node2.node_value()) {
found = true;
break;
}
}
if (!found)
rs.add(node);
}
rs = NodeType.linarize(rs);
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class OpUnion method op_union.
/**
* Op-Union operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of operation.
*/
public static ResultSequence op_union(Collection args) throws DynamicError {
ResultBuffer rs = new ResultBuffer();
// convert arguments
Collection cargs = Function.convert_arguments(args, expected_args());
// get arguments
Iterator iter = cargs.iterator();
ResultSequence one = (ResultSequence) iter.next();
ResultSequence two = (ResultSequence) iter.next();
// XXX i don't fink u've ever seen anything lamer than this
rs.concat(one);
rs.concat(two);
rs = NodeType.linarize(rs);
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit element test.
*
* @param e
* is the element test.
* @return a result sequence
*/
public Object visit(ElementTest e) {
// filter out all elements
ResultSequence rs = kind_test((ResultSequence) ((Pair) _param)._two, ElementType.class);
// match the name if it's not a wild card
ResultBuffer rb = new ResultBuffer();
QName nameTest = e.name();
QName typeTest = e.type();
for (Iterator i = rs.iterator(); i.hasNext(); ) {
NodeType node = (NodeType) i.next();
if (nameTest != null && !e.wild()) {
// skip if there's a name test and the name does not match
if (!name_test((ElementType) node, nameTest, "element"))
continue;
}
if (typeTest != null) {
// check if element derives from
if (!derivesFrom(node, typeTest))
continue;
// nilled may be true or false
if (!e.qmark()) {
XSBoolean nilled = (XSBoolean) node.nilled().first();
if (nilled.value())
continue;
}
}
rb.add(node);
}
((Pair) _param)._two = rb.getSequence();
return ((Pair) _param)._two;
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit decimal literal.
*
* @param e
* is the decimal literal.
* @return a result sequence
*/
public Object visit(DecimalLiteral e) {
ResultBuffer rs = new ResultBuffer();
rs.add(e.value());
return rs.getSequence();
}
Aggregations