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);
    }
  }
  public void handlerCustom(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems,
      String operation)
      throws VerticalAdminException, VerticalEngineException {

    if (operation.equals("selectsite")) {
      String returnKey = null;
      String returnView = null;
      int returnRow = -1;

      if (!(request.getParameter("returnkey") == null
          || request.getParameter("returnkey").toString().equals(""))) {
        returnKey = request.getParameter("returnkey").toString();
      } else {
        String message = "Parameter not found: returnkey";
        VerticalAdminLogger.errorAdmin(message);
      }

      if (!(request.getParameter("returnview") == null
          || request.getParameter("returnview").toString().equals(""))) {
        returnView = request.getParameter("returnview").toString();
      } else {
        String message = "Parameter not found: returnview";
        VerticalAdminLogger.errorAdmin(message);
      }

      if (!(request.getParameter("returnrow") == null
          || request.getParameter("returnrow").toString().equals(""))) {
        returnRow = Integer.parseInt(request.getParameter("returnrow").toString());
      }

      Document doc = admin.getContentTypes(false).getAsDOMDocument();

      HashMap<String, String> parameters = new HashMap<String, String>();
      parameters.put("returnview", returnView);
      parameters.put("returnkey", returnKey);

      if (returnRow != -1) {
        parameters.put("returnrow", String.valueOf(returnRow));
      }

      transformXML(request, response, doc, "contenttype_selector.xsl", parameters);
    } else if ("regenerateindex".equals(operation)) {
      int contentTypeKey = formItems.getInt("contenttypekey");
      //            ( "regenerate index for content type key: " + contentTypeKey );

      admin.regenerateIndexForContentType(contentTypeKey);

      redirectClientToReferer(request, response);
    }
  }
Ejemplo n.º 3
0
  protected boolean logUserStoreLogin(
      User user,
      AdminService admin,
      String remoteIP,
      String remoteHost,
      UserStoreKey userStoreKey) {

    try {
      Document doc = XMLTool.createDocument("logentry");
      Element rootElement = doc.getDocumentElement();
      // UserStoreKey userStoreKey = user.getUserStoreKey();
      if (userStoreKey != null) {
        rootElement.setAttribute("userstorekey", String.valueOf(userStoreKey));
      }
      rootElement.setAttribute("sitekey", String.valueOf(0));
      rootElement.setAttribute("typekey", String.valueOf(LogType.LOGIN_USERSTORE.asInteger()));
      rootElement.setAttribute("inetaddress", remoteIP);
      XMLTool.createElement(doc, rootElement, "data");

      admin.createLogEntries(user, XMLTool.documentToString(doc));
    } catch (VerticalSecurityException vse) {
      String message = "Failed to create log entry because of security error: %t";
      VerticalAdminLogger.error(this.getClass(), 1, message, vse);
      return false;
    }

    return true;
  }
Ejemplo n.º 4
0
  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);
  }
  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);
  }
  /** Uses the form input to remove one selected content type from the system. */
  public void handlerRemove(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems,
      int key)
      throws VerticalAdminException, VerticalEngineException {

    User user = securityService.getLoggedInAdminConsoleUser();
    admin.removeContentType(user, key);
    redirectClientToReferer(request, response);
  }
  /** Provides a list of all the content types in the system. */
  public boolean handlerSelect(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems)
      throws VerticalAdminException {

    String returnKey = null;
    String returnView = null;
    int returnRow = -1;

    if (!(request.getParameter("returnkey") == null
        || request.getParameter("returnkey").toString().equals(""))) {
      returnKey = request.getParameter("returnkey").toString();
    } else {
      String message = "Parameter not found: returnkey";
      VerticalAdminLogger.errorAdmin(message);
    }

    if (!(request.getParameter("returnview") == null
        || request.getParameter("returnview").toString().equals(""))) {
      returnView = request.getParameter("returnview").toString();
    } else {
      String message = "Parameter not found: returnview";
      VerticalAdminLogger.errorAdmin(message);
    }

    if (!(request.getParameter("returnrow") == null
        || request.getParameter("returnrow").toString().equals(""))) {
      returnRow = Integer.parseInt(request.getParameter("returnrow").toString());
    }

    Document doc = admin.getContentTypes().getAsDOMDocument();

    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("returnview", returnView);
    parameters.put("returnkey", returnKey);

    if (returnRow != -1) {
      parameters.put("returnrow", String.valueOf(returnRow));
    }

    transformXML(request, response, doc, "contenttype_selector.xsl", parameters);

    return true;
  }
Ejemplo n.º 8
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);
          }
        }
      }
    }
  }
  public void handlerForm(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems)
      throws VerticalAdminException {

    boolean createContent = formItems.containsKey("create");
    boolean reloading = formItems.getString("reload", "").equals("true");
    boolean usehandlerindexing = false;
    HashMap<String, String> parameters = new HashMap<String, String>();
    Element contentTypeElem = null;
    Document xmlData = null;
    Document doc = null;
    String referer = request.getHeader("referer");

    int contentTypeKey = -1;
    String generateKey = formItems.getString("generatectykey", "");
    if (generateKey.equals("true")) {
      parameters.put("generatectykey", "true");
    } else {
      String keyStr = (String) request.getParameter("key");
      if (keyStr != null && keyStr.length() > 0) {
        contentTypeKey = Integer.parseInt(keyStr);
      }
    }

    int contentHandlerKey = formItems.getInt("contenthandlerkey", 0);

    if (reloading || hasErrors()) {
      if (reloading) {
        usehandlerindexing = true;
      }

      doc = XMLTool.createDocument("contenttypes");
      Document contentTypeDoc = XMLTool.domparse(buildContentTypeXML(formItems, reloading));
      contentTypeElem = contentTypeDoc.getDocumentElement();
      if (formItems.containsKey("key")) {
        int key = formItems.getInt("key");
        int contentCount = admin.getContentCountByContentType(key);
        contentTypeElem.setAttribute("contentcount", String.valueOf(contentCount));
      }
      doc.getDocumentElement().appendChild(doc.importNode(contentTypeElem, true));

      referer = formItems.getString("referer");
    } else if (contentTypeKey == -1) {
      // Blank form, make dummy document
      doc = XMLTool.createDocument("contenttypes");

      usehandlerindexing = true;

      // Create content type element
      contentTypeElem = XMLTool.createElement(doc, doc.getDocumentElement(), "contenttype");
      createContent = true;
    } else {
      // Edit content type
      xmlData = admin.getContentType(contentTypeKey, true).getAsDOMDocument();

      doc = xmlData;

      contentTypeElem = XMLTool.getElement(doc.getDocumentElement(), "contenttype");
      String contentHandlerString = contentTypeElem.getAttribute("contenthandlerkey");
      if (contentHandlerString.length() > 0) {
        contentHandlerKey = Integer.parseInt(contentHandlerString);
      }
      String cssString = contentTypeElem.getAttribute("csskey");
      if (cssString.length() > 0) {
        ResourceKey cssKey = new ResourceKey(cssString);
        parameters.put("cssname", cssKey.toString());

        ResourceFile contentTypeStylesheet = this.resourceService.getResourceFile(cssKey);
        if (contentTypeStylesheet == null) {
          parameters.put("cssexist", "false");
        } else {
          parameters.put("cssexist", "true");
        }
      }
    }
    Document contentHandlersDoc = admin.getContentHandlers().getAsDOMDocument();
    doc.getDocumentElement()
        .appendChild(doc.importNode(contentHandlersDoc.getDocumentElement(), true));

    addErrorsXML(doc);

    if (createContent) {
      parameters.put("create", "1");
    } else {
      parameters.put("create", "0");
    }
    parameters.put("referer", referer);

    if (contentHandlerKey > -1) {
      parameters.put("contenthandlerkey", Integer.toString(contentHandlerKey));
    }
    parameters.put("usehandlerindexing", String.valueOf(usehandlerindexing));
    parameters.put("page", String.valueOf(request.getParameter("page").toString()));
    parameters.put("errorInConfig", formItems.getString("errorInConfig", ""));

    transformXML(request, response, doc, "contenttype_form.xsl", parameters);
  }