use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.
the class FnReplace method expected_args.
/**
* Obtain a list of expected arguments.
*
* @return Result of operation.
*/
public static synchronized Collection expected_args() {
if (_expected_args == null) {
_expected_args = new ArrayList();
SeqType arg = new SeqType(new XSString(), SeqType.OCC_QMARK);
_expected_args.add(arg);
_expected_args.add(new SeqType(new XSString(), SeqType.OCC_NONE));
_expected_args.add(new SeqType(new XSString(), SeqType.OCC_NONE));
_expected_args.add(new SeqType(new XSString(), SeqType.OCC_NONE));
}
return _expected_args;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.
the class FnReplace method replace.
/**
* Replace operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:replace operation.
*/
public static ResultSequence replace(Collection args) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
// 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();
ResultSequence arg3 = (ResultSequence) argiter.next();
ResultSequence arg4 = null;
if (argiter.hasNext()) {
arg4 = (ResultSequence) argiter.next();
String flags = arg4.first().getStringValue();
if (flags.length() == 0) {
arg4 = null;
} else if (isFlagValid(flags) == false) {
throw new DynamicError("FORX0001", "Invalid regular expression. flags");
}
}
String pattern = ((XSString) arg2.first()).value();
String replacement = ((XSString) arg3.first()).value();
try {
return new XSString(str1.replaceAll(pattern, replacement));
} catch (PatternSyntaxException err) {
throw DynamicError.regex_error(null);
} catch (IllegalArgumentException ex) {
throw new DynamicError("FORX0004", "invalid regex.");
} catch (IndexOutOfBoundsException ex) {
String className = ex.getClass().getName();
if (className.endsWith("StringIndexOutOfBoundsException")) {
throw new DynamicError("FORX0004", "result out of bounds");
}
throw new DynamicError("FORX0003", "invalid regex.");
} catch (Exception ex) {
throw new DynamicError("FORX0004", "invalid regex.");
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.
the class FnIDREF method expected_args.
/**
* Obtain a list of expected arguments.
*
* @return Result of operation.
*/
public static synchronized Collection expected_args() {
if (_expected_args == null) {
_expected_args = new ArrayList();
SeqType arg = new SeqType(new XSString(), SeqType.OCC_STAR);
_expected_args.add(arg);
_expected_args.add(new SeqType(SeqType.OCC_NONE));
}
return _expected_args;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.
the class FnInScopePrefixes method createPrefixResultSet.
private static void createPrefixResultSet(ResultBuffer rs, List prefixList) {
for (int i = 0; i < prefixList.size(); i++) {
String prefix = (String) prefixList.get(i);
rs.add(new XSString(prefix));
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.
the class FnLocalName method local_name.
/**
* Local-Name operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:local-name operation.
*/
public static ResultSequence local_name(Collection args, EvaluationContext context) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
// get arg
ResultSequence arg1 = null;
if (cargs.isEmpty()) {
if (context.getContextItem() == null)
throw DynamicError.contextUndefined();
else {
arg1 = (AnyType) context.getContextItem();
}
} else {
arg1 = (ResultSequence) cargs.iterator().next();
}
if (arg1.empty()) {
return new XSString("");
}
NodeType an = (NodeType) arg1.first();
QName name = an.node_name();
String sname = "";
if (name != null)
sname = name.local();
return new XSString(sname);
}
Aggregations