@Nonnull
  @Nonempty
  private static String _createScopeID(@Nonnull final HttpServletRequest aHttpRequest) {
    ValueEnforcer.notNull(aHttpRequest, "HttpRequest"); // $NON-NLS-1$

    return GlobalIDFactory.getNewIntID() + "@" + aHttpRequest.getRequestURI(); // $NON-NLS-1$
  }
예제 #2
0
  /**
   * Create a new MockHttpSession.
   *
   * @param aServletContext the ServletContext that the session runs in
   * @param sID a unique identifier for this session
   */
  public MockHttpSession(
      @Nullable final ServletContext aServletContext, @Nullable final String sID) {
    m_aServletContext = aServletContext;
    m_sID = StringHelper.hasText(sID) ? sID : GlobalIDFactory.getNewStringID();

    final HttpSessionEvent aHSE = new HttpSessionEvent(this);
    for (final HttpSessionListener aListener : MockHttpListener.getAllHttpSessionListeners())
      aListener.sessionCreated(aHSE);
  }
  @Override
  protected final void fillContent(@Nonnull final WPECTYPE aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();

    // Get the selected object
    final DATATYPE aSelectedObject = getSelectedObject(aWPEC, getSelectedObjectID(aWPEC));

    final boolean bIsEditAllowed = isEditAllowed(aWPEC, aSelectedObject);
    boolean bShowList = true;
    final String sAction = aWPEC.getAction();
    EWebPageFormAction eFormAction = null;
    if (ACTION_VIEW.equals(sAction) && aSelectedObject != null)
      eFormAction = EWebPageFormAction.VIEW;
    else if (ACTION_CREATE.equals(sAction)) eFormAction = EWebPageFormAction.CREATE;
    else if (ACTION_EDIT.equals(sAction) && bIsEditAllowed && aSelectedObject != null)
      eFormAction = EWebPageFormAction.EDIT;
    else if (ACTION_COPY.equals(sAction) && aSelectedObject != null)
      eFormAction = EWebPageFormAction.COPY;
    else if (ACTION_DELETE.equals(sAction) && aSelectedObject != null)
      eFormAction = EWebPageFormAction.DELETE;
    else if (ACTION_UNDELETE.equals(sAction) && aSelectedObject != null)
      eFormAction = EWebPageFormAction.UNDELETE;

    // Try to lock object
    if (beforeProcessing(aWPEC, aSelectedObject, eFormAction).isContinue()) {
      if (eFormAction == EWebPageFormAction.VIEW) {
        // Valid object found - show details
        handleViewObject(aWPEC, aSelectedObject, bIsEditAllowed);

        bShowList = false;
      } else {
        if (eFormAction == EWebPageFormAction.CREATE
            || eFormAction == EWebPageFormAction.EDIT
            || eFormAction == EWebPageFormAction.COPY) {
          final boolean bIsEdit = eFormAction == EWebPageFormAction.EDIT;
          final boolean bIsCopy = eFormAction == EWebPageFormAction.COPY;

          // Create or edit a client
          final FormErrors aFormErrors = new FormErrors();
          boolean bShowInputForm = true;

          if (aWPEC.hasSubAction(CHCParam.ACTION_SAVE)) {
            // try to save
            validateAndSaveInputParameters(aWPEC, aSelectedObject, aFormErrors, bIsEdit);
            if (aFormErrors.isEmpty()) {
              // Save successful
              bShowInputForm = false;

              // Remove an optionally stored state
              FormStateManager.getInstance()
                  .deleteFormState(aWPEC.getAttributeAsString(FIELD_FLOW_ID));
            } else {
              // Show: changes could not be saved...
              aNodeList.addChild(getStyler().createIncorrectInputBox(aWPEC));
            }
          }

          if (bShowInputForm) {
            // Show the input form. Either for the first time or because of form
            // errors a n-th time
            bShowList = false;
            final HCForm aForm =
                isFileUploadForm(aWPEC) ? createFormFileUploadSelf(aWPEC) : createFormSelf(aWPEC);
            aForm.setID(INPUT_FORM_ID);
            aNodeList.addChild(aForm);

            // The unique form ID, that allows to identify on "transaction"
            // -> Used only for "form state remembering"
            aForm.addChild(
                new HCHiddenField(
                    new RequestField(FIELD_FLOW_ID, GlobalIDFactory.getNewStringID())));

            modifyFormBeforeShowInputForm(aWPEC, aForm);

            // Is there as saved state to use?
            final String sRestoreFlowID = aWPEC.getAttributeAsString(FIELD_RESTORE_FLOW_ID);
            if (sRestoreFlowID != null) {
              final FormState aSavedState =
                  FormStateManager.getInstance().getFormStateOfID(sRestoreFlowID);
              if (aSavedState != null) {
                // Restore all form values
                aForm.addChild(
                    new HCScriptOnDocumentReady(
                        JSFormHelper.setAllFormValues(
                            INPUT_FORM_ID, aSavedState.getAsAssocArray())));
              }
            }

            // Show the main input form
            showInputForm(aWPEC, aSelectedObject, aForm, bIsEdit, bIsCopy, aFormErrors);

            // Toolbar on bottom
            if (bIsEdit) {
              if (showEditToolbar(aWPEC, aSelectedObject))
                aForm.addChild(createEditToolbar(aWPEC, aForm, aSelectedObject));
            } else {
              if (showCreateToolbar(aWPEC, aSelectedObject))
                aForm.addChild(createCreateToolbar(aWPEC, aForm, aSelectedObject));
            }
          }
        } else if (eFormAction == EWebPageFormAction.DELETE) {
          bShowList = handleDeleteAction(aWPEC, aSelectedObject);
        } else if (eFormAction == EWebPageFormAction.UNDELETE) {
          bShowList = handleUndeleteAction(aWPEC, aSelectedObject);
        } else {
          // Other proprietary actions
          bShowList = handleCustomActions(aWPEC, aSelectedObject);
        }
      }
    }

    if (bShowList) {
      showListOfExistingObjects(aWPEC);
    }

    // Call after everything
    afterProcessing(aWPEC, aSelectedObject, eFormAction);
  }