The diffs for the modified files:
Index: src/com/ecyrd/jspwiki/WikiEngine.java
===================================================================
RCS file: /p/cvs/JSPWiki/src/com/ecyrd/jspwiki/WikiEngine.java,v
retrieving revision 1.104
diff -u -r1.104 WikiEngine.java
--- src/com/ecyrd/jspwiki/WikiEngine.java       14 Jan 2003 19:26:48 -0000      1.104
+++ src/com/ecyrd/jspwiki/WikiEngine.java       9 Feb 2003 08:17:16 -0000
@@ -48,6 +48,11 @@
  */
 public class WikiEngine
 {
+    /**
+     * Hierarchical page names like Admin\Home,Admin\NewHire, Tech\Home etc.
+     * Within Admin\Home you can create a link to Admin\NewHire with a relative link [NewHire].
+     */
+    public static  final char WIKI_PAGE_NAME_DELIMITER = '\\';
     private static final Category   log = Category.getInstance(WikiEngine.class);

     /** True, if log4j has been configured. */
@@ -188,6 +193,33 @@

         return engine;
     }
+
+    /**
+     * For a page called Admin\Policy\SickLeave, Admin\Policy is its group name, SickLeave is base name
+     * For page About, group name is null, this indicates it's a relative page
+     * For page \About, group name is "", this indicates it's absolute page name
+     */
+    static public String getPageWikiGroupName(String page) {
+        String group = null;
+        int lastDelimiter = page.lastIndexOf(WIKI_PAGE_NAME_DELIMITER);
+        // for page \Main we treat it as group ""
+        if (lastDelimiter == 0)
+            group = "";
+        else if ( 0 < lastDelimiter && lastDelimiter < page.length() ) { // \ not on borders
+            group = page.substring( 0, lastDelimiter);
+        }
+        return group;
+    }
+
+    static public String getPageBaseName(String page) {
+        String base = page;
+        int lastDelimiter = page.lastIndexOf(WIKI_PAGE_NAME_DELIMITER);
+        // for page \Main we treat it as page Main
+        if ( lastDelimiter >= 0 && lastDelimiter < page.length() ) {
+            base = page.substring( lastDelimiter+1 );
+        }
+        return base;
+    }

     /**
      *  Instantiate the WikiEngine using a given set of properties.
@@ -346,6 +378,7 @@
         try
         {
             Collection pages = m_pageManager.getAllPages();
+
             pages.addAll( m_attachmentManager.getAllAttachments() );

             // Build a new manager with default key lists.
@@ -369,7 +402,7 @@
                 {
                     String content = m_pageManager.getPageText( page.getName(),
                                                                 WikiPageProvider.LATEST_VERSION );
-                    Collection links = scanWikiLinks( content );
+                    Collection links = scanWikiLinks(page.getName(),  content );
                     Collection attachments = m_attachmentManager.listAttachments( page );

                     for( Iterator atti = attachments.iterator(); atti.hasNext(); )
@@ -462,6 +495,32 @@
     {
         return m_startTime;
     }
+
+    /**
+     * Given a internal wiki page name, if it is a relative page name, then reeturn its full hierarchical name
+     * based on current page context.
+     * @param pageName name of the page linked to (target page), could be absolute (Admin\NewHire) or relative (NewHire).
+     */
+    public static String getFullHierarchicalNameOfPageLinkedTo (WikiContext context,String pageName) {
+        String targetPageName = pageName;
+        String targetPageGroupname = WikiEngine.getPageWikiGroupName(targetPageName);
+        String targetPageBasename = WikiEngine.getPageBaseName(targetPageName);
+        // we want to normalize page \About the page name "About"
+        if (targetPageGroupname == null) {
+            targetPageName = targetPageBasename;
+        }
+        if (context != null) {
+            String currPageName =  context.getPage().getName();
+            // if name is hierarchical, extract its group name
+            String currPageGroupname = WikiEngine.getPageWikiGroupName(currPageName);
+            // user is using a relative page name, e.g. within page Admin\Policy\Holiday using a link [Vacation],
+            // then prepend current page's group name to get the full hierarchical name of the target page.
+            if (currPageGroupname != null && targetPageGroupname == null) {
+                targetPageName = currPageGroupname + WIKI_PAGE_NAME_DELIMITER + targetPageName;
+            }
+        }
+        return targetPageName;
+    }

     /**
      *  Returns the basic URL to a page, without any modifications.
@@ -469,17 +528,18 @@
      *
      *  @since 2.0.3
      */
-    public String getViewURL( String pageName )
-    {/*
-        pageName = encodeName( pageName );
-        String srcString = "%uWiki.jsp?page=%p";
-
-        srcString = TextUtil.replaceString( srcString, "%u", m_baseURL );
-        srcString = TextUtil.replaceString( srcString, "%p", pageName );
-
-        return srcString;
+    public String getViewURL(String pageName )    {
+        return   getViewURL(null, pageName );
+    }
+
+    /**
+     * Returns the basic URL to a page, if the page is a relative page name, then first find out its full hierarchical name
+     * based on current page context.
+     * @param pageName name of the page linked to (target page), could be absolute (Admin\NewHire) or relative (NewHire).
      */
-        return m_baseURL+"Wiki.jsp?page="+encodeName(pageName);
+    public String getViewURL(WikiContext context,  String pageName )
+    {
+        return m_baseURL+"Wiki.jsp?page="+ encodeName(getFullHierarchicalNameOfPageLinkedTo(context,pageName));
     }

     /**
@@ -487,9 +547,13 @@
      *
      *  @since 2.0.3
      */
-    public String getEditURL( String pageName )
+    public String getEditURL(String pageName )    {
+        return   getEditURL(null, pageName );
+    }
+
+    public String getEditURL(WikiContext context, String pageName )
     {
-        return m_baseURL+"Edit.jsp?page="+encodeName(pageName);
+        return m_baseURL+"Edit.jsp?page="+ encodeName(getFullHierarchicalNameOfPageLinkedTo(context,pageName));
     }

     /**
@@ -941,12 +1005,14 @@
     /**
      *  Reads a WikiPageful of data from a String and returns all links
      *  internal to this Wiki in a Collection.
+     * @param pageName name of the Wiki page
+     * @param pagedata data of the Wiki page
      */
-    protected Collection scanWikiLinks( String pagedata )
+    protected Collection scanWikiLinks(String pageName, String pagedata )
     {
         LinkCollector localCollector = new LinkCollector();

-        textToHTML( new WikiContext(this,""),
+        textToHTML( new WikiContext(this,pageName),
                     pagedata,
                     localCollector,
                     null,
@@ -1029,7 +1095,7 @@
         text = TextUtil.normalizePostData(text);

         // Hook into cross reference collection.
-        m_referenceManager.updateReferences( page, scanWikiLinks( text ) );
+        m_referenceManager.updateReferences( page, scanWikiLinks(page,  text ) );

         try
         {
@@ -1136,7 +1202,7 @@
             // Hook into cross reference collection.
             // Notice that this is definitely after the saveText() call above,
             // since it can be called externally and we only want this done once.
-            m_referenceManager.updateReferences( page, scanWikiLinks( text ) );
+            m_referenceManager.updateReferences( page, scanWikiLinks(page,  text ) );

             WikiPage p = new WikiPage( page );


Index: src/com/ecyrd/jspwiki/TranslatorReader.java
===================================================================
RCS file: /p/cvs/JSPWiki/src/com/ecyrd/jspwiki/TranslatorReader.java,v
retrieving revision 2.23
diff -u -r2.23 TranslatorReader.java
--- src/com/ecyrd/jspwiki/TranslatorReader.java 17 Jan 2003 06:33:02 -0000      2.23
+++ src/com/ecyrd/jspwiki/TranslatorReader.java 9 Feb 2003 08:18:51 -0000
@@ -359,11 +359,11 @@
         switch(type)
         {
           case READ:
-            result = "<A CLASS=\"wikipage\" HREF=\""+m_engine.getViewURL(link)+"\">"+text+"</A>";
+            result = "<A CLASS=\"wikipage\" HREF=\""+m_engine.getViewURL(m_context, link)+"\">"+text+"</A>";
             break;

           case EDIT:
-            result = "<U>"+text+"</U><A HREF=\""+m_engine.getEditURL(link)+"\">?</A>";
+            result = "<U>"+text+"</U><A HREF=\""+m_engine.getEditURL(m_context, link)+"\">?</A>";
             break;

           case EMPTY:
@@ -404,7 +404,7 @@
             break;

           case IMAGEWIKILINK:
-            String pagelink = m_engine.getViewURL(text);
+            String pagelink = m_engine.getViewURL(m_context, text);
             result = "<A CLASS=\"wikipage\" HREF=\""+pagelink+"\"><IMG CLASS=\"inline\" SRC=\""+link+"\" ALT=\""+text+"\" /></A>";
             break;

@@ -445,9 +445,28 @@
     public static String cleanLink( String link )
     {
         StringBuffer clean = new StringBuffer();
-
         if( link == null ) return null;

+        // relative names like [Policy] within an [Admin\Home] page ?
+        boolean linkIsRelative = link.indexOf(WikiEngine.WIKI_PAGE_NAME_DELIMITER) == -1;
+
+        // break hierarchical names down to several parts
+        StringTokenizer st = new StringTokenizer( link, "" +  WikiEngine.WIKI_PAGE_NAME_DELIMITER);
+        while( st.hasMoreTokens() ) {
+            StringBuffer component = new StringBuffer(st.nextToken());
+            // this will normalize partial hier names like Admin\Home to full hierarchical names like \Admin\Home
+            if (!linkIsRelative)
+                clean.append(WikiEngine.WIKI_PAGE_NAME_DELIMITER);
+            clean.append(getCompressedName(component.toString()) );
+        }
+        return clean.toString();
+    }
+
+     /**
+      * From a link name (which has no group delimiters in it), convert it to a  canonical Wiki name
+      */
+    private static String getCompressedName (String link) {
+        StringBuffer clean = new StringBuffer();
         //
         //  Compress away all whitespace and capitalize
         //  all words in between.

             //
@@ -820,7 +838,9 @@
             {
                 // It's an internal Wiki link
                 reallink = cleanLink( reallink );
-
+                // if link is a relative page, determine the full hierarchical name of the page
+                reallink = WikiEngine.getFullHierarchicalNameOfPageLinkedTo( m_context,reallink);
+
                 callMutatorChain( m_localLinkMutatorChain, reallink );

                 String matchedLink;
@@ -1413,6 +1433,9 @@
         return "~";
     }

+    /**
+     * convert wiki source on-the-fly to a string buffer m_data
+     */
     private void fillBuffer()
         throws IOException
     {



Index: src/com/ecyrd/jspwiki/WikiPage.java
===================================================================
RCS file: /p/cvs/JSPWiki/src/com/ecyrd/jspwiki/WikiPage.java,v
retrieving revision 1.8
diff -u -r1.8 WikiPage.java
--- src/com/ecyrd/jspwiki/WikiPage.java 2 Jan 2003 22:40:23 -0000       1.8
+++ src/com/ecyrd/jspwiki/WikiPage.java 9 Feb 2003 08:10:45 -0000
@@ -39,6 +39,9 @@

     public WikiPage( String name )
     {
+        // normalize names like About to \About
+        if (WikiEngine.getPageWikiGroupName(name) == null)
+            name = WikiEngine.WIKI_PAGE_NAME_DELIMITER + name;
         m_name = name;
     }



Index: src/webdocs/Wiki.jsp
===================================================================
RCS file: /p/cvs/JSPWiki/src/webdocs/Wiki.jsp,v
retrieving revision 1.43
diff -u -r1.43 Wiki.jsp
--- src/webdocs/Wiki.jsp        10 Jan 2003 20:27:05 -0000      1.43
+++ src/webdocs/Wiki.jsp        9 Feb 2003 16:08:54 -0000
@@ -15,6 +15,10 @@

 <%
     String pagereq = wiki.safeGetParameter( request, "page" );
+    // turn  page names like "About" to "\About" to normalize it to absolute page names
+    if (WikiEngine.getPageWikiGroupName(pagereq) == null) {
+        pagereq = WikiEngine.WIKI_PAGE_NAME_DELIMITER + pagereq;
+    }
     String skin    = wiki.safeGetParameter( request, "skin" );

     if( pagereq == null )


Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-4) was last changed on 30-Nov-2004 12:38 by Jawe