private void recurseSiteNodeTree(
      Integer siteNodeId,
      Integer languageId,
      TemplateController templateController,
      Principal principal /*, DatabaseWrapper dbWrapper*/,
      int maxLevel,
      int currentLevel)
      throws Exception {
    SiteNode siteNode =
        SiteNodeController.getController()
            .getSiteNodeWithId(siteNodeId, templateController.getDatabase(), true);
    SiteNodeVO siteNodeVO = templateController.getSiteNode(siteNodeId);

    templateController.getContentAttribute(
        siteNodeVO.getMetaInfoContentId(), languageId, "Title", true);
    templateController.getContentAttribute(
        siteNodeVO.getMetaInfoContentId(), languageId, "NavigationTitle", true);
    templateController.getContentAttribute(
        siteNodeVO.getMetaInfoContentId(), languageId, "NiceURIName", true);
    templateController.getContentAttribute(
        siteNodeVO.getMetaInfoContentId(), languageId, "Description", true);
    templateController.getContentAttribute(
        siteNodeVO.getMetaInfoContentId(), languageId, "ComponentStructure", true);

    List childPages = templateController.getChildPages(siteNodeId);

    templateController.getRepositoryRootSiteNode(siteNodeVO.getRepositoryId());
    templateController.getParentSiteNode(siteNodeVO.getId());

    Collection childSiteNodes = siteNode.getChildSiteNodes();

    /*
       List childSiteNodeIds = new ArrayList();
       Iterator childSiteNodesIterator = childSiteNodes.iterator();
    while(childSiteNodesIterator.hasNext())
       {
        SiteNode childSiteNode = (SiteNode)childSiteNodesIterator.next();
        childSiteNodeIds.add(childSiteNode.getSiteNodeId());
       }

       templateController.commitDatabase();

    Iterator childSiteNodeIdsIterator = childSiteNodeIds.iterator();
    while(childSiteNodeIdsIterator.hasNext())
       {
        Integer childSiteNodeId = (Integer)childSiteNodeIdsIterator.next();
        recurseSiteNodeTree(childSiteNodeId, languageId, templateController, principal);
       }

       */

    Iterator childSiteNodesIterator = childSiteNodes.iterator();
    while (childSiteNodesIterator.hasNext()) {
      SiteNode childSiteNode = (SiteNode) childSiteNodesIterator.next();
      if (maxLevel > currentLevel)
        recurseSiteNodeTree(
            childSiteNode.getId(),
            languageId,
            templateController,
            principal,
            maxLevel,
            currentLevel + 1);
    }

    Repository repository =
        RepositoryController.getController()
            .getRepositoryWithId(siteNodeVO.getRepositoryId(), templateController.getDatabase());
    Collection languages = repository.getRepositoryLanguages();
    Iterator languagesIterator = languages.iterator();
    while (languagesIterator.hasNext()) {
      RepositoryLanguage repositoryLanguage = (RepositoryLanguage) languagesIterator.next();
      LanguageDeliveryController.getLanguageDeliveryController()
          .getLanguageIfSiteNodeSupportsIt(
              templateController.getDatabase(),
              repositoryLanguage.getLanguage().getId(),
              siteNodeId);
    }

    Integer contentId = new Integer(-1);

    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 subTemplateController =
        getTemplateController(
            templateController.getDatabaseWrapper(),
            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);

    subTemplateController.setDeliveryContext(deliveryContext);

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

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

    String pagePath = subTemplateController.getCurrentPagePath();

    CacheController.cacheObject("newPagePathCache", deliveryContext.getPageKey(), pagePath);
  }
  public String doExecute() throws Exception {
    try {
      CreateSiteNodeWizardInfoBean createSiteNodeWizardInfoBean = getCreateSiteNodeWizardInfoBean();
      if (createSiteNodeWizardInfoBean.getParentSiteNodeId() == null) {
        return "stateLocation";
      }

      createSiteNodeWizardInfoBean
          .getSiteNodeVO()
          .setCreatorName(this.getInfoGluePrincipal().getName());
      this.ceb = createSiteNodeWizardInfoBean.getSiteNodeVO().validate();

      if (!this.ceb.isEmpty()) {
        return "inputSiteNode";
      }

      Integer repositoryId = createSiteNodeWizardInfoBean.getRepositoryId();
      SiteNodeVO newSiteNodeVO = null;

      Database db = CastorDatabaseService.getDatabase();
      ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();

      beginTransaction(db);

      try {
        createSiteNodeWizardInfoBean.getSiteNodeVO().setIsBranch(new Boolean(true));
        SiteNode newSiteNode =
            SiteNodeControllerProxy.getSiteNodeControllerProxy()
                .acCreate(
                    this.getInfoGluePrincipal(),
                    createSiteNodeWizardInfoBean.getParentSiteNodeId(),
                    createSiteNodeWizardInfoBean.getSiteNodeTypeDefinitionId(),
                    repositoryId,
                    createSiteNodeWizardInfoBean.getSiteNodeVO(),
                    db);
        newSiteNodeVO = newSiteNode.getValueObject();
        SiteNodeController.getController()
            .createSiteNodeMetaInfoContent(
                db,
                newSiteNodeVO,
                repositoryId,
                this.getInfoGluePrincipal(),
                createSiteNodeWizardInfoBean.getPageTemplateContentId(),
                new ArrayList());

        commitTransaction(db);
      } catch (Exception e) {
        logger.error("An error occurred so we should not completes the transaction:" + e, e);
        rollbackTransaction(db);
        throw new SystemException(e.getMessage());
      }

      String returnAddress = createSiteNodeWizardInfoBean.getReturnAddress();
      returnAddress =
          returnAddress.replaceAll(
              "#entityId", createSiteNodeWizardInfoBean.getSiteNodeVO().getId().toString());
      returnAddress =
          returnAddress.replaceAll("#path", createSiteNodeWizardInfoBean.getSiteNodeVO().getName());

      this.invalidateCreateSiteNodeWizardInfoBean();

      this.getResponse().sendRedirect(returnAddress);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return NONE;
  }