private void addSiteNodeInconsistency(List inconsistencies, RegistryVO registryVO, Database db)
      throws Exception {
    try {
      String referencingEntityName = registryVO.getReferencingEntityName();
      String referencingEntityCompletingName = registryVO.getReferencingEntityCompletingName();
      Integer referencingEntityId = new Integer(registryVO.getReferencingEntityId());
      Integer referencingEntityCompletingId =
          new Integer(registryVO.getReferencingEntityCompletingId());

      if (referencingEntityCompletingName.equals(SiteNode.class.getName())) {
        SiteNodeVO siteNodeVO =
            SiteNodeController.getController()
                .getSiteNodeVOWithId(
                    new Integer(registryVO.getReferencingEntityCompletingId()), db);
        if (siteNodeVO != null) {
          LanguageVO masterLanguageVO =
              LanguageController.getController().getMasterLanguage(siteNodeVO.getRepositoryId());
          SiteNodeVersionVO siteNodeVersionVO =
              SiteNodeVersionController.getController()
                  .getLatestActiveSiteNodeVersionVO(db, siteNodeVO.getId());

          if (siteNodeVersionVO != null
              && siteNodeVersionVO.getId().intValue() == referencingEntityId.intValue())
            inconsistencies.add(registryVO);
        }
      } else if (referencingEntityCompletingName.equals(Content.class.getName())) {
        ContentVO contentVO =
            ContentController.getContentController()
                .getContentVOWithId(new Integer(registryVO.getReferencingEntityCompletingId()), db);
        if (contentVO != null) {
          LanguageVO masterLanguageVO =
              LanguageController.getController().getMasterLanguage(contentVO.getRepositoryId());
          ContentVersionVO contentVersionVO =
              ContentVersionController.getContentVersionController()
                  .getLatestActiveContentVersionVO(contentVO.getId(), masterLanguageVO.getId(), db);

          if (contentVersionVO != null
              && contentVersionVO.getId().intValue() == referencingEntityId.intValue())
            inconsistencies.add(registryVO);
        }
      } else {
        logger.error(
            "The registry contained a not supported referencingEntityCompletingName:"
                + referencingEntityCompletingName);
      }
    } catch (Exception e) {
      logger.error(
          "There seems to be a problem with finding the inconsistency for registryVO "
              + registryVO.getRegistryId()
              + ":"
              + e.getMessage());
    }
  }
  /**
   * This method simulates a call to a page so all castor caches fills up before we throw the old
   * page cache.
   *
   * @param db
   * @param siteNodeId
   * @param languageId
   * @param contentId
   */
  public void recache(DatabaseWrapper dbWrapper, Integer siteNodeId)
      throws SystemException, Exception {
    logger.info("recache starting..");

    HttpHelper helper = new HttpHelper();
    String recacheUrl =
        CmsPropertyHandler.getRecacheUrl()
            + "?siteNodeId="
            + siteNodeId
            + "&refresh=true&isRecacheCall=true";
    String response = helper.getUrlContent(recacheUrl, 30000);

    String recacheBaseUrl = CmsPropertyHandler.getRecacheUrl().replaceAll("/ViewPage.action", "");
    String pathsToRecacheOnPublishing = CmsPropertyHandler.getPathsToRecacheOnPublishing();
    if (pathsToRecacheOnPublishing.indexOf("pathsToRecacheOnPublishing") == -1) {
      String[] pathsToRecacheOnPublishingArray = pathsToRecacheOnPublishing.split(",");
      for (int i = 0; i < pathsToRecacheOnPublishingArray.length; i++) {
        recacheUrl =
            recacheBaseUrl
                + pathsToRecacheOnPublishingArray[i]
                + "?refresh=true&isRecacheCall=true";
        logger.info("calling recacheUrl:" + recacheUrl);
      }
    }

    LanguageVO masterLanguageVO =
        LanguageDeliveryController.getLanguageDeliveryController()
            .getMasterLanguageForSiteNode(dbWrapper.getDatabase(), siteNodeId);
    if (masterLanguageVO == null)
      throw new SystemException("There was no master language for the siteNode " + siteNodeId);

    Integer languageId = masterLanguageVO.getLanguageId();
    if (languageId == null) languageId = masterLanguageVO.getLanguageId();

    Integer contentId = new Integer(-1);

    Principal principal = (Principal) CacheController.getCachedObject("userCache", "anonymous");
    if (principal == null) {
      Map arguments = new HashMap();
      arguments.put("j_username", CmsPropertyHandler.getAnonymousUser());
      arguments.put("j_password", CmsPropertyHandler.getAnonymousPassword());

      principal =
          ExtranetController.getController()
              .getAuthenticatedPrincipal(dbWrapper.getDatabase(), arguments);

      if (principal != null) CacheController.cacheObject("userCache", "anonymous", principal);
    }

    FakeHttpSession fakeHttpServletSession = new FakeHttpSession();
    FakeHttpServletResponse fakeHttpServletResponse = new FakeHttpServletResponse();
    FakeHttpServletRequest fakeHttpServletRequest = new FakeHttpServletRequest();
    fakeHttpServletRequest.setParameter("siteNodeId", "" + siteNodeId);
    fakeHttpServletRequest.setParameter("languageId", "" + languageId);
    fakeHttpServletRequest.setParameter("contentId", "" + contentId);
    fakeHttpServletRequest.setRequestURI("ViewPage.action");

    fakeHttpServletRequest.setAttribute("siteNodeId", "" + siteNodeId);
    fakeHttpServletRequest.setAttribute("languageId", "" + languageId);
    fakeHttpServletRequest.setAttribute("contentId", "" + contentId);

    fakeHttpServletRequest.setServletContext(DeliverContextListener.getServletContext());

    BrowserBean browserBean = new BrowserBean();
    // this.browserBean.setRequest(getRequest());

    NodeDeliveryController nodeDeliveryController =
        NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId);
    IntegrationDeliveryController integrationDeliveryController =
        IntegrationDeliveryController.getIntegrationDeliveryController(
            siteNodeId, languageId, contentId);
    TemplateController templateController =
        getTemplateController(
            dbWrapper,
            siteNodeId,
            languageId,
            contentId,
            new FakeHttpServletRequest(),
            (InfoGluePrincipal) principal,
            false,
            browserBean,
            nodeDeliveryController,
            integrationDeliveryController);

    DeliveryContext deliveryContext =
        DeliveryContext.getDeliveryContext(/*(InfoGluePrincipal)this.principal*/ );
    // deliveryContext.setRepositoryName(repositoryName);
    deliveryContext.setSiteNodeId(siteNodeId);
    deliveryContext.setContentId(contentId);
    deliveryContext.setLanguageId(languageId);
    deliveryContext.setPageKey("" + System.currentTimeMillis());
    // deliveryContext.setSession(new Session(fakeHttpServletSession));
    // deliveryContext.setInfoGlueAbstractAction(null);
    deliveryContext.setHttpServletRequest(fakeHttpServletRequest);
    deliveryContext.setHttpServletResponse(fakeHttpServletResponse);

    templateController.setDeliveryContext(deliveryContext);

    // We don't want a page cache entry to be created
    deliveryContext.setDisablePageCache(true);

    SiteNodeVO siteNodeVO = templateController.getSiteNode(siteNodeId);
    SiteNodeVO rootSiteNodeVO =
        templateController.getRepositoryRootSiteNode(siteNodeVO.getRepositoryId());

    recurseSiteNodeTree(
        rootSiteNodeVO.getId(), languageId, templateController, principal /*, dbWrapper*/, 1, 0);

    List templates =
        ContentController.getContentController()
            .getContentVOWithContentTypeDefinition("HTMLTemplate", dbWrapper.getDatabase());
    Iterator templatesIterator = templates.iterator();
    {
      ContentVO template = (ContentVO) templatesIterator.next();

      String templateString =
          templateController.getContentAttribute(template.getId(), languageId, "Template", true);
    }

    RepositoryVO repository =
        RepositoryDeliveryController.getRepositoryDeliveryController()
            .getMasterRepository(dbWrapper.getDatabase());

    RepositoryDeliveryController.getRepositoryDeliveryController()
        .getRepositoryVOListFromServerName(
            dbWrapper.getDatabase(), "localhost", "8080", repository.getName());

    logger.info("recache stopped..");
  }
  public String doExecute() throws Exception {
    AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer();

    if (this.extraMultiParameter == null || this.extraMultiParameter.length == 0) {
      if (interceptionPointCategory.equalsIgnoreCase("Content")) {
        Integer contentId = new Integer(parameters);
        ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId);
        if (!contentVO.getCreatorName().equalsIgnoreCase(this.getInfoGluePrincipal().getName())) {
          Integer protectedContentId =
              ContentControllerProxy.getController().getProtectedContentId(contentId);
          if (ContentControllerProxy.getController().getIsContentProtected(contentId)
              && !AccessRightController.getController()
                  .getIsPrincipalAuthorized(
                      this.getInfoGluePrincipal(),
                      "Content.ChangeAccessRights",
                      protectedContentId.toString()))
            ceb.add(new AccessConstraintException("Content.contentId", "1006"));
        }
      } else if (interceptionPointCategory.equalsIgnoreCase("SiteNodeVersion")) {
        Integer siteNodeVersionId = new Integer(parameters);
        SiteNodeVersionVO siteNodeVersionVO =
            SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId);

        // If in published state we must first make it working state so it can later be published
        if (siteNodeVersionVO.getStateId().intValue() != SiteNodeVersionVO.WORKING_STATE) {
          this.oldParameters = "" + siteNodeVersionId;
          List events = new ArrayList();
          siteNodeVersionVO =
              SiteNodeStateController.getController()
                  .changeState(
                      siteNodeVersionVO.getId(),
                      SiteNodeVersionVO.WORKING_STATE,
                      "Access right changes",
                      true,
                      this.getInfoGluePrincipal(),
                      siteNodeVersionVO.getSiteNodeId(),
                      events);
          this.newParameters = "" + siteNodeVersionVO.getId();
          this.parameters = "" + siteNodeVersionVO.getId();
          siteNodeVersionId = siteNodeVersionVO.getId();
        }

        if (!siteNodeVersionVO
            .getVersionModifier()
            .equalsIgnoreCase(this.getInfoGluePrincipal().getName())) {
          Integer protectedSiteNodeVersionId =
              SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy()
                  .getProtectedSiteNodeVersionId(siteNodeVersionId);
          if (protectedSiteNodeVersionId != null
              && !AccessRightController.getController()
                  .getIsPrincipalAuthorized(
                      this.getInfoGluePrincipal(),
                      "SiteNodeVersion.ChangeAccessRights",
                      protectedSiteNodeVersionId.toString()))
            ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeId", "1006"));
        }
      }
      ceb.throwIfNotEmpty();
    }

    // logger.info("this.extraMultiParameters[i]:" + this.extraMultiParameter);
    if (this.extraMultiParameter != null && this.extraMultiParameter.length > 0) {
      for (int i = 0; i < this.extraMultiParameter.length; i++) {
        // logger.info("this.extraMultiParameters[i]:" + this.extraMultiParameter[i]);
        AccessRightController.getController()
            .update(this.extraMultiParameter[i], this.getRequest(), interceptionPointCategory);
      }
    } else {
      // logger.info("this.parameters:" + this.parameters);
      AccessRightController.getController()
          .update(this.parameters, this.getRequest(), interceptionPointCategory);
    }

    this.url = getResponse().encodeRedirectURL(this.returnAddress);

    if (newParameters != null) {
      this.url = this.url.replaceAll(this.oldParameters, this.newParameters);
      if (this.url.indexOf("ViewAccessRights") > -1)
        this.url =
            this.url + (!this.url.endsWith("&") ? "&stateChanged=true" : "stateChanged=true");
    }

    if (this.url.indexOf("ViewAccessRights") > -1) {
      this.url = this.url.replaceAll("&saved=true", "");
      this.url = this.url + "&saved=true";
    }

    if (this.closeOnLoad) {
      this.url = this.url.replaceAll("&KeepThis=true", "&closeOnLoad=true&KeepThis=true");
    }

    if (this.url.indexOf("ViewAccessRights") > -1) {
      this.url = this.url.replaceAll("&anchor=[0-9]{1,2}", "");
      this.url = this.url + "&anchor=" + this.anchor;
    }

    if (this.returnAddress.indexOf("http") == 0) {
      getResponse().sendRedirect(url);
      return Action.NONE;
    } else return "success";
  }
  public String doAddGroups() throws Exception {
    AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer();

    if (interceptionPointCategory.equalsIgnoreCase("Content")) {
      Integer contentId = new Integer(parameters);
      ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId);
      if (!contentVO.getCreatorName().equalsIgnoreCase(this.getInfoGluePrincipal().getName())) {
        Integer protectedContentId =
            ContentControllerProxy.getController().getProtectedContentId(contentId);
        if (ContentControllerProxy.getController().getIsContentProtected(contentId)
            && !AccessRightController.getController()
                .getIsPrincipalAuthorized(
                    this.getInfoGluePrincipal(),
                    "Content.ChangeAccessRights",
                    protectedContentId.toString()))
          ceb.add(new AccessConstraintException("Content.contentId", "1006"));
      }
    } else if (interceptionPointCategory.equalsIgnoreCase("SiteNodeVersion")) {
      Integer siteNodeVersionId = new Integer(parameters);
      SiteNodeVersionVO siteNodeVersionVO =
          SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId);

      // If in published state we must first make it working state so it can later be published
      if (siteNodeVersionVO.getStateId().intValue() != SiteNodeVersionVO.WORKING_STATE) {
        this.oldParameters = "" + siteNodeVersionId;
        List events = new ArrayList();
        siteNodeVersionVO =
            SiteNodeStateController.getController()
                .changeState(
                    siteNodeVersionVO.getId(),
                    SiteNodeVersionVO.WORKING_STATE,
                    "Access right changes",
                    true,
                    this.getInfoGluePrincipal(),
                    siteNodeVersionVO.getSiteNodeId(),
                    events);
        this.newParameters = "" + siteNodeVersionVO.getId();
        this.parameters = "" + siteNodeVersionVO.getId();
        siteNodeVersionId = siteNodeVersionVO.getId();
      }

      if (!siteNodeVersionVO
          .getVersionModifier()
          .equalsIgnoreCase(this.getInfoGluePrincipal().getName())) {
        Integer protectedSiteNodeVersionId =
            SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy()
                .getProtectedSiteNodeVersionId(siteNodeVersionId);
        if (protectedSiteNodeVersionId != null
            && !AccessRightController.getController()
                .getIsPrincipalAuthorized(
                    this.getInfoGluePrincipal(),
                    "SiteNodeVersion.ChangeAccessRights",
                    siteNodeVersionId.toString()))
          ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeId", "1006"));
      }
    }

    ceb.throwIfNotEmpty();

    String[] groupNames = this.getRequest().getParameterValues("groupName");
    AccessRightController.getController()
        .updateGroups(this.accessRightId, this.parameters, groupNames);

    this.url = getResponse().encodeRedirectURL(this.returnAddress);

    if (newParameters != null) {
      this.url = this.url.replaceAll(this.oldParameters, this.newParameters);
      if (this.url.indexOf("ViewAccessRights") > -1)
        this.url =
            this.url + (!this.url.endsWith("&") ? "&stateChanged=true" : "stateChanged=true");
    }

    if (this.returnAddress.indexOf("http") == 0) {
      getResponse().sendRedirect(url);
      return Action.NONE;
    } else return "success";
  }
  public String doV3() throws Exception {
    userSessionKey = "" + System.currentTimeMillis();

    String moveContentInlineOperationDoneHeader =
        getLocalizedString(
            getLocale(),
            "tool.contenttool.moveContentsInlineOperationDoneHeader",
            contentVO.getName());
    String moveContentInlineOperationBackToCurrentPageLinkText =
        getLocalizedString(
            getLocale(),
            "tool.contenttool.moveContentsInlineOperationBackToCurrentContentLinkText");
    String moveContentInlineOperationBackToCurrentPageTitleText =
        getLocalizedString(
            getLocale(),
            "tool.contenttool.moveContentsInlineOperationBackToCurrentContentTitleText");

    if (parentContentId == null && newParentContentId != null) parentContentId = newParentContentId;

    setActionMessage(userSessionKey, moveContentInlineOperationDoneHeader);
    addActionLink(
        userSessionKey,
        new LinkBean(
            "currentPageUrl",
            moveContentInlineOperationBackToCurrentPageLinkText,
            moveContentInlineOperationBackToCurrentPageTitleText,
            moveContentInlineOperationBackToCurrentPageTitleText,
            this.originalAddress,
            false,
            ""));
    setActionExtraData(userSessionKey, "refreshToolbarAndMenu", "" + true);
    setActionExtraData(userSessionKey, "repositoryId", "" + this.repositoryId);
    setActionExtraData(userSessionKey, "contentId", "" + newParentContentId);
    setActionExtraData(userSessionKey, "unrefreshedContentId", "" + parentContentId);
    setActionExtraData(userSessionKey, "unrefreshedNodeId", "" + parentContentId);
    setActionExtraData(userSessionKey, "changeTypeId", "" + this.changeTypeId);

    if (this.newParentContentId == null) {
      this.repositories =
          RepositoryController.getController()
              .getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), false);
      return "chooseDestinationV3";
    }

    ceb.throwIfNotEmpty();

    try {
      if (this.qualifyerXML != null && this.qualifyerXML.length() != 0) {
        Document document = new DOMBuilder().getDocument(this.qualifyerXML);
        List contents = parseContentsFromXML(this.qualifyerXML);
        Iterator i = contents.iterator();
        while (i.hasNext()) {
          ContentVO contentVO = (ContentVO) i.next();
          try {
            ContentControllerProxy.getController()
                .acMoveContent(this.getInfoGluePrincipal(), contentVO, this.newParentContentId);
          } catch (Exception e) {
            this.errorsOccurred = true;
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    this.topContentId =
        ContentController.getContentController()
            .getRootContentVO(this.repositoryId, this.getInfoGluePrincipal().getName())
            .getContentId();

    if (this.returnAddress != null && !this.returnAddress.equals("")) {
      String arguments = "userSessionKey=" + userSessionKey + "&isAutomaticRedirect=false";
      String messageUrl = returnAddress + (returnAddress.indexOf("?") > -1 ? "&" : "?") + arguments;

      this.getResponse().sendRedirect(messageUrl);
      return NONE;
    } else {
      return "successV3";
    }
  }
 public Integer getContentId() {
   return contentVO.getContentId();
 }