From: <dr...@us...> - 2003-07-02 03:05:27
|
Update of /cvsroot/webmacro/wiki/src/org/tcdi/opensource/wiki In directory sc8-pr-cvs1:/tmp/cvs-serv14910/src/org/tcdi/opensource/wiki Modified Files: Wiki.java WikiSystem.java WikiUtil.java Log Message: - fix bug where page names with numbers were not accessible (reported by Keats) - cleanup user admin screens - add a "PageTree" page that displays a tree (based on links) of all pages in the site - add a "IndexPage" page that displays a simple index of all pages, group by first letter (suggested by Christian) - update webmacro.jar to whatever we have in CVS as of today (living dangerously!) Index: Wiki.java =================================================================== RCS file: /cvsroot/webmacro/wiki/src/org/tcdi/opensource/wiki/Wiki.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Wiki.java 27 Nov 2002 06:21:41 -0000 1.8 --- Wiki.java 2 Jul 2003 03:01:52 -0000 1.9 *************** *** 80,83 **** --- 80,84 ---- private volatile String[] _pageNames; private volatile Map _pageLookup; + private List _pageTree; /** the page renderer this Wiki is configured to use */ *************** *** 103,106 **** --- 104,123 ---- } + public String[] getPages(String prefix) { + String[] names = getCurrentPageNames(); + if (prefix == null || prefix.trim().length() == 0) + prefix = "*"; + + prefix = prefix.toLowerCase(); + List l = new ArrayList(); + for (int x=0; x<names.length; x++) { + if (prefix.equals("*") || names[x].toLowerCase().startsWith(prefix)) { + l.add (names[x]); + } + } + + return (String[]) l.toArray(new String[l.size()]); + } + public Enumeration getPageNames() { return _pageStore.keys(); *************** *** 138,141 **** --- 155,162 ---- e.printStackTrace(); } + + synchronized (this) { + _pageTree = null; + } } *************** *** 166,169 **** --- 187,194 ---- _pageStore.remove(title); populatePageNames(); + + synchronized (this) { + _pageTree = null; + } } *************** *** 412,416 **** this.savePage(page); } ! /** * Is the specified String a Wiki page reference? --- 437,441 ---- this.savePage(page); } ! /** * Is the specified String a Wiki page reference? *************** *** 418,423 **** public boolean isWikiTermReference(String word) { char[] chars = word.toCharArray(); ! int ucase = 0, lcase = 0; // does the word end in a backwards tick? if (chars[chars.length - 1] == '`') --- 443,450 ---- public boolean isWikiTermReference(String word) { char[] chars = word.toCharArray(); ! int ucase = 0, lcase = 0; + + // does the word end in a backwards tick? if (chars[chars.length - 1] == '`') *************** *** 453,455 **** --- 480,530 ---- return _properties.getProperty("StartPage").trim(); } + + public synchronized List getPageTree() { + if (_pageTree == null) { + _pageTree = new ArrayList(); + Map lookup = new HashMap(); + String[] pageNames = getCurrentPageNames(); + for (int x=0; x<pageNames.length; x++) { + String name = pageNames[x]; + WikiPage wiki_page = getPage(name); + if (wiki_page == null) + continue; + + if (!lookup.containsKey(name)) { + _pageTree.add (new WikiSystem.PageTreeEntry(wiki_page, 0)); + lookup.put(name, null); + addChildren (_pageTree, lookup, wiki_page, 0); + } + } + lookup.clear(); // no longer needed + } + + return _pageTree; + } + + private void addChildren(List pages, Map lookup, WikiPage root, int depth) { + WikiData[] data = root.getData(); + for (int x=0; x<data.length; x++) { + switch (data[x].getType()) { + case WikiDataTypes.PAGE_REFERENCE: + WikiPage wiki_page = getPage((String) data[x].getData()); + if (wiki_page == null) + continue; + + String name = wiki_page.getTitle(); + if (!lookup.containsKey(name)) { + pages.add (new PageTreeEntry(wiki_page, depth+1)); + lookup.put (name, null); + addChildren (pages, lookup, wiki_page, depth+1); + } + + break; + + default: + break; + } + } + } + } Index: WikiSystem.java =================================================================== RCS file: /cvsroot/webmacro/wiki/src/org/tcdi/opensource/wiki/WikiSystem.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** WikiSystem.java 27 Nov 2002 06:22:06 -0000 1.4 --- WikiSystem.java 2 Jul 2003 03:01:52 -0000 1.5 *************** *** 52,55 **** --- 52,77 ---- */ public interface WikiSystem extends WikiTermMatcher { + + /** + * Represents a single entry in our Page Tree + */ + public static class PageTreeEntry { + private final WikiPage _page; + private final int _depth; + + public PageTreeEntry (WikiPage page, int depth) { + _page = page; + _depth = depth; + } + + public WikiPage getPage() { + return _page; + } + + public int getDepth() { + return _depth; + } + } + /** * @param title the title of the WikiPage to retrieve. This should be a propertly formed WikiTerm *************** *** 59,62 **** --- 81,92 ---- /** + * Return a list of all page names that begin with the specified string. + * The special string "*" is understood to mean <i>all pages</i>. + * So is <code>null</code> and the empty string. + */ + public String[] getPages(String prefix); + + + /** * return a list of all page names, including names of deleted pages * and old versions of pages. User should take care to filter these *************** *** 228,230 **** --- 258,265 ---- */ public void indexCurrentPages () throws Exception; + + /** + * Returns a tree-like structure ordered by page links. + */ + public List getPageTree(); } Index: WikiUtil.java =================================================================== RCS file: /cvsroot/webmacro/wiki/src/org/tcdi/opensource/wiki/WikiUtil.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WikiUtil.java 27 Nov 2002 06:21:41 -0000 1.3 --- WikiUtil.java 2 Jul 2003 03:01:52 -0000 1.4 *************** *** 92,96 **** * takes provided phrase and turns it into a WikiTerm by * .toUpperCase() first letter, and first letter of each word. ! * Strips all non-alpha characters * * @param phrase a phrase to convert to a WikiTerm --- 92,96 ---- * takes provided phrase and turns it into a WikiTerm by * .toUpperCase() first letter, and first letter of each word. ! * Strips all non-alphanumeric characters * * @param phrase a phrase to convert to a WikiTerm *************** *** 108,112 **** chars[x] = Character.toUpperCase(chars[x]); ! if (Character.isLetter(chars[x])) sb.append(chars[x]); } --- 108,112 ---- chars[x] = Character.toUpperCase(chars[x]); ! if (Character.isLetterOrDigit (chars[x])) sb.append(chars[x]); } |