2013年11月19日 星期二

Full Dispatch

<%@ include file="/libs/foundation/global.jsp" %><%

%><%@ page contentType="text/html; charset=utf-8" import="

    java.net.*,

    java.io.*,

    org.apache.sling.jcr.api.SlingRepository,

    javax.jcr.Session"

%>

<%
/***
    MUST ACTIVATE ALL PAGE IN ORDER TO DISPATCH WHOLE SITE
***/
    try{

        String path = "/content/test_search/";
        final Session adminSession = currentNode.getSession();
        Node pageNode = (Node)adminSession.getItem(path);
     
        NodeIterator pageNodes = pageNode.getNodes();

        while (pageNodes.hasNext()){
            Node node = (Node) pageNodes.next();
            getChild(node, out);
            if (node.hasProperty("jcr:primaryType")){
                String s = node.getProperty("jcr:primaryType").getString();
                if (s.equals("cq:Page"))
                {
                    out.println("http://127.0.0.1:8010" + node.getPath() + ".html<br />");
                    URL hp = new URL("http://127.0.0.1:8010" + node.getPath() + ".html");
                    URLConnection hpCon = hp.openConnection();
                    InputStream input = hpCon.getInputStream();
                }
            }
        }
    }

    catch(Exception e){
        out.println(e.toString());
    }

%>

<%!

    public void getChild(Node node, JspWriter out){
      
        try{
            NodeIterator pages = node.getNodes();
            while (pages.hasNext()){
                Node node2 = (Node) pages.next();
                out.println(node2.getPath() + "<br />");
                if (node2.hasProperty("jcr:primaryType")){
                    String s = node2.getProperty("jcr:primaryType").getString();
                    if (s.equals("cq:Page"))
                    {
                      
                        //out.println("http://127.0.0.1:8010" + node2.getPath() + ".html<br />");
                        URL hp = new URL("http://127.0.0.1:8010" + node2.getPath() + ".html");
                        URLConnection hpCon = hp.openConnection();
                        InputStream input = hpCon.getInputStream();

                    }

                }

                getChild(node2, out);
             

            }

        }

        catch(Exception e){
            try{
                out.println(e.toString());
            }
            catch(Exception ex){}
        }
      
    }

%>

沒有留言:

張貼留言