Package de.metalcon.utils

Examples of de.metalcon.utils.FormItemList


    final TomcatClientResponder responder = new TomcatClientResponder(
        response);
    response.setHeader("Access-Control-Allow-Origin",
        this.config.getHeaderAccessControl());
    CreateResponse createResponse = new CreateResponse();
    FormItemList formItemList = null;
    try {
      formItemList = FormItemList.extractFormItems(request, FACTORY);
    } catch (final FileUploadException e) {
      responder.error(500,
          "errors encountered while processing the request");
      return;
    }

    if (formItemList != null) {
      final CreateRequest createRequest = CreateRequest.checkRequest(
          formItemList, createResponse);

      boolean commandStacked = false;
      if (createRequest != null) {
        switch (createRequest.getType()) {

        // create a user
        case USER:
          final CreateUserResponse createUserResponse = new CreateUserResponse();
          final CreateUserRequest createUserRequest = CreateUserRequest
              .checkRequest(formItemList, createRequest,
                  createUserResponse);
          createResponse = createUserResponse;

          if (createUserRequest != null) {
            // create user
            final CreateUser createUserCommand = new CreateUser(
                this, createUserResponse, createUserRequest);
            this.commandQueue.add(createUserCommand);

            commandStacked = true;
          }
          break;

        // create a follow edge
        case FOLLOW:
          final CreateFollowResponse createFollowResponse = new CreateFollowResponse();
          final CreateFollowRequest createFollowRequest = CreateFollowRequest
              .checkRequest(formItemList, createRequest,
                  createFollowResponse);
          createResponse = createFollowResponse;

          if (createFollowRequest != null) {
            // create follow edge
            final CreateFollow createFollowCommand = new CreateFollow(
                this, createFollowResponse, createFollowRequest);
            this.commandQueue.add(createFollowCommand);

            commandStacked = true;
          }
          break;

        // create a status update
        default:
          final CreateStatusUpdateResponse createStatusUpdateResponse = new CreateStatusUpdateResponse();
          final CreateStatusUpdateRequest createStatusUpdateRequest = CreateStatusUpdateRequest
              .checkRequest(formItemList, createRequest,
                  createStatusUpdateResponse);
          createResponse = createStatusUpdateResponse;

          if (createStatusUpdateRequest != null) {
            try {
              this.writeFiles(createStatusUpdateRequest
                  .getStatusUpdateTemplate(), formItemList);

              // create a new status update of the type specified
              final StatusUpdate statusUpdate = StatusUpdateManager
                  .instantiateStatusUpdate(
                      createStatusUpdateRequest
                          .getStatusUpdateTemplate()
                          .getName(), formItemList);
              statusUpdate.setId(createStatusUpdateRequest
                  .getStatusUpdateId());
              createStatusUpdateRequest
                  .setStatusUpdate(statusUpdate);

              // create status update
              final CreateStatusUpdate createStatusUpdateCommand = new CreateStatusUpdate(
                  this, createStatusUpdateResponse,
                  createStatusUpdateRequest);
              this.commandQueue.add(createStatusUpdateCommand);

              commandStacked = true;
            } catch (final StatusUpdateInstantiationFailedException e) {
              // remove the files
              FormFile fileItem;
              File file;
              for (String fileIdentifier : formItemList
                  .getFileIdentifiers()) {
                fileItem = formItemList.getFile(fileIdentifier);
                file = fileItem.getFile();

                if (file != null) {
                  file.delete();
                }
View Full Code Here


   */
  public static ProcessCreateResponse handleServlet(
      HttpServletRequest request, ServletContext context) {
    ProcessCreateResponse response = new ProcessCreateResponse(context);

    FormItemList items = null;
    try {
      items = FormItemList.extractFormItems(request, factory);
    } catch (FileUploadException e) {
      e.printStackTrace();
    }
View Full Code Here

  private ProcessCreateResponse processTestRequest(String key, String term,
      String weight, String index, FileItem image) {

    ProcessCreateResponse response = new ProcessCreateResponse(
        this.servletConfig.getServletContext());
    FormItemList testItems = new FormItemList();
    if (key != null) {
      testItems.addField(ProtocolConstants.SUGGESTION_KEY, key);
    }
    if (term != null) {
      testItems.addField(ProtocolConstants.SUGGESTION_STRING, term);
    }
    if (weight != null) {
      testItems.addField(ProtocolConstants.SUGGESTION_WEIGHT, weight);
    }
    if (index != null) {
      testItems.addField(ProtocolConstants.INDEX_PARAMETER, index);
    }
    if (image != null) {
      testItems.addFile(ProtocolConstants.IMAGE, image);
    }
    return ProcessCreateRequest.checkRequestParameter(testItems, response,
        this.servletConfig.getServletContext());
  }
View Full Code Here

  }

  private void fillRequest(final String type, final String userId,
      final String statusUpdateId, final String statusUpdateType) {
    // create form item list
    final FormItemList formItemList = new FormItemList();
    formItemList.addField(ProtocolConstants.Parameters.Create.TYPE, type);

    final CreateResponse createResponse = new CreateResponse();
    CreateRequest createRequest;
    createRequest = CreateRequest
        .checkRequest(formItemList, createResponse);

    if (createRequest == null) {
      this.jsonResponse = extractJson(createResponse);
    } else {
      formItemList
          .addField(
              ProtocolConstants.Parameters.Create.StatusUpdate.USER_IDENTIFIER,
              userId);
      formItemList
          .addField(
              ProtocolConstants.Parameters.Create.StatusUpdate.STATUS_UPDATE_IDENTIFIER,
              statusUpdateId);
      formItemList
          .addField(
              ProtocolConstants.Parameters.Create.StatusUpdate.STATUS_UPDATE_TYPE,
              statusUpdateType);

      final CreateStatusUpdateResponse createStatusUpdateResponse = new CreateStatusUpdateResponse();
View Full Code Here

   */
  public StatusUpdateCreationItem(final Node user, final long timestamp)
      throws StatusUpdateInstantiationFailedException {
    this.user = user;

    final FormItemList values = new FormItemList();
    values.addField("message", String.valueOf(timestamp));

    this.statusUpdate = StatusUpdateManager.instantiateStatusUpdate(
        "Plain", values);
  }
View Full Code Here

  private CreateFollowRequest createFollowRequest;

  private void fillRequest(final String type, final String userId,
      final String followedId) {
    // create form item list
    final FormItemList formItemList = new FormItemList();
    formItemList.addField(ProtocolConstants.Parameters.Create.TYPE, type);

    final CreateResponse createResponse = new CreateResponse();
    CreateRequest createRequest;
    createRequest = CreateRequest
        .checkRequest(formItemList, createResponse);

    if (createRequest == null) {
      this.jsonResponse = extractJson(createResponse);
    } else {
      formItemList.addField(
          ProtocolConstants.Parameters.Create.Follow.USER_IDENTIFIER,
          userId);
      formItemList.addField(
          ProtocolConstants.Parameters.Create.Follow.FOLLOWED_IDENTIFIER,
          followedId);

      final CreateFollowResponse createFollowResponse = new CreateFollowResponse();
      this.createFollowRequest = CreateFollowRequest.checkRequest(
View Full Code Here

  private CreateUserRequest createUserRequest;

  private void fillRequest(final String type, final String userId,
      final String displayName, final String profilePicturePath) {
    // create form item list
    final FormItemList formItemList = new FormItemList();
    formItemList.addField(ProtocolConstants.Parameters.Create.TYPE, type);

    final CreateResponse createResponse = new CreateResponse();
    CreateRequest createRequest;
    createRequest = CreateRequest
        .checkRequest(formItemList, createResponse);

    if (createRequest == null) {
      this.jsonResponse = extractJson(createResponse);
    } else {
      formItemList.addField(
          ProtocolConstants.Parameters.Create.User.USER_IDENTIFIER, userId);
      formItemList.addField(
          ProtocolConstants.Parameters.Create.User.DISPLAY_NAME,
          displayName);
      formItemList.addField(
          ProtocolConstants.Parameters.Create.User.PROFILE_PICTURE_PATH,
          profilePicturePath);

      final CreateUserResponse createUserResponse = new CreateUserResponse();
      this.createUserRequest = CreateUserRequest.checkRequest(
View Full Code Here

   *             if errors encountered while processing the request
   */
  public static CreateRequest checkRequest(final HttpServletRequest request,
      final DiskFileItemFactory factory,
      final CreateResponse createResponse) throws FileUploadException {
    final FormItemList formItemList = FormItemList.extractFormItems(
        request, factory);
    return checkRequest(formItemList, createResponse);
  }
View Full Code Here

TOP

Related Classes of de.metalcon.utils.FormItemList

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.