Package org.hdiv.state

Examples of org.hdiv.state.IState


    assertNotNull(stateId);
    request.addParameter("_PREVIOUS_HDIV_STATE_", stateId);

    // New request
    IState state = this.stateUtil.restoreState(stateId);
    IPage page = this.session.getPage(state.getPageId() + "");
    dataComposer = this.dataComposerFactory.newInstance(request);
    HDIVUtil.setDataComposer(dataComposer, request);

    dataComposer.startPage(page);
    dataComposer.beginRequest(state);
    dataComposer.compose("parameter1", "3", false);
    String stateId2 = dataComposer.endRequest();
    dataComposer.endPage();

    assertEquals(stateId, stateId2);
    IState state2 = this.stateUtil.restoreState(stateId2);
    assertEquals(state2.getParameter("parameter1").getConfidentialValue(), "1");
    assertTrue(state2.getParameter("parameter1").existValue("3"));
  }
View Full Code Here


    assertNotNull(stateId);
    assertNotNull(stateIdInner);
    assertNotSame(stateId, stateIdInner);

    IState state = this.stateUtil.restoreState(stateId);
    IState stateInner = this.stateUtil.restoreState(stateIdInner);
    String action = state.getAction();
    String actionInner = stateInner.getAction();
    assertEquals("test.do", action);
    assertEquals("testinner.do", actionInner);
  }
View Full Code Here

    String stateId = dataComposer.endRequest();
    dataComposer.endPage();

    assertNotNull(stateId);

    IState state = this.stateUtil.restoreState(stateId);

    assertEquals("test.do", state.getAction());

    IParameter param = state.getParameter("parameter1");
    List<String> values = param.getValues();
    assertEquals(1, values.size());
    assertEquals("è-test", values.get(0));// escaped value is the same

    IParameter param2 = state.getParameter("parameterEscaped");
    List<String> values2 = param2.getValues();
    assertEquals(1, values2.size());
    // State stored value is not escaped value, it is the unescaped value
    assertEquals("è-test", values2.get(0));
  }
View Full Code Here

    String stateId = dataComposer.endRequest();
    dataComposer.endPage();

    assertNotNull(stateId);

    IState state = this.stateUtil.restoreState(stateId);

    assertEquals("test.do", state.getAction());

    IParameter param = state.getParameter("parameter1");
    List<String> values = param.getValues();
    assertEquals(0, values.size());
  }
View Full Code Here

    dataComposer2.endPage();

    assertEquals(stateId, stateId2);

    // Restore state
    IState state = this.stateUtil.restoreState(stateId);

    // State contains both parameters
    IParameter param = state.getParameter("parameter1");
    String val = param.getValues().get(0);
    assertEquals("1", val);

    param = state.getParameter("parameter2");
    val = param.getValues().get(0);
    assertEquals("2", val);
  }
View Full Code Here

    // Ajax request to add states
    ajaxDataComposer.beginRequest("GET", "/test/1");
    String ajaxStateId = ajaxDataComposer.endRequest();

    // Restore states
    IState state = this.stateUtil.restoreState(stateId);
    IState ajaxState = this.stateUtil.restoreState(ajaxStateId);

    assertEquals(state.getPageId(), ajaxState.getPageId());
    assertEquals(state.getId() + 1, ajaxState.getId());
  }
View Full Code Here

    dataComposer.beginRequest("POST", "test.do");
    String result = dataComposer.compose("test.do", "parameter1", "2", false);
    assertEquals("0", result);
    String stateId = dataComposer.endRequest();

    IState state = this.stateUtil.restoreState(stateId);
    assertNotNull(state);
    assertEquals("test.do", state.getAction());

    dataComposer.endPage();
  }
View Full Code Here

    String stateId = dataComposer.endRequest();
    dataComposer.endPage();

    assertNotNull(stateId);

    IState state = this.stateUtil.restoreState(stateId);

    assertEquals("test test.do", state.getAction());

    // Encoded action url
    dataComposer = this.dataComposerFactory.newInstance(request);
    HDIVUtil.setDataComposer(dataComposer, request);

    dataComposer.startPage();
    dataComposer.beginRequest("POST", "test%20test.do");
    stateId = dataComposer.endRequest();
    dataComposer.endPage();

    assertNotNull(stateId);

    state = this.stateUtil.restoreState(stateId);

    // State action value is decoded because we store decoded values only
    assertEquals("test test.do", state.getAction());
  }
View Full Code Here

    String paramName = (String) request.getSession().getAttribute(Constants.MODIFY_STATE_HDIV_PARAMETER);
    String preState = paramName != null ? request.getParameter(paramName) : null;
    if (preState != null && preState.length() > 0) {

      // We are modifying an existing state, preload dataComposer with it
      IState state = this.stateUtil.restoreState(preState);
      if (state.getPageId() > 0) {
        IPage page = this.session.getPage(state.getPageId() + "");
        if (page != null) {
          dataComposer.startPage(page);
        }
      }
      if (state != null) {
        dataComposer.beginRequest(state);
      }

    } else if (this.reuseExistingPage(request)) {
      String hdivStateParamName = (String) request.getSession().getAttribute(Constants.HDIV_PARAMETER);
      String hdivState = request.getParameter(hdivStateParamName);

      if (hdivState != null) {
        IState state = this.stateUtil.restoreState(hdivState);
        if (state.getPageId() > 0) {
          IPage page = this.session.getPage(Integer.toString(state.getPageId()));
          dataComposer.startPage(page);
        } else {
          dataComposer.startPage();
        }
      } else {
View Full Code Here

   *
   * @return Obtains the state encoded in Base64 that will be added to the request in the HDIV extra parameter.
   */
  public String endRequest() {

    IState state = super.getStatesStack().pop();
    state.setPageId(this.getPage().getId());

    String id = null;
    String stateWithSuffix = null;

    String stateData = encodingUtil.encode64(state);

    // if state's length it's too long for GET methods we have to change the
    // strategy to memory
    if (stateData.length() > this.allowedLength) {

      if (log.isDebugEnabled()) {
        log.debug("Move from Hash strategy to Memory because state data [" + stateData.length()
            + "] is greater than allowedLength [" + this.allowedLength);
      }

      this.getPage().addState(state);
      state.setPageId(this.getPage().getId());

      id = this.getPage().getId() + DASH + state.getId() + DASH + this.getStateSuffix(state.getMethod());

    } else {
      // generate hash to add to the page that will be stored in session
      stateWithSuffix = stateData + DASH + this.getStateSuffix(state.getMethod());
      String stateHash = this.encodingUtil.calculateStateHash(stateWithSuffix);
      this.getPage().addState(state.getId(), stateHash);
    }

    // Save Page in session if this is the first state to add
    boolean firstState = page.getStatesCount() == 1;
    if (firstState) {
View Full Code Here

TOP

Related Classes of org.hdiv.state.IState

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.