[jboss-cvs] jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node ...

Christian Bauer christian.bauer at jboss.com
Fri Feb 16 11:26:44 EST 2007


  User: cbauer  
  Date: 07/02/16 11:26:44

  Modified:    examples/wiki/src/org/jboss/seam/wiki/core/node       
                        WikiRoot.java DocumentHome.java Menu.java
                        NodeBrowser.java DirectoryHome.java Directory.java
                        Node.java
  Log:
  Fixed the Wiki, basics work now
  
  Revision  Changes    Path
  1.2       +1 -0      jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node/WikiRoot.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: WikiRoot.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node/WikiRoot.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- WikiRoot.java	1 Feb 2007 07:08:26 -0000	1.1
  +++ WikiRoot.java	16 Feb 2007 16:26:44 -0000	1.2
  @@ -22,6 +22,7 @@
   
       @Transactional
       private void loadWikiRoot() {
  +        entityManager.joinTransaction();
           try {
               wikiRoot =(Directory)entityManager
                       .createQuery("select d from Directory d where d.parent is null")
  
  
  
  1.2       +8 -3      jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node/DocumentHome.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DocumentHome.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node/DocumentHome.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- DocumentHome.java	1 Feb 2007 07:08:26 -0000	1.1
  +++ DocumentHome.java	16 Feb 2007 16:26:44 -0000	1.2
  @@ -7,6 +7,7 @@
   import org.jboss.seam.annotations.*;
   import org.jboss.seam.wiki.core.links.WikiLinkResolver;
   import org.jboss.seam.core.FacesMessages;
  +import org.jboss.seam.core.Events;
   import org.jboss.seam.ScopeType;
   
   import java.util.List;
  @@ -43,7 +44,7 @@
           }
       }
   
  -    @Begin(flushMode = FlushModeType.MANUAL)
  +    @Begin(flushMode = FlushModeType.MANUAL, join = true)
       @Transactional
       public void create() {
           super.create();
  @@ -85,6 +86,8 @@
               wikiLinkResolver.convertToWikiLinks(parentDirectory, getFormContent())
           );
   
  +        Events.instance().raiseEvent("Nodes.menuStructureModified");
  +
           return super.update();
       }
   
  @@ -93,13 +96,15 @@
           // Unlink the document from its directory
           getInstance().getParent().removeChild(getInstance());
   
  +        Events.instance().raiseEvent("Nodes.menuStructureModified");
  +
           return super.remove();
       }
   
       public String getFormContent() {
           // Load the document content and resolve links
           if (formContent == null)
  -            formContent = wikiLinkResolver.convertFromWikiLinks(getInstance().getContent());
  +            formContent = wikiLinkResolver.convertFromWikiLinks(parentDirectory, getInstance().getContent());
           return formContent;
       }
   
  @@ -152,7 +157,7 @@
       private boolean isUniqueWikinameInArea() {
           getEntityManager().joinTransaction();
           // Unique document name within area
  -        Document foundDocument = wikiLinkResolver.findDocumentInArea(parentDirectory, getInstance().getWikiname());
  +        Document foundDocument = wikiLinkResolver.findDocumentInArea(parentDirectory.getAreaNumber(), getInstance().getWikiname());
           if ( foundDocument != null && foundDocument != getInstance()) {
               facesMessages.addFromResourceBundle(
                   "name",
  
  
  
  1.2       +9 -3      jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node/Menu.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Menu.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node/Menu.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- Menu.java	1 Feb 2007 07:08:26 -0000	1.1
  +++ Menu.java	16 Feb 2007 16:26:44 -0000	1.2
  @@ -2,6 +2,8 @@
   
   import org.jboss.seam.annotations.*;
   import org.jboss.seam.ScopeType;
  +import org.jboss.seam.Component;
  +import org.jboss.seam.wiki.core.links.WikiLinkResolver;
   
   import javax.persistence.EntityManager;
   import java.util.List;
  @@ -32,7 +34,7 @@
        * implementation might use a nested set approach (we need one anyway for recursive
        * deletion of subtrees).
        */
  -    @Observer("Nodes.directoryStructureModified")
  +    @Observer("Nodes.menuStructureModified")
       @Transactional
       public void refreshMenuItems() {
           items = new ArrayList<MenuItem>();
  @@ -43,7 +45,7 @@
   
       // Recursive
       private void addNodesToMenuTree(List<MenuItem> menuItems, int i, Node node) {
  -        MenuItem menuItem = new MenuItem(node);
  +        MenuItem menuItem = new MenuItem(node, WikiLinkResolver.renderURL(node));
           menuItem.setLevel(i);
           if (node.isMenuItem()) menuItems.add(menuItem); // Check flag in-memory
           if (node.getChildren() != null && node.getChildren().size() > 0) {
  @@ -62,8 +64,9 @@
           private Node node;
           private int level;
           private List<MenuItem> subItems = new ArrayList<MenuItem>();
  +        private String url;
   
  -        public MenuItem(Node node) { this.node = node; }
  +        public MenuItem(Node node, String url) { this.node = node; this.url = url; }
   
           public Node getNode() { return node; }
           public void setNode(Node node) { this.node = node; }
  @@ -73,6 +76,9 @@
   
           public List<MenuItem> getSubItems() { return subItems; }
           public void setSubItems(List<MenuItem> subItems) { this.subItems = subItems; }
  +
  +        public String getUrl() { return url; }
  +        public void setUrl(String url) { this.url = url; }
       }
   
       
  
  
  
  1.2       +57 -46    jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node/NodeBrowser.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: NodeBrowser.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node/NodeBrowser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- NodeBrowser.java	1 Feb 2007 07:08:26 -0000	1.1
  +++ NodeBrowser.java	16 Feb 2007 16:26:44 -0000	1.2
  @@ -2,9 +2,8 @@
   
   import org.jboss.seam.annotations.*;
   import org.jboss.seam.ScopeType;
  +import org.jboss.seam.wiki.core.links.WikiLinkResolver;
   
  -import javax.persistence.EntityManager;
  -import javax.persistence.EntityNotFoundException;
   import java.util.*;
   
   /**
  @@ -15,43 +14,43 @@
    * <pre>
    * http://host/         -- rewrite filter --> http://host/docDisplay.seam (DONE)
    * http://host/123.html -- rewrite filter --> http://host/docDisplay.seam?nodeId=123 (DONE)
  - * http://host/Foo      -- rewrite filter --> http://host/docDisplay.seam?dirName=Foo (PLANNED)
  - * http://host/Foo/Bar  -- rewrite filter --> http://host/docDisplay.seam?dirName=Foo&docName=Bar (PLANNED)
  + * http://host/Foo      -- rewrite filter --> http://host/docDisplay.seam?areaName=Foo (PLANNED)
  + * http://host/Foo/Bar  -- rewrite filter --> http://host/docDisplay.seam?areaName=Foo&nodeName=Bar (PLANNED)
    * </pre>
    * 'Foo' is a WikiName of a directory with a parentless parent (ROOT), we call this a logical area.
  - * 'Bar' is a WikiName of a document in that logical area, unique within that directory subtree.
  + * 'Bar' is a WikiName of a node in that logical area, unique within that area subtree.
    * <p>
    * We _never_ have URLs like <tt>http://host/Foo/Baz/Bar</tt> because 'Baz' would be a subdirectory
  - * we don't need. An area name and a document name is enough, the document name is unique within
  - * a subtree. We also never have <tt>http://host/Bar</tt>, a document name alone is not enough to
  - * identify a document, we also need the area name. In that case, 'Bar' would be treated like an
  - * area name and the default document of that area would be shown.
  + * we don't need. An area name and a node name is enough, the node name is unique within
  + * a subtree. We also never have <tt>http://host/Bar</tt>, a node name alone is not enough to
  + * identify a node, we also need the area name.
    *
    * @author Christian Bauer
    */
   @Name("browser")
  + at Scope(ScopeType.EVENT)
   public class NodeBrowser {
   
   
       @RequestParameter
  -    protected String dirName;
  +    protected String areaName;
   
       @RequestParameter
  -    protected String docName;
  +    protected String nodeName;
   
       protected Long nodeId;
       public Long getNodeId() { return nodeId; }
       public void setNodeId(Long nodeId) { this.nodeId = nodeId; }
   
  -    @In(create = true)
  -    protected EntityManager entityManager;
  -
       @In
       protected org.jboss.seam.core.Redirect redirect;
   
       @In(create = true)
       protected Directory wikiRoot;
   
  +    @In(create = true)
  +    protected WikiLinkResolver wikiLinkResolver;
  +
       // These are only EVENT scoped, we don't want them to jump from DocumentBrowser to
       // DirectoryBrowser over redirects
       @In(required=false) @Out(scope = ScopeType.EVENT, required = false)
  @@ -75,7 +74,7 @@
        * to redirect out of).
        */
       public void redirectToLastBrowsedPage() {
  -/*
  +
           // We don't want to redirect to an action, so if the last browsed page was called with an action, remove it
           redirect.getParameters().remove("actionOutcome");
           redirect.getParameters().remove("actionMethod");
  @@ -85,8 +84,8 @@
   
           // We also don't want to redirect the long-running conversation, the caller has ended it already
           redirect.setConversationPropagationEnabled(false);
  -*/
  -        redirect.execute();
  +
  +        redirect.returnToCapturedView();
       }
   
       // Just a convenience method for recursive calling
  @@ -96,62 +95,74 @@
               addDirectoryToPath(path, directory.getParent());
       }
   
  -    public String prepareAndCapture() {
  -        // Store the view-id that called this method (as a page action) for return (exit of a later conversation)
  -        redirect.captureCurrentRequest();
  -        return prepare();
  -    }
  -
       @Transactional
       public String prepare() {
   
  -        // Have we been called with a nodeId request parameter, could be document or directory
  -        if (nodeId != null) {
  +        // Store the view-id that called this method (as a page action) for return (exit of a later conversation)
  +        redirect.captureCurrentRequest();
  +        // TODO: I'm not using captureCurrentView() because it starts a conversation
   
  -            entityManager.joinTransaction();
  +        // Have we been called with a nodeId request parameter, could be document or directory
  +        if (nodeId != null && !nodeId.equals(wikiRoot.getId())) {
   
               // Try to find a document
  -            try {
  -                currentDocument = entityManager.find(Document.class, nodeId);
  -            } catch (EntityNotFoundException ex) {}
  +            currentDocument = wikiLinkResolver.findDocument(nodeId);
   
               // Document not found, see if it is a directory
               if (currentDocument == null) {
  -                try {
  -                    currentDirectory = entityManager.find(Directory.class, nodeId);
  -                } catch (EntityNotFoundException ex) {}
  +                currentDirectory = wikiLinkResolver.findDirectory(nodeId);
   
                   // Try to get a default document of that directory
  -                if (currentDirectory != null) {
  -                    currentDocument = currentDirectory.getDefaultDocument();
  -                } else {
  -                }
  +                if (currentDirectory != null) currentDocument = currentDirectory.getDefaultDocument();
  +
               } else {
                   // Document found, take its directory
                   currentDirectory = currentDocument.getParent();
               }
  +
  +        // Have we been called with an areaName and nodeName request parameter
  +        } else if (areaName != null && nodeName != null) {
  +
  +            // Try to find the area
  +            Directory area = wikiLinkResolver.findArea(areaName);
  +            if (area != null) {
  +                Node node = wikiLinkResolver.findNodeInArea(area.getAreaNumber(), nodeName);
  +                if (isDirectory(node)) {
  +                    currentDirectory = (Directory)node;
  +                    currentDocument = currentDirectory.getDefaultDocument();
  +                 } else {
  +                    currentDocument = (Document)node;
  +                    currentDirectory = currentDocument != null ? currentDocument.getParent() : area;
  +                }
  +            }
  +
  +        // Or have we been called just with an areaName request parameter
  +        } else if (areaName != null) {
  +            currentDirectory = wikiLinkResolver.findArea(areaName);
  +            if (currentDirectory != null) currentDocument = currentDirectory.getDefaultDocument();
           }
   
           // Fall back to wiki root
           if (currentDirectory== null) currentDirectory = wikiRoot;
   
  +        // Set the id for later
  +        nodeId = currentDocument != null ? currentDocument.getId() : currentDirectory.getId();
  +
           // Prepare directory path for breadcrumb
           addDirectoryToPath(currentDirectoryPath, currentDirectory);
           Collections.reverse(currentDirectoryPath);
   
  -        // This handles the wiki names in dirName and docName request parameters.
  -        // The logic here is the same as the code that will resolve wiki URLs during rendering of
  -        // pages, so we need to do that later...
  -        if (dirName != null) {
  -            System.out.println("#### NEED TO RESOLVE DIR NAME: " + dirName);
  -        }
  -        if (docName != null) {
  -            System.out.println("#### NEED TO RESOLVE DOC NAME: " + docName);
  -        }
  -
           // Return not-null outcome so we can navigate from here
           return "prepared";
       }
   
  +    // Replacement for missing instaceOf in EL (can't use string comparison, might be proxy)
  +    public static boolean isDirectory(Node node) {
  +        return node != null && Directory.class.isAssignableFrom(node.getClass());
  +    }
  +
  +    public static boolean isDocument(Node node) {
  +        return node != null && Document.class.isAssignableFrom(node.getClass());
  +    }
   
   }
  
  
  
  1.2       +8 -11     jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node/DirectoryHome.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DirectoryHome.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node/DirectoryHome.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- DirectoryHome.java	1 Feb 2007 07:08:26 -0000	1.1
  +++ DirectoryHome.java	16 Feb 2007 16:26:44 -0000	1.2
  @@ -25,7 +25,7 @@
       Long dirId;
   
       @RequestParameter
  -    Long parentDirectoryId;
  +    Long parentDirId;
   
       Directory parentDirectory;
   
  @@ -58,8 +58,8 @@
           currentDirectory = getInstance(); // Prepare for outjection
   
           getEntityManager().joinTransaction();
  -        if (parentDirectoryId != null) {
  -            parentDirectory = getEntityManager().find(Directory.class, parentDirectoryId);
  +        if (parentDirId != null) {
  +            parentDirectory = getEntityManager().find(Directory.class, parentDirId);
           } else {
               parentDirectory = getInstance().getParent();
           }
  @@ -105,11 +105,7 @@
           if (!isUniqueWikinameInDirectory(getInstance()) ||
               !isUniqueWikinameInArea()) return null;
   
  -        Events.instance().raiseEvent("Nodes.directoryStructureModified");
  -
  -// TODO: What the superclass.update() is doing breaks the menu preview http://jira.jboss.com/jira/browse/JBSEAM-713
  -//        FacesMessages.instance().add("Updated object");
  -//        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Updated Object"));
  +        Events.instance().raiseEvent("Nodes.menuStructureModified");
   
           return super.update();
       }
  @@ -122,10 +118,11 @@
           // Null the outjected value
           currentDirectory = null;
   
  +        Events.instance().raiseEvent("Nodes.menuStructureModified");
  +
           return super.remove();
       }
   
  -
       public Directory getParentDirectory() {
           return parentDirectory;
       }
  @@ -177,7 +174,7 @@
       }
   
       public void previewMenuItems() {
  -        Events.instance().raiseEvent("Nodes.directoryStructureModified");
  +        Events.instance().raiseEvent("Nodes.menuStructureModified");
       }
   
       // Validation rules for persist(), update(), and remove();
  @@ -223,7 +220,7 @@
           getEntityManager().joinTransaction();
           // Unique directory name within area
           Directory foundDirectory =
  -                wikiLinkResolver.findDirectoryInArea(parentDirectory, getInstance().getWikiname());
  +                wikiLinkResolver.findDirectoryInArea(parentDirectory.getAreaNumber(), getInstance().getWikiname());
           if (foundDirectory != null && foundDirectory != getInstance()) {
               facesMessages.addFromResourceBundle(
                   "name",
  
  
  
  1.2       +1 -1      jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node/Directory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Directory.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node/Directory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- Directory.java	1 Feb 2007 07:08:26 -0000	1.1
  +++ Directory.java	16 Feb 2007 16:26:44 -0000	1.2
  @@ -7,7 +7,7 @@
   @DiscriminatorValue("DIRECTORY")
   public class Directory extends Node {
   
  -    @ManyToOne(fetch = FetchType.EAGER) // Lazy would break UI logic that relies on classnames (proxy doesn't work)
  +    @ManyToOne(fetch = FetchType.LAZY)
       @JoinColumn(name = "DEFAULT_DOCUMENT_ID", nullable = true)
       private Document defaultDocument;
   
  
  
  
  1.2       +9 -0      jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node/Node.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Node.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/org/jboss/seam/wiki/core/node/Node.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- Node.java	1 Feb 2007 07:08:26 -0000	1.1
  +++ Node.java	16 Feb 2007 16:26:44 -0000	1.2
  @@ -155,4 +155,13 @@
           setLastModifiedOn(new Date());
       }
   
  +    public Directory getArea() {
  +        Node currentNode = this;
  +        // TODO: This is hardcoding the "parentless parent" logic for the wiki root
  +        while (currentNode.getParent() != null && currentNode.getParent().getParent() != null) {
  +            currentNode = currentNode.getParent();
  +        }
  +        return (Directory)currentNode;
  +    }
  +
   }
  
  
  



More information about the jboss-cvs-commits mailing list