Package org.exist.xquery.value

Examples of org.exist.xquery.value.JavaObjectValue


    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.");}
  }
View Full Code Here


        }
        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 BooleanValue(((RequestWrapper) value.getObject()).isMultipartContent());
        } else {
            throw new XPathException(this, "Variable $request is not bound to a Request object.");
        }
    }
View Full Code Here

          "Variable $request is not bound to an Java object.");}

    // get parameters
    final String param = args[0].getStringValue();

    final JavaObjectValue value = (JavaObjectValue) var.getValue().itemAt(0);
    if (value.getObject() instanceof RequestWrapper) {
      final String headerValue = ((RequestWrapper) value.getObject())
          .getHeader(param);
      if (headerValue == null) {
        return Sequence.EMPTY_SEQUENCE;
      } else {
        return XPathUtil.javaObjectToXPath(headerValue, null, false);
View Full Code Here

            final Variable respVar = myModule.resolveVariable(ResponseModule.RESPONSE_VAR);
            if(respVar == null)
                {throw new XPathException(this, "No response object found in the current XQuery context.");}
            if(respVar.getValue().getItemType() != Type.JAVA_OBJECT)
                {throw new XPathException(this, "Variable $response is not bound to an Java object.");}
            final JavaObjectValue respValue = (JavaObjectValue)
                respVar.getValue().itemAt(0);
            if (!"org.exist.http.servlets.HttpResponseWrapper".equals(respValue.getObject().getClass().getName()))
                {throw new XPathException(this, signatures[1].toString() +
                        " can only be used within the EXistServlet or XQueryServlet");}
            final ResponseWrapper response = (ResponseWrapper) respValue.getObject();
           
            //setup the response correctly
            final String mediaType = handler.getTransformer().getOutputProperty("media-type");
            final String encoding = handler.getTransformer().getOutputProperty("encoding");
            if(mediaType != null)
View Full Code Here

  /* (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
  {
    JavaObjectValue session;
   
    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() );
      }
    }
       
    final SessionModule myModule = (SessionModule)context.getModule( SessionModule.NAMESPACE_URI );

    // session object is read from global variable $session
    final Variable var = myModule.resolveVariable( SessionModule.SESSION_VAR );
   
    if( var == null || var.getValue() == null ) {
      // No saved session, so create one
      session = SessionModule.createSession( context, this );
    } else if( var.getValue().getItemType() != Type.JAVA_OBJECT ) {
      throw( new XPathException( this, "Variable $session is not bound to a Java object." ) );
    } else {
      session = (JavaObjectValue)var.getValue().itemAt( 0 );
    }
   
    // get attribute name parameter
    final int interval = ((IntegerValue)getArgument(0).eval( contextSequence, contextItem ).convertTo(Type.INT)).getInt();
   
    if( session.getObject() instanceof SessionWrapper ) {
      ((SessionWrapper)session.getObject()).setMaxInactiveInterval(interval);
    } else {
      throw( new XPathException( this, "Type error: variable $session is not bound to a session object" ) );
    }

    return( Sequence.EMPTY_SEQUENCE );
View Full Code Here

    final 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.");}
    final JavaObjectValue session = (JavaObjectValue) var.getValue().itemAt(0);
   
    if(session.getObject() instanceof SessionWrapper)
    {
      final ValueSequence result = new ValueSequence();
      final SessionWrapper sessionWrapper = (SessionWrapper)session.getObject();
      for(final Enumeration<String> e = sessionWrapper.getAttributeNames(); e.hasMoreElements();)
      {
        final String attribName = e.nextElement();
        result.add(new StringValue(attribName));
      }
View Full Code Here

    final 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.");}
    final JavaObjectValue session = (JavaObjectValue) var.getValue().itemAt(0);
   
    if(session.getObject() instanceof SessionWrapper)
    {
      final SessionWrapper sessionWrapper = (SessionWrapper)session.getObject();
      for(final Enumeration<String> e = sessionWrapper.getAttributeNames(); e.hasMoreElements();)
      {
        final String attribName = (String) e.nextElement();
        sessionWrapper.removeAttribute(attribName);
      }
View Full Code Here

   * @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
  {

    JavaObjectValue session;
   
        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() );
      }
        }
       
    final SessionModule myModule = (SessionModule)context.getModule( SessionModule.NAMESPACE_URI );

    // session object is read from global variable $session
    final Variable var = myModule.resolveVariable( SessionModule.SESSION_VAR );
   
    if( var == null || var.getValue() == null ) {
      // No saved session, so create one
      session = SessionModule.createSession( context, this );
    } else if( var.getValue().getItemType() != Type.JAVA_OBJECT ) {
      throw( new XPathException( this, "Variable $session is not bound to a Java object." ) );
    } else {
      session = (JavaObjectValue)var.getValue().itemAt( 0 );
    }
   
    // get attribute name parameter
    final String attribName = getArgument(0).eval( contextSequence, contextItem ).getStringValue();
    final Sequence attribValue = getArgument(1).eval( contextSequence, contextItem) ;
   
    if( session.getObject() instanceof SessionWrapper ) {
      ((SessionWrapper)session.getObject()).setAttribute (attribName, attribValue );
    } else {
      throw( new XPathException( this, "Type error: variable $session is not bound to a session object" ) );
    }

    return( Sequence.EMPTY_SEQUENCE );
View Full Code Here

    final 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 a Java object.");}
    final JavaObjectValue session = (JavaObjectValue) var.getValue().itemAt(0);
   
    // get attribute name parameter
    final String attrib = getArgument(0).eval(contextSequence, contextItem).getStringValue();
    if(session.getObject() instanceof SessionWrapper)
      {((SessionWrapper)session.getObject()).removeAttribute(attrib);}
    else
      {throw new XPathException(this, "Type error: variable $session is not bound to a session object");}

    return Sequence.EMPTY_SEQUENCE;
  }
View Full Code Here

        }

        if( var.getValue().getItemType() != Type.JAVA_OBJECT ) {
            throw( new XPathException( this, "Variable $response is not bound to a Java object." ) );
        }
        final JavaObjectValue response  = (JavaObjectValue)var.getValue().itemAt( 0 );

        //get parameters
        final String          name      = getArgument( 0 ).eval( contextSequence, contextItem ).getStringValue();
        final String          value     = getArgument( 1 ).eval( contextSequence, contextItem ).getStringValue();

        Sequence        ageSeq    = Sequence.EMPTY_SEQUENCE;
        Sequence        secureSeq = Sequence.EMPTY_SEQUENCE;
        Sequence        domainSeq = Sequence.EMPTY_SEQUENCE;
        Sequence        pathSeq   = Sequence.EMPTY_SEQUENCE;
        int             maxAge    = -1;

        if( getArgumentCount() > 2 ) {
            ageSeq    = getArgument( 2 ).eval( contextSequence, contextItem );
            secureSeq = getArgument( 3 ).eval( contextSequence, contextItem );

            if( !ageSeq.isEmpty() ) {
                final Duration duration = ( (DurationValue)ageSeq.itemAt( 0 ) ).getCanonicalDuration();
                maxAge = (int)( duration.getTimeInMillis( new Date( System.currentTimeMillis() ) ) / 1000L );
            }

            if( getArgumentCount() > 4 ) {
                domainSeq = getArgument( 4 ).eval( contextSequence, contextItem );
                pathSeq   = getArgument( 5 ).eval( contextSequence, contextItem );
            }
        }

        //set response header
        if( response.getObject() instanceof ResponseWrapper ) {

            switch( getArgumentCount() ) {

                case 2: {
                    ( (ResponseWrapper)response.getObject() ).addCookie( name, value );
                    break;
                }

                case 4: {
                    if( secureSeq.isEmpty() ) {
                        ( (ResponseWrapper)response.getObject() ).addCookie( name, value, maxAge );
                    } else {
                        ( (ResponseWrapper)response.getObject() ).addCookie( name, value, maxAge, ( (BooleanValue)secureSeq.itemAt( 0 ) ).effectiveBooleanValue() );
                    }
                    break;
                }

                case 6: {
                    boolean secure = false;
                    String  domain = null;
                    String  path   = null;
                    if( !secureSeq.isEmpty() ) {
                        secure = ( (BooleanValue)secureSeq.itemAt( 0 ) ).effectiveBooleanValue();
                    }
                    if( !domainSeq.isEmpty() ) {
                        domain = domainSeq.itemAt( 0 ).getStringValue();
                    }
                    if( !pathSeq.isEmpty() ) {
                        path = pathSeq.itemAt( 0 ).getStringValue();
                    }
                    ( (ResponseWrapper)response.getObject() ).addCookie( name, value, maxAge, secure, domain, path );
                    break;
                }
            }
        } else {
            throw( new XPathException( this, "Type error: variable $response is not bound to a response object" ) );
View Full Code Here

TOP

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

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.