/* (non-Javadoc)
   * @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[], org.exist.xquery.value.Sequence)
   */
  public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    RequestModule myModule = (RequestModule) context.getModule(RequestModule.NAMESPACE_URI);

    // request object is read from global variable $request
    Variable var = myModule.resolveVariable(RequestModule.REQUEST_VAR);
    if (var == null || var.getValue() == null || var.getValue().getItemType() != Type.JAVA_OBJECT)
      return Sequence.EMPTY_SEQUENCE;

    JavaObjectValue value = (JavaObjectValue) var.getValue().itemAt(0);
    if (value.getObject() instanceof RequestWrapper) {
      Cookie[] cookies = ((RequestWrapper) value.getObject()).getCookies();
      if (cookies != null) {
        if (cookies.length != 0) {
          ValueSequence names = new ValueSequence();

          for (int c = 0; c < cookies.length; c++) {
            names.add(new StringValue(cookies[c].getName()));
          }

          return names;
        }
      }
      return Sequence.EMPTY_SEQUENCE;
    } else throw new XPathException("Variable $request is not bound to a Request object.");
  }
Beispiel #2
0
 public static Sequence atomize(Sequence input) throws XPathException {
   if (input.hasOne()) return input.itemAt(0).atomize();
   Item next;
   ValueSequence result = new ValueSequence();
   for (SequenceIterator i = input.iterate(); i.hasNext(); ) {
     next = i.nextItem();
     result.add(next.atomize());
   }
   return result;
 }
Beispiel #3
0
 public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
   ValueSequence result = new ValueSequence();
   try {
     ExistRepository repo = getContext().getRepository();
     Repository parent_repo = repo.getParentRepo();
     for (Packages pkg : parent_repo.listPackages()) {
       String name = pkg.name();
       result.add(new StringValue(name));
     }
   } catch (Exception ex) {
     throw new XPathException("Problem listing packages in expath repository ", ex);
   }
   return result;
 }
Beispiel #4
0
  @Override
  public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    try {
      // Verify clientid and get client
      String mongodbClientId = args[0].itemAt(0).getStringValue();
      MongodbClientStore.getInstance().validate(mongodbClientId);
      MongoClient client = MongodbClientStore.getInstance().get(mongodbClientId);

      // Get parameters
      String dbname = args[1].itemAt(0).getStringValue();

      // Retrieve database
      DB db = client.getDB(dbname);

      // Retrieve collection names
      Set<String> collectionNames = db.getCollectionNames();

      // Storage for results
      ValueSequence valueSequence = new ValueSequence();

      // Iterate over collection names ; only pairs of collections
      // with names ending .chunks and .files are buckets
      for (String collName : collectionNames) {
        if (collName.endsWith(".chunks")) {
          String bucketName = StringUtils.removeEnd(collName, ".chunks");
          if (collectionNames.contains(bucketName + ".files")) {
            valueSequence.add(new StringValue(bucketName));
          }
        }
      }

      return valueSequence;

    } catch (XPathException ex) {
      LOG.error(ex.getMessage(), ex);
      throw new XPathException(this, ex.getMessage(), ex);

    } catch (MongoException ex) {
      LOG.error(ex.getMessage(), ex);
      throw new XPathException(this, GridfsModule.GRFS0002, ex.getMessage());

    } catch (Throwable ex) {
      LOG.error(ex.getMessage(), ex);
      throw new XPathException(this, GridfsModule.GRFS0003, ex.getMessage());
    }

    // return Sequence.EMPTY_SEQUENCE;
  }