Search in sources :

Example 1 with StaticContext

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

the class FnDateTime method dateTime.

/**
 * 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 dateTime(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();
    ResultSequence arg2 = (ResultSequence) argiter.next();
    // is an empty sequence
    if (arg1.empty() || arg2.empty()) {
        return ResultBuffer.EMPTY;
    }
    XSDate param1 = (XSDate) arg1.first();
    XSTime param2 = (XSTime) arg2.first();
    Calendar cal = Calendar.getInstance();
    cal.set(param1.year(), param1.month() - 1, param1.day());
    cal.set(Calendar.HOUR_OF_DAY, param2.hour());
    cal.set(Calendar.MINUTE, param2.minute());
    cal.set(Calendar.SECOND, (new Double(Math.floor(param2.second())).intValue()));
    cal.set(Calendar.MILLISECOND, 0);
    XSDuration dateTimeZone = param1.tz();
    XSDuration timeTimeZone = param2.tz();
    if ((dateTimeZone != null && timeTimeZone != null) && !dateTimeZone.getStringValue().equals(timeTimeZone.getStringValue())) {
        // it's an error, if the arguments have different timezones
        throw DynamicError.inconsistentTimeZone();
    } else if (dateTimeZone == null && timeTimeZone != null) {
        return new XSDateTime(cal, timeTimeZone);
    } else if (dateTimeZone != null && timeTimeZone == null) {
        return new XSDateTime(cal, dateTimeZone);
    } else if ((dateTimeZone != null && timeTimeZone != null) && dateTimeZone.getStringValue().equals(timeTimeZone.getStringValue())) {
        return new XSDateTime(cal, dateTimeZone);
    } else {
        return new XSDateTime(cal, null);
    }
}
Also used : XSDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration) XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) XSDate(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDate) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Calendar(java.util.Calendar) Iterator(java.util.Iterator) Collection(java.util.Collection) XSTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSTime)

Example 2 with StaticContext

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

the class FnPrefixFromQName method prefix.

/**
 * Prefix-from-QName operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:prefix-from-QName operation.
 */
public static ResultSequence prefix(Collection args, StaticContext sc) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get arg
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty())
        return ResultBuffer.EMPTY;
    QName qname = (QName) arg1.first();
    String prefix = qname.prefix();
    if (prefix != null) {
        if (!XMLConstants.NULL_NS_URI.equals(sc.getNamespaceContext().getNamespaceURI(prefix))) {
            return new XSNCName(prefix);
        } else {
            throw DynamicError.invalidPrefix();
        }
    }
    return ResultBuffer.EMPTY;
}
Also used : XSNCName(org.eclipse.wst.xml.xpath2.processor.internal.types.XSNCName) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) Collection(java.util.Collection)

Example 3 with StaticContext

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

the class SeqType method make_atomic.

private AnyAtomicType make_atomic(StaticContext sc, QName qname) {
    String ns = qname.namespace();
    Map functionLibraries = sc.getFunctionLibraries();
    if (!functionLibraries.containsKey(ns))
        return null;
    FunctionLibrary fl = (FunctionLibrary) functionLibraries.get(ns);
    if (!(fl instanceof ConstructorFL))
        return null;
    ConstructorFL cfl = (ConstructorFL) fl;
    return cfl.atomic_type(qname);
}
Also used : FunctionLibrary(org.eclipse.wst.xml.xpath2.processor.internal.function.FunctionLibrary) ConstructorFL(org.eclipse.wst.xml.xpath2.processor.internal.function.ConstructorFL) Map(java.util.Map)

Example 4 with StaticContext

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

the class ElementTest method createElementType.

private AnyType createElementType(Item at, StaticContext sc) {
    anyType = new ElementType();
    NodeType nodeType = (NodeType) at;
    Node node = nodeType.node_value();
    Document doc = null;
    if (node.getNodeType() == Node.DOCUMENT_NODE) {
        doc = (Document) node;
    } else {
        doc = nodeType.node_value().getOwnerDocument();
    }
    NodeList nodeList = null;
    if (!wild()) {
        nodeList = doc.getElementsByTagNameNS(name().namespace(), name().local());
    } else {
        nodeList = new SingleItemNodeListImpl(node);
    }
    if (nodeList.getLength() > 0) {
        anyType = createElementForXSDType(nodeList, sc);
    }
    return anyType;
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document)

Example 5 with StaticContext

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

the class AttributeTest method createAttrForXSDType.

private AnyType createAttrForXSDType(Node node, StaticContext sc) {
    Attr attr = (Attr) node;
    TypeModel typeModel = sc.getTypeModel();
    TypeDefinition typedef = typeModel.getType(attr);
    if (typedef != null) {
        if (typedef.derivedFrom(type().namespace(), type().local(), getDerviationTypes())) {
            anyType = new AttrType(attr, sc.getTypeModel());
        }
    } else {
        anyType = new AttrType(attr, sc.getTypeModel());
    }
    return anyType;
}
Also used : AttrType(org.eclipse.wst.xml.xpath2.processor.internal.types.AttrType) TypeModel(org.eclipse.wst.xml.xpath2.api.typesystem.TypeModel) Attr(org.w3c.dom.Attr) TypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)

Aggregations

ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)5 Collection (java.util.Collection)4 Iterator (java.util.Iterator)4 TypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)3 TypeModel (org.eclipse.wst.xml.xpath2.api.typesystem.TypeModel)3 Engine (org.eclipse.wst.xml.xpath2.processor.Engine)3 ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)3 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)3 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)3 Map (java.util.Map)2 DynamicContext (org.eclipse.wst.xml.xpath2.api.DynamicContext)2 StaticContext (org.eclipse.wst.xml.xpath2.api.StaticContext)2 XPath2Expression (org.eclipse.wst.xml.xpath2.api.XPath2Expression)2 AttrType (org.eclipse.wst.xml.xpath2.processor.internal.types.AttrType)2 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)2 DynamicContextBuilder (org.eclipse.wst.xml.xpath2.processor.util.DynamicContextBuilder)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 URI (java.net.URI)1 Calendar (java.util.Calendar)1