/* (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.");
  }
  /* (non-Javadoc)
   * @see org.exist.xquery.Expression#eval(org.exist.dom.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
   */
  public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
    if (context.getProfiler().isEnabled()) {
      context.getProfiler().start(this);
      context
          .getProfiler()
          .message(
              this,
              Profiler.DEPENDENCIES,
              "DEPENDENCIES",
              Dependency.getDependenciesName(this.getDependencies()));
      if (contextSequence != null)
        context
            .getProfiler()
            .message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
      if (contextItem != null)
        context
            .getProfiler()
            .message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
    }

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

    // response object is read from global variable $response
    Variable var = myModule.resolveVariable(ResponseModule.RESPONSE_VAR);
    if (var == null || var.getValue() == null) throw new XPathException("Response not set");
    if (var.getValue().getItemType() != Type.JAVA_OBJECT)
      throw new XPathException("Variable $response is not bound to a Java object.");
    JavaObjectValue response = (JavaObjectValue) var.getValue().itemAt(0);

    // get parameter
    int code =
        ((IntegerValue) getArgument(0).eval(contextSequence, contextItem).convertTo(Type.INTEGER))
            .getInt();

    // set response status code
    if (response.getObject() instanceof ResponseWrapper)
      ((ResponseWrapper) response.getObject()).setStatusCode(code);
    else
      throw new XPathException("Type error: variable $response is not bound to a response object");

    return Sequence.EMPTY_SEQUENCE;
  }
Exemple #3
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.");
    }
  }
Exemple #4
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 {

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

    // session object is read from global variable $session
    Variable var = myModule.resolveVariable(SessionModule.SESSION_VAR);
    if (var == null || var.getValue() == null) throw new XPathException(this, "Session not set");
    if (var.getValue().getItemType() != Type.JAVA_OBJECT)
      throw new XPathException(this, "Variable $session is not bound to an Java object.");
    JavaObjectValue session = (JavaObjectValue) var.getValue().itemAt(0);

    if (session.getObject() instanceof SessionWrapper) {
      SessionWrapper sessionWrapper = (SessionWrapper) session.getObject();
      for (Enumeration e = sessionWrapper.getAttributeNames(); e.hasMoreElements(); ) {
        String attribName = (String) e.nextElement();
        sessionWrapper.removeAttribute(attribName);
      }
      return Sequence.EMPTY_SEQUENCE;
    } else
      throw new XPathException(
          this, "Type error: variable $session is not bound to a session object");
  }