Package org.exist.xquery.value

Examples of org.exist.xquery.value.Sequence


            }
            // process attributes
            final AttributesImpl attrs = new AttributesImpl();
            if(attributes != null) {
                AttributeConstructor constructor;
                Sequence attrValues;
                QName attrQName;
                // first, search for xmlns attributes and declare in-scope namespaces
                for (int i = 0; i < attributes.length; i++) {
                    constructor = attributes[i];
                    if(constructor.isNamespaceDeclaration()) {
                        final int p = constructor.getQName().indexOf(':');
                        if(p == Constants.STRING_NOT_FOUND)
                            {context.declareInScopeNamespace("", constructor.getLiteralValue());}
                        else {
                            final String prefix = constructor.getQName().substring(p + 1);
                            context.declareInScopeNamespace(prefix, constructor.getLiteralValue());
                        }
                    }
                }
                String v = null;
                // process the remaining attributes
                for (int i = 0; i < attributes.length; i++) {
                    context.proceed(this, builder);
                    constructor = attributes[i];
                    attrValues = constructor.eval(contextSequence, contextItem);
                    attrQName = QName.parse(context, constructor.getQName(), "");
                   
                    final String namespaceURI = attrQName.getNamespaceURI();
                if (namespaceURI != null && !namespaceURI.isEmpty() && attrQName.getPrefix() == null) {
                  String prefix = context.getPrefixForURI(namespaceURI);
                 
                  if (prefix != null) {
                    attrQName.setPrefix(prefix);
                  } else {
                    //generate prefix
                    for (final int n = 1; i < 100; i++) {
                      prefix = "eXnsp"+n;
                            if (context.getURIForPrefix(prefix) == null) {
                              attrQName.setPrefix(prefix);
                              break;
                            }
                           
                            prefix = null;
                    }
                    if (prefix == null)
                                {throw new XPathException(this, "Prefix can't be generate.");}
                  }
                }
                   
                    if (attrs.getIndex(attrQName.getNamespaceURI(), attrQName.getLocalName()) != -1)
                        {throw new XPathException(this, ErrorCodes.XQST0040, "'" + attrQName.getLocalName() + "' is a duplicate attribute name");}
                   
                    v = DynamicAttributeConstructor.normalize(this, attrQName, attrValues.getStringValue());
                   
                    attrs.addAttribute(attrQName.getNamespaceURI(), attrQName.getLocalName(),
                            attrQName.getStringValue(), "CDATA", v);
                }
            }
            context.proceed(this, builder);

            // create the element
            final Sequence qnameSeq = qnameExpr.eval(contextSequence, contextItem);
            if(!qnameSeq.hasOne())
              {throw new XPathException(this, ErrorCodes.XPTY0004, "Type error: the node name should evaluate to a single item");}
            final Item qnitem = qnameSeq.itemAt(0);
            QName qn;
            if (qnitem instanceof QNameValue) {
                qn = ((QNameValue)qnitem).getQName();
            } else {
                //Do we have the same result than Atomize there ? -pb
View Full Code Here


        callArgs.add(ref);
      } else {
        // fixed argument: just compute the argument value
        try {
                    param.analyze(cachedContextInfo);
          final Sequence seq = param.eval(contextSequence, contextItem);
          callArgs.add(new PrecomputedValue(context, seq));
        } catch (final XPathException e) {
          if(e.getLine() <= 0) {
            e.setLocation(line, column, getSource());
          }
View Full Code Here

                    "checking function parameter " + (i + 1) + " in call " + ExpressionDumper.dump(this) + ": ");
                throw e;
            }
        }
          
        final Sequence result = eval(args, contextSequence);
       
        if (context.getProfiler().isEnabled())          
            {context.getProfiler().end(this, "", result);}  
    
        return result;       
View Full Code Here

            context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
            if (contextSequence != null)
                {context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);}
        }
       
        Sequence result;
    if (args[0].isEmpty())
      {return Sequence.EMPTY_SEQUENCE;}
        else {
        final AtomicValue srch = args[1].itemAt(0).atomize();
        Collator collator;
        if (getSignature().getArgumentCount() == 3) {
          final String collation = args[2].getStringValue();
          collator = context.getCollator(collation);
        } else
          {collator = context.getDefaultCollator();}
        result = new ValueSequence();
        int j = 1;
        for (final SequenceIterator i = args[0].iterate(); i.hasNext(); j++) {
          final AtomicValue next = i.nextItem().atomize();
          try {
            if (ValueComparison.compareAtomic(collator, next, srch, Constants.TRUNC_NONE, Constants.EQ))
              {result.add(new IntegerValue(j));}
          } catch (final XPathException e) {
            //Ignore me : values can not be compared
          }
        }       
        }
View Full Code Here

        }
       
        //if(contextItem != null)
      //contextSequence = contextItem.toSequence();
       
    final Sequence seq = getArgument(0).eval(contextSequence, contextItem);
    final Sequence result = seq.isEmpty() ? BooleanValue.FALSE : BooleanValue.TRUE;
       
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
       
        return result;           
View Full Code Here

                {context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);}
            if (contextItem != null)
                {context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());}
        }

        Sequence result;
    final Sequence stringArg = getArgument(0).eval(contextSequence, contextItem);
    if (stringArg.isEmpty())
            {result = StringValue.EMPTY_STRING;}
        else {       
        final String string = stringArg.getStringValue();
        final Sequence patternSeq = getArgument(1).eval(contextSequence, contextItem);
                final String pattern =
          translateRegexp(patternSeq.getStringValue());
           
                final Sequence replaceSeq = getArgument(2).eval(contextSequence, contextItem);
                final String replace =
          replaceSeq.getStringValue();
            //An error is raised [err:FORX0004] if the value of $replacement contains a "$" character that is not immediately followed by a digit 0-9 and not immediately preceded by a "\".
            //An error is raised [err:FORX0004] if the value of $replacement contains a "\" character that is not part of a "\\" pair, unless it is immediately followed by a "$" character.           
            for (int i = 0 ; i < replace.length() ; i++) {
              //Commented out : this seems to be a total non sense
              /*
 
View Full Code Here

            "let $XQTSCatalog := xmldb:document('/db/XQTS/XQTSCatalog.xml') "+
            "return xs:string($XQTSCatalog/catalog:test-suite/@version)";

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

        if (! results.isEmpty()) {
            String catalog = (String) results.itemAt(0).getStringValue();
            catalog = "XQTS_"+adoptString(catalog);
            File subfolder = new File(folder.getAbsolutePath()+sep+catalog);
            processGroups(null, subfolder, "."+catalog);
        }
    }
View Full Code Here

            label="";
        }
       
        final Serializer serializer= context.getBroker().getSerializer();
       
        Sequence result ;
       
        if(args[0].isEmpty()){
            result = Sequence.EMPTY_SEQUENCE;
           
        } else {
            // Copy all Items from input to output sequence
            result = new ValueSequence();
           
            int position = 0;

            for (final SequenceIterator i = args[0].iterate(); i.hasNext();) {

                // Get item
                final Item next = i.nextItem();

                // Only write if debug mode
                if (true) {
                   
                    String value = null;
                    position++;

                    final int type = next.getType();
                   
                    // Serialize an element type
                    if (Type.ELEMENT == type) {
                        final Writer sw = new StringWriter();
                        try {
                            serializer.serialize((NodeValue) next, sw);

                        } catch (final SAXException ex) {
                            LOG.error(ex.getMessage());
                        }
                        value = sw.toString();

                    // Get string value for other types
                    } else {
                        value = next.getStringValue();

                    }
                   
                    // Write to log
                    LOG.info(label + " [" + position + "]: " + Type.getTypeName(type) + ": " + value);
                }

                // Add to result
                result.add(next);
            }
        }

        return result;
    }
View Full Code Here

            query += "for $testGroup in $XQTSCatalog//catalog:test-group[@name = '"+parentName+"']/catalog:test-group";

        query += "\treturn xs:string($testGroup/@name)";

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

        if (!results.isEmpty()) {
            File subfolder;
            String subPackage;

            //if (parentName == null) {
                //subfolder = folder;
                //subPackage = _package_;
            //} else {
                //subfolder = new File(folder.getAbsolutePath()+sep+parentName);
                //subPackage = _package_+"."+adoptString(parentName);
            //}

            BufferedWriter allTests = startAllTests(folder, _package_);

            boolean first = true;
            if (testCases(parentName, folder, _package_)) {
                if (!first)
                    allTests.write(",\n");
                else
                    first = false;
                allTests.write("\t\tC_"+adoptString(parentName)+".class");
            }

            for (int i = 0; i < results.getItemCount(); i++) {
                String groupName = results.itemAt(i).getStringValue();
                subfolder = new File(folder.getAbsolutePath()+sep+groupName);
                subPackage = _package_+"."+adoptString(groupName);

                if (processGroups(groupName, subfolder, subPackage)) {
                    if (!first)
View Full Code Here

            "let $XQTSCatalog := xmldb:document('/db/XQTS/XQTSCatalog.xml')"+
            "for $testGroup in $XQTSCatalog//catalog:test-group[@name = '"+testGroup+"']/catalog:test-case"+
            "\treturn xs:string($testGroup/@name)";

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

        if (!results.isEmpty()) {
            folder.mkdirs();
            File jTest = new File(folder.getAbsolutePath()+sep+"C_"+adoptString(testGroup)+".java");
            FileWriter fstream = new FileWriter(jTest.getAbsoluteFile());
            BufferedWriter out = new BufferedWriter(fstream);

            out.write("package org.exist.xquery.xqts"+_package_+";\n\n"+
                "import org.exist.xquery.xqts.XQTS_case;\n" +
                //"import static org.junit.Assert.*;\n" +
                "import org.junit.Test;\n\n" +
                "public class C_"+adoptString(testGroup)+" extends XQTS_case {\n" +
                "\tprivate String testGroup = \""+testGroup+"\";\n\n");

            for (int i = 0; i < results.getItemCount(); i++) {
                String caseName = results.itemAt(i).getStringValue();
                out.write("\t/* "+caseName+" */" +
                    "\t@Test\n" +
                    "\tpublic void test_"+adoptString(caseName)+"() {\n" +
                    "\tgroupCase(testGroup, \""+caseName+"\");"+
                    "\t}\n\n");
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.