Search in sources :

Example 66 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.

the class FnCollection method collection.

/**
 * Doc operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param dc
 *            Result of dynamic context operation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:doc operation.
 */
public static ResultSequence collection(Collection args, EvaluationContext ec) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get args
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = null;
    String uri = DEFAULT_COLLECTION_URI;
    if (argiter.hasNext()) {
        arg1 = (ResultSequence) argiter.next();
        uri = ((XSString) arg1.first()).value();
    }
    try {
        new URI(uri);
    } catch (URISyntaxException ex) {
        throw DynamicError.doc_not_found(null);
    }
    if (uri.indexOf(":") < 0) {
        throw DynamicError.invalidCollectionArgument();
    }
    URI resolved = ec.getDynamicContext().resolveUri(uri);
    if (resolved == null)
        throw DynamicError.invalid_doc(null);
    ResultSequence rs = getCollection(uri, ec);
    if (rs.empty())
        throw DynamicError.doc_not_found(null);
    return rs;
}
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) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 67 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.

the class FnCollection 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);
    }
    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 68 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.

the class FnConcat method concat.

/**
 * Concatenate the arguments.
 *
 * @param args
 *            are concatenated.
 * @throws DynamicError
 *             Dynamic error.
 * @return The result of the concatenation of the arguments.
 */
public static ResultSequence concat(Collection args) throws DynamicError {
    // sanity check
    if (args.size() < 2)
        DynamicError.throw_type_error();
    ResultBuffer rs = new ResultBuffer();
    String result = "";
    // go through args
    StringBuffer buf = new StringBuffer();
    for (Iterator argi = args.iterator(); argi.hasNext(); ) {
        ResultSequence arg = (ResultSequence) argi.next();
        int size = arg.size();
        // sanity check
        if (size > 1)
            DynamicError.throw_type_error();
        if (size == 0) {
            continue;
        }
        Item at = arg.first();
        buf.append(at.getStringValue());
    }
    result = buf.toString();
    rs.add(new XSString(result));
    return rs.getSequence();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 69 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.

the class FnDoc method doc.

/**
 * Doc operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param dc
 *            Result of dynamic context operation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:doc operation.
 */
public static ResultSequence doc(Collection args, EvaluationContext ec) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get args
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    if (arg1.empty())
        return ResultSequenceFactory.create_new();
    String uri = ((XSString) arg1.item(0)).value();
    DynamicContext dc = ec.getDynamicContext();
    URI resolved = dc.resolveUri(uri);
    if (resolved == null)
        throw DynamicError.invalid_doc(null);
    Document doc = dc.getDocument(resolved);
    if (doc == null)
        throw DynamicError.doc_not_found(null);
    return new DocType(doc, ec.getStaticContext().getTypeModel());
}
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) Document(org.w3c.dom.Document) URI(java.net.URI) DocType(org.eclipse.wst.xml.xpath2.processor.internal.types.DocType) DynamicContext(org.eclipse.wst.xml.xpath2.api.DynamicContext)

Example 70 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.

the class FnDoc 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);
    }
    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)

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