Package org.exist.xquery.value

Examples of org.exist.xquery.value.IntegerValue


    if (contextSequence == null)
      {throw new XPathException(this, ErrorCodes.XPDY0002, "Undefined context item");}
   
    final String strval = contextSequence.getStringValue();

    final Sequence result = new IntegerValue(FunStringToCodepoints.getCodePointCount(strval));
       
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
       
        return result;           
View Full Code Here


            final QName fnName = getSignature().getName();
            if(doc != null) {
                if(fnName.equals(QN_DOCUMENT_NAME)) {
                   result = new StringValue(doc.getFileURI().toString());
                } else if(fnName.equals(QN_DOCUMENT_ID)) {
                    result = new IntegerValue(doc.getDocId(), Type.INT);
                } else if(fnName.equals(QN_ABSOLUTE_RESOURCE_ID)) {
                   
                    BigInteger absoluteId = BigInteger.valueOf(doc.getCollection().getId());
                    absoluteId = absoluteId.shiftLeft(32);
                    absoluteId = absoluteId.or(BigInteger.valueOf(doc.getDocId()));
                    absoluteId = absoluteId.shiftLeft(1);
                    absoluteId = absoluteId.or(BigInteger.valueOf(doc.getResourceType() & 1));
                    result = new IntegerValue(absoluteId, Type.INTEGER);
                   
                }
            } else {
                if(fnName.equals(QN_GET_RESOURCE_BY_ABSOLUTE_ID)) {
                   
                    final IntegerValue absoluteIdParam = (IntegerValue)args[0].itemAt(0);
                    BigInteger absoluteId = (BigInteger)absoluteIdParam.toJavaObject(BigInteger.class);
                   
                    final byte resourceType = absoluteId.testBit(0) ? DocumentImpl.BINARY_FILE : DocumentImpl.XML_FILE;
                    absoluteId = absoluteId.shiftRight(1);
                    final int documentId = absoluteId.and(BigInteger.valueOf(0xFFFFFFFF)).intValue();
                    absoluteId = absoluteId.shiftRight(32);
View Full Code Here

                params[0] = new StringValue(str.substring(firstMatch.getOffset(), firstMatch.getOffset() + firstMatch.getLength()));
                // if the callback function accepts 4 arguments, the last argument should contain additional
                // information on the match:
                if (callback.getSignature().getArgumentCount() == 4) {
                  params[3] = new ValueSequence();
                  params[3].add(new IntegerValue(nextOffset - 1));
                  params[3].add(new IntegerValue(firstMatch.getOffset()));
                  params[3].add(new IntegerValue(firstMatch.getLength()));
                }
                // now execute the callback func.
                final Sequence callbackResult = callback.evalFunction(null, null, params);
                // iterate through the result of the callback
                for (final SequenceIterator iter = callbackResult.iterate(); iter.hasNext(); ) {
                  final Item next = iter.nextItem();
                  if (Type.subTypeOf(next.getType(), Type.NODE)) {
                    nodeNr = builder.getDocument().getLastNode();
                    try {
              next.copyTo(context.getBroker(), receiver);
              result.add(builder.getDocument().getNode(++nodeNr));
              lastNodeNr = nodeNr;
            } catch (final SAXException e) {
              throw new XPathException(this, "Internal error while copying nodes: " + e.getMessage(), e);
            }
                  }
                }
                currentWidth += firstMatch.getLength();
                pos += firstMatch.getLength();
            } else
                {width = str.length();}
           
            // output the rest of the text and matches
            Match.Offset offset;
            for (int i = nextOffset; i < offsets.size() && currentWidth < width; i++) {
                offset = offsets.get(i);
                if (offset.getOffset() > pos) {
                    int len = offset.getOffset() - pos;
                    if (currentWidth + len > width)
                        {len = width - currentWidth;}
                    nodeNr = builder.characters(str.substring(pos, pos + len));
                    if (lastNodeNr != nodeNr)
                      {result.add(builder.getDocument().getNode(nodeNr));}
                    currentWidth += len;
                    pos += len;
                }
               
                if (currentWidth + offset.getLength() < width) {
                  // put the matching term into argument 0 of the callback function
                    params[0] = new StringValue(str.substring(offset.getOffset(), offset.getOffset() + offset.getLength()));
                    // if the callback function accepts 4 arguments, the last argument should contain additional
                    // information on the match:
                    if (callback.getSignature().getArgumentCount() == 4) {
                      params[3] = new ValueSequence();
                      params[3].add(new IntegerValue(i));
                      params[3].add(new IntegerValue(offset.getOffset()));
                      params[3].add(new IntegerValue(offset.getLength()));
                    }
                    // execute the callback function
                    final Sequence callbackResult = callback.evalFunction(null, null, params);
                    for (final SequenceIterator iter = callbackResult.iterate(); iter.hasNext(); ) {
                      final Item next = iter.nextItem();
                      if (Type.subTypeOf(next.getType(), Type.NODE)) {
                        nodeNr = builder.getDocument().getLastNode();
                        try {
                  next.copyTo(context.getBroker(), receiver);
                  result.add(builder.getDocument().getNode(++nodeNr));
                  lastNodeNr = nodeNr;
                } catch (final SAXException e) {
                  throw new XPathException(this, "Internal error while copying nodes: " + e.getMessage(), e);
                }
                      }
                    }
                    currentWidth += offset.getLength();
                    pos += offset.getLength();
                } else
                    {break;}
            }
            // print the final text chunk if more space is available
            if (currentWidth < width && pos < str.length()) {
                boolean truncated = false;
                int len = str.length() - pos;
                if (len > width - currentWidth) {
                    truncated = true;
                    len = width - currentWidth;
                }
                nodeNr = builder.characters(str.substring(pos, pos + len));
                if (lastNodeNr != nodeNr)
                  {result.add(builder.getDocument().getNode(nodeNr));}
                lastNodeNr = nodeNr;
                currentWidth += len;
               
                if (truncated) {
                    nodeNr = builder.characters(" ...");
                    if (lastNodeNr != nodeNr)
                      {result.add(builder.getDocument().getNode(nodeNr));}
                    lastNodeNr = nodeNr;
                }
            }
        }
       
        // if the user specified a result callback function, call it now
        if (resultCallback != null) {
            final Sequence params[] = new Sequence[3];
            params[0] = result;
            params[1] = new IntegerValue(currentWidth);
            params[2] = extraArgs;
            return resultCallback.evalFunction(null, null, params);
        } else
            {return result;}
    }
View Full Code Here

            final int i = args[0].toJavaObject(Integer.class);
            final String octal = i == 0 ? "0" : "0" + Integer.toOctalString(i);
            return new StringValue(octal);
        } else if(isCalledAs(qnOctalToInt.getLocalName())) {
            final String octal = args[0].toString();
            return new IntegerValue(Integer.parseInt(octal, 8));
        } else {
            throw new XPathException("Unknown function call: " + getSignature());
        }
    }
View Full Code Here

    if (var.getValue().getItemType() != Type.JAVA_OBJECT)
      {throw new XPathException(this, "Variable $request is not bound to an Java object.");}

    final JavaObjectValue value = (JavaObjectValue) var.getValue().itemAt(0);
    if (value.getObject() instanceof RequestWrapper) {
      return new IntegerValue(((RequestWrapper) value.getObject()).getServerPort());
    } else
      {throw new XPathException(this, "Variable $request is not bound to a Request object.");}
  }
View Full Code Here

                }
                match = match.getNextMatch();
           }
          }
      }
      result = new IntegerValue(count);
    }

        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
       
View Full Code Here

    else if(isCalledAs("get-memory-free"))
    {
      memory = rt.freeMemory();
    }
   
    return new IntegerValue(memory, Type.LONG);
  }
View Full Code Here

            final int after = countTotalNumberOfGrammar(grammarpool);
            LOG.debug("Remained "+after+" grammars");
           
            final int delta=before-after;
           
            result.add(new IntegerValue(delta));
           
            return result;
           
           
        } else if (isCalledAs("show-grammar-cache")){
View Full Code Here

        final String number = args[0].itemAt(0).getStringValue();
        final int intBase = ((IntegerValue) args[1].itemAt(0)).getInt();

        if (isCalledAs("base-to-integer")) {
            intValue = Integer.parseInt(number, intBase);
            return new IntegerValue(intValue);
        } else {
            switch (Base.getBase(intBase)) {
                case BINARY:
                    stringValue = Integer.toBinaryString(Integer.parseInt(number));
                    break;
View Full Code Here

      Sequence contextSequence)
        throws XPathException {

        try {
      final Resource resource = collection.getResource(new AnyURIValue(args[1].getStringValue()).toXmldbURI().toString());
      return new IntegerValue(((EXistResource)resource).getContentLength(), Type.LONG);
    } catch (final XMLDBException e) {
            logger.error("Failed to retrieve size: " + e.getMessage());
      throw new XPathException(this, "Failed to retrieve size: " + e.getMessage(), e);
    }
  }
View Full Code Here

TOP

Related Classes of org.exist.xquery.value.IntegerValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.