Search in sources :

Example 1 with ResultSequence

use of org.eclipse.wst.xml.xpath2.api.ResultSequence in project webtools.sourceediting by eclipse.

the class FnAdjustTimeToTimeZone method adjustTime.

/**
 * Evaluate the function using the arguments passed.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param sc
 *            Result of static context operation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of the fn:dateTime operation.
 */
public static ResultSequence adjustTime(Collection args, DynamicContext dc) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expectedArgs());
    // get args
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    ResultSequence arg2 = ResultBuffer.EMPTY;
    if (argiter.hasNext()) {
        arg2 = (ResultSequence) argiter.next();
    }
    XSTime time = (XSTime) arg1.first();
    XSDayTimeDuration timezone = null;
    if (arg2.empty()) {
        if (time.timezoned()) {
            XSTime localized = new XSTime(time.calendar(), null);
            return localized;
        } else {
            return arg1;
        }
    }
    XMLGregorianCalendar xmlCalendar = null;
    if (time.tz() != null) {
        xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) time.normalizeCalendar(time.calendar(), time.tz()));
    } else {
        xmlCalendar = _datatypeFactory.newXMLGregorianCalendarTime(time.hour(), time.minute(), (int) time.second(), 0);
    }
    timezone = (XSDayTimeDuration) arg2.first();
    if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc)) {
        throw DynamicError.invalidTimezone();
    }
    if (time.tz() == null) {
        return new XSTime(time.calendar(), timezone);
    }
    Duration duration = _datatypeFactory.newDuration(timezone.getStringValue());
    xmlCalendar.add(duration);
    return new XSTime(xmlCalendar.toGregorianCalendar(), timezone);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Collection(java.util.Collection) Duration(javax.xml.datatype.Duration) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) XSTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSTime)

Example 2 with ResultSequence

use of org.eclipse.wst.xml.xpath2.api.ResultSequence in project webtools.sourceediting by eclipse.

the class FnBaseUri method base_uri.

/**
 * Base-Uri operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param d_context
 * 			  Dynamic context
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:base-uri operation.
 */
public static ResultSequence base_uri(Collection args, EvaluationContext ec) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence rs = null;
    if (cargs.size() == 0) {
        // support for arity 0
        // get base-uri from the context item.
        Item contextItem = ec.getContextItem();
        if (contextItem != null) {
            rs = getBaseUri(contextItem);
        } else {
            throw DynamicError.contextUndefined();
        }
    } else if (cargs.size() == 1) {
        // support for arity 1
        ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
        Item att = arg1.empty() ? null : arg1.first();
        rs = getBaseUri(att);
    } else {
        // arity other than 0 or 1 is not allowed
        throw DynamicError.throw_type_error();
    }
    return rs;
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Collection(java.util.Collection)

Example 3 with ResultSequence

use of org.eclipse.wst.xml.xpath2.api.ResultSequence in project webtools.sourceediting by eclipse.

the class FnBaseUri method getBaseUri.

/*
	 * Helper function for base-uri support
	 */
public static ResultSequence getBaseUri(Item att) {
    ResultBuffer rs = new ResultBuffer();
    XSAnyURI baseUri = null;
    if (att instanceof NodeType) {
        NodeType node = (NodeType) att;
        Node domNode = node.node_value();
        String buri = domNode.getBaseURI();
        if (buri != null) {
            baseUri = new XSAnyURI(buri);
        } else {
            baseUri = new XSAnyURI("null");
        }
    }
    if (baseUri != null) {
        rs.add(baseUri);
    }
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) XSAnyURI(org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node)

Example 4 with ResultSequence

use of org.eclipse.wst.xml.xpath2.api.ResultSequence in project webtools.sourceediting by eclipse.

the class FnCodepointsToString method codepoints_to_string.

/**
 * Codepoints to string operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:codepoints-to-string operation.
 */
public static ResultSequence codepoints_to_string(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty()) {
        return new XSString("");
    }
    int[] codePointArray = new int[arg1.size()];
    int codePointIndex = 0;
    for (Iterator i = arg1.iterator(); i.hasNext(); ) {
        XSInteger code = (XSInteger) i.next();
        int codepoint = code.int_value().intValue();
        if (codepoint < MIN_LEGAL_CODEPOINT || codepoint > MAX_LEGAL_CODEPOINT) {
            throw DynamicError.unsupported_codepoint("U+" + Integer.toString(codepoint, 16).toUpperCase());
        }
        codePointArray[codePointIndex] = codepoint;
        codePointIndex++;
    }
    try {
        String str = UTF16.newString(codePointArray, 0, codePointArray.length);
        return new XSString(str);
    } catch (IllegalArgumentException iae) {
        // This should be duoble checked above, but rather safe than sorry
        throw DynamicError.unsupported_codepoint(iae.getMessage());
    }
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) 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 5 with ResultSequence

use of org.eclipse.wst.xml.xpath2.api.ResultSequence in project webtools.sourceediting by eclipse.

the class FnCompare method compare.

/**
 * Compare the arguments.
 *
 * @param args
 *            are compared (optional 3rd argument is the collation)
 * @param dynamicContext
 * 	       Current dynamic context
 * @throws DynamicError
 *             Dynamic error.
 * @return The result of the comparison of the arguments.
 */
public static ResultSequence compare(Collection args, DynamicContext context) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    ResultSequence arg2 = (ResultSequence) argiter.next();
    String collationUri = context.getCollationProvider().getDefaultCollation();
    if (argiter.hasNext()) {
        ResultSequence collArg = (ResultSequence) argiter.next();
        collationUri = collArg.first().getStringValue();
    }
    XSString xstr1 = arg1.empty() ? null : (XSString) arg1.first();
    XSString xstr2 = arg2.empty() ? null : (XSString) arg2.first();
    BigInteger result = compare_string(collationUri, xstr1, xstr2, context);
    if (result != null) {
        return ResultSequenceFactory.create_new(new XSInteger(result));
    } else {
        return ResultSequenceFactory.create_new();
    }
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator) Collection(java.util.Collection) BigInteger(java.math.BigInteger) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Aggregations

ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)8383 URL (java.net.URL)8366 XSModel (org.apache.xerces.xs.XSModel)8363 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)8279 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)8279 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)8208 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)173 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)156 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)130 Schema (javax.xml.validation.Schema)102 Iterator (java.util.Iterator)92 Collection (java.util.Collection)83 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)83 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)74 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)74 XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)74 DynamicContext (org.eclipse.wst.xml.xpath2.processor.DynamicContext)72 Item (org.eclipse.wst.xml.xpath2.api.Item)56 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)34 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)32