You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2009/07/30 16:32:24 UTC

svn commit: r799286 - in /myfaces/tobago/trunk/example/test/src: main/java/org/apache/myfaces/tobago/example/test/ main/webapp/ test/java/org/apache/myfaces/tobago/example/test/

Author: lofwyr
Date: Thu Jul 30 14:32:23 2009
New Revision: 799286

URL: http://svn.apache.org/viewvc?rev=799286&view=rev
Log:
test application:
 - using iframe for content
 - using tree for navigation

Added:
    myfaces/tobago/trunk/example/test/src/main/webapp/navigation.xhtml   (contents, props changed)
      - copied, changed from r796288, myfaces/tobago/trunk/example/test/src/main/webapp/navi.xhtml
Removed:
    myfaces/tobago/trunk/example/test/src/main/webapp/navi-sheet.xhtml
    myfaces/tobago/trunk/example/test/src/main/webapp/navi.xhtml
Modified:
    myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/DirectoryBrowser.java
    myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Filter.java
    myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/PageItem.java
    myfaces/tobago/trunk/example/test/src/main/webapp/index.html
    myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/FilterUnitTest.java

Modified: myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/DirectoryBrowser.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/DirectoryBrowser.java?rev=799286&r1=799285&r2=799286&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/DirectoryBrowser.java (original)
+++ myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/DirectoryBrowser.java Thu Jul 30 14:32:23 2009
@@ -19,6 +19,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.tobago.model.TreeState;
 
 import javax.faces.context.FacesContext;
 import javax.servlet.ServletContext;
@@ -31,15 +32,22 @@
 
   private static final Log LOG = LogFactory.getLog(DirectoryBrowser.class);
 
-  public List<PageItem> getList() {
-    FacesContext facesContext = FacesContext.getCurrentInstance();
-    List<PageItem> list = new ArrayList<PageItem>();
-    locateResourcesInWar(((ServletContext) facesContext.getExternalContext().getContext()), list, "/");
-    Collections.sort(list);
-    return list;
+  private PageItem tree;
+  private TreeState state;
+  private PageItem current;
+
+  public DirectoryBrowser() {
+    tree = new PageItem("/");
+    ServletContext servletContext
+        = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
+
+    locateResourcesInWar(tree, servletContext);
+    current = tree;
   }
 
-  private void locateResourcesInWar(ServletContext servletContext, List<PageItem> list, String path) {
+  private void locateResourcesInWar(PageItem node, ServletContext servletContext) {
+
+    String path = node.getName();
 
     // fix for jetty6
     if (path.endsWith("/") && path.length() > 1) {
@@ -52,14 +60,19 @@
       }
       return;
     }
+
+    List<PageItem> list = new ArrayList<PageItem>();
+
     for (String childPath : resourcePaths) {
       if (childPath.endsWith("/")) {
         // ignore, because weblogic puts the path directory itself in the Set
         if (!childPath.equals(path)) {
-          if (LOG.isDebugEnabled()) {
-            LOG.debug("childPath dir " + childPath);
+          if (Filter.isValid(childPath)) {
+            if (LOG.isDebugEnabled()) {
+              LOG.debug("childPath dir " + childPath);
+            }
+            list.add(new PageItem(childPath));
           }
-          locateResourcesInWar(servletContext, list, childPath);
         }
       } else {
         if (Filter.isValid(childPath)) {
@@ -68,5 +81,35 @@
         }
       }
     }
+
+    Collections.sort(list);
+
+    for (PageItem pageItem : list) {
+      node.add(pageItem);
+
+      if (pageItem.isFolder()) {
+        locateResourcesInWar(pageItem, servletContext);
+      }
+    }
+  }
+
+  public PageItem getTree() {
+    return tree;
+  }
+
+  public PageItem getCurrent() {
+    return current;
+  }
+
+  public void setCurrent(PageItem current) {
+    this.current = current;
+  }
+
+  public TreeState getState() {
+    return state;
+  }
+
+  public void setState(TreeState state) {
+    this.state = state;
   }
 }

Modified: myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Filter.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Filter.java?rev=799286&r1=799285&r2=799286&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Filter.java (original)
+++ myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Filter.java Thu Jul 30 14:32:23 2009
@@ -30,6 +30,7 @@
   private static final Log LOG = LogFactory.getLog(Filter.class);
 
   public static final List<String> ALLOWED = Arrays.asList(
+      ".*\\/",
       ".*\\.xhtml",
       ".*\\.jsp",
       ".*\\.jspx",
@@ -39,14 +40,17 @@
   public static final Set<String> FORBIDDEN = new HashSet<String>(Arrays.asList(
       "/META-INF.*",
       "/WEB-INF.*",
+      "/org/.*",
+      "/src/.*",
+
       "/index.html",
+      "/navigation.xhtml",
+
       "/meta-test/meta-1.*",
       "/meta-test/meta-2.*\\.jspx",
       "/meta-test/meta-3.*\\.xhtml",
       "/meta-test/meta-4.*",
-      "/navi.*",
-      "/org/apache/myfaces/tobago/renderkit/html/standard/blank.html",
-      "/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/dojo/.*",
+
       "/tc/button/plain.html",
       "/tc/button/plain_de.html",
       "/tc/gridLayout/horizontal-600px-default-300px.*",

Modified: myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/PageItem.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/PageItem.java?rev=799286&r1=799285&r2=799286&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/PageItem.java (original)
+++ myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/PageItem.java Thu Jul 30 14:32:23 2009
@@ -17,43 +17,67 @@
  * limitations under the License.
  */
 
-public class PageItem implements Comparable {
+import org.apache.myfaces.tobago.util.VariableResolverUtil;
 
+import javax.faces.context.FacesContext;
+import javax.swing.tree.DefaultMutableTreeNode;
+
+
+public class PageItem extends DefaultMutableTreeNode implements Comparable {
+
+  private String name;
   private String resource;
   private boolean jsfResource;
   private String label;
+  private boolean folder;
 
   public PageItem(String name) {
-    this.resource = name.substring(1);
-    label = name.replaceAll("_", "__");
+    this.name = name;
+    resource = name.substring(1);
     jsfResource = name.endsWith(".xhtml") || name.endsWith(".jspx");
+    folder = name.endsWith("/");
+
+    label = name;
+    if (folder && label.length() > 1) {
+      label = label.substring(0, label.length() - 1);
+    }
+    label = label.substring(label.lastIndexOf("/") + 1);
+//    label = label.replaceAll("_", "__");
   }
 
-  public String getResource() {
-    return resource;
+  public String getName() {
+    return name;
   }
 
-  public void setResource(String resource) {
-    this.resource = resource;
+  public String getResource() {
+    return resource;
   }
 
   public boolean isJsfResource() {
     return jsfResource;
   }
 
-  public void setJsfResource(boolean jsfResource) {
-    this.jsfResource = jsfResource;
-  }
-
   public String getLabel() {
     return label;
   }
 
-  public void setLabel(String label) {
-    this.label = label;
-  }
-
   public int compareTo(Object object) {
     return label.compareTo(((PageItem) object).label);
   }
+
+  public boolean isFolder() {
+    return folder;
+  }
+
+  public String navigate() {
+    DirectoryBrowser browser =
+        (DirectoryBrowser) VariableResolverUtil.resolveVariable(FacesContext.getCurrentInstance(), "browser");
+    browser.setCurrent(this);
+    return null; // here it works, but return null is usually not a good idea.
+  }
+
+  @Override
+  public String toString() {
+    return name;
+  }
 }

Modified: myfaces/tobago/trunk/example/test/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/webapp/index.html?rev=799286&r1=799285&r2=799286&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/webapp/index.html (original)
+++ myfaces/tobago/trunk/example/test/src/main/webapp/index.html Thu Jul 30 14:32:23 2009
@@ -1,10 +1,24 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
-<HTML>
-<HEAD>
-  <TITLE>Tobago Test Page</TITLE>
-</HEAD>
-<FRAMESET COLS="320,70%">
-  <FRAME SRC="faces/navi.xhtml" NAME="navi">
-  <FRAME NAME="test">
-</FRAMESET>
-</HTML>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+-->
+
+<html>
+<head>
+  <meta http-equiv="Refresh" content="0; URL=faces/navigation.xhtml">
+</head>
+</html>

Copied: myfaces/tobago/trunk/example/test/src/main/webapp/navigation.xhtml (from r796288, myfaces/tobago/trunk/example/test/src/main/webapp/navi.xhtml)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/webapp/navigation.xhtml?p2=myfaces/tobago/trunk/example/test/src/main/webapp/navigation.xhtml&p1=myfaces/tobago/trunk/example/test/src/main/webapp/navi.xhtml&r1=796288&r2=799286&rev=799286&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/webapp/navi.xhtml (original)
+++ myfaces/tobago/trunk/example/test/src/main/webapp/navigation.xhtml Thu Jul 30 14:32:23 2009
@@ -7,15 +7,20 @@
     xmlns:ui="http://java.sun.com/jsf/facelets"
     xmlns:h="http://java.sun.com/jsf/html"
     xmlns:f="http://java.sun.com/jsf/core">
-  <tc:page id="page" label="XXX">
+  <tc:page id="page" label="Tobago Example Test">
     <f:facet name="layout">
-      <tc:gridLayout rows="fixed;fixed;fixed;fixed;fixed;fixed;fixed;fixed;fixed;fixed;fixed"/>
+      <tc:gridLayout columns="300px;*"/>
     </f:facet>
+    <tc:gridLayoutConstraint width="1000px" height="700px"/>
 
-    <ui:repeat value="#{browser.list}" var="path">
-      <tc:link link="#{path.resource}" label="#{path.label}" target="test"/>
-      <tc:out value="&lt;br/&gt;" escape="false"/>
-    </ui:repeat>
+    <tc:tree>
+      <tc:treeData  value="#{browser.tree}" var="node">
+        <tc:treeNode link="#{node.resource}" label="#{node.label}" target="page:content"/>
+      </tc:treeData>
+    </tc:tree>
+
+    <!-- src will be set via tc:treeNode -->
+    <tc:object id="content" />
 
   </tc:page>
 </f:view>

Propchange: myfaces/tobago/trunk/example/test/src/main/webapp/navigation.xhtml
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/FilterUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/FilterUnitTest.java?rev=799286&r1=799285&r2=799286&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/FilterUnitTest.java (original)
+++ myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/FilterUnitTest.java Thu Jul 30 14:32:23 2009
@@ -35,7 +35,7 @@
     Assert.assertFalse(Filter.isValid("/NETA-INF"));
     Assert.assertFalse(Filter.isValid("/META-INF/"));
 
-    Assert.assertFalse(Filter.isValid("/navi.xhtml"));
+    Assert.assertFalse(Filter.isValid("/navigation.xhtml"));
     Assert.assertTrue(Filter.isValid("/nav.xhtml"));
   }
 }