I am trying to create a simplified Sitemap template based on some existing
code in 
tomcat/webapps/jahia/jsp/jahia/components/tree.inc

It worked for a minute!  I was able to get the output that is usually passed
to the dtree javascript.  The site I'm developing in only has about 10
pages, and the size of the TreeSiteMapViewHelper was 9.    It output all 9
pages as expected.

For some reason, now it is only outputting the Home page, ie.  the output is

[[0,0,'root','/'],[1,1,'Home','/tlf/lang/en/pid/1','staging_OK',]]

In my debug output it seems that the treeJahiaSiteMap.getContentPage(i) is
null for every item except home ???

Here is the code I'm using:

<%--
Copyright 2002-2006 Jahia Ltd

Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
(JCDDL), 
Version 1.0 (the "License"), or (at your option) any later version; you may 
not use this file except in compliance with the License. You should have 
received a copy of the License along with this program; if not, you may
obtain 
a copy of the License at 

 http://www.jahia.org/license/

Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License.
--%><%@ page import="org.jahia.services.sitemap.JahiaSiteMapService" %>
<%@ page import="org.jahia.registries.ServicesRegistry" %>
<%@ page import="org.jahia.data.viewhelper.sitemap.TreeSiteMapViewHelper" %>
<%@ page import="org.jahia.data.JahiaData" %>
<%@ page import="org.jahia.params.ProcessingContext" %>
<%@ page import="org.jahia.services.pages.ContentPage" %>
<%@ page import="org.jahia.exceptions.JahiaException" %>
<%@ page import="org.jahia.params.ParamBean" %>
<%@ page import="org.jahia.engines.shared.BigText_Field" %>
<%@ page import="org.jahia.data.fields.JahiaField" %>
<%@ page import="java.util.HashMap" %>
<%!
    /*
    * This is a model for a generic tree that can be used for several
purposes.
    * For example, it may be used to display the tree representing the
sitemap
    *
    * This JSP generates the necessary paramters to feed in the javascript
tree definition
    * contained in dtree.js
    */

    private static final org.apache.log4j.Logger treeLogger =
            org.apache.log4j.Logger.getLogger("jsp.jahia.components.tree");

    private final static ServicesRegistry servicesRegistry =
ServicesRegistry.getInstance();
    private final static JahiaSiteMapService siteMapService =
            servicesRegistry.getJahiaSiteMapService();

    public static final int PAGES = 0;
    public static final int FILES = 1;

    /**
     * Returns a String containing the parameters to initialize the dtree
javascript object.
     *
     * @param jData JahiaData instance
     * @param currentLanguageCode Language of the node name
     * @param displayLevel The starting depth of the tree
     * @param checkboxes TRUE will display checkboxes in front of the nodes
     * @param pageState TRUE will generate extra parameters showing the page
states (used by FCK editor)
     * @param nodeType What are the node showing ?  (PAGES or FILES)
     * @param canExpandAll TRUE will add an expandAll and a collapseAll
button
     *
     * @throws JahiaException If something goes wrong while getting the tree
information
     */
    public String getTree(final JahiaData jData,
                          final String currentLanguageCode,
                          final int displayLevel,
                          final boolean checkboxes,
                          final boolean pageState,
                          final int nodeType,
                          final boolean canExpandAll) throws JahiaException
{
        treeLogger.debug("Getting tree with params: displayLevel = " +
displayLevel + ", checkboxes = " +
                checkboxes + ", pageState = " + pageState);

        final StringBuffer result = new StringBuffer(128);
        result.append("[[0,0,\'root\','/'],");
        final ProcessingContext processingContext =
jData.getProcessingContext();

        final int pageInfosFlag;
        if (jData.gui().isNormalMode()) {
            pageInfosFlag = ContentPage.ACTIVE_PAGE_INFOS;
        } else {
            pageInfosFlag = ContentPage.ACTIVE_PAGE_INFOS |
ContentPage.STAGING_PAGE_INFOS;
        }
        
        System.out.println("Page infos flag: "+pageInfosFlag);

        try {
            final ContentPage theContentPage =
servicesRegistry.getJahiaPageService().
                   
lookupContentPage(processingContext.getSite().getHomePageID(), false);

            final TreeSiteMapViewHelper treeJahiaSiteMap =
(TreeSiteMapViewHelper) siteMapService.
                    getTreeSiteMapViewHelper(processingContext.getUser(),
theContentPage,
                            processingContext.getSessionID(), pageInfosFlag,
                            currentLanguageCode, displayLevel - 1 );

            for (int i = 0; i < treeJahiaSiteMap.size(); i++) {
                System.out.print("Node: "+i+" of "+treeJahiaSiteMap.size());
                final ContentPage contentPage =
treeJahiaSiteMap.getContentPage(i);
                if (contentPage == null) {
                        System.out.print(" is null\n");
                    continue;
                }

                final int pid = contentPage.getID();
                String pageTitle = treeJahiaSiteMap.getPageTitle(i,
currentLanguageCode);

                if (pageTitle == null || pageTitle.length() == 0) {
                    pageTitle = new StringBuffer().append("[pid =
").append(pid).append("]").toString();
                        System.out.print(" has null title "+pageTitle+"\n");
                } else {                
                        System.out.print(" has title "+pageTitle+"\n");
                }
                

                final StringBuffer pageUrl = new StringBuffer();
                pageUrl.append(((ParamBean)
processingContext).getRequest().getContextPath()).
                       
append("/lang/").append(currentLanguageCode).append("/pid/").append(pid);

                addParamsAsString(result, treeJahiaSiteMap, i, pageTitle,
pageUrl.toString(),
                        pid, currentLanguageCode, null, processingContext,
null, pageState);

            }
            result.deleteCharAt(result.length() - 1);
            result.append("]");

        } catch (JahiaException je) {
            throw je;
        }

        treeLogger.debug("Result: " + result);
        return result.toString();
    }

    /**
     * calls getTree with the given parameters + pageState = false &
nodeType = PAGES
     */
    public String getSiteMap(final JahiaData jData,
                             final String currentLanguageCode,
                             final int displayLevel,
                             final boolean checkboxes,
                             final boolean canExpandAll) throws
JahiaException {

        return getTree(jData, currentLanguageCode, displayLevel, checkboxes,
false, PAGES, canExpandAll);
    }

    /**
     * calls getTree with the given parameters + nodeType = PAGES
     */
    public String getSiteMap(final JahiaData jData,
                             final String currentLanguageCode,
                             final int displayLevel,
                             final boolean checkboxes,
                             final boolean pageState,
                             final boolean canExpandAll) throws
JahiaException {

        return getTree (jData, currentLanguageCode, displayLevel,
checkboxes, pageState, PAGES, canExpandAll);
    }

    /**
     * Adds a String containing the javascript parameters to the Result
StringBuffer
     */
    private void addParamsAsString(final StringBuffer buff,
                                   final TreeSiteMapViewHelper
treeJahiaSiteMap,
                                   final int i,
                                   final String pageTitle,
                                   final String pageUrl,
                                   final int pageId,
                                   final String currentLanguageCode,
                                   final JahiaField theField,
                                   final ProcessingContext jParams,
                                   final HashMap engineMap,
                                   final boolean showPageState) throws
JahiaException {

        buff.append("[").append((treeJahiaSiteMap.getPageLevel(i) + 1)).
                append(",").append((i + 1)).append(",\'").
                append(pageTitle.replaceAll("'", "\\\\'")).
                append("\','").append(pageUrl.toString().replaceAll("'",
"\\\\'")).append("\',");

        if (showPageState) {
            buff.append("\'").
                    append(BigText_Field.getInstance().getPageState(pageId,
currentLanguageCode)).
                    append("\',");
        }
        if (theField != null && engineMap != null) {
            buff.append("\'").
                   
append(BigText_Field.getInstance().getFieldGroupsNotHavingAccessOnPageAsString(
                            pageId, theField, jParams,
engineMap)).append("\'");
        }
        buff.append("],");
    }

%>
<h3>New sitemap</h3>
<%=     getSiteMap(jData, languageCode, 1, false, true, true) %>
-- 
View this message in context: 
http://www.nabble.com/Sitemap-using-tree.inc-tf3490644.html#a9748331
Sent from the Jahia - Dev mailing list archive at Nabble.com.

Reply via email to