Example #1
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;
  }
  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);
    }
  }
Example #3
0
  public void handlerPage(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      ExtendedMap formItems,
      ExtendedMap parameters,
      User oldUser,
      Document verticalDoc)
      throws VerticalAdminException, VerticalEngineException {

    Map<Integer, String> contentTypeKeyHandlerMapping = new HashMap<Integer, String>();

    UserEntity user = securityService.getUser(oldUser);
    String maximize = formItems.getString("maximize", null);

    // ----
    // get last modified
    // ----
    if (maximize == null || "lastmodified".equals(maximize)) {
      handleRecentItems(verticalDoc, contentTypeKeyHandlerMapping, formItems, user);
    }

    // ----
    // Get content assigned to current user
    // ----
    if (maximize == null || "assignedto".equals(maximize)) {
      handleAssignedToMe(verticalDoc, contentTypeKeyHandlerMapping, formItems, user);
    }

    // ----
    // Get content waiting for activation
    // ---

    if (maximize == null || "activation".equals(maximize)) {
      handleActivation(verticalDoc, contentTypeKeyHandlerMapping, formItems, user);
    }

    // Default browse config
    Document defaultBrowseConfig =
        AdminStore.getXml(session, "defaultbrowseconfig.xml").getAsDOMDocument();
    XMLTool.mergeDocuments(verticalDoc, defaultBrowseConfig, true);

    Document contentTypeKeyHandlerMappingDoc =
        createContentTypeKeyHandlerMappingXml(contentTypeKeyHandlerMapping);
    XMLTool.mergeDocuments(verticalDoc, contentTypeKeyHandlerMappingDoc, true);

    // Feedback
    addFeedback(verticalDoc, formItems);

    addParameters(formItems, parameters, maximize);

    transformXML(request, response, verticalDoc, "dashboard.xsl", parameters);
  }
Example #4
0
  protected static final Element buildAccessRightElement(
      Document doc, Element root, String key, ExtendedMap paramsInValue) {

    Element element = XMLTool.createElement(doc, root, "accessright");

    if (key != null) {
      element.setAttribute("groupkey", key);
    }
    element.setAttribute("grouptype", paramsInValue.getString("grouptype", ""));
    element.setAttribute("adminread", paramsInValue.getString("adminread", "false"));
    element.setAttribute("read", paramsInValue.getString("read", "false"));
    element.setAttribute("update", paramsInValue.getString("update", "false"));
    element.setAttribute("delete", paramsInValue.getString("delete", "false"));
    element.setAttribute("create", paramsInValue.getString("create", "false"));
    element.setAttribute("publish", paramsInValue.getString("publish", "false"));
    element.setAttribute("administrate", paramsInValue.getString("administrate", "false"));
    element.setAttribute("approve", paramsInValue.getString("approve", "false"));
    element.setAttribute("add", paramsInValue.getString("add", "false"));

    String displayName = paramsInValue.getString("name", null);
    if (displayName != null) {
      element.setAttribute("displayname", displayName);
    }

    return element;
  }
Example #5
0
  public void addErrorsXML(Document doc) {
    if (errorCodes.size() > 0) {
      Element errorsElem = XMLTool.createElement(doc, doc.getDocumentElement(), "errors");

      for (int i = 0; i < errorCodes.size(); i++) {
        ErrorCode ec = errorCodes.get(i);
        Element errorElem = XMLTool.createElement(doc, errorsElem, "error");
        errorElem.setAttribute("code", Integer.toString(ec.code));
        errorElem.setAttribute("name", ec.name);

        Element valueElem = XMLTool.createElement(doc, errorElem, "value");
        XMLTool.createCDATASection(doc, valueElem, ec.value);
      }
    }
    errorCodes.removeAllElements();
  }
  public String buildContentTypeXML(ExtendedMap formItems, boolean reload) {
    StringWriter sw = new StringWriter();

    try {
      Document doc = XMLTool.createDocument();

      // Create unit element
      Element contentType = XMLTool.createRootElement(doc, "contenttype");

      if (formItems.containsKey("key")) {
        contentType.setAttribute("key", formItems.getString("key"));
      }
      if (formItems.containsKey("sitekey")) {
        contentType.setAttribute("sitekey", formItems.getString("sitekey"));
      }
      if (formItems.containsKey("contenthandlerkey")) {
        contentType.setAttribute("contenthandlerkey", formItems.getString("contenthandlerkey"));
      }
      if (formItems.containsKey("csskey")) {
        contentType.setAttribute("csskey", formItems.getString("csskey"));
      }

      XMLTool.createElement(doc, contentType, "name", formItems.getString("name", ""));
      XMLTool.createElement(
          doc, contentType, "description", formItems.getString("description", ""));

      // Module XML
      String moduleXML = formItems.getString("module", "");
      if (moduleXML == null || moduleXML.length() == 0) {
        XMLTool.createElement(doc, contentType, "moduledata");
      } else {
        if (!reload) {
          try {
            Document modDocTemp = XMLTool.domparse(moduleXML, "contenttype");

            Document modDoc = XMLTool.createDocument("moduledata");
            XMLTool.mergeDocuments(modDoc, modDocTemp, false);

            contentType.appendChild(doc.importNode(modDoc.getDocumentElement(), true));
          } catch (Exception e) {
            addError(2, "module", moduleXML);
          }
        }
      }
      XMLTool.printDocument(sw, doc);
    } catch (Exception e) {
      System.err.println("[Error] Something failed:\n" + e.toString());
    }
    return sw.toString();
  }
Example #7
0
  public Object getDataFromXML(Node node) {
    String text = XMLTool.getNodeText(node);

    if (text == null || text.length() == 0) {
      return null;
    } else {
      return Boolean.valueOf(text);
    }
  }
Example #8
0
  private void toXML(final Element parent) {
    final Document doc = parent.getOwnerDocument();
    final Element sessionElem = XMLTool.createElement(doc, parent, "session");

    for (final Map.Entry<String, Object> entry : entrySet()) {
      final Element attributeElem = XMLTool.createElement(doc, sessionElem, "attribute");
      attributeElem.setAttribute("name", entry.getKey());

      final Object value = entry.getValue();
      if (value instanceof Document) {
        final Document xmlDoc = (Document) value;
        final Element rootElem = xmlDoc.getDocumentElement();
        attributeElem.appendChild(doc.importNode(rootElem, true));
      } else if (value != null) {
        XMLTool.createTextNode(doc, attributeElem, value.toString());
      }
    }
  }
Example #9
0
  protected String buildAccessRightsXML(String key, ExtendedMap formItems, int accessrightsType) {

    Document doc = buildAccessRightsXML(null, key, formItems, accessrightsType);
    if (doc != null) {
      return XMLTool.documentToString(doc);
    }

    return null;
  }
Example #10
0
  private void handleRecentItems(
      Document verticalDoc,
      Map<Integer, String> contentTypeKeyHandlerMapping,
      final ExtendedMap formItems,
      UserEntity user) {

    String maximize = formItems.getString("maximize", null);
    int index = formItems.getInt("index", 0);
    int count = formItems.getInt("count", maximize != null ? 20 : 10);

    ContentLogEntrySpecification logSpecification = new ContentLogEntrySpecification();
    logSpecification.setUser(user);
    logSpecification.setTypes(
        new LogType[] {LogType.ENTITY_OPENED, LogType.ENTITY_CREATED, LogType.ENTITY_UPDATED});
    logSpecification.setTableTypes(new Table[] {Table.CONTENT});
    logSpecification.setAllowDuplicateEntries(false);
    logSpecification.setAllowDeletedContent(false);

    Calendar now = GregorianCalendar.getInstance();
    final int monthsInPast = 3;
    now.add(Calendar.MONTH, -monthsInPast);
    logSpecification.setDateFilter(now.getTime());

    LogEntryResultSet logResult =
        logService.getLogEntries(logSpecification, "timestamp DESC", count, index);

    if (logResult.getLength() > 0) {

      // build contentTypeKey and handler mapping
      List<ContentKey> contentKeys = new ArrayList<ContentKey>();
      for (LogEntryEntity entity : logResult.getLogEntries()) {
        contentKeys.add(new ContentKey(entity.getKeyValue()));
      }

      ContentByContentQuery contentByContentQuery = new ContentByContentQuery();
      contentByContentQuery.setContentKeyFilter(contentKeys);
      contentByContentQuery.setUser(user);
      contentByContentQuery.setIndex(0);
      contentByContentQuery.setCount(logResult.getLength());
      ContentResultSet contentResultSet = contentService.queryContent(contentByContentQuery);
      for (ContentEntity entity : contentResultSet.getContents()) {
        contentTypeKeyHandlerMapping.put(
            entity.getContentType().getKey(),
            entity.getContentType().getContentHandlerName().getHandlerClassShortName());
      }
    }

    ContentLogXMLCreator logXMLCreator = new ContentLogXMLCreator();
    logXMLCreator.setIncludeContentData(true);
    logXMLCreator.setContentDao(contentDao);
    XMLDocument xmlDocument = logXMLCreator.createLogsDocument(logResult);

    Document lastModifiedDoc = xmlDocument.getAsDOMDocument();

    lastModifiedDoc.getDocumentElement().setAttribute("type", "lastmodified");
    XMLTool.mergeDocuments(verticalDoc, lastModifiedDoc, true);
  }
Example #11
0
  private void handleActivation(
      Document verticalDoc,
      Map<Integer, String> contentTypeKeyHandlerMapping,
      final ExtendedMap formItems,
      UserEntity user) {

    String maximize = formItems.getString("maximize", null);
    int index = formItems.getInt("index", 0);
    int count = formItems.getInt("count", maximize != null ? 20 : 3);

    ContentBySectionQuery contentBySectionQuery = new ContentBySectionQuery();
    contentBySectionQuery.setSectionFilterStatus(SectionFilterStatus.UNAPPROVED_ONLY);
    contentBySectionQuery.setSearchInAllSections();
    contentBySectionQuery.setCount(count);
    contentBySectionQuery.setUser(user);
    contentBySectionQuery.setOrderBy("timestamp DESC");
    contentBySectionQuery.setIndex(index);
    contentBySectionQuery.setFilterIncludeOfflineContent();
    contentBySectionQuery.setLevels(Integer.MAX_VALUE);

    List<CategoryAccessType> categoryAccessTypeFilter = new ArrayList<CategoryAccessType>();
    categoryAccessTypeFilter.add(CategoryAccessType.ADMINISTRATE);
    categoryAccessTypeFilter.add(CategoryAccessType.APPROVE);
    contentBySectionQuery.setCategoryAccessTypeFilter(
        categoryAccessTypeFilter, CategoryAccessTypeFilterPolicy.OR);

    ContentResultSet contentResultSet = null;
    try {
      contentResultSet = contentService.queryContent(contentBySectionQuery);
    } catch (Exception e) {
      throw new VerticalAdminException("Failed to get unapproved content", e);
    }

    // build contentTypeKey and handlerName mapping
    for (ContentEntity entity : contentResultSet.getContents()) {
      contentTypeKeyHandlerMapping.put(
          entity.getContentType().getKey(),
          entity.getContentType().getContentHandlerName().getHandlerClassShortName());
    }

    SectionXmlCreator sectionXmlCreator =
        new SectionXmlCreator(
            siteDao, new CategoryAccessResolver(groupDao), new ContentAccessResolver(groupDao));
    XMLDocument sectionDocument =
        sectionXmlCreator.createSectionsDocument(user, contentResultSet, count);

    Document waitingForActivationDoc = sectionDocument.getAsDOMDocument();
    // waitingForActivationDoc.getDocumentElement().setAttribute("type", "activation");

    XMLTool.mergeDocuments(verticalDoc, waitingForActivationDoc, true);
  }
Example #12
0
  public static final Document buildAccessRightsXML(
      Element rootElem, String key, ExtendedMap formItems, int accessrightsType) {

    // Handle this in calling methods instead
    // if (!formItems.containsKey("updateaccessrights"))
    //    return null;

    Document doc;
    Element elmAccessRights;
    if (rootElem != null) {
      doc = rootElem.getOwnerDocument();
      elmAccessRights = XMLTool.createElement(doc, rootElem, "accessrights");
    } else {
      doc = XMLTool.createDocument("accessrights");
      elmAccessRights = doc.getDocumentElement();
    }

    if (key != null) {
      elmAccessRights.setAttribute("key", key);
    }
    if (accessrightsType != Integer.MIN_VALUE) {
      elmAccessRights.setAttribute("type", String.valueOf(accessrightsType));
    }

    for (Object parameterKey : formItems.keySet()) {
      String paramName = (String) parameterKey;
      if (paramName.startsWith("accessright[key=")) {
        String paramValue = formItems.getString(paramName);
        ExtendedMap paramsInName = ParamsInTextParser.parseParamsInText(paramName, "[", "]", ";");
        ExtendedMap paramsInValue = ParamsInTextParser.parseParamsInText(paramValue, "[", "]", ";");

        buildAccessRightElement(doc, elmAccessRights, paramsInName.getString("key"), paramsInValue);
      }
    }

    return doc;
  }
Example #13
0
  private void handleAssignedToMe(
      Document verticalDoc,
      Map<Integer, String> contentTypeKeyHandlerMapping,
      final ExtendedMap formItems,
      UserEntity user) {
    String maximize = formItems.getString("maximize", null);
    int index = formItems.getInt("index", 0);
    int count = formItems.getInt("count", maximize != null ? 20 : ASSIGNED_TO_COUNT);

    ContentSpecification contentSpecification = new ContentSpecification();
    // contentSpecification.setUser( user );
    contentSpecification.setAssignee(user);
    contentSpecification.setAssignedDraftsOnly(false);

    ContentResultSet contentResultSet =
        contentService.getContent(
            contentSpecification, "c.assignmentDueDate ASC, c.timestamp DESC", count, index);

    for (ContentEntity content : contentResultSet.getContents()) {
      contentTypeKeyHandlerMapping.put(
          content.getContentType().getKey(),
          content.getContentType().getContentHandlerName().getHandlerClassShortName());
    }

    ContentXMLCreator contentXMLCreator = new ContentXMLCreator();
    contentXMLCreator.setResultIndexing(index, count);
    contentXMLCreator.setIncludeOwnerAndModifierData(true);
    contentXMLCreator.setIncludeContentData(true);
    contentXMLCreator.setIncludeCategoryData(true);
    contentXMLCreator.setIncludeAccessRightsInfo(false);
    contentXMLCreator.setIncludeRelatedContentsInfo(false);
    contentXMLCreator.setIncludeRepositoryPathInfo(true);
    contentXMLCreator.setIncludeVersionsInfoForAdmin(true);
    contentXMLCreator.setIncludeAssignment(true);
    contentXMLCreator.setIncludeDraftInfo(true);
    contentXMLCreator.setIncludeSectionActivationInfo(true);
    XMLDocument xmlDocument =
        contentXMLCreator.createContentVersionsDocument(
            user, contentResultSet, new RelatedContentResultSetImpl());

    Document doc = xmlDocument.getAsDOMDocument();
    doc.getDocumentElement().setAttribute("type", "assignedto");

    XMLTool.mergeDocuments(verticalDoc, doc, true);
  }
  private Document filterResources(Document resourceDoc, String searchText) {

    if (searchText == null || searchText.length() == 0) {
      return resourceDoc;
    }

    Element root = resourceDoc.getDocumentElement();
    Element[] children = XMLTool.selectElements(root, "//resource");

    for (Element child : children) {
      String name = child.getAttribute("name");
      if (!name.toLowerCase().contains(searchText.toLowerCase())) {
        child.getParentNode().removeChild(child);
      }
    }

    return resourceDoc;
  }
Example #15
0
 public Document toXML() {
   final Document doc = XMLTool.createDocument("sessions");
   toXML(doc.getDocumentElement());
   return doc;
 }
Example #16
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);
          }
        }
      }
    }
  }
Example #17
0
 public String toString() {
   return XMLTool.documentToString(toXML());
 }
  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);
  }
Example #19
0
  protected Document applyChangesInAccessRights(
      Document docExistingAccessRights,
      Map<String, ExtendedMap> removedAccessRights,
      Map<String, ExtendedMap> modifiedAccessRights,
      Map<String, ExtendedMap> addedAccessRights) {

    // We have to make a clone of this hashtable, because we may have to remove some elements
    // and we don't want to affect this on the original hashtable.
    addedAccessRights = new HashMap<String, ExtendedMap>(addedAccessRights);

    // ("removedAccessRights = " + removedAccessRights);
    // ("modifiedAccessRights = " + modifiedAccessRights);
    // ("addedAccessRights = " + addedAccessRights);

    Element elExistingAccessRights = docExistingAccessRights.getDocumentElement();

    // ("antall accessrights: " + elExistingAccessRights.getChildNodes().getLength());
    // Loop thru existing accessrights and check if there is anyone to remove or modify
    Element curAccessRight = (Element) elExistingAccessRights.getFirstChild();
    while (curAccessRight != null) {

      String groupKey = curAccessRight.getAttribute("groupkey");
      // ("checking accessright, groupkey = " + groupKey);

      boolean remove = removedAccessRights.containsKey(groupKey);
      boolean modify = modifiedAccessRights.containsKey(groupKey);
      boolean add = addedAccessRights.containsKey(groupKey);
      boolean overwrite = (modify || add);

      // Remove accessright
      if (remove) {

        // ("removing accessright, groupkey = " + groupKey);
        curAccessRight = XMLTool.removeChildFromParent(elExistingAccessRights, curAccessRight);
      }
      // Overwrite accessright
      else if (overwrite) {

        ExtendedMap params;
        if (modify) {
          params = modifiedAccessRights.get(groupKey);
          // ("modifying/overwriting accessright, groupkey = " + groupKey);
        } else // add == true:
        {
          params = addedAccessRights.get(groupKey);
          // ("adding/overwriting accessright, groupkey = " + groupKey);
        }

        Document docNewAccessRight = XMLTool.createDocument("foo");
        Element elNewAccessRight =
            buildAccessRightElement(
                docNewAccessRight, docNewAccessRight.getDocumentElement(), groupKey, params);

        Element imported = (Element) docExistingAccessRights.importNode(elNewAccessRight, true);
        elExistingAccessRights.replaceChild(imported, curAccessRight);
        curAccessRight = imported;

        // Hvis vi overskriver eksisterende rettighet i stedet for å legge til, fordi den finnes fra
        // før
        // må vi fjerne rettigheten fra addedAccessRights, slik at vi ikke legger til den to ganger.
        if (add) {
          // ("Found an accessright that we wanted to add, that existed - we overwrite it
          // inseated, and removes the groupkey ("+groupKey+")from the addAccessRights hashtable so
          // that it
          // want be added later");
          addedAccessRights.remove(groupKey);
        }

        //
        curAccessRight = (Element) curAccessRight.getNextSibling();
      } else {
        curAccessRight = (Element) curAccessRight.getNextSibling();
      }
    }
    // Add new accessrights
    for (Object addedAccessRightKey : addedAccessRights.keySet()) {
      String currentGroupKey = (String) addedAccessRightKey;

      // ("adding new accessright, groupkey = " + currentGroupKey);

      ExtendedMap params = addedAccessRights.get(currentGroupKey);
      Document docNewAccessRight = XMLTool.createDocument("foo");
      Element elNewAccessRight =
          buildAccessRightElement(
              docNewAccessRight, docNewAccessRight.getDocumentElement(), currentGroupKey, params);

      elExistingAccessRights.appendChild(
          docExistingAccessRights.importNode(elNewAccessRight, true));
    }

    return docExistingAccessRights;
  }
Example #20
0
  protected Document buildChangedAccessRightsXML(ExtendedMap formItems) {

    Document doc = XMLTool.createDocument("changedaccessrights");
    Element changed = doc.getDocumentElement();

    // Lager xml for diffen - de som er fjernet
    for (Object parameterKey : formItems.keySet()) {

      String paramName = (String) parameterKey;
      if (paramName.startsWith("original_accessright[key=")) {

        ExtendedMap paramsInName = ParamsInTextParser.parseParamsInText(paramName, "[", "]", ";");
        String key = paramsInName.getString("key");

        if (!formItems.containsKey("accessright[key=" + key + "]")) {
          String paramValue = formItems.getString(paramName);
          ExtendedMap paramsInValue =
              ParamsInTextParser.parseParamsInText(paramValue, "[", "]", ";");
          Element elmAccessRight = buildAccessRightElement(doc, changed, key, paramsInValue);
          elmAccessRight.setAttribute("diffinfo", "removed");
        }
      }
    }
    // Lager xml for diffen - de som er lagt til
    for (Object parameterKey : formItems.keySet()) {
      String paramName = (String) parameterKey;
      if (paramName.startsWith("accessright[key=")) {

        ExtendedMap paramsInName = ParamsInTextParser.parseParamsInText(paramName, "[", "]", ";");
        String key = paramsInName.getString("key");

        if (!formItems.containsKey("original_accessright[key=" + key + "]")) {

          String paramValue = formItems.getString(paramName);
          ExtendedMap paramsInValue =
              ParamsInTextParser.parseParamsInText(paramValue, "[", "]", ";");

          Element elmAccessRight = buildAccessRightElement(doc, changed, key, paramsInValue);
          elmAccessRight.setAttribute("diffinfo", "added");
        }
      }
    }
    // Lager xml for diffen - de som er endret
    for (Object paramKey : formItems.keySet()) {

      String paramName = (String) paramKey;

      if (paramName.startsWith("accessright[key=")) {

        ExtendedMap paramsInName = ParamsInTextParser.parseParamsInText(paramName, "[", "]", ";");
        String key = paramsInName.getString("key");

        if (formItems.containsKey("original_accessright[key=" + key + "]")) {

          String originalValue = formItems.getString("original_accessright[key=" + key + "]");
          String currentValue = formItems.getString(paramName);
          if (!currentValue.equals(originalValue)) {

            ExtendedMap paramsInValue =
                ParamsInTextParser.parseParamsInText(currentValue, "[", "]", ";");
            Element elmAccessRight = buildAccessRightElement(doc, changed, key, paramsInValue);
            elmAccessRight.setAttribute("diffinfo", "modified");
          }
        }
      }
    }

    return doc;
  }
Example #21
0
 public void addFeedback(Document doc, int feedbackCode) {
   Element feedbackElem =
       XMLTool.createElementIfNotPresent(doc, doc.getDocumentElement(), "feedback");
   feedbackElem.setAttribute("code", String.valueOf(feedbackCode));
 }
Example #22
0
 public Object getDataFromXML(Node node) {
   Document tmpDoc = XMLTool.createDocument();
   tmpDoc.appendChild(tmpDoc.importNode(node, true));
   return XMLTool.documentToString(tmpDoc);
 }