Esempio n. 1
0
  @SuppressWarnings("unchecked")
  private void handlerCreateContentWizardStep1(
      HttpServletRequest request,
      HttpServletResponse response,
      ExtendedMap formItems,
      ExtendedMap parameters,
      User user)
      throws VerticalAdminException, VerticalEngineException {

    final UserEntity runningUser = securityService.getUser(user);
    List<ContentTypeEntity> filteredContentTypes = new ArrayList<ContentTypeEntity>();

    for (ContentTypeEntity contentType : contentTypeDao.getAll()) {
      if (userHasAccessOnCategoriesOfContentType(runningUser, contentType, CREATE_BROWSE)) {
        filteredContentTypes.add(contentType);
      }
    }

    ContentTypeXmlCreator xmlCreator = new ContentTypeXmlCreator();
    XMLDocument doc = xmlCreator.createContentTypesDocument(filteredContentTypes);

    parameters.put("step", "1");
    parameters.put("source", formItems.getString("source", "mypage"));
    parameters.put("subop", formItems.getString("subop", ""));
    parameters.put("fieldrow", formItems.getString("fieldrow", ""));
    parameters.put("fieldname", formItems.getString("fieldname", ""));
    transformXML(request, response, doc.getAsJDOMDocument(), "createcontentwizard.xsl", parameters);
  }
Esempio n. 2
0
  private void addParameters(ExtendedMap formItems, ExtendedMap parameters, String maximize) {
    int index = formItems.getInt("index", 0);
    int count = formItems.getInt("count", maximize != null ? 20 : ASSIGNED_TO_COUNT);

    parameters.put("index", index);
    parameters.put("count", count);
    parameters.put("maximize", maximize);
  }
  public void handlerCustom(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems,
      String operation,
      ExtendedMap parameters,
      User user,
      Document verticalDoc)
      throws VerticalAdminException, VerticalEngineException, MessagingException, IOException {

    if (operation.equals("insert")) {
      int categoryKey = formItems.getInt("cat");
      int unitKey = admin.getUnitKey(categoryKey);
      int page = formItems.getInt("page");

      ExtendedMap xslParams = new ExtendedMap();
      xslParams.put("page", String.valueOf(page));

      Document newDoc =
          admin
              .getContent(user, Integer.parseInt(formItems.getString("key")), 0, 1, 0)
              .getAsDOMDocument();
      if (newDoc != null) {
        String filename = XMLTool.getElementText(newDoc, "/contents/content/contentdata/name");
        int index = filename.lastIndexOf(".");
        if (index != -1) {
          String filetype = filename.substring(index + 1).toLowerCase();
          if ("swf".equals(filetype)) {
            xslParams.put("flash", "true");
          } else if ("jpg".equals(filetype)
              || "jpeg".equals(filetype)
              || "png".equals(filetype)
              || "gif".equals(filetype)) {
            xslParams.put("image", "true");
          }
        }
      }

      Document xmlCategory =
          admin.getSuperCategoryNames(categoryKey, false, true).getAsDOMDocument();
      XMLTool.mergeDocuments(newDoc, xmlCategory, true);

      addCommonParameters(admin, user, request, xslParams, unitKey, -1);

      if (formItems.containsKey("subop")) {
        xslParams.put("subop", formItems.getString("subop"));
      }

      transformXML(request, response, newDoc, "editor/" + "imagepopup_selected.xsl", xslParams);
    } else {
      super.handlerCustom(
          request, response, session, admin, formItems, operation, parameters, user, verticalDoc);
    }
  }
Esempio n. 4
0
  private ExtendedMap parseSimpleRequest(HttpServletRequest request, boolean keepEmpty) {
    ExtendedMap formItems = new ExtendedMap(keepEmpty);

    Enumeration paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
      String key = paramNames.nextElement().toString();
      String[] paramValues = request.getParameterValues(key);

      if (paramValues != null) {
        if (paramValues.length == 1 && paramValues[0] != null) {
          String value = paramValues[0];
          if (value.length() > 0) {
            if ("true".equals(value)) {
              formItems.putBoolean(key, true);
            } else if ("false".equals(value)) {
              formItems.putBoolean(key, false);
            } else {
              formItems.putString(key, value);
            }
          } else if (keepEmpty) {
            formItems.putString(key, value);
          }
        } else if (paramValues.length > 1) {
          formItems.put(key, paramValues);
        }
      }
    }

    return formItems;
  }
  public void handlerBrowse(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems,
      ExtendedMap parameters,
      User user,
      Document verticalDoc)
      throws VerticalAdminException, TransformerException, IOException {

    String path = formItems.getString("path", "/");
    String deploymentPath = DeploymentPathResolver.getAdminDeploymentPath(request);
    String resourcePickerPathBase64Encoded = Base64Util.encode(path.getBytes("UTF-8"));
    String resourcePickerPathBase64EncodedAndUrlEncoded =
        UrlPathEncoder.encode(resourcePickerPathBase64Encoded);
    CookieUtil.setCookie(
        response,
        "resourcePickerPath",
        resourcePickerPathBase64EncodedAndUrlEncoded,
        ContentBaseHandlerServlet.COOKIE_TIMEOUT,
        deploymentPath);

    Document doc;
    if (request.getParameter("searchtext") != null) {
      String searchText = formItems.getString("searchtext", "");
      doc = admin.getResourceTreeXml(path, true, true, -1, true, true).getAsDOMDocument();
      doc = filterResources(doc, searchText);
      parameters.put("searchtext", searchText);
      parameters.put("search", "true");
    } else {
      doc = admin.getResourceTreeXml(path, true, true, 1, false, true).getAsDOMDocument();
    }

    addAccessLevelParameters(user, parameters);

    parameters.put("mimetype", formItems.get("mimetype", ""));
    parameters.put("extension", formItems.get("extension", ""));
    parameters.put("fieldname", formItems.get("fieldname"));
    parameters.put("path", doc.getDocumentElement().getAttribute("root"));
    parameters.put("sortby", formItems.get("sortby", "@name"));
    parameters.put("sortby-direction", formItems.get("sortby-direction", "ascending"));
    parameters.put("reload", formItems.get("reload", false));
    parameters.put("move", formItems.get("move", false));

    transformXML(request, response, doc, "resource_browse.xsl", parameters);
  }
  private void handlerPopup(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems,
      ExtendedMap parameters,
      User user,
      Document verticalDoc)
      throws VerticalAdminException {

    parameters.put("mimetype", formItems.get("mimetype", ""));
    parameters.put("extension", formItems.get("extension", ""));
    parameters.put("fieldname", formItems.get("fieldname"));
    parameters.put("user-agent", request.getHeader("user-agent"));

    transformXML(request, response, verticalDoc, "resource_selector_frameset.xsl", parameters);
  }
  public void handlerMenu(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems,
      ExtendedMap parameters,
      User user,
      Document verticalDoc)
      throws VerticalAdminException, TransformerException, IOException {

    // get resource tree xml
    ResourceFolder root = resourceService.getResourceRoot();
    ResourceXmlCreator xmlCreator = new ResourceXmlCreator();
    xmlCreator.setIncludeFullPath(true);
    xmlCreator.setListFolders(true);
    xmlCreator.setListResources(false);
    XMLDocument resourcesDoc = xmlCreator.createResourceTreeXml(root);

    Cookie cookie = CookieUtil.getCookie(request, "resourcePickerPath");
    if (cookie != null) {
      try {
        String resourcePickerPathBase64AndUrlEncoded = cookie.getValue();
        String resourcePickerPathBase64Encoded =
            UrlPathDecoder.decode(resourcePickerPathBase64AndUrlEncoded);
        String resourcePickerPath =
            new String(Base64Util.decode(resourcePickerPathBase64Encoded), "UTF-8");
        if (resourcePickerPath != null) {
          parameters.put("path", resourcePickerPath);
        }
      } catch (IllegalArgumentException e) {
        LOG.warn("Value in Cookie 'resourcePickerPath' is not base64 encoded ");
      }
    }

    // add popup parameters
    parameters.put("mimetype", formItems.get("mimetype", ""));
    parameters.put("extension", formItems.get("extension", ""));
    parameters.put("fieldname", formItems.get("fieldname"));
    parameters.put("subop", formItems.get("subop", ""));
    parameters.put("sourceKey", formItems.get("sourceKey", ""));
    parameters.put("destinationKey", formItems.get("destinationKey", ""));

    transformXML(
        request,
        response,
        resourcesDoc.getAsDOMDocument(),
        "resource_selector_frame1.xsl",
        parameters);
  }
  public void handlerCreate(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems)
      throws VerticalAdminException, VerticalEngineException {

    User user = securityService.getLoggedInAdminConsoleUser();

    // Enforce unique names
    String name = formItems.getString("name");
    if (admin.getContentTypeKeyByName(name) > -1) {
      addError(7, "name", name);
    }

    String xmlData = buildContentTypeXML(formItems, false);

    ContentHandlerKey contentHandlerKey =
        new ContentHandlerKey(formItems.getString("contenthandlerkey"));
    ContentHandlerEntity contentHandler = contentHandlerDao.findByKey(contentHandlerKey);
    ContentHandlerName contentHandlerName = ContentHandlerName.parse(contentHandler.getClassName());
    String errorInConfig = validateConfig(contentHandlerName, xmlData);

    if (this.hasErrors() || errorInConfig != null) {
      if (errorInConfig != null) {
        String moduleXML = formItems.getString("module", "");
        addError(2, "module", moduleXML);
        formItems.put("errorInConfig", errorInConfig);
      }
      handlerForm(request, response, session, admin, formItems);
      return;
    }

    admin.createContentType(user, xmlData);

    MultiValueMap queryParams = new MultiValueMap();
    queryParams.put("page", formItems.get("page"));
    queryParams.put("op", "browse");
    redirectClientToAdminPath("adminpage", queryParams, request, response);
  }
  /** Insert the method's description here. */
  public void handlerBrowse(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems)
      throws VerticalAdminException {

    List<ContentTypeEntity> allContentTypes = contentTypeDao.getAll();
    ContentTypeXmlCreator xmlCreator = new ContentTypeXmlCreator();

    XMLDocument contentTypesDoc = xmlCreator.createContentTypesDocument(allContentTypes);

    Document doc = contentTypesDoc.getAsDOMDocument();

    // Parameters
    ExtendedMap parameters = new ExtendedMap();
    parameters.put("page", String.valueOf(request.getParameter("page").toString()));
    addSortParamteres("name", "ascending", formItems, session, parameters);

    transformXML(request, response, doc, "contenttype_browse.xsl", parameters);
  }
Esempio n. 10
0
  @SuppressWarnings("unchecked")
  private void handlerCreateContentWizardStep2(
      HttpServletRequest request,
      HttpServletResponse response,
      ExtendedMap formItems,
      ExtendedMap parameters,
      User user)
      throws VerticalAdminException, VerticalEngineException {

    final UserEntity runningUser = securityService.getUser(user);

    ContentTypeKey contentTypeKey = new ContentTypeKey(formItems.getInt("contenttypekey"));
    CategoryKey topCategoryKey = CategoryKey.parse(formItems.getInt("topcategorykey", -1));

    CategoryXmlCreator xmlCreator = new CategoryXmlCreator();
    xmlCreator.setCategoryAccessResolver(new CategoryAccessResolver(groupDao));
    xmlCreator.setUser(runningUser);
    xmlCreator.setAnonymousUser(securityService.getUser(securityService.getAnonymousUserKey()));
    xmlCreator.setAllowedContentType(contentTypeKey);
    xmlCreator.setIncludeOwnerAndModiferInfo(false);
    xmlCreator.setIncludeCreatedAndTimestampInfo(false);
    xmlCreator.setIncludeAutoApproveInfo(false);
    xmlCreator.setIncludeDescriptionInfo(false);
    xmlCreator.setIncludeSuperCategoryKeyInfo(false);
    xmlCreator.setRootAccess(false);

    List<CategoryEntity> rootCategories;
    if (runningUser.isEnterpriseAdmin()) {
      rootCategories = categoryDao.findRootCategories();
    } else {
      rootCategories = categoryDao.findRootCategories(runningUser.getAllMembershipsGroupKeys());
    }
    final XMLDocument doc = xmlCreator.createCategoryBranch(rootCategories, topCategoryKey);

    parameters.put("step", "2");
    parameters.put("contenttypekey", contentTypeKey);
    parameters.put("source", formItems.getString("source"));
    parameters.put("subop", formItems.getString("subop", ""));
    parameters.put("fieldrow", formItems.getString("fieldrow", ""));
    parameters.put("fieldname", formItems.getString("fieldname", ""));
    transformXML(request, response, doc.getAsJDOMDocument(), "createcontentwizard.xsl", parameters);
  }
Esempio n. 11
0
  /**
   * Process incoming requests for information
   *
   * @param request Object that encapsulates the request to the servlet
   * @param response Object that encapsulates the response from the servlet
   */
  private void performTask(HttpServletRequest request, HttpServletResponse response) {
    HttpSession session;
    session = request.getSession(false);
    response.setContentType("text/html;charset=UTF-8");

    // Make IE 9 behave like IE 8
    // http://msdn.microsoft.com/en-us/library/cc288325%28v=vs.85%29.aspx#Servers
    response.setHeader("X-UA-Compatible", "IE=EmulateIE8");

    if (session == null) {
      VerticalAdminLogger.debug(
          this.getClass(), 100, "Session is null. Redirecting to login.", null);

      // failed to get session, redirect to login page
      try {
        redirectClientToAdminPath("login", (MultiValueMap) null, request, response);
      } catch (VerticalAdminException vae) {
        String message = "Failed to redirect to login page: %t";
        VerticalAdminLogger.fatalAdmin(this.getClass(), 0, message, vae);
      }
    } else {
      // lookup admin bean
      AdminService admin = lookupAdminBean();
      User user = securityService.getLoggedInAdminConsoleUser();
      if (user == null) {
        // no logged in user, invalidate session and redirect to login page
        String message = "No user logged in. Redirecting to login.";
        VerticalAdminLogger.debug(this.getClass(), 0, message, null);
        try {
          redirectClientToAdminPath("login", (MultiValueMap) null, request, response);
        } catch (VerticalAdminException vae) {
          message = "Failed to redirect to login page: %t";
          VerticalAdminLogger.fatalAdmin(this.getClass(), 0, message, vae);
        }
      } else {
        response.setContentType("text/html; charset=UTF-8");
        try {
          ExtendedMap formItems = parseForm(request, false);

          String operation;
          if (formItems.containsKey("op")) {
            operation = formItems.getString("op");
          } else {
            operation = request.getParameter("op");
          }

          // Common parameters and variables
          ExtendedMap parameters = new ExtendedMap();
          int unitKey = formItems.getInt("selectedunitkey", -1);
          int menuKey = formItems.getInt("selectedmenukey", -1);
          int page = formItems.getInt("page", -1);
          if (page == 993) {
            int contentKey = -1;

            String contentKeyStr = request.getParameter("key");
            if (contentKeyStr != null) {
              contentKey = Integer.parseInt(contentKeyStr);
            }

            if (contentKey == -1) {
              String versionKeyStr = request.getParameter("versionkey");
              if (versionKeyStr != null) {
                int versionKey = Integer.parseInt(versionKeyStr);
                contentKey = admin.getContentKeyByVersionKey(versionKey);
              }
            }

            if (contentKey != -1) {
              int contentTypeKey = admin.getContentTypeKey(contentKey);
              page = contentTypeKey + 999;
              formItems.put("page", page);
            }
          }

          if (page == 991) {
            int categoryKey = formItems.getInt("categorykey", -1);
            if (categoryKey == -1) {
              categoryKey = formItems.getInt("cat", -1);
            }

            if (categoryKey != -1) {
              int contentTypeKey = admin.getContentTypeKeyByCategory(categoryKey);
              if (contentTypeKey != -1) {
                page = contentTypeKey + 999;
              }
            }
          }
          parameters.put("page", Integer.toString(page));
          addCommonParameters(admin, user, request, parameters, unitKey, menuKey);
          Document verticalDoc = XMLTool.createDocument("data");

          if ("create".equals(operation)) {
            handlerCreate(request, response, session, admin, formItems);
          } else if ("update".equals(operation)) {
            handlerUpdate(request, response, session, admin, formItems);
          } else if ("remove".equals(operation)) {
            String keyStr = request.getParameter("key");
            if (StringUtil.isIntegerString(keyStr)) {
              int key = -1;
              try {
                key = Integer.parseInt(keyStr);
              } catch (NumberFormatException nfe) {
                String message = "Failed to parse key (%0): %t";
                VerticalAdminLogger.errorAdmin(this.getClass(), 5, message, keyStr, nfe);
              }
              handlerRemove(request, response, session, admin, formItems, key);
            } else {
              handlerRemove(request, response, session, admin, formItems, keyStr);
            }
          } else if ("copy".equals(operation)) {
            String keyStr = request.getParameter("key");
            int key = -1;
            try {
              key = Integer.parseInt(keyStr);
            } catch (NumberFormatException nfe) {
              String message = "Failed to parse key (%0): %t";
              VerticalAdminLogger.errorAdmin(this.getClass(), 5, message, keyStr, nfe);
            }

            handlerCopy(request, response, session, admin, formItems, user, key);
          } else if ("import".equals(operation)) {
            throw new IllegalArgumentException("Unsupported operation: import");
          } else if ("browse".equals(operation)) {
            handlerBrowse(
                request, response, session, admin, formItems, parameters, user, verticalDoc);
          } else if ("select".equals(operation)) {
            handlerSelect(request, response, session, admin, formItems);
          } else if ("show".equals(operation)) {
            handlerShow(request, response, session, admin, formItems);
          } else if ("form".equals(operation)) {
            this.clearErrors();
            handlerForm(request, response, session, admin, formItems);
          } else if ("searchform".equals(operation)) {
            handlerSearch(request, response, session, admin, formItems);
          } else if ("searchresults".equals(operation)) {
            handlerSearchResults(request, response, session, admin, formItems);
          } else if ("report".equals(operation)) {
            String subOp = formItems.getString("subop");
            handlerReport(request, response, session, admin, formItems, subOp);
          } else if ("closewindow".equals(operation)) {
            closeWindow(response);
          } else if ("preview".equals(operation)) {
            handlerPreview(request, response, session, admin, formItems);
          } else if ("menu".equals(operation)) {
            handlerMenu(
                request, response, session, admin, formItems, parameters, user, verticalDoc);
          } else if ("notify".equals(operation)) {
            handlerNotify(request, response, session, admin, formItems, user);
          } else if ("wizard".equals(operation)) {
            String wizardName = formItems.getString("name");
            handlerWizard(
                request, response, session, admin, formItems, parameters, user, wizardName);
          } else if (operation != null) {
            handlerCustom(
                request,
                response,
                session,
                admin,
                formItems,
                operation,
                parameters,
                user,
                verticalDoc);
          } else {
            handlerCustom(request, response, session, admin, formItems, "missing");
          }
        } catch (Exception e) {
          try {
            if (!(e instanceof VerticalException) && !(e instanceof VerticalRuntimeException)) {
              String message = "Unexpected error occurred during handling of admin page: %t";
              VerticalAdminLogger.error(this.getClass(), 8, message, e);
            }
            ErrorPageServlet.Error error = new ErrorPageServlet.ThrowableError(e);
            session.setAttribute("com.enonic.vertical.error", error);
            redirectClientToAdminPath("errorpage", (MultiValueMap) null, request, response);
          } catch (VerticalAdminException vae) {
            String message = "Failed to redirect to error page: %t";
            VerticalAdminLogger.fatalAdmin(this.getClass(), 0, message, vae);
          }
        }
      }
    }
  }
Esempio n. 12
0
  private ExtendedMap parseMultiPartRequest(HttpServletRequest request)
      throws FileUploadException, IOException {
    ExtendedMap formItems = new ExtendedMap();
    List paramList = fileUpload.parseRequest(request);
    for (Object parameter : paramList) {
      FileItem fileItem = (FileItem) parameter;

      String name = fileItem.getFieldName();

      if (fileItem.isFormField()) {
        String value = fileItem.getString("UTF-8");
        if (formItems.containsKey(name)) {
          ArrayList<Object> values = new ArrayList<Object>();
          Object obj = formItems.get(name);
          if (obj instanceof Object[]) {
            String[] objArray = (String[]) obj;
            for (int i = 0; i < objArray.length; i++) {
              values.add(objArray[i]);
            }
          } else {
            values.add(obj);
          }
          values.add(value);
          formItems.put(name, values.toArray(new String[values.size()]));
        } else {
          formItems.put(name, value);
        }
      } else {
        if (fileItem.getSize() > 0) {
          if (formItems.containsKey(name)) {
            ArrayList<Object> values = new ArrayList<Object>();
            Object obj = formItems.get(name);
            if (obj instanceof FileItem[]) {
              FileItem[] objArray = (FileItem[]) obj;
              for (int i = 0; i < objArray.length; i++) {
                values.add(objArray[i]);
              }
            } else {
              values.add(obj);
            }
            values.add(fileItem);
            formItems.put(name, values.toArray(new FileItem[values.size()]));
          } else {
            formItems.put(name, fileItem);
          }
        }
      }
    }

    // Add parameters from url
    Map paramMap = URLUtil.decodeParameterMap(request.getParameterMap());
    for (Object parameterEntry : paramMap.entrySet()) {
      Map.Entry entry = (Map.Entry) parameterEntry;
      String key = (String) entry.getKey();
      String[] values = (String[]) entry.getValue();
      for (String value : values) {
        formItems.put(key, value);
      }
    }

    // Remove all empty parameters that are NOT in an array
    ArrayList<String> remove = new ArrayList<String>();
    for (Object parameterKey : formItems.keySet()) {
      String key = (String) parameterKey;
      Object value = formItems.get(key);
      if (!(value instanceof String[])
          && value instanceof String
          && ((String) value).length() == 0) {
        remove.add(key);
      }
    }
    for (String key : remove) {
      formItems.remove(key);
    }

    return formItems;
  }