Search in sources :

Example 41 with XSString

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;
}
Also used : SeqType(org.eclipse.wst.xml.xpath2.processor.internal.SeqType) ArrayList(java.util.ArrayList) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 42 with XSString

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());
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) CodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.CodePointIterator) StringCodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.StringCodePointIterator) Iterator(java.util.Iterator) CodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.CodePointIterator) StringCodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.StringCodePointIterator) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) StringCodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.StringCodePointIterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 43 with XSString

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);
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 44 with XSString

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;
}
Also used : SeqType(org.eclipse.wst.xml.xpath2.processor.internal.SeqType) ArrayList(java.util.ArrayList) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 45 with XSString

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;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) Iterator(java.util.Iterator) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Aggregations

XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)73 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)37 ArrayList (java.util.ArrayList)32 Collection (java.util.Collection)32 Iterator (java.util.Iterator)29 SeqType (org.eclipse.wst.xml.xpath2.processor.internal.SeqType)29 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)9 Item (org.eclipse.wst.xml.xpath2.api.Item)7 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)7 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)6 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)6 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)5 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)5 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)5 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)5 XSDouble (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble)5 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)4 XSUntypedAtomic (org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic)4 URL (java.net.URL)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3