Hi,

I've written this code which takes a specified starting page, and
iterates around every subpage, printing out the contents.

I'm slightly confused however. It is necessary to have the line

        text=""; (near the very end)

Otherwise every time you refresh the page, the variable text appends
another copy of itself onto the end of the string.
How do you stop this happening (other than setting it = "" at the end)
i.e. how do you clear everything from memory once the scriptlet has been
processed?

I've tried adding this.destroy() at the end but this has no effect.

(admittedly I could just be happy with the effect of text=""; but I am
finding similar problems in other code I'm writing i.e. it works fine
the first time you run it, but the following times the variables are
clearly still stored in memory, again resulting in undesirable
behaviour).

Cheers for any help,

Chris



<jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page";
        xmlns:cms="urn:jsptld:cms-taglib"
        xmlns:cmsu="urn:jsptld:cms-util-taglib"
        xmlns:c="urn:jsptld:http://java.sun.com/jsp/jstl/core";>
<jsp:directive.page import="java.util.ArrayList"/>
        

        <jsp:directive.page contentType="text/html; charset=UTF-8"
                session="false" />
        <jsp:output doctype-root-element="html"
                doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
        
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"; />

        <html>
        <head>
        </head>
        <body>
        <jsp:directive.page import="info.magnolia.cms.core.Content" />
        <jsp:directive.page
import="info.magnolia.cms.beans.config.ContentRepository" />
        <jsp:directive.page
import="info.magnolia.cms.core.HierarchyManager" />
        <jsp:directive.page import="info.magnolia.context.MgnlContext"
/>
        <jsp:directive.page import="javax.servlet.ServletResponse" />
        <jsp:directive.page import="java.util.Iterator" />
        <jsp:directive.page import="info.magnolia.cms.core.ItemType" />
        <jsp:directive.page import="info.magnolia.cms.core.MetaData" />
        <jsp:directive.page import="java.util.regex.*" />
        <jsp:directive.page import="info.magnolia.cms.security.*" />
        <jsp:directive.page import="java.util.Collection" />
        <jsp:directive.page
import="org.apache.commons.lang.StringUtils"/>
        <jsp:directive.page import="info.magnolia.cms.util.Resource" />


        <jsp:declaration>
                <![CDATA[
                
                String text ="";
                static int levelOffset = 0;
                String pagePath;
                
                public String processChildren( Content c,
ServletResponse response ) {

                        try {
                                

                                Pattern pageTitle =
Pattern.compile("(.)*Paragraphs(.)*");
                                Matcher t =
pageTitle.matcher(c.getHandle());
                                
                                if(!t.matches())
                                {
                                        int head = c.getLevel()-
levelOffset;
                                        text += "<h" + head + ">" +
c.getNodeData("title").getString() + "</h" + head + ">";
                                }
                                
                                Pattern mainColumn =
Pattern.compile("(.)*mainColumn(.)*");
                                Matcher m =
mainColumn.matcher(c.getHandle());
                                
                                if(m.matches())
                                {
                                        text += "<b>" +
c.getNodeData("title").getString() + "</b><br />";
                                        text +=
c.getNodeData("text").getString().replaceAll("src=\"(.)*mainColumnParagr
aphs", "src=\"http://localhost:8080/author"; + getPath(c));              
                                }
                                                                
                                Iterator childContentNodesIterator =
c.getChildren( ItemType.CONTENTNODE ).iterator();
                                while (
childContentNodesIterator.hasNext() ) {
                                        Content childNode =
(Content)childContentNodesIterator.next();
                                        processChildren( childNode,
response );     
                                }                               
                                
                                Iterator childNodesIterator =
c.getChildren( ItemType.CONTENT ).iterator();
                                while ( childNodesIterator.hasNext() ) {
                                        Content childNode =
(Content)childNodesIterator.next();
                                        processChildren( childNode,
response );
                                }
                                
                        }
                        catch ( Exception e ) {}
                return text;                    
                }
                ]]>
        </jsp:declaration>
        
        <jsp:declaration>
        <![CDATA[
        
                String path;
                public String getPath( Content c ) {
                try
                {
                path = c.getAncestor(c.getLevel()-1).getHandle();
                }
                catch ( Exception e ) {System.out.println("Exception
caught");}
                return path;
                }
        ]]>
        </jsp:declaration>
        


        <jsp:scriptlet>
        <![CDATA[
        
        
        response.resetBuffer();
        HierarchyManager
hm=MgnlContext.getHierarchyManager(ContentRepository.WEBSITE);
        
        String link =
Resource.getLocalContentNode(request).getNodeData("sectionPath").getStri
ng();
        link = hm.getContentByUUID(link).getHandle();
        Content rootNode = hm.getContent(link);

        levelOffset = rootNode.getLevel() -1;
        
        int level = rootNode.getLevel();

        out.print(processChildren( rootNode, response ));
        text=""; 
        ]]>
        </jsp:scriptlet>
        </body>
        </html>

</jsp:root>

----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/developer.html
----------------------------------------------------------------

Reply via email to