use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.
the class FnTranslate method expected_args.
/**
* Calculate the expected arguments.
*
* @return The expected arguments.
*/
public static synchronized Collection expected_args() {
if (_expected_args == null) {
_expected_args = new ArrayList();
_expected_args.add(new SeqType(new XSString(), SeqType.OCC_QMARK));
_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 FnTranslate method translate.
/**
* Translate arguments.
*
* @param args
* are translated.
* @throws DynamicError
* Dynamic error.
* @return The result of translating the arguments.
*/
public static ResultSequence translate(Collection args) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
Iterator argi = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argi.next();
ResultSequence arg2 = (ResultSequence) argi.next();
ResultSequence arg3 = (ResultSequence) argi.next();
if (arg1.empty()) {
return new XSString("");
}
String str = ((XSString) arg1.first()).value();
String mapstr = ((XSString) arg2.first()).value();
String transstr = ((XSString) arg3.first()).value();
Map replacements = buildReplacementMap(mapstr, transstr);
StringBuffer sb = new StringBuffer(str.length());
CodePointIterator strIter = new StringCodePointIterator(str);
for (int input = strIter.current(); input != CodePointIterator.DONE; input = strIter.next()) {
Integer inputCodepoint = new Integer(input);
if (replacements.containsKey(inputCodepoint)) {
Integer replaceWith = (Integer) replacements.get(inputCodepoint);
if (replaceWith != null) {
sb.append(UCharacter.toChars(replaceWith.intValue()));
}
} else {
sb.append(UCharacter.toChars(input));
}
}
return new XSString(sb.toString());
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.
the class FnNormalizeUnicode method normalize_unicode.
/**
* Normalize unicode codepoints in the argument.
*
* @param args
* are used to obtain the input string and optionally the normalization type from.
* @throws DynamicError
* Dynamic error.
* @return The result of normalizing the space in the arguments.
*/
public static ResultSequence normalize_unicode(Collection args, DynamicContext d_context) throws DynamicError {
assert args.size() >= 1 && args.size() <= 2;
Collection cargs = Function.convert_arguments(args, expected_args());
Iterator cargsIterator = cargs.iterator();
ResultSequence arg1 = (ResultSequence) cargsIterator.next();
String normalizationType = "NFC";
if (cargsIterator.hasNext()) {
ResultSequence arg2 = (ResultSequence) cargsIterator.next();
// Trim and convert to upper as per the spec
if (arg2.empty()) {
normalizationType = "";
} else {
normalizationType = ((XSString) arg2.first()).value().trim().toUpperCase();
}
}
String argument = "";
if (!arg1.empty())
argument = ((XSString) arg1.first()).value();
String normalized = normalizationType.equals("") ? argument : getNormalizer().normalize(argument, normalizationType);
return new XSString(normalized);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.
the class FnQName 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));
}
return _expected_args;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.
the class FnQName method resolve_QName.
/**
* Resolve the QName of the given arguments.
*
* @param args
* Result from teh expressions evaluation.
* @param sc
* Result of static context operation.
* @throws DynamicError
* Dynamic error.
* @return Result of the fn:QName operation.
*/
public static ResultSequence resolve_QName(Collection args, StaticContext sc) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
// get args
Iterator argiter = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argiter.next();
String ns = null;
if (!arg1.empty())
ns = ((XSString) arg1.first()).value();
ResultSequence arg2 = (ResultSequence) argiter.next();
String name = ((XSString) arg2.first()).value();
QName qn = QName.parse_QName(name);
if (qn == null)
throw DynamicError.lexical_error(null);
qn.set_namespace(ns);
return qn;
}
Aggregations