Author: szimano Date: 2005-08-10 15:53:46 -0400 (Wed, 10 Aug 2005) New Revision: 809 Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/Credentials.java trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/FileDataSource.java trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiContext.java trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiEngine.java trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPage.java trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Wiki.jsp trunk/forge/portal-extensions/portal-default/to-copy/jboss-portal.sar/portal-core.war/WEB-INF/default-portal.xml Log: wiki - browsable... publishing on forge.sicore Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/Credentials.java =================================================================== --- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/Credentials.java 2005-08-10 19:17:27 UTC (rev 808) +++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/Credentials.java 2005-08-10 19:53:46 UTC (rev 809) @@ -18,4 +18,8 @@ public void setName(String name) { this.name = name; } + + public String toString() { + return name; + } } Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/FileDataSource.java =================================================================== --- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/FileDataSource.java 2005-08-10 19:17:27 UTC (rev 808) +++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/FileDataSource.java 2005-08-10 19:53:46 UTC (rev 809) @@ -20,7 +20,7 @@ * </p> * */ - private final String propFileName = "/home/tomek/java/sandbox/new_svn/trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/filedatasource.properties"; + private final String propFileName = "filedatasource.properties";//"/home/tomek/java/sandbox/new_svn/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/filedatasource.properties"; private String pathToMedia; @@ -32,7 +32,7 @@ fileDSProps = new Properties(); try { - fileDSProps.load(new FileInputStream(new File(propFileName))); + fileDSProps.load(FileDataSource.class.getResourceAsStream(propFileName)); } catch (IOException ioe) { System.err.println("Can't load the file " + propFileName + "\n" + ioe); Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiContext.java =================================================================== --- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiContext.java 2005-08-10 19:17:27 UTC (rev 808) +++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiContext.java 2005-08-10 19:53:46 UTC (rev 809) @@ -24,4 +24,23 @@ * */ public WikiType wikiType; + + public WikiContext(User user, WikiType requestedType) { + this.user = user; + this.requestedType = requestedType; + } + + public WikiType getRequestedType() { + return requestedType; + } + + + public User getUser() { + return user; + } + + public WikiType getWikiType() { + return wikiType; + } + } Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiEngine.java =================================================================== --- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiEngine.java 2005-08-10 19:17:27 UTC (rev 808) +++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiEngine.java 2005-08-10 19:53:46 UTC (rev 809) @@ -1,5 +1,6 @@ package org.jboss.wiki; +import java.util.HashMap; import java.util.Map; /** @@ -30,23 +31,14 @@ * */ private Map wikiTypePlugins; + /** * <p></p> * */ - private WikiPagesHolder pages; -/** - * <p></p> - * - */ - public WikiPage wikiPage; -/** - * <p></p> - * - * - * @poseidon-type WikiPage - */ - public java.util.Collection wikiPage_1 = new java.util.TreeSet(); + private HashMap<String, WikiPage> pages; + + private MediaDataSource mediaDataSource; /** * <p>Does ...</p> @@ -96,9 +88,22 @@ * @return * @param wikiContext */ - public WikiPage getByName(String pageName, WikiContext wikiContext) { - // your code here - return null; + public WikiPage getByName(String pageName, WikiContext wikiContext) { + + // TODO: make user authentication with wikiContext + + WikiPage ret = null; + + if (pages.containsKey(pageName)) { + ret = pages.get(pageName); + } + else { + ret = mediaDataSource.getPage(pageName); + + pages.put(pageName, ret); + } + + return ret; } /** @@ -202,5 +207,9 @@ * <p></p> * */ - public WikiPortlet wikiPortlet; + public WikiEngine() { + mediaDataSource = new FileDataSource(); + pages = new HashMap<String, WikiPage>(); + + } } Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPage.java =================================================================== --- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPage.java 2005-08-10 19:17:27 UTC (rev 808) +++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPage.java 2005-08-10 19:53:46 UTC (rev 809) @@ -60,15 +60,11 @@ * */ private MediaDataSource mediaDataSource; + /** * <p></p> * */ - public WikiPagesHolder wikiPagesHolder; -/** - * <p></p> - * - */ public WikiEngine wikiEngine; /** * <p></p> @@ -210,7 +206,7 @@ public void showPage() { System.out.println("Page name: "+getName()); - System.out.println("Page author: "+getLastAuthor().getName()); + System.out.println("Page author: "+getLastAuthor()); System.out.println("Page version: "+getLastVersion()); System.out.println("Page editdate: "+getEditDate()); System.out.println("Page Content: \n"+getContent()); Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java =================================================================== --- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java 2005-08-10 19:17:27 UTC (rev 808) +++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java 2005-08-10 19:53:46 UTC (rev 809) @@ -6,85 +6,165 @@ * See terms of license at gnu.org. * * * *****************************************/ - - package org.jboss.wiki; - - import javax.portlet.*; - import org.jboss.portlet.*; - import java.util.Enumeration; - - public class WikiPortlet extends JBossPortlet { - - final static String jspPath = "/WEB-INF/jsp/"; - - private String page = "Wiki.jsp"; - - public void init() - { +package org.jboss.wiki; + +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.portlet.*; +import org.jboss.portlet.*; + +public class WikiPortlet extends JBossPortlet { + + final static String jspPath = "/WEB-INF/jsp/"; + + private String defaultPage = "Main"; + + private String page = "Wiki.jsp"; + + private String wikiPage = defaultPage; + + private WikiEngine wiki; + + private WikiContext wikiContext; + + public void init() { + wiki = new WikiEngine(); } - - public void processAction(JBossActionRequest rReq, JBossActionResponse rResp) { - Enumeration en = rReq.getParameterNames(); - - System.out.println("Parametry(action):"); - - if(en.hasMoreElements()) { - while (en.hasMoreElements()) { - String elem = (String)en.nextElement(); - System.out.println(elem+" "+rReq.getParameter(elem)); - } + + public String translateLinks(String content, String actionURL) { + String href1regex = "\\[.+\\|.+\\]"; + String href2regex = "\\[.+\\]"; + + String translatedContent = content; + + Matcher match; + + while ((match = Pattern.compile(href1regex).matcher(translatedContent)) + .find()) { + translatedContent = match.replaceFirst("<a href=\"" + + actionURL + + "&page=" + + (translatedContent.substring(translatedContent.indexOf( + "|", match.start() + 1) + 1, match.end() - 1)).trim() + + "\">" + + translatedContent.substring(match.start() + 1, + translatedContent.indexOf("|", match.start() + 1)) + + "</a>"); } - else { - System.out.println("BRAK PARAMETROW!!!"); + + while ((match = Pattern.compile(href2regex).matcher(translatedContent)) + .find()) { + translatedContent = match.replaceFirst("<a href=\"" + + actionURL + + "&page=" + + (translatedContent.substring(match.start() + 1, match + .end() - 1)).trim() + + "\">" + + translatedContent.substring(match.start() + 1, match + .end() - 1) + "</a>"); } - - if ((rReq.getParameter("action") != null)&&(rReq.getParameter("action").equals("Edit"))) { + + translatedContent = translatedContent.replace("\n", "<BR>\n"); + + return translatedContent; + } + + public void processAction(JBossActionRequest rReq, JBossActionResponse rResp) { + if ((rReq.getParameter("action") != null) + && (rReq.getParameter("action").equals("Edit"))) { page = "Edit.jsp"; - } - else { + } else { page = "Wiki.jsp"; } + + if (rReq.getParameter("page") != null) { + wikiPage = rReq.getParameter("page"); + } + + if (rReq.getParameter("editAction") != null) { + System.out.println("EDITING PAGE"); + + // saving, previewing or canceling + + if (rReq.getParameter("editAction").equals("Save")) { + Credentials credentials = new Credentials( + (rReq.getUser() != null) ? rReq.getUser().getUserName() + : "Unknown"); + System.out.println("SAVING PAGE"); + + // save the page + WikiPage edPage = wiki.getByName(rReq + .getParameter("editedPage"), wikiContext); + + if (edPage == null) { + edPage = new WikiPage(rReq.getParameter("editedPage"), + credentials, "", 0, new Date()); + } + + // set new content + edPage.setPageContent(rReq.getParameter("wikiContent")); + + // set author name for new version + edPage.setLastAuthor(credentials); + + // increase page version + edPage.setLastVersion(edPage.getLastVersion() + 1); + + // set new data + edPage.setEditDate(new Date()); + + // finnaly save the page + edPage.save(); + } + } + } - - public void doView(JBossRenderRequest rReq, JBossRenderResponse rRes) throws PortletException, java.io.IOException { - //System.out.println("\n\nURL "+jr.getURL()+"\n\n"); - - //System.out.println(decodeUrl(jr.getURL())); - - PortletURL newAgreementURL = rRes.createActionURL(); - rReq.setAttribute("actionURL", newAgreementURL.toString()); - - rReq.setAttribute("wikiName", "Szimano Wiki"); - - Enumeration en = rReq.getParameterNames(); - - System.out.println("Parametry:"); - - if(en.hasMoreElements()) { - while (en.hasMoreElements()) { - String elem = (String)en.nextElement(); - System.out.println(elem+" "+rReq.getParameter(elem)); + public void doView(JBossRenderRequest rReq, JBossRenderResponse rRes) + throws PortletException, java.io.IOException { + + wikiContext = new WikiContext(rReq.getUser(), new WikiType()); + + PortletURL wikiURL = rRes.createActionURL(); + + rReq.setAttribute("actionURL", wikiURL.toString()); + + rReq.setAttribute("wikiName", "Szimano Wiki"); + + WikiPage pageToShow = wiki.getByName(wikiPage, wikiContext); + + if (pageToShow == null) { + // TODO Make this show, that page isn't there yet + + wikiPage = defaultPage; + + pageToShow = wiki.getByName(wikiPage, wikiContext); } + + rReq.setAttribute("wikiContent", (page == "Wiki.jsp") ? translateLinks( + pageToShow.getContent(), wikiURL.toString()) : pageToShow + .getContent()); + + rReq.setAttribute("wikiPage", wikiPage); + + rReq.setAttribute("editDate", pageToShow.getEditDate()); + + rReq.setAttribute("author", pageToShow.getLastAuthor()); + + rRes.setTitle("Wiki"); + if (javax.portlet.WindowState.NORMAL.equals(rReq.getWindowState()) + || javax.portlet.WindowState.MAXIMIZED.equals(rReq + .getWindowState())) { + rRes.setContentType("text/html"); + javax.portlet.PortletRequestDispatcher pRD = this + .getPortletContext().getRequestDispatcher(jspPath + page); + pRD.include(rReq, rRes); + return; + } + doDispatch(rReq, rRes); } - else { - System.out.println("BRAK PARAMETROW!!!"); - } - - - System.out.println("Page = "+rReq.getParameters().get("page", null)); - - - rRes.setTitle("Wiki"); - if(javax.portlet.WindowState.NORMAL.equals(rReq.getWindowState()) || javax.portlet.WindowState.MAXIMIZED.equals(rReq.getWindowState())) - { - rRes.setContentType("text/html"); - javax.portlet.PortletRequestDispatcher pRD = this.getPortletContext().getRequestDispatcher(jspPath+page); - pRD.include(rReq, rRes); - return; - } - doDispatch(rReq, rRes); - } - - } \ No newline at end of file + +} \ No newline at end of file Modified: trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp =================================================================== --- trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp 2005-08-10 19:17:27 UTC (rev 808) +++ trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp 2005-08-10 19:53:46 UTC (rev 809) @@ -9,77 +9,21 @@ <% String actionURL = (String)request.getAttribute("actionURL"); String wikiName = (String)request.getAttribute("wikiName"); + String wikiContent = (String)request.getAttribute("wikiContent"); + String wikiPage = (String)request.getAttribute("wikiPage"); %> -<h2><%=wikiName%>: Main</h2> +<h2><%=wikiName%>: <%=wikiPage%></h2> <hr /> <form method="post" action="<%=actionURL%>"> <textarea name="wikiContent" rows="40" cols="80" style="width:100%;"> -<H3>Welcome to JBoss Labs</H3> -<P> -<B>JBoss Labs</B> is: -<UL> -<LI> a Professional Open Source community where Professional Open Source programmers around the world come to collaborate and create software for everyone -</LI> -<LI> the culmination of the efforts of developers (listed below as well as of all contributors to JEMS) to bring about a set of processes and infrastructure that enable the communication of ideas between the open source developers and their community. -</LI> -</UL> -<P> -<B>The Place To Be Is Our Wiki</B>: -<UL> -<LI> the place where we create and document the processes for Professional Open Source development. + <%=wikiContent%> -</LI> -<LI> main goal of Wiki is to provide an easy environment for POS communities to provide access to the products of their ideas. -</LI> -</UL> -<P> -JBoss is helping to nurture communication in open source communities with its JEMS offering a commitment to Professional Open Source developers around the world . -<P> -<IMG CLASS="inline" SRC="http://labs.jboss.com/file-access/default/members/default/images/LabsLayers.png" ALT="http://labs.jboss.com/file-access/default/members/default/images/LabsLayers.png" /> -<P> -JBoss Labs consists of: -<P> -<UL> -<LI> A set of <A CLASS="wikipage" HREF="Wiki.jsp?page=Processes">processes</A> that enable Professional Open Source software development. - -</LI> -<LI> An infrastructure, called <A CLASS="wikipage" HREF="Wiki.jsp?page=WhatIsJBossForge">JBoss Forge</A>, on which these processes manifest. -</LI> -<LI> A <A CLASS="wikipage" HREF="Wiki.jsp?page=JBossCommitters">community of developers</A> around the world contributing constantly. -</LI> -<LI> A <A CLASS="wikipage" HREF="Wiki.jsp?page=Projects">set of projects</A> which utilize the processes and infrustructure of JBoss Labs. - -</LI> -<LI> A Professional Open Source standard by which we measure quality and service offerings. -</LI> -<LI> And finally, a pathway for top-notch open source projects to enter the JEMS sofware suite--a symbol of Professional Open Source excellence and quality. -</LI> -</UL> -<P> -JBoss Labs' infrastructure is being developed by a community of developers from around the world. -<P> -Our developers are:<BR /> -<UL> -<LI><U>Damon Sicore</U><A HREF="Edit.jsp?page=Damon">?</A><BR /> - -</LI> -<LI><A CLASS="wikipage" HREF="Wiki.jsp?page=Rali">Rali Genova</A><BR /> -</LI> -<LI><A CLASS="wikipage" HREF="Wiki.jsp?page=Tomek">Tomek Szymański</A><BR /> -</LI> -<LI><A CLASS="wikipage" HREF="Wiki.jsp?page=Adam">Adam Warski</A><BR /> -</LI> -</UL> -<BR /> -and others... -<P> -This infrastructure is hosting several open source projects, and by the time you read this, there should be a few more. The current projects hosted on forge can be found on the <A CLASS="wikipage" HREF="Wiki.jsp?page=Projects">projects page</A>. - </textarea> +<input type="hidden" name="editedPage" value="<%=wikiPage%>" /> <input type="submit" value="Save" name="editAction" /> <input type="submit" value="Preview" name="editAction" /> <input type="submit" value="Cancel" name="editAction" /> Modified: trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Wiki.jsp =================================================================== --- trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Wiki.jsp 2005-08-10 19:17:27 UTC (rev 808) +++ trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Wiki.jsp 2005-08-10 19:53:46 UTC (rev 809) @@ -9,79 +9,33 @@ <% String actionURL = (String)request.getAttribute("actionURL"); String wikiName = (String)request.getAttribute("wikiName"); + String wikiContent = (String)request.getAttribute("wikiContent"); + String wikiPage = (String)request.getAttribute("wikiPage"); + java.util.Date editDate = (java.util.Date)request.getAttribute("editDate"); + org.jboss.wiki.Credentials author = (org.jboss.wiki.Credentials)request.getAttribute("author"); %> -<h2><%=wikiName%>: Main</h2> +<h2><%=wikiName%>: <%=wikiPage%></h2> -<div class="wikiTrail">Your trail:</div> +<div style="text-align: right;"> +<form method="post" action="<%=actionURL%>"> +<input type="text" name="page" /> +<input type="submit" value="GO" /> +</form> +</div> + <hr /> +<div class="wikiTrail">Your trail: <i>TO BE DONE</i></div> + +<hr /> + <table> <tr> <td class="wikiContent"> -<H3>Welcome to JBoss Labs</H3> -<P> -<B>JBoss Labs</B> is: -<UL> -<LI> a Professional Open Source community where Professional Open Source programmers around the world come to collaborate and create software for everyone -</LI> -<LI> the culmination of the efforts of developers (listed below as well as of all contributors to JEMS) to bring about a set of processes and infrastructure that enable the communication of ideas between the open source developers and their community. -</LI> -</UL> -<P> -<B>The Place To Be Is Our Wiki</B>: -<UL> -<LI> the place where we create and document the processes for Professional Open Source development. - -</LI> -<LI> main goal of Wiki is to provide an easy environment for POS communities to provide access to the products of their ideas. -</LI> -</UL> -<P> -JBoss is helping to nurture communication in open source communities with its JEMS offering a commitment to Professional Open Source developers around the world . -<P> -<IMG CLASS="inline" SRC="http://labs.jboss.com/file-access/default/members/default/images/LabsLayers.png" ALT="http://labs.jboss.com/file-access/default/members/default/images/LabsLayers.png" /> -<P> -JBoss Labs consists of: -<P> -<UL> -<LI> A set of <A CLASS="wikipage" HREF="Wiki.jsp?page=Processes">processes</A> that enable Professional Open Source software development. - -</LI> -<LI> An infrastructure, called <A CLASS="wikipage" HREF="Wiki.jsp?page=WhatIsJBossForge">JBoss Forge</A>, on which these processes manifest. -</LI> -<LI> A <A CLASS="wikipage" HREF="Wiki.jsp?page=JBossCommitters">community of developers</A> around the world contributing constantly. -</LI> -<LI> A <A CLASS="wikipage" HREF="Wiki.jsp?page=Projects">set of projects</A> which utilize the processes and infrustructure of JBoss Labs. - -</LI> -<LI> A Professional Open Source standard by which we measure quality and service offerings. -</LI> -<LI> And finally, a pathway for top-notch open source projects to enter the JEMS sofware suite--a symbol of Professional Open Source excellence and quality. -</LI> -</UL> -<P> -JBoss Labs' infrastructure is being developed by a community of developers from around the world. -<P> -Our developers are:<BR /> -<UL> -<LI><U>Damon Sicore</U><A HREF="Edit.jsp?page=Damon">?</A><BR /> - -</LI> -<LI><A CLASS="wikipage" HREF="Wiki.jsp?page=Rali">Rali Genova</A><BR /> -</LI> -<LI><A CLASS="wikipage" HREF="Wiki.jsp?page=Tomek">Tomek Szymański</A><BR /> -</LI> -<LI><A CLASS="wikipage" HREF="Wiki.jsp?page=Adam">Adam Warski</A><BR /> -</LI> -</UL> -<BR /> -and others... -<P> -This infrastructure is hosting several open source projects, and by the time you read this, there should be a few more. The current projects hosted on forge can be found on the <A CLASS="wikipage" HREF="Wiki.jsp?page=Projects">projects page</A>. - - + <%=wikiContent%> + <td> </tr> <tr> @@ -91,4 +45,5 @@ </td> </tr> </table> - +<br /> +<div class="author">The page last changed on <%=editDate%> by <%=author%>. </div> Modified: trunk/forge/portal-extensions/portal-default/to-copy/jboss-portal.sar/portal-core.war/WEB-INF/default-portal.xml =================================================================== --- trunk/forge/portal-extensions/portal-default/to-copy/jboss-portal.sar/portal-core.war/WEB-INF/default-portal.xml 2005-08-10 19:17:27 UTC (rev 808) +++ trunk/forge/portal-extensions/portal-default/to-copy/jboss-portal.sar/portal-core.war/WEB-INF/default-portal.xml 2005-08-10 19:53:46 UTC (rev 809) @@ -115,20 +115,20 @@ <height>2</height> <window-state>normal</window-state> </window> - <window> + <!--<window> <window-name>JSPWikiPortletWindow</window-name> <instance-ref>jspwikiportlet.JSPWikiPortlet.JSPWikiPortletInstance</instance-ref> <default>true</default> <region>center</region> <height>0</height> - </window> - <!--<window> + </window>--> + <window> <window-name>WikiPortletWindow</window-name> <instance-ref>wikiportlet.WikiPortlet.WikiPortletInstance</instance-ref> <default>true</default> <region>center</region> <height>0</height> - </window>--> + </window> </page> <page> |