예제 #1
0
  /* (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.");
  }
예제 #2
0
  /* (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 {

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

    // request object is read from global variable $request
    final Variable var = myModule.resolveVariable(RequestModule.REQUEST_VAR);
    if (var == null || var.getValue() == null) {
      throw new XPathException(this, "No request object found in the current XQuery context.");
    }
    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 StringValue(((RequestWrapper) value.getObject()).getRemoteHost());
    } else {
      throw new XPathException(this, "Variable $request is not bound to a Request object.");
    }
  }