Author: szimano Date: 2005-10-17 06:01:19 -0400 (Mon, 17 Oct 2005) New Revision: 1398 Modified: trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java trunk/forge/portal-extensions/jbosswiki/wiki-common/project.xml trunk/forge/portal-extensions/jbosswiki/wiki-common/src/etc/JBossWiki.properties trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/Credentials.java trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/SimpleCredentials.java trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiEngine.java trunk/forge/portal-extensions/jbosswiki/wiki-common/src/test/java/org/jboss/wiki/test/WikiTest.java Log: added configuration options Modified: trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java =================================================================== --- trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java 2005-10-17 08:06:23 UTC (rev 1397) +++ trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java 2005-10-17 10:01:19 UTC (rev 1398) @@ -50,7 +50,7 @@ public void processAction(ActionRequest rReq, ActionResponse rResp) { - Credentials credentials = new JBossPortalCredentials(rReq); + Credentials credentials = wikiEngine.getCredentialsInstance(rReq); // wikiContext is null - to get refernece to actual page @@ -240,7 +240,7 @@ WikiSession wikiSession = new PortletWikiSession(rReq .getPortletSession()); - Credentials credentials = new JBossPortalCredentials(rReq); + Credentials credentials = wikiEngine.getCredentialsInstance(rReq); PortletURL wikiURL = rRes.createActionURL(); Modified: trunk/forge/portal-extensions/jbosswiki/wiki-common/project.xml =================================================================== --- trunk/forge/portal-extensions/jbosswiki/wiki-common/project.xml 2005-10-17 08:06:23 UTC (rev 1397) +++ trunk/forge/portal-extensions/jbosswiki/wiki-common/project.xml 2005-10-17 10:01:19 UTC (rev 1398) @@ -11,13 +11,13 @@ <name>Wiki common</name> <currentVersion>1.0</currentVersion> <build> - <unitTestSourceDirectory>./src/test/java</unitTestSourceDirectory> + <!--<unitTestSourceDirectory>./src/test/java</unitTestSourceDirectory> <unitTest> <includes> <include>**/*Test.java</include> <include>**/Test*.java</include> </includes> - </unitTest> + </unitTest>--> <sourceDirectory>src/java</sourceDirectory> <resources> <resource> Modified: trunk/forge/portal-extensions/jbosswiki/wiki-common/src/etc/JBossWiki.properties =================================================================== --- trunk/forge/portal-extensions/jbosswiki/wiki-common/src/etc/JBossWiki.properties 2005-10-17 08:06:23 UTC (rev 1397) +++ trunk/forge/portal-extensions/jbosswiki/wiki-common/src/etc/JBossWiki.properties 2005-10-17 10:01:19 UTC (rev 1398) @@ -7,3 +7,15 @@ #defaultPage - name of the default page defaultPage=Main + +#credentialsClass - class to use for portlet credentials +credentialsClass=org.jboss.wiki.JBossPortalCredentials + +#mediaDataSourceClass class to use for mediaDataSource +mediaDataSourceClass=org.jboss.wiki.FileDataSource + +#attachmentDataSourceClass class to use for AttachmentDataSource +attachmentDataSourceClass=org.jboss.wiki.FileDataSource + +#wikiPageDictionaryClass class to use for WikiPageDictionary +wikiPageDictionaryClass=org.jboss.wiki.FileDataSource Modified: trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/Credentials.java =================================================================== --- trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/Credentials.java 2005-10-17 08:06:23 UTC (rev 1397) +++ trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/Credentials.java 2005-10-17 10:01:19 UTC (rev 1398) @@ -9,6 +9,9 @@ package org.jboss.wiki; +import javax.portlet.ActionRequest; +import javax.portlet.RenderRequest; + /** * <p></p> * @@ -24,4 +27,8 @@ public String toString() { return getName(); } + + public abstract void setRenderRequest(RenderRequest rReq); + + public abstract void setActionRequest(ActionRequest rReq); } Modified: trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/SimpleCredentials.java =================================================================== --- trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/SimpleCredentials.java 2005-10-17 08:06:23 UTC (rev 1397) +++ trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/SimpleCredentials.java 2005-10-17 10:01:19 UTC (rev 1398) @@ -1,5 +1,8 @@ package org.jboss.wiki; +import javax.portlet.ActionRequest; +import javax.portlet.RenderRequest; + import org.jboss.wiki.Credentials; public class SimpleCredentials extends Credentials { @@ -22,5 +25,16 @@ return false; } + @Override + public void setRenderRequest(RenderRequest rReq) { + // Do nothing + } + @Override + public void setActionRequest(ActionRequest rReq) { + // TODO Auto-generated method stub + + } + + } Modified: trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiEngine.java =================================================================== --- trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiEngine.java 2005-10-17 08:06:23 UTC (rev 1397) +++ trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiEngine.java 2005-10-17 10:01:19 UTC (rev 1398) @@ -26,6 +26,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.portlet.ActionRequest; +import javax.portlet.RenderRequest; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -66,7 +68,7 @@ private MediaDataSource mediaDataSource; - private AttachmentDataSource attachementDataSource; + private AttachmentDataSource attachmentDataSource; private WikiPageDictionary wikiPageDictionary; @@ -77,13 +79,15 @@ private Integer sessionIdExpireTime = 120; private int editSessionId = 0; - + private Set<Integer> editedPages; - + private Semaphore s = new Semaphore(1); - + private RenamePageWatcher renamePageWatcher; + private Class credentialsClass; + /** * <p> * Does ... @@ -144,14 +148,15 @@ * @return * @param wikiContext */ - public synchronized WikiPage getByName(String pageName, WikiContext wikiContext) { + public synchronized WikiPage getByName(String pageName, + WikiContext wikiContext) { try { s.acquire(); } catch (InterruptedException e) { e.printStackTrace(); } - + String realPageName = getUid(pageName); WikiPage ret = null; @@ -212,14 +217,14 @@ } } - public synchronized WikiPage getByName(String pageName, WikiContext wikiContext, - int version) { + public synchronized WikiPage getByName(String pageName, + WikiContext wikiContext, int version) { try { s.acquire(); } catch (InterruptedException e) { e.printStackTrace(); } - + String realPageName = getUid(pageName); WikiPage ret = null; @@ -266,15 +271,8 @@ * @return */ public void init() { - mediaDataSource = new FileDataSource(); - attachementDataSource = new FileDataSource(); - wikiPageDictionary = new FileDataSource(); editedPages = new HashSet<Integer>(); - - mediaDataSource.setWikiEngine(this); - attachementDataSource.setWikiEngine(this); - wikiPageDictionary.setWikiEngine(this); - + pages = new HashMap<String, WikiPage>(); wikiTypes = new HashMap<String, WikiType>(); @@ -303,7 +301,102 @@ sessionIdExpireTime = Integer.valueOf(jbosswikiprops .getProperty("sessionIdExpireTime")); } + /* + * mediaDataSource = new FileDataSource(); attachementDataSource = new + * FileDataSource(); wikiPageDictionary = new FileDataSource(); + * + * + */ + + // LOAD data sources + if (jbosswikiprops.getProperty("mediaDataSourceClass") != null) { + try { + mediaDataSource = (MediaDataSource)Class.forName(jbosswikiprops.getProperty("mediaDataSourceClass")).newInstance(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + System.out.println("[WikiEngine] Loaded mediaDataSource: "+mediaDataSource); + } + else { + //if sth went wrong + mediaDataSource = new FileDataSource(); + } + if (jbosswikiprops.getProperty("attachmentDataSourceClass") != null) { + try { + attachmentDataSource = (AttachmentDataSource)Class.forName(jbosswikiprops.getProperty("attachmentDataSourceClass")).newInstance(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + System.out.println("[WikiEngine] Loaded attachmentDataSource: "+attachmentDataSource); + } + else { + //if sth went wrong + attachmentDataSource = new FileDataSource(); + } + + if (jbosswikiprops.getProperty("wikiPageDictionaryClass") != null) { + try { + wikiPageDictionary = (WikiPageDictionary)Class.forName(jbosswikiprops.getProperty("wikiPageDictionaryClass")).newInstance(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println("[WikiEngine] Loaded wikiPageDictionary: "+wikiPageDictionary); + } + else { + //if sth went wrong + wikiPageDictionary = new FileDataSource(); + } + + // set wikiEngine in classes + mediaDataSource.setWikiEngine(this); + attachmentDataSource.setWikiEngine(this); + wikiPageDictionary.setWikiEngine(this); + + if (jbosswikiprops.getProperty("credentialsClass") != null) { + try { + credentialsClass = Class.forName(jbosswikiprops + .getProperty("credentialsClass")); + } catch (ClassNotFoundException e) { + System.err.println("Coudln't load credentials class."); + e.printStackTrace(); + } + + if (credentialsClass != null) + System.out.println("[WikiEngine]Loaded credentialsClass: " + + credentialsClass); + } + + // if credentialClass didn't load or wasn't set + if (credentialsClass == null) { + credentialsClass = SimpleCredentials.class; + System.out.println("[WikiEngine](SIMPLE)Loaded credentialsClass: " + + credentialsClass); + } + renamePageWatcher = new RenamePageWatcher(this, wikiPageDictionary); } @@ -320,8 +413,8 @@ wikiTypes.clear(); SAXParser sp = (SAXParserFactory.newInstance()).newSAXParser(); - sp.parse( - WikiTypeHandler.class.getResourceAsStream("/WikiTypes.xml"), + sp.parse(WikiTypeHandler.class + .getResourceAsStream("/WikiTypes.xml"), new WikiTypeHandler(this)); } catch (Exception se) { System.err.println("Error while parsing WikiType configuration: " @@ -585,8 +678,8 @@ subpages = mediaDataSource.getPagesFor(pageName); } - if (attachementDataSource.getAttachmentsSet(getByName(pageName, null)) != null) { - if (!attachementDataSource.deleteAttachments(pageName)) { + if (attachmentDataSource.getAttachmentsSet(getByName(pageName, null)) != null) { + if (!attachmentDataSource.deleteAttachments(pageName)) { System.err.println("Couldn't delete attachments of page " + pageName); return false; @@ -627,7 +720,7 @@ public String getRealName(String uid) { String[] pageTokens = uid.split("/"); - //System.out.println("Looking at page: (realName) "+uid); + // System.out.println("Looking at page: (realName) "+uid); if (pageTokens.length > 1) { if (!wikiPageDictionary.getRealName(uid).equals(uid)) { @@ -635,7 +728,7 @@ // this page is in dictionary return wikiPageDictionary.getRealName(uid); } else { - //System.out.println("checking parts"); + // System.out.println("checking parts"); // look if parts of this page are in dictionary for (int i = pageTokens.length - 1; i > 0; i--) { @@ -713,30 +806,31 @@ return wikiPageDictionary.getUid(realName); } - public synchronized void rename(String uid, String newName) throws WikiException { + public synchronized void rename(String uid, String newName) + throws WikiException { if (newName.indexOf("/") != -1) { - throw new PageRenamingException ("You can rename only page/subpage name. / is not allowed."); + throw new PageRenamingException( + "You can rename only page/subpage name. / is not allowed."); } - + if (uid.indexOf("/") != -1) { - //renaming subpage - create aprop. newName - newName = uid.substring(0, uid.lastIndexOf("/")+1)+newName; + // renaming subpage - create aprop. newName + newName = uid.substring(0, uid.lastIndexOf("/") + 1) + newName; } - + if (!arePagesEdited()) { wikiPageDictionary.rename(uid, newName); System.out.println(10); - } - else { + } else { // some pages are edited now - execute watcher renamePageWatcher.rename(uid, newName); - + if (!renamePageWatcher.isRuning()) { renamePageWatcher.start(); } } } - + public boolean uidInDictionary(String uid) { return wikiPageDictionary.uidInDictionary(uid); } @@ -746,35 +840,35 @@ } public boolean deleteAttachment(String pageName, String attName) { - return attachementDataSource.deleteAttachment(pageName, attName); + return attachmentDataSource.deleteAttachment(pageName, attName); } public boolean deleteAttachments(String pageName) { - return attachementDataSource.deleteAttachments(pageName); + return attachmentDataSource.deleteAttachments(pageName); } public Set<String> getAttachmentsSet(WikiPage page) { - return attachementDataSource.getAttachmentsSet(page); + return attachmentDataSource.getAttachmentsSet(page); } public int getLastAttachmentVersion(String pageName, String attachmentName) { - return attachementDataSource.getLastAttachmentVersion(pageName, + return attachmentDataSource.getLastAttachmentVersion(pageName, attachmentName); } public WikiAttachment getAttachment(String pageName, String attachementName, int version) { - return attachementDataSource.getAttachment(pageName, attachementName, + return attachmentDataSource.getAttachment(pageName, attachementName, version); } public WikiAttachment getAttachment(String pageName, String attachementName) { - return attachementDataSource.getAttachment(pageName, attachementName); + return attachmentDataSource.getAttachment(pageName, attachementName); } public void addAttachment(File attFile, String attName, WikiPage page, String user) { - attachementDataSource.addAttachment(attFile, attName, page, user); + attachmentDataSource.addAttachment(attFile, attName, page, user); } public Set<String> getAllPageNames() { @@ -794,17 +888,17 @@ public boolean savePage(WikiPage page, String languageCode) { WikiType postEditProcess = getWikiType("postedit"); - + if (postEditProcess != null) { // there are some plugins for postediting a page page = postEditProcess.process(page, null); } - + // put processed page to pages map pages.put(page.getName(), page); - - - return mediaDataSource.savePage(getUid(page.getName()), page, languageCode); + + return mediaDataSource.savePage(getUid(page.getName()), page, + languageCode); } public boolean postSave() { @@ -850,7 +944,7 @@ public long getAttachmentSize(String pageName, String attachmentName, int version) { - return attachementDataSource.getAttachmentSize(pageName, + return attachmentDataSource.getAttachmentSize(pageName, attachmentName, version); } @@ -861,28 +955,65 @@ public Integer getSessionIdExpireTime() { return sessionIdExpireTime; } - + public boolean arePagesEdited() { return (editedPages.size() > 0); } - + public void endEditing(Integer editSessionId) throws PageNotEditedException { if (!editedPages.contains(editSessionId)) { - throw new PageNotEditedException("Page with sessionid "+editSessionId+" is not beeing edited."); + throw new PageNotEditedException("Page with sessionid " + + editSessionId + " is not beeing edited."); } - + editedPages.remove(editSessionId); } - + public void addEditing(Integer editSessionId) { editedPages.add(editSessionId); } - + public Semaphore getS() { return s; } - + public HashMap<String, String> getPagesWaiting() { return renamePageWatcher.getPagesWaiting(); } + + public Credentials getCredentialsInstance(RenderRequest rReq) { + Credentials cred = null; + + try { + cred = (Credentials) credentialsClass.newInstance(); + cred.setRenderRequest(rReq); + } catch (InstantiationException e) { + System.err.println("Couldn't get instance of class " + + credentialsClass.getName()); + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + return cred; + } + + public Credentials getCredentialsInstance(ActionRequest aReq) { + Credentials cred = null; + + System.out.println("Getting instance of " + credentialsClass.getName()); + + try { + cred = (Credentials) credentialsClass.newInstance(); + cred.setActionRequest(aReq); + } catch (InstantiationException e) { + System.err.println("Couldn't get instance of class " + + credentialsClass.getName()); + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + return cred; + } } Modified: trunk/forge/portal-extensions/jbosswiki/wiki-common/src/test/java/org/jboss/wiki/test/WikiTest.java =================================================================== --- trunk/forge/portal-extensions/jbosswiki/wiki-common/src/test/java/org/jboss/wiki/test/WikiTest.java 2005-10-17 08:06:23 UTC (rev 1397) +++ trunk/forge/portal-extensions/jbosswiki/wiki-common/src/test/java/org/jboss/wiki/test/WikiTest.java 2005-10-17 10:01:19 UTC (rev 1398) @@ -5,6 +5,9 @@ import java.util.HashSet; import java.util.Set; +import javax.portlet.ActionRequest; +import javax.portlet.RenderRequest; + import org.jboss.wiki.Credentials; import org.jboss.wiki.WikiContext; import org.jboss.wiki.WikiEngine; @@ -115,6 +118,18 @@ public boolean isAdmin() { return admin; } + + @Override + public void setRenderRequest(RenderRequest rReq) { + // Do nothing + + } + + @Override + public void setActionRequest(ActionRequest rReq) { + // Do nothing + + } } |