Search in sources :

Example 46 with XSString

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;
}
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 47 with XSString

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.");
    }
}
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) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) PatternSyntaxException(java.util.regex.PatternSyntaxException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 48 with XSString

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;
}
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 49 with XSString

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

Example 50 with XSString

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