portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r353907 - in /portals/jetspeed-2/trunk/components/page-manager/src: java/org/apache/jetspeed/om/folder/impl/ java/org/apache/jetspeed/page/document/impl/ test/org/apache/jetspeed/page/
Date Sun, 04 Dec 2005 21:01:59 GMT
Author: rwatler
Date: Sun Dec  4 13:01:54 2005
New Revision: 353907

URL: http://svn.apache.org/viewcvs?rev=353907&view=rev
Log:
add Page/Folder/Link title defaulting from name

Modified:
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/folder/impl/FolderImpl.java
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/document/impl/DocumentImpl.java
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/document/impl/NodeImpl.java
    portals/jetspeed-2/trunk/components/page-manager/src/test/org/apache/jetspeed/page/TestDatabasePageManager.java

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/folder/impl/FolderImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/folder/impl/FolderImpl.java?rev=353907&r1=353906&r2=353907&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/folder/impl/FolderImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/folder/impl/FolderImpl.java
Sun Dec  4 13:01:54 2005
@@ -404,6 +404,21 @@
     }
 
     /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.BaseElement#getTitle()
+     */
+    public String getTitle()
+    {
+        // default title to folder name
+        String title = super.getTitle();
+        if (title == null)
+        {
+            title = defaultTitleFromName();
+            setTitle(title);
+        }
+        return title;
+    }
+
+    /* (non-Javadoc)
      * @see org.apache.jetspeed.om.folder.Folder#getDocumentOrder()
      */
     public List getDocumentOrder()

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/document/impl/DocumentImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/document/impl/DocumentImpl.java?rev=353907&r1=353906&r2=353907&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/document/impl/DocumentImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/document/impl/DocumentImpl.java
Sun Dec  4 13:01:54 2005
@@ -33,15 +33,31 @@
         super(constraints);
     }
     
-    /**
-     * @return Returns the version.
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.BaseElement#getTitle()
+     */
+    public String getTitle()
+    {
+        // default title to document name
+        String title = super.getTitle();
+        if (title == null)
+        {
+            title = defaultTitleFromName();
+            setTitle(title);
+        }
+        return title;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.Document#setVersion()
      */
     public String getVersion()
     {
         return version;
     }
-    /**
-     * @param version The version to set.
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.Document#setVersion(java.lang.String)
      */
     public void setVersion(String version)
     {

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/document/impl/NodeImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/document/impl/NodeImpl.java?rev=353907&r1=353906&r2=353907&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/document/impl/NodeImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/document/impl/NodeImpl.java
Sun Dec  4 13:01:54 2005
@@ -119,6 +119,50 @@
         return pageMetadata;
     }
 
+    /**
+     * defaultTitleFromName
+     *
+     * Compute default title from name.
+     *
+     * @return default title
+     */
+    protected String defaultTitleFromName()
+    {
+        // transform name to title
+        String title = getName();
+        if (title != null)
+        {
+            // strip extensions and default root folder name
+            if ((getType() != null) && title.endsWith(getType()))
+            {
+                title = title.substring(0, title.length()-getType().length());
+            }
+            else if (title.equals(Folder.PATH_SEPARATOR))
+            {
+                title = "top";
+            }
+            // use space as word separator
+            title = title.replace('_', ' ');
+            title = title.replace('-', ' ');
+            // use title case for title words
+            int wordIndex = -1;
+            do
+            {
+                if (!Character.isTitleCase(title.charAt(wordIndex+1)))
+                {
+                    StringBuffer makeTitle = new StringBuffer();
+                    makeTitle.append(title.substring(0, wordIndex+1));
+                    makeTitle.append(Character.toTitleCase(title.charAt(wordIndex+1)));
+                    makeTitle.append(title.substring(wordIndex+2));
+                    title = makeTitle.toString();
+                }
+                wordIndex = title.indexOf(' ', wordIndex+1);
+            }
+            while (wordIndex != -1);
+        }
+        return title;
+    }
+
     /* (non-Javadoc)
      * @see org.apache.jetspeed.om.page.impl.BaseElementImpl#getName()
      */

Modified: portals/jetspeed-2/trunk/components/page-manager/src/test/org/apache/jetspeed/page/TestDatabasePageManager.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/test/org/apache/jetspeed/page/TestDatabasePageManager.java?rev=353907&r1=353906&r2=353907&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/test/org/apache/jetspeed/page/TestDatabasePageManager.java
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/test/org/apache/jetspeed/page/TestDatabasePageManager.java
Sun Dec  4 13:01:54 2005
@@ -144,6 +144,7 @@
 
         // test document and folder creation
         Folder folder = pageManager.newFolder("/");
+        assertEquals("Top", folder.getTitle());
         folder.setTitle("Root Folder");
         folder.setDefaultPage("default-page.psml");
         folder.setShortTitle("Root");
@@ -225,6 +226,7 @@
         assertNull(folder.getParent());
 
         Page page = pageManager.newPage("/default-page.psml");
+        assertEquals("Default Page", page.getTitle());
         page.setTitle("Default Page");
         page.setVersion("6.89");
         page.setDefaultDecorator("tigris", Fragment.LAYOUT);
@@ -330,11 +332,13 @@
         assertEquals(1, folder.getPages().size());
 
         page = pageManager.newPage("/another-page.psml");
+        assertEquals("Another Page", page.getTitle());
         page.setTitle("Another Page");
         pageManager.updatePage(page);
         assertNotNull(page.getParent());
         assertEquals(page.getParent().getId(), folder.getId());
         page = pageManager.newPage("/some-other-page.psml");
+        assertEquals("Some Other Page", page.getTitle());
         page.setTitle("Some Other Page");
         pageManager.updatePage(page);
         assertNotNull(page.getParent());
@@ -342,6 +346,7 @@
         assertEquals(3, folder.getPages().size());
 
         Link link = pageManager.newLink("/default.link");
+        assertEquals("Default", link.getTitle());
         link.setTitle("Default Link");
         link.setVersion("1.23");
         link.setShortTitle("Default");



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message