Package org.exist.xquery.value

Examples of org.exist.xquery.value.Sequence


   * @param contextItem
   * @param arg
   * @throws XPathException
   */
  private Sequence evalBoolean(Sequence contextSequence, Item contextItem, Expression arg) throws XPathException {
        final Sequence seq = arg.eval(contextSequence, contextItem);
    return seq.effectiveBooleanValue() ? BooleanValue.FALSE : BooleanValue.TRUE;
  }
View Full Code Here


    public java.lang.String[] retrieveByDocument(java.lang.String sessionId, int start, int howmany, java.lang.String path, boolean indent, boolean xinclude, java.lang.String highlight) throws java.rmi.RemoteException {
        final Session session = getSession(sessionId);
        DBBroker broker = null;
        try {
            broker = pool.get(session.getUser());
            final Sequence qr = (Sequence) session.getQueryResult().result;
            if (qr == null)
                {throw new RemoteException("result set unknown or timed out");}
            String xml[] = null;
            if (Type.subTypeOf(qr.getItemType(), Type.NODE)) {
                // Fix typecast exception RMT
//        NodeList resultSet = (NodeSet)qr;
                final ExtArrayNodeSet hitsByDoc = new ExtArrayNodeSet();
                NodeProxy p;
                String ppath;
                for (final SequenceIterator i = qr.iterate(); i.hasNext(); ) {
//        for (Iterator i = ((NodeSet) resultSet).iterator(); i.hasNext();) {
                    p = (NodeProxy) i.nextItem();
                    ///TODO : use dedicated function in XmldbURI
                    ppath = p.getDocument().getCollection().getURI().toString() + '/' + p.getDocument().getFileURI();
                    if (ppath.equals(path))
View Full Code Here

    if (getSignature().getArgumentCount() == 0) {
      if (contextSequence == null)
        {throw new XPathException(this, ErrorCodes.XPDY0002, "Undefined context item");}
      value = !contextSequence.isEmpty() ? contextSequence.itemAt(0).getStringValue() : "";
    } else {
      final Sequence seq = getArgument(0).eval(contextSequence);
      if (seq == null)
        {throw new XPathException(this, ErrorCodes.XPDY0002, "Undefined context item");}     
      if (!seq.isEmpty())
                {value = seq.getStringValue();}
    }
       
        Sequence result;
        if (value == null)
            {result = StringValue.EMPTY_STRING;}
        else {           
        final StringBuilder buf = new StringBuilder();
        if (value.length() > 0) {
View Full Code Here

            broker.getConfiguration().setProperty(XQueryContext.PROPERTY_XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL, true);

            String query = "declare namespace qt='" + QT_NS + "';\n" + "let $testCases := xmldb:document('/db/QT3/" + file + "')\n"
                    + "let $tc := $testCases//qt:environment\n" + "return $tc";

            Sequence result = xquery.execute(query, null, AccessContext.TEST);

            String col = XmldbURI.create("/db/QT3/" + file).removeLastSegment().toString();

            for (NodeProxy node : result.toNodeSet()) {
                ElementImpl el = (ElementImpl) node.getNode();

                String name = el.getAttribute("name");
                if (name == null)
                    continue;
View Full Code Here

            String query = "declare namespace qt='" + QT_NS + "';\n" + "let $testCases := xmldb:document('/db/QT3/" + file + "')\n"
                    + "let $tc := $testCases//qt:environment[@name eq '" + name + "']\n" + "let $catalog := xmldb:document('/db/QT3/catalog.xml')\n"
                    + "let $cat := $catalog//qt:environment[@name eq '" + name + "']\n" + "return ($tc, $cat)";

            Sequence result = xquery.execute(query, null, AccessContext.TEST);

            String col = XmldbURI.create("/db/QT3/" + file).removeLastSegment().toString();

            for (NodeProxy node : result.toNodeSet()) {
                ElementImpl el = (ElementImpl) node.getNode();

                String _name = el.getAttribute("name");
                if (_name == null)
                    continue;
View Full Code Here

    protected void testCase(String file, String tcName) {
        System.out.println("test " + tcName);

        DBBroker broker = null;
        Sequence result = null;
        XQuery xquery = null;

        // try {
        Set<String> extectedError = new HashSet<String>();
        try {
            broker = db.get(db.getSecurityManager().getSystemSubject());
            xquery = broker.getXQueryService();

            final XQueryContext context = new XQueryContext(db, AccessContext.TEST);

            broker.getConfiguration().setProperty(XQueryContext.PROPERTY_XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL, true);

            String query = "declare namespace qt='" + QT_NS + "';\n" + "let $testCases := xmldb:document('/db/QT3/" + file + "')\n"
                    + "let $tc := $testCases//qt:test-case[@name eq \"" + tcName + "\"]\n" + "return $tc";

            XQuery xqs = broker.getXQueryService();

            Sequence results = xqs.execute(query, null, AccessContext.TEST);

            Assert.assertFalse("", results.isEmpty());

            ElementImpl TC = (ElementImpl) results.toNodeSet().get(0).getNode();

            Sequence contextSequence = null;

            NodeList expected = null;
            String nodeName = "";

            // compile & evaluate
            String caseScript = null;

            List<String> staticDocs = new ArrayList<String>();
            NodeList childNodes = TC.getChildNodes();
            for (int i = 0; i < childNodes.getLength(); i++) {
                Node child = childNodes.item(i);
                switch (child.getNodeType()) {
                case Node.ATTRIBUTE_NODE:
                    // String name = ((Attr)child).getName();
                    // if (name.equals("scenario"))
                    // scenario = ((Attr)child).getValue();
                    break;
                case Node.ELEMENT_NODE:
                    nodeName = ((ElementImpl) child).getLocalName();
                    if (nodeName.equals("test")) {
                        ElementImpl el = ((ElementImpl) child);
                        caseScript = el.getNodeValue();

                    } else if (nodeName.equals("environment")) {
                        ElementImpl el = ((ElementImpl) child);

                        String ref = el.getAttribute("ref");
                        if (!(ref == null || "empty".equals(ref) || ref.isEmpty())) {
                            Assert.assertNull(contextSequence);
                            String contextDoc = getEnviroment(file, ref);
                            staticDocs.add(contextDoc);
                        } else {
                            NodeList _childNodes = el.getChildNodes();
                            for (int j = 0; j < _childNodes.getLength(); j++) {
                                Node _child = _childNodes.item(j);
                                switch (_child.getNodeType()) {
                                case Node.ELEMENT_NODE:
                                    nodeName = ((ElementImpl) _child).getLocalName();
                                    if (nodeName.equals("param")) {
                                        el = ((ElementImpl) _child);
                                        Variable var = new VariableImpl(QName.parse(context, el.getAttribute("name")));

                                        String type = el.getAttribute("as");
                                        if ("xs:date".equals(type)) {
                                            var.setStaticType(Type.DATE);

                                            Sequence res = xquery.execute(el.getAttribute("select"), null, AccessContext.TEST);
                                            Assert.assertEquals(1, res.getItemCount());
                                            var.setValue(res);
                                        } else if ("xs:dateTime".equals(type)) {
                                            var.setStaticType(Type.DATE_TIME);

                                            Sequence res = xquery.execute(el.getAttribute("select"), null, AccessContext.TEST);
                                            Assert.assertEquals(1, res.getItemCount());
                                            var.setValue(res);
                                        } else if ("xs:string".equals(type)) {
                                            var.setStaticType(Type.STRING);

                                            Sequence res = xquery.execute(el.getAttribute("select"), null, AccessContext.TEST);
                                            Assert.assertEquals(1, res.getItemCount());
                                            var.setValue(res);
                                        } else {
                                            Assert.fail("unknown type '" + type + "'");
                                        }
                                        context.declareGlobalVariable(var);
View Full Code Here

                final Node exNode = expected.item(i);
                String exString = null;
                if (exNode.getNodeType() == Node.ATTRIBUTE_NODE) {
                    final Attr attr = (Attr) exNode;
                    if (attr.getName().equals("file")) {
                        final Sequence seq = enviroment(XmldbURI.create(attr.getBaseURI()).removeLastSegment() + "/" + attr.getValue());
                        StringBuilder sb = new StringBuilder();
                        for (int j = 0; j < seq.getItemCount(); j++) {
                            sb.append(toString(seq.itemAt(j)));
                        }
                        exString = sb.toString();
                    } else if (attr.getName().equals("ignore-prefixes")) {
                        ignorePrefixes = Boolean.parseBoolean(attr.getValue());
                        exString = expected.item(++i).getNodeValue();
View Full Code Here

                "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
            if (contextSequence != null)
                {context.getProfiler().message(this, Profiler.START_SEQUENCES,
                    "CONTEXT SEQUENCE", contextSequence);}
        }
        Sequence result;
        if (args[0].isEmpty() || args[1].isEmpty()) {
            result = Sequence.EMPTY_SEQUENCE;
        } else if (args[0].hasMany()) {
            throw new XPathException(this, ErrorCodes.XPTY0004,
                "Expected at most one xs:date", args[0]);
View Full Code Here

      if(gotOne && sep != null)
        {out.append(sep);}
      out.append(next.getStringValue());
      gotOne = true;
    }
    final Sequence result = new StringValue(out.toString());
       
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
       
        return result;
View Full Code Here

        }
       
    if (contextItem != null)
        {contextSequence = contextItem.toSequence();}
   
        Sequence result;

        final Sequence s1 = getArgument(0).eval(contextSequence);
        if (s1.isEmpty())
            {result = StringValue.EMPTY_STRING;}
        else {
            String newNormalizationForm = "NFC";
      if (getArgumentCount() > 1)
        {newNormalizationForm = getArgument(1).eval(contextSequence).getStringValue().toUpperCase().trim();}
      //TODO : handle the "FULLY-NORMALIZED" string...
      if ("".equals(newNormalizationForm))
        {result =  new StringValue(s1.getStringValue());}
      else {
        Object returnedObject = null;
        try {
              if (clazz == null)
                {clazz = Class.forName("com.ibm.icu.text.Normalizer");}
              if (modeField == null || !normalizationForm.equals(newNormalizationForm)) {
                try {
                  modeField = clazz.getField(newNormalizationForm);
                } catch (final NoSuchFieldException e) {
                            logger.error("err:FOCH0003: unknown normalization form");
                  throw new XPathException(this, ErrorCodes.FOCH0003, "unknown normalization form");
                }
                  //com.ibm.icu.text.Normalizer.Mode
                  modeObject = modeField.get(null);
                normalizationForm = newNormalizationForm;
              }
              if (constructor == null)
                //Second argument shouldn't be a problem : modeField always has the same type
                  {constructor = clazz.getConstructor(
                      new Class[] { String.class, modeField.getType(), Integer.TYPE}
                    );}
              final Object[] args = new Object[] { s1.getStringValue(), modeObject, DUMMY_INTEGER };
              if (method == null)
                {method = clazz.getMethod( "getText", (Class[])null );}
 
              //Normalizer n = new Normalizer(s1.getStringValue(), Normalizer.NFC, 0);
              final Object instance = constructor.newInstance(args);
View Full Code Here

TOP

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

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.