Exemplo n.º 1
0
 public Sequence<? extends Item> eval(Sequence<? extends Item> contextSeq, DynamicContext dynEnv)
     throws XQueryException {
   if (contextSeq == null) {
     throw new DynamicError("err:XPDY0002", "ContextItem is not set");
   }
   if (contextSeq instanceof XQNode) {
     final XQNode n = (XQNode) contextSeq;
     if (n.nodeKind() == NodeKind.ELEMENT) {
       if (n instanceof DMElement) {
         return ((DMElement) n).attribute(_nodeTest, dynEnv);
       } else {
         return new AttributeEmurationSequence((DTMElement) n, _nodeTest, dynEnv);
       }
     } else {
       return NodeSequence.<XQNode>emptySequence();
     }
   }
   final INodeSequence<XQNode> src = ProxyNodeSequence.wrap(contextSeq, dynEnv);
   final IFocus<XQNode> srcItor = src.iterator();
   if (srcItor.hasNext()) {
     final XQNode n = srcItor.next();
     if (srcItor.hasNext()) {
       srcItor.closeQuietly();
       reportError(
           "err:XPTY0020", "Context item is expected to be a node, but was node sequence.");
     }
     if (n.nodeKind() == NodeKind.ELEMENT) {
       srcItor.closeQuietly();
       return new AttributeEmurationSequence((DTMElement) n, _nodeTest, dynEnv);
     }
   }
   srcItor.closeQuietly();
   return NodeSequence.<XQNode>emptySequence();
 }
Exemplo n.º 2
0
 private String processContentExpr(Sequence<? extends Item> contextSeq, DynamicContext dynEnv)
     throws XQueryException {
   final StringBuilder buf = new StringBuilder(128);
   final Sequence<? extends Item> seq = _contentExpr.eval(contextSeq, dynEnv);
   final IAtomized<AtomicValue> atomized = AtomizedSequence.wrap(seq, dynEnv);
   final IFocus<AtomicValue> itor = atomized.iterator();
   for (AtomicValue it : itor) {
     buf.append(it.stringValue());
     if (itor.hasNext()) {
       buf.append(' ');
     }
   }
   itor.closeQuietly();
   return buf.toString();
 }
Exemplo n.º 3
0
 @Override
 public Sequence<? extends Item> eval(Sequence<? extends Item> contextSeq, DynamicContext dynEnv)
     throws XQueryException {
   if (contextSeq == null) {
     throw new DynamicError("err:XPDY0002", "ContextItem is not set");
   }
   final INodeSequence<XQNode> src = ProxyNodeSequence.wrap(contextSeq, dynEnv);
   final IFocus<XQNode> srcItor = src.iterator();
   if (srcItor.hasNext()) {
     final XQNode n = srcItor.next();
     if (srcItor.hasNext()) {
       srcItor.closeQuietly();
       reportError(
           "err:XPTY0020", "Context item is expected to be a node, but was node sequence.");
     }
     final XQNode parent = n.parent();
     if (parent != null) {
       srcItor.closeQuietly();
       return new AncestorOrSelfEmuration(parent, getNodeTest(), dynEnv);
     }
   }
   srcItor.closeQuietly();
   return NodeSequence.<XQNode>emptySequence();
 }