Package org.hdiv.state

Examples of org.hdiv.state.IState


  /*
   * Test method for 'org.hdiv.state.StateUtil.encode64Cipher(Object)'
   */
  public void testEncode64() {

    IState state = new State(0);

    state.setAction("action1");
    Parameter parameter1 = new Parameter("parameter1", "value1", false, "text", false);
    parameter1.addValue("value2");
    Parameter parameter2 = new Parameter("parameter2""value1", false, "text", false);
    parameter2.addValue("value2");
    Parameter parameter3 = new Parameter("parameter3""value1", false, "text", false);
    parameter3.addValue("value2");
   
    state.addParameter(parameter1);
    state.addParameter(parameter2);
    state.addParameter(parameter3);

    String data = encodingUtil.encode64Cipher(state);
    State obj = (State) encodingUtil.decode64Cipher(data);

    assertEquals(obj.getAction(), state.getAction());
  }
View Full Code Here


      throw new HDIVException(Constants.ENCODING_UTF_8 + " enconding not supported.", e);
    } catch (IllegalArgumentException e) {
    }

    // Create new IState
    IState state = new State(this.requestCounter);
    state.setAction(action);
    state.setMethod(method);

    return this.beginRequest(state);
  }
View Full Code Here

   *
   * @return Identifier composed by the page identifier and the state identifier.
   */
  public String endRequest() {

    IState state = this.getStatesStack().pop();

    // Add to scope
    String currentScope = this.getCurrentScope();
    StateScope stateScope = this.stateScopeManager.getStateScopeByName(currentScope);
    if (stateScope != null) {
      // Its custom Scope
      String stateId = stateScope.addState(state, this.getStateSuffix(state.getMethod()));
      return stateId;
    }

    // Add to page scope
    IPage page = this.getPage();
    state.setPageId(page.getId());
    page.addState(state);

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

      super.session.addPage(page.getName(), page);
    }

    String id = this.getPage().getId() + DASH + state.getId() + DASH + this.getStateSuffix(state.getMethod());
    return id;
  }
View Full Code Here

   *
   * @return String with the encoded state. If the Memory strategy has been used, an identifier.
   */
  public String endRequest() {

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

    // Prepare data to cipher
    String token = this.getStateSuffix(state.getMethod());
    Object[] cipherData = new Object[2];
    cipherData[0] = state;
    cipherData[1] = token;

    String stateData = this.encodingUtil.encode64Cipher(cipherData);
    String id = null;

    // 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 Cipher strategy to Memory because state data [" + stateData.length()
            + "] is greater than allowedLength [" + this.allowedLength);
      }

      this.savePage = true;
      super.startPage();

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

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

    return (id != null) ? id : stateData;
  }
View Full Code Here

    assertTrue(stateId.startsWith("U-"));

    StateScope scope = this.stateScopeManager.getStateScope(stateId);
    assertEquals("user-session", scope.getScopeName());
    int id = Integer.parseInt(stateId.substring(stateId.indexOf("-") + 1, stateId.indexOf("-") + 2));
    IState state = scope.restoreState(id);
    assertEquals("test.do", state.getAction());

  }
View Full Code Here

    String stateId = cache.addState(state, token);
    assertNotNull(stateId);

    String id = stateId.substring(0, stateId.indexOf("-"));
    IState restored = cache.getState(Integer.parseInt(id));

    assertEquals(state, restored);

    // Restore non existent
    restored = cache.getState(99999);
View Full Code Here

    assertTrue(stateScope.isScopeState("U-111-11111"));
  }

  public void testAddState() {

    IState state = new State(0);
    state.setAction("/action");

    this.stateScope.addState(state, "token");

    IState state2 = this.stateScope.restoreState(0);

    assertEquals(state, state2);
  }
View Full Code Here

    assertEquals(state, state2);
  }

  public void testAddSameActionState() {

    IState state = new State(0);
    state.setAction("/action");
    IParameter param = new Parameter("uno", "value", false, null, false);
    state.addParameter(param);

    String id = this.stateScope.addState(state, "token");

    IState state2 = new State(1);
    state2.setAction("/action");
    IParameter param2 = new Parameter("uno", "value", false, null, false);
    state2.addParameter(param2);

    String id2 = this.stateScope.addState(state2, "token");

    assertEquals(id, id2);
  }
View Full Code Here

    assertTrue(stateScope.isScopeState("A-111-11111"));
  }

  public void testAddState() {

    IState state = new State(0);
    state.setAction("/action");

    this.stateScope.addState(state, "token");

    IState state2 = this.stateScope.restoreState(0);

    assertEquals(state, state2);
  }
View Full Code Here

    assertEquals(state, state2);
  }

  public void testAddSameActionState() {

    IState state = new State(0);
    state.setAction("/action");
    IParameter param = new Parameter("uno", "value", false, null, false);
    state.addParameter(param);

    String id = this.stateScope.addState(state, "token");

    IState state2 = new State(1);
    state2.setAction("/action");
    IParameter param2 = new Parameter("uno", "value", false, null, false);
    state2.addParameter(param2);

    String id2 = this.stateScope.addState(state2, "token");

    assertEquals(id, id2);
  }
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.