[jboss-svn-commits] JBL Code SVN: r21121 - in labs/jbosslabs/trunk/portal-extensions/jbosswiki: wiki-common and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jul 18 11:01:52 EDT 2008
Author: szimano
Date: 2008-07-18 11:01:52 -0400 (Fri, 18 Jul 2008)
New Revision: 21121
Removed:
labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/ShotokuAttachmentDataSource.java
labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/ShotokuMediaDataSource.java
labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/ShotokuWikiPageDictionary.java
Modified:
labs/jbosslabs/trunk/portal-extensions/jbosswiki/common.xml
labs/jbosslabs/trunk/portal-extensions/jbosswiki/project.properties
labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/build.xml
labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/project.properties
labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/project.xml
labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/etc/org/jboss/wiki/filedatasource.properties.sample
Log:
removed old shotoku deps from jboss wiki
Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/common.xml
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jbosswiki/common.xml 2008-07-18 14:56:15 UTC (rev 21120)
+++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/common.xml 2008-07-18 15:01:52 UTC (rev 21121)
@@ -52,18 +52,6 @@
<jar>portal-portlet-lib.jar</jar>
</dependency>
- <dependency>
- <groupId>shotoku</groupId>
- <artifactId>shotoku-base</artifactId>
- <jar>shotoku-base.jar</jar>
- </dependency>
-
- <dependency>
- <groupId>shotoku</groupId>
- <artifactId>shotoku-aop</artifactId>
- <jar>shotoku-aop.jar</jar>
- </dependency>
-
<dependency>
<groupId>guice</groupId>
<artifactId>guice</artifactId>
Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/project.properties
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jbosswiki/project.properties 2008-07-18 14:56:15 UTC (rev 21120)
+++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/project.properties 2008-07-18 15:01:52 UTC (rev 21121)
@@ -4,10 +4,6 @@
maven.jar.override=on
-maven.jar.shotoku-base=${ext.root.dir}/shotoku/shotoku-base/target/shotoku-base.jar
-maven.jar.shotoku-aop=${ext.root.dir}/shotoku/shotoku-aop/target/shotoku-aop.jar
-
-maven.jar.shotoku-cache=${ext.root.dir}/shotoku/shotoku-cache/cache-base/dist/shotoku-cache.jar
maven.jar.jboss-cache=${ext.root.dir}/shotoku/lib/jboss-cache/jboss-cache.jar
maven.jar.jgroups=${ext.root.dir}/shotoku/lib/jboss-cache/jgroups.jar
Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/build.xml
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/build.xml 2008-07-18 14:56:15 UTC (rev 21120)
+++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/build.xml 2008-07-18 15:01:52 UTC (rev 21121)
@@ -1,7 +1,7 @@
<project name="wiki-common" default="all">
<!-- some variables used -->
<property name="lib.dir" value="lib" />
- <property name="clearspace.dir" value="/services/jbossorg2/clearspace/cs/webapps/ROOT.war/WEB-INF/lib" />
+ <property name="clearspace.dir" value="/services/jbossorg/clearspace/cs/webapps/ROOT.war/WEB-INF/lib" />
<property name="build.dir" value="build-migration" />
<property name="src.dir" value="src/java-migration" />
<property name="target.dir" value="target" />
Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/project.properties
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/project.properties 2008-07-18 14:56:15 UTC (rev 21120)
+++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/project.properties 2008-07-18 15:01:52 UTC (rev 21121)
@@ -4,8 +4,6 @@
maven.jar.override=on
-maven.jar.shotoku-base=${ext.root.dir}/shotoku/shotoku-base/target/shotoku-base.jar
-maven.jar.shotoku-aop=${ext.root.dir}/shotoku/shotoku-aop/target/shotoku-aop.jar
maven.jar.liferay=${ext.root.dir}/jbosswiki/lib/liferay-portal-impl.jar
maven.jar.liferay-service=${ext.root.dir}/jbosswiki/lib/liferay-portal-service.jar
maven.jar.liferay-kernel=${ext.root.dir}/jbosswiki/lib/liferay-portal-kernel.jar
Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/project.xml
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/project.xml 2008-07-18 14:56:15 UTC (rev 21120)
+++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/project.xml 2008-07-18 15:01:52 UTC (rev 21121)
@@ -164,11 +164,6 @@
<version>3.2.3</version>
</dependency>
- <dependency>
- <groupId>shotoku-cache</groupId>
- <artifactId>shotoku-cache</artifactId>
- <jar>shotoku-cache.jar</jar>
- </dependency>
<dependency>
<groupId>jboss-cache</groupId>
Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/etc/org/jboss/wiki/filedatasource.properties.sample
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/etc/org/jboss/wiki/filedatasource.properties.sample 2008-07-18 14:56:15 UTC (rev 21120)
+++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/etc/org/jboss/wiki/filedatasource.properties.sample 2008-07-18 15:01:52 UTC (rev 21121)
@@ -2,8 +2,8 @@
# pathToMedia - points, where JSPWiki file structure is situated
#pathToMedia=/usr/local/forge/wiki
-pathToMedia=
+pathToMedia=/services/jbossorg/clearspace/wiki
# pathToAttachements - points, where JSPWiki attachemets are situated
#pathToAttachements=/usr/local/forge/wiki
-pathToAttachements=
+pathToAttachements=/services/jbossorg/clearspace/wiki
Deleted: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/ShotokuAttachmentDataSource.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/ShotokuAttachmentDataSource.java 2008-07-18 14:56:15 UTC (rev 21120)
+++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/ShotokuAttachmentDataSource.java 2008-07-18 15:01:52 UTC (rev 21121)
@@ -1,303 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.wiki;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.apache.log4j.Logger;
-import org.jboss.shotoku.ContentManager;
-import org.jboss.shotoku.Node;
-import org.jboss.shotoku.Resource;
-import org.jboss.shotoku.exceptions.DeleteException;
-import org.jboss.shotoku.exceptions.NameFormatException;
-import org.jboss.shotoku.exceptions.ResourceAlreadyExists;
-import org.jboss.shotoku.exceptions.ResourceDoesNotExist;
-import org.jboss.shotoku.exceptions.SaveException;
-import org.jboss.wiki.configuration.ConfigurationParser;
-
-public class ShotokuAttachmentDataSource implements AttachmentDataSource{
-
- private static final String AUTHOR = "ShotokuDataSource:pageAuthor";
-
- private static final String EDIT_DATE = "ShotokuDataSource:editDate";
-
- private static final String ATT_PREFIX = "att-";
-
- private static final String PROP_FILE = "shotokudatasource.properties";
-
- private Logger log = Logger.getLogger(this.getClass());
-
- private ContentManager attManager;
-
- private String langCode;
-
- private WikiEngine wikiEngine;
-
- public ShotokuAttachmentDataSource() {
- attManager = ContentManager.getContentManager(getPathToAtt());
- }
-
- private String getPathToAtt() {
- // load paths
- InputStream is = ShotokuMediaDataSource.class.getResourceAsStream(PROP_FILE);
-
- Properties props = new Properties();
-
- try {
- props.load(is);
- } catch (IOException e) {
- log.error(e);
- } finally {
- try {
- is.close();
- } catch (IOException e) {
- log.error(e);
- }
- }
-
- return props.getProperty("pathToAttachements");
- }
-
- public void addAttachment(InputStream attFile, String attName,
- String uid, String user) {
-
- Node attNode = null;
-
- try {
- attNode = attManager.getNode(uid + "/" + attName);
- } catch (ResourceDoesNotExist e) {
- try {
- attNode = attManager.getRootDirectory().newNode(
- uid + "/" + ATT_PREFIX + attName);
- } catch (ResourceAlreadyExists e1) {
- // shouldn't happen
- log.error(e);
- return;
- } catch (NameFormatException e1) {
- log.error(e);
- return;
- }
- }
-
- attNode.setContent(attFile);
-
- // set author
- attNode.setProperty(AUTHOR, user);
-
- // set date
- attNode.setProperty(EDIT_DATE, String.valueOf(new Date().getTime()));
-
- try {
- attNode.save("Saving attachment: " + attName + " for page: "
- + uid);
- } catch (SaveException e) {
- log.error(e);
- }
- }
-
- public Set<String> getAttachmentsSet(String uid) {
- Set<String> attSet = new TreeSet<String>();
-
- try {
- List<Node> nodeList = attManager.getDirectory(uid)
- .getNodes().toList();
-
- for (Node node : nodeList) {
- if (node.getName().startsWith(ATT_PREFIX)) {
- attSet.add(node.getName().substring(ATT_PREFIX.length()));
- }
- }
-
- } catch (ResourceDoesNotExist e) {
- // just return empty set
- }
-
- return attSet;
- }
-
- public WikiAttachment getAttachment(String pageName, String attachmentName) {
- try {
- Node attNode = attManager.getNode(pageName + "/" + ATT_PREFIX
- + attachmentName);
-
- Date editDate = new Date(Long.valueOf(attNode
- .getProperty(EDIT_DATE)));
-
- String author = attNode.getProperty(AUTHOR);
-
- return new WikiAttachment(attachmentName, editDate, author, attNode
- .getLength(), attNode.getContentInputStream(), attNode
- .getRevisionNumber());
-
- } catch (ResourceDoesNotExist e) {
- // no such attachment
-
- return null;
- }
- }
-
- public WikiAttachment getAttachment(String pageName, String attachmentName,
- int version) {
- try {
- Node attNode = attManager.getNode(pageName + "/" + ATT_PREFIX
- + attachmentName).getHistory().getNodeAtRevision(version-1);
-
- Date editDate = new Date(Long.valueOf(attNode
- .getProperty(EDIT_DATE)));
-
- String author = attNode.getProperty(AUTHOR);
-
- return new WikiAttachment(attachmentName, editDate, author, attNode
- .getLength(), attNode.getContentInputStream(), attNode
- .getRevisionNumber());
-
- } catch (ResourceDoesNotExist e) {
- // no such attachment
-
- return null;
- }
- }
-
- public int getLastAttachmentVersion(String pageName, String attachmentName) {
- try {
- Node attNode = attManager.getNode(pageName + "/" + ATT_PREFIX
- + attachmentName);
-
- return attNode.getRevisionNumber();
-
- } catch (ResourceDoesNotExist e) {
- log.error(e);
- return 0;
- }
- }
-
- public long getAttachmentSize(String pageName, String attachmentName,
- int version) {
- try {
- Node attNode = attManager.getNode(pageName + "/" + ATT_PREFIX
- + attachmentName).getHistory().getNodeAtRevision(version);
-
- return attNode.getLength();
-
- } catch (ResourceDoesNotExist e) {
- log.error(e);
- return 0;
- }
- }
-
- public boolean deleteAttachment(String pageName, String attachmentName) {
- try {
- Node attNode = attManager.getNode(pageName + "/" + ATT_PREFIX
- + attachmentName);
-
- // TODO trash
- attNode.delete();
-
- return true;
-
- } catch (ResourceDoesNotExist e) {
- log.error(e);
- return false;
- } catch (DeleteException e) {
- log.error(e);
- return false;
- }
- }
-
- public boolean deleteAttachments(String pageName) {
- try {
- List<Node> nodeList = attManager.getDirectory(pageName).getNodes().toList();
-
- for (Node node : nodeList) {
- if (node.getName().startsWith(ATT_PREFIX)) {
- // TODO trash
- node.delete();
- }
- }
-
- return true;
-
- } catch (ResourceDoesNotExist e) {
- log.error(e);
- return false;
- } catch (DeleteException e) {
- log.error(e);
- return false;
- }
- }
-
- public void setWikiEngine(WikiEngine wikiEngine) {
- this.wikiEngine = wikiEngine;
-
- if (langCode == null) {
- langCode = ConfigurationParser.getDefaultLangugeCode();
- }
- }
-
- public void setLanguageCode(String langCode) {
- attManager = ContentManager.getContentManager(getPathToAtt() + "/"
- + ShotokuMediaDataSource.LANG_DIR + "/" + langCode);
-
- this.langCode = langCode;
-
- log.info("Lang code set: "+langCode+" path is: "+attManager.getPrefix());
- }
-
- public void addLangCode(String langCode, String langDesc) {
- ContentManager baseAtt = ContentManager
- .getContentManager(getPathToAtt());
-
- List<Resource> newDirs = new ArrayList<Resource>();
-
- try {
- baseAtt.getDirectory(ShotokuMediaDataSource.LANG_DIR + "/" + langCode);
- } catch (ResourceDoesNotExist e) {
- try {
- newDirs.add(baseAtt.getRootDirectory().newDirectory(
- ShotokuMediaDataSource.LANG_DIR + "/" + langCode));
- } catch (ResourceAlreadyExists e1) {
- // wont happen
- log.error(e1);
- } catch (NameFormatException e1) {
- log.error(e1);
- return;
- }
- }
-
- if (newDirs.size() > 0) {
- try {
- attManager.save("Adding new language: " + langCode, newDirs);
- } catch (SaveException e) {
- log.error(e);
- return;
- }
- }
- }
-
-}
Deleted: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/ShotokuMediaDataSource.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/ShotokuMediaDataSource.java 2008-07-18 14:56:15 UTC (rev 21120)
+++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/ShotokuMediaDataSource.java 2008-07-18 15:01:52 UTC (rev 21121)
@@ -1,691 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.wiki;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
-import org.apache.log4j.Logger;
-import org.jboss.shotoku.ContentManager;
-import org.jboss.shotoku.Directory;
-import org.jboss.shotoku.Node;
-import org.jboss.shotoku.Resource;
-import org.jboss.shotoku.cache.CacheItem;
-import org.jboss.shotoku.cache.CacheItemUser;
-import org.jboss.shotoku.cache.ShotokuResourceWatcher;
-import org.jboss.shotoku.cache.ValueChange;
-import org.jboss.shotoku.cache.ValueInit;
-import org.jboss.shotoku.exceptions.DeleteException;
-import org.jboss.shotoku.exceptions.NameFormatException;
-import org.jboss.shotoku.exceptions.RepositoryException;
-import org.jboss.shotoku.exceptions.ResourceAlreadyExists;
-import org.jboss.shotoku.exceptions.ResourceDoesNotExist;
-import org.jboss.shotoku.exceptions.SaveException;
-import org.jboss.wiki.configuration.ConfigurationParser;
-import org.jboss.wiki.credentials.SimpleCredentials;
-import org.jboss.wiki.exceptions.DataSourceException;
-import org.jboss.wiki.exceptions.WikiSaveException;
-
-/**
- * <p>
- * </p>
- *
- */
-public class ShotokuMediaDataSource implements MediaDataSource {
-
- private static final String AUTHOR = "ShotokuDataSource:pageAuthor";
-
- private static final String LAST_VERSION = "ShotokuDataSource:lastVersion";
-
- private static final String MODS = "ShotokuDataSource:mods";
-
- private static final String ROLE_PREFIX_EDITABLE = "ShotokuDataSource:rolesEditable";
-
- private static final String ROLE_PREFIX_VIEWABLE = "ShotokuDataSource:rolesViewable";
-
- private static final String EDIT_DATE = "ShotokuDataSource:editDate";
-
- private static final String NODE_NAME = "page";
-
- private static final String PROPS_PREFIX = "ShotokuDataSource:props";
-
- private static final String PROP_FILE = "shotokudatasource.properties";
-
- public static final String LANG_DIR = "lang";
-
- private Logger log = Logger.getLogger(this.getClass());
-
- private WikiEngine wikiEngine;
-
- private ContentManager manager;
-
- private String langCode = null;
-
- public ShotokuMediaDataSource() {
-
- // load props and get content managers
-
- manager = ContentManager.getContentManager(getPathToMedia());
-
- }
-
- private String getPathToMedia() {
- // load paths
- InputStream is = ShotokuMediaDataSource.class
- .getResourceAsStream(PROP_FILE);
-
- Properties props = new Properties();
-
- try {
- props.load(is);
- } catch (IOException e) {
- log.error(e);
- } finally {
- try {
- is.close();
- } catch (IOException e) {
- log.error(e);
- }
- }
-
- return props.getProperty("pathToMedia");
- }
-
- public void preSave() throws WikiSaveException{
- // do noting
- }
-
- private String getPagePath(String uid) {
- return uid + "/" + NODE_NAME;
- }
-
- public void savePage(String uid, WikiPage page) throws WikiSaveException{
- Node pageNode = null;
-
- try {
- pageNode = manager.getNode(getPagePath(uid));
- } catch (ResourceDoesNotExist e) {
- // page is saved for the first time
- Directory nodeDir = null;
-
- try {
- nodeDir = manager.getDirectory(uid);
- } catch (ResourceDoesNotExist e1) {
- // This dir is not yet created
- try {
- nodeDir = manager.getRootDirectory().newDirectory(uid);
- } catch (ResourceAlreadyExists e2) {
- // This shouldn't happen
- throw new WikiSaveException(e2);
- } catch (NameFormatException e2) {
- throw new WikiSaveException(e2);
- }
- try {
- nodeDir.save("Directory for page: " + uid + " (revision: "
- + page.getLastVersion() + ") by "
- + page.getLastAuthor().getName());
- } catch (SaveException e2) {
- throw new WikiSaveException(e2);
- }
- }
-
- try {
- pageNode = nodeDir.newNode(NODE_NAME);
- } catch (ResourceAlreadyExists e1) {
- // This shouldn't happen
- throw new WikiSaveException(e1);
- } catch (NameFormatException e1) {
- throw new WikiSaveException(e1);
- }
- }
-
- // set content
- pageNode.setContent(page.getContent());
-
- // set version
- pageNode.setProperty(LAST_VERSION, String
- .valueOf(page.getLastVersion()));
-
- // set mods
- pageNode.setProperty(MODS, String
- .valueOf((page.isViewableForAll() ? VIEWABLE : 0)
- + (page.isEditableForAll() ? EDITABLE : 0)));
-
- // set edit date
- pageNode.setProperty(EDIT_DATE, String.valueOf(page.getEditDate()
- .getTime()));
-
- // set author
- pageNode.setProperty(AUTHOR, page.getLastAuthor().getName());
-
- try {
- pageNode.save("Page: " + uid + " (revision: "
- + page.getLastVersion() + ") by "
- + page.getLastAuthor().getName());
- } catch (SaveException e) {
- throw new WikiSaveException(e);
- }
-
- }
-
- public void postSave() throws WikiSaveException{
- // do nothing
- }
-
- public boolean preGet() {
- return true;
- }
-
- public WikiPage getPage(String pageName) {
- try {
- Node page = manager.getNode(getPagePath(pageName));
-
- String key = getLangCode() + getPagePath(pageName);
-
- CacheItemUser<String, String> pgch = CacheItem.create(new PageChangeWatcher(key));
-
- // initialize watcher
- pgch.get(key);
-
- WikiPage wikiPage = getPageFromNode(page);
-
- wikiPage.setMetaDataProps(getMetadataProps(pageName));
-
- return wikiPage;
-
- } catch (ResourceDoesNotExist e) {
- return null;
- }
- }
-
- private WikiPage getPageFromNode(Node page) {
- // gets WikiPage from node
-
- int pageMods = Integer.valueOf(page.getProperty(MODS));
-
- WikiPage wikiPage = new WikiPage(page.getFullName(),
- new SimpleCredentials(page.getProperty(AUTHOR)), page
- .getContent(), Integer.valueOf(page
- .getProperty(LAST_VERSION)), page.getRevisionNumber(),
- new Date(Long.valueOf(page.getProperty(EDIT_DATE))),
- wikiEngine, (pageMods & VIEWABLE) == VIEWABLE,
- (pageMods & EDITABLE) == EDITABLE, getRoles(page, EDITABLE),
- getRoles(page, EDITABLE), page.getLength(), langCode);
-
- return wikiPage;
- }
-
- private Set<String> getRoles(Node page, int action) {
- String prefix = (action == VIEWABLE) ? ROLE_PREFIX_VIEWABLE
- : ROLE_PREFIX_EDITABLE;
-
- Set<String> roles = new TreeSet<String>();
-
- int i = 0;
-
- if (page.getProperty(prefix + i) != null) {
- roles.add(page.getProperty(prefix + i));
- i++;
- }
-
- if (roles.size() > 0) {
- return roles;
- } else {
- return null;
- }
- }
-
- public boolean postGet() {
- return true;
- }
-
- private Node getNodeAtVersion(Node pageNode, int version)
- throws ResourceDoesNotExist {
-
- Node retNode = pageNode.getHistory().getNodeAtRevision(version);
-
- if (Integer.valueOf(retNode.getProperty(LAST_VERSION)) <= version) {
- int i = version + 1;
-
- Node compNode = pageNode.getHistory().getNodeAtRevision(i);
-
- while (Integer.valueOf(compNode.getProperty(LAST_VERSION)) < (version + 1)) {
- retNode = compNode;
- compNode = pageNode.getHistory().getNodeAtRevision(++i);
- }
-
- return retNode;
- } else {
- int i = version - 1;
-
- retNode = pageNode.getHistory().getNodeAtRevision(i);
-
- while (Integer.valueOf(retNode.getProperty(LAST_VERSION)) > version) {
- retNode = pageNode.getHistory().getNodeAtRevision(--i);
- }
-
- return retNode;
- }
-
- }
-
- public WikiPage getPageAtVersion(WikiPage originPage, String uid,
- boolean loadContent, int version) {
-
- if (version >= originPage.getLastVersion()) {
- return null;
- }
-
- Node pageNode = null;
- try {
- pageNode = manager.getNode(getPagePath(uid));
- } catch (ResourceDoesNotExist e) {
- return null;
- }
-
- WikiPage pageToReturn = null;
-
- try {
- pageToReturn = (WikiPage) originPage.clone();
- } catch (CloneNotSupportedException e) {
- log.error(e);
- return null;
- }
-
- try {
- pageNode = getNodeAtVersion(pageNode, version);
- } catch (ResourceDoesNotExist e) {
- log.error(e);
- return null;
- }
-
- // set version
- pageToReturn.setVersion(Integer.valueOf(pageNode
- .getProperty(LAST_VERSION)));
-
-
- int pageMods = Integer.valueOf(pageNode.getProperty(MODS));
-
- // set viewable
- pageToReturn.setViewable((pageMods & VIEWABLE) == VIEWABLE);
-
- // set editable
- pageToReturn.setViewable((pageMods & EDITABLE) == EDITABLE);
-
- // set edit date
- pageToReturn.setEditDate(new Date(Long.valueOf(pageNode
- .getProperty(EDIT_DATE))));
-
- // set author
- pageToReturn.setLastAuthor(new SimpleCredentials(pageNode
- .getProperty(AUTHOR)));
-
- // set content
- if (loadContent) {
- pageToReturn.setContent(pageNode.getContent());
- }
-
- // set meta props
- pageToReturn.setMetaDataProps(getMetadataProps(uid));
-
- return pageToReturn;
- }
-
- public boolean pageExists(String pageName) {
- try {
- manager.getNode(getPagePath(pageName));
- return true;
- } catch (ResourceDoesNotExist e) {
- return false;
- }
- }
-
- public void getContentAtVersion(WikiPage page, String uid,
- boolean loadContent, int version) {
- if (loadContent) {
- Node pageNode = null;
- try {
- pageNode = getNodeAtVersion(manager.getNode(getPagePath(uid)),
- version);
- } catch (ResourceDoesNotExist e) {
- log.error(e);
- return;
- }
-
- page.setContent(pageNode.getContent());
- }
- }
-
- public Set<String> getAllPageNames() {
- Directory dir = manager.getRootDirectory();
-
- Set<String> names = new TreeSet<String>();
-
- List<Directory> dirList = dir.getDirectories();
-
- try {
- dirList.remove(manager.getDirectory(LANG_DIR));
- } catch (ResourceDoesNotExist e) {
- // no lang dir - do nothing
- }
-
- getNodesNamesInDir(dirList, names);
-
- return names;
- }
-
- private void getNodesNamesInDir(List<Directory> dirList, Set<String> names) {
-
- for (Directory dirIn : dirList) {
-
- try {
- dirIn.getNode(NODE_NAME);
- names.add(dirIn.getFullName());
- } catch (ResourceDoesNotExist e) {
- // / no page in this directory
- }
-
- getNodesNamesInDir(dirIn.getDirectories(), names);
- }
- }
-
- public Set<String> getPagesFor(String pageName) {
- Set<String> retSet = new TreeSet<String>();
-
- try {
- Directory dir = manager.getDirectory(pageName);
-
- List<Directory> dirList = dir.getDirectories();
-
- for (Directory inDir : dirList) {
- try {
- // if subdir contain a NODE_NAME node - there's a page
- // inside
- inDir.getNode(NODE_NAME);
- retSet.add(inDir.getFullName());
- } catch (RepositoryException e) {
- // there's no page - just directory
- }
- }
- } catch (ResourceDoesNotExist e) {
- // there is no such page
- }
-
- return retSet;
- }
-
- public int getPageMod(String pageName) {
- try {
- Node pageNode = manager.getNode(getPagePath(pageName));
-
- return Integer.valueOf(pageNode.getProperty(MODS));
- } catch (ResourceDoesNotExist e) {
- log.error(e);
- return 0;
- }
- }
-
- public void setPageMod(String pageName, int mods) {
- try {
- Node pageNode = manager.getNode(getPagePath(pageName));
-
- pageNode.setProperty(MODS, String.valueOf(mods));
- } catch (ResourceDoesNotExist e) {
- log.error(e);
- }
- }
-
- public boolean deletePage(String pageName) {
- // TODO make trash
- try {
- Node pageNode = manager.getNode(getPagePath(pageName));
-
- try {
- pageNode.delete();
- } catch (DeleteException e) {
- log.error(e);
- return false;
- }
-
- return true;
- } catch (ResourceDoesNotExist e) {
- log.error(e);
- return false;
- }
- }
-
- public void setWikiEngine(WikiEngine wikiEngine) {
- this.wikiEngine = wikiEngine;
-
- if (langCode == null) {
- langCode = ConfigurationParser.getDefaultLangugeCode();
- }
- }
-
- public void saveRolesSet(String uid, Set<String> roles, int action)
- throws DataSourceException {
-
- Node pageNode = null;
-
- try {
- pageNode = manager.getNode(getPagePath(uid));
- } catch (ResourceDoesNotExist e) {
- throw new DataSourceException(e);
- }
-
- String prefix = (action == VIEWABLE) ? ROLE_PREFIX_VIEWABLE
- : ROLE_PREFIX_EDITABLE;
-
- clearProps(prefix, pageNode);
-
- int i = 0;
-
- for (String role : roles) {
- pageNode.setProperty(prefix + i, role);
- }
-
- try {
- pageNode.save("Saving roles set for page " + uid);
- } catch (SaveException e) {
- log.error(e);
- }
-
- }
-
- private void clearProps(String prefix, Node pageNode) {
- Map<String, String> props = pageNode.getProperties();
-
- for (String key : props.keySet()) {
- if (key.startsWith(prefix)) {
- pageNode.deleteProperty(key);
- log.info("Removed prop: " + key);
- }
- }
- }
-
- public void saveMetadataProps(String uid, Properties props) {
- try {
- Node pageNode = manager.getNode(getPagePath(uid));
-
- clearProps(PROPS_PREFIX, pageNode);
-
- for (Object key : props.keySet()) {
- pageNode.setProperty(PROPS_PREFIX + key, props
- .getProperty((String) key));
- log.info("added prop: " + key);
- }
-
- pageNode.save("Saving metaProps for page: " + uid);
-
- log.info("props set for: " + manager.getPrefix()+ " " +pageNode.getFullName());
-
- } catch (ResourceDoesNotExist e) {
- log.error(e);
- return;
- } catch (SaveException e) {
- log.error(e);
- }
- }
-
-public Properties getMetadataProps(String uid) {
- try {
- Node pageNode = manager.getNode(getPagePath(uid));
-
- Properties retProps = new Properties();
-
- Map<String, String> props = pageNode.getProperties();
-
- // get all properties starting with PROPS_PREFIX (those are meta
- // props for page)
- for (String key : props.keySet()) {
- if (key.startsWith(PROPS_PREFIX)) {
- retProps.setProperty(key.substring(PROPS_PREFIX.length()),
- props.get(key));
- }
- }
-
- return retProps;
- } catch (ResourceDoesNotExist e) {
- log.error(e);
- return null;
- }
- } public void setLanguageCode(String langCode) {
- manager = ContentManager.getContentManager(getPathToMedia() + "/"
- + LANG_DIR + "/" + langCode);
-
- this.langCode = langCode;
-
- log.info("Lang code set: " + langCode + " path is: "
- + manager.getPrefix());
- }
-
- public Map<String, String> getAvailableLanguages() {
- Map<String, String> map = new TreeMap<String, String>();
-
- map.put(ConfigurationParser.getDefaultLangugeCode(), wikiEngine.getAllLanguageCodes()
- .get(ConfigurationParser.getDefaultLangugeCode()));
-
- try {
- Directory dir = getBaseManager().getDirectory(LANG_DIR);
-
- List<Directory> dirList = dir.getDirectories();
-
- for (Directory inDir : dirList) {
- if (wikiEngine.getAllLanguageCodes().get(inDir.getName()) != null) {
- map.put(inDir.getName(), wikiEngine.getAllLanguageCodes()
- .get(inDir.getName()));
- }
- }
- } catch (ResourceDoesNotExist e) {
- // no other langs then default
- }
-
- return map;
- }
-
- private ContentManager getBaseManager() {
- return ContentManager.getContentManager(getPathToMedia());
- }
-
- public void addLangCode(String langCode, String langDesc) {
- ContentManager baseMngr = ContentManager
- .getContentManager(getPathToMedia());
-
- List<Resource> newDirs = new ArrayList<Resource>();
-
- try {
- baseMngr.getDirectory(LANG_DIR + "/" + langCode);
- } catch (ResourceDoesNotExist e) {
- try {
- newDirs.add(baseMngr.getRootDirectory().newDirectory(
- LANG_DIR + "/" + langCode));
- } catch (ResourceAlreadyExists e1) {
- // wont happen
- log.error(e1);
- } catch (NameFormatException e1) {
- log.error(e1);
- return;
- }
- }
-
- if (newDirs.size() > 0) {
- try {
- manager.save("Adding new language: " + langCode, newDirs);
- } catch (SaveException e) {
- log.error(e);
- return;
- }
- }
-
- }
-
- public String getLangCode() {
- return langCode;
- }
-
- class PageChangeWatcher extends ShotokuResourceWatcher<String, String> {
-
- private String keyBase;
-
- public PageChangeWatcher(String keyBase) {
- super();
- this.keyBase = keyBase;
- }
-
- protected ValueChange<String> update(String key, String currentObject, Map changes) {
- wikiEngine.refreshPage(keyBase.substring(getLangCode().length(),
- keyBase.length() - ("/" + NODE_NAME).length()),
- getLangCode());
-
- return ValueChange.noChange();
- }
-
- public ValueInit<String> init(String key) {
- addWatchedPath(key, keyBase.substring(getLangCode().length()));
-
- return ValueInit.realValue("not changed");
- }
-
- protected ContentManager initContentManager(String key) {
- return manager;
- }
-
- }
-
- public void setGlobalProperty(String key, String value) throws DataSourceException {
- // TODO Auto-generated method stub
-
- }
-
- public String getGlobalProperty(String key) throws DataSourceException {
- // TODO Auto-generated method stub
- return null;
- }
-}
Deleted: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/ShotokuWikiPageDictionary.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/ShotokuWikiPageDictionary.java 2008-07-18 14:56:15 UTC (rev 21120)
+++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/ShotokuWikiPageDictionary.java 2008-07-18 15:01:52 UTC (rev 21121)
@@ -1,275 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.wiki;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.log4j.Logger;
-import org.jboss.shotoku.ContentManager;
-import org.jboss.shotoku.Directory;
-import org.jboss.shotoku.exceptions.NameFormatException;
-import org.jboss.shotoku.exceptions.ResourceAlreadyExists;
-import org.jboss.shotoku.exceptions.ResourceDoesNotExist;
-import org.jboss.shotoku.exceptions.SaveException;
-import org.jboss.wiki.configuration.ConfigurationParser;
-import org.jboss.wiki.exceptions.PageRenamingException;
-
-public class ShotokuWikiPageDictionary implements WikiPageDictionary {
-
- private static final String WIKI_DICT_PREFIX = "ShotokuDataSource:wikiDict";
-
- private static final String PROP_FILE = "shotokudatasource.properties";
-
- private Directory dictDir;
-
- private Logger log = Logger.getLogger(this.getClass());
-
- private Map<String, String> uidToReal;
-
- private Map<String, String> realToUid;
-
- // private DictChangeWatcher dictChange;
-
- private WikiEngine wikiEngine;
-
- private String langCode;
-
- private Long lastLangModDate = null;
-
- // wikipage dictionary
-
- public ShotokuWikiPageDictionary() {
- ContentManager manager = ContentManager
- .getContentManager(getPathToMedia());
-
- try {
- dictDir = manager.getDirectory(ShotokuMediaDataSource.LANG_DIR);
- } catch (ResourceDoesNotExist e) {
- try {
- dictDir = manager.getRootDirectory().newDirectory(
- ShotokuMediaDataSource.LANG_DIR);
- } catch (ResourceAlreadyExists e1) {
- // shoudln't happen
- log.error(e);
- } catch (NameFormatException e1) {
- log.error(e);
- }
- }
-
- uidToReal = new HashMap<String, String>();
- realToUid = new HashMap<String, String>();
-
- loadDictionary();
-
- }
-
- private String getPathToMedia() {
- // load paths
- InputStream is = ShotokuMediaDataSource.class
- .getResourceAsStream(PROP_FILE);
-
- Properties props = new Properties();
-
- try {
- props.load(is);
- } catch (IOException e) {
- log.error(e);
- } finally {
- try {
- is.close();
- } catch (IOException e) {
- log.error(e);
- }
- }
-
- return props.getProperty("pathToMedia");
- }
-
- public String getRealName(String uid) {
- loadDictionary();
-
- return (uidToReal.get(uid) != null) ? uidToReal.get(uid) : uid;
- }
-
- public String getUid(String realName) {
- loadDictionary();
-
- return (realToUid.get(realName) != null) ? realToUid.get(realName)
- : realName;
- }
-
- public void rename(String uid, String newName) throws PageRenamingException {
- loadDictionary();
-
- synchronized (this) {
- if (uidInDictionary(uid)) {
- realToUid.remove(uidToReal.get(uid));
- uidToReal.remove(uid);
- }
-
- realToUid.put(newName, uid);
- uidToReal.put(uid, newName);
-
- try {
- saveDictionary();
- } catch (SaveException e) {
- throw new PageRenamingException(e);
- }
- }
- }
-
- private void saveDictionary() throws SaveException {
- removeDictionary();
-
- for (String key : uidToReal.keySet()) {
- dictDir.setProperty(WIKI_DICT_PREFIX + key, uidToReal.get(key));
- }
-
- dictDir.save("New dictionary for language: " + dictDir.getName());
- }
-
- private void removeDictionary() {
- Map<String, String> props = dictDir.getProperties();
-
- // remove all props
- for (String key : props.keySet()) {
- if (key.startsWith(WIKI_DICT_PREFIX)) {
- dictDir.deleteProperty(key);
- }
- }
- }
-
- public boolean uidInDictionary(String uid) {
- loadDictionary();
-
- return uidToReal.containsKey(uid);
- }
-
- public boolean realNameInDictionary(String realName) {
- loadDictionary();
-
- return realToUid.containsKey(realName);
- }
-
- public void removeDictForPage(String uid) throws PageRenamingException {
- loadDictionary();
-
- synchronized (this) {
- realToUid.remove(uidToReal.get(uid));
- uidToReal.remove(uid);
-
- try {
- saveDictionary();
- } catch (SaveException e) {
- throw new PageRenamingException(e);
- }
- }
- }
-
- public void setWikiEngine(WikiEngine wikiEngine) {
- this.wikiEngine = wikiEngine;
-
- if (langCode == null) {
- langCode = ConfigurationParser.getDefaultLangugeCode();
- }
- }
-
- public void setLanguageCode(String langCode) {
- // TODO ShotokuCache.remove(dictDir.getFullName());
-
- ContentManager manager = ContentManager
- .getContentManager(getPathToMedia());
-
- try {
- dictDir = manager.getDirectory(ShotokuMediaDataSource.LANG_DIR
- + "/" + langCode);
- } catch (ResourceDoesNotExist e) {
- // something's wrong
- log.error(e);
- }
-
- // make lastLangModDate null - this will force reloading dictionary
- lastLangModDate = null;
-
- loadDictionary();
-
- /*
- * dictChange = new DictChangeWatcher(dictDir.getFullName());
- *
- * dictChange.get(dictDir.getFullName());
- */
-
- this.langCode = langCode;
- }
-
- private void loadDictionary() {
- // reload dictionary if it's executed for first time (lastLangModDate is
- // null) or dicLang have changed
- if (lastLangModDate == null
- || dictDir.getLastModification() != lastLangModDate) {
- synchronized (this) {
- Map<String, String> props = dictDir.getProperties();
-
- // load all mapings and build 2 maps
- for (String key : props.keySet()) {
- if (key.startsWith(WIKI_DICT_PREFIX)) {
- String uid = key.substring(WIKI_DICT_PREFIX.length());
- String real = props.get(key);
-
- realToUid.put(real, uid);
- uidToReal.put(uid, real);
- }
- }
- }
- }
- }
-
- public Map<String, String> getRenameMapings() {
- loadDictionary();
-
- return new HashMap<String, String>(uidToReal);
- }
-
- /*
- * class DictChangeWatcher extends ShotokuResourceWatcher<String, String> {
- *
- * private String keyBase;
- *
- * public DictChangeWatcher(String keyBase) { super(); this.keyBase =
- * keyBase; }
- *
- * protected void update(String key, String currentObject, Map changes) {
- * loadDictionary(); }
- *
- * public String init(String key) { addWatchedPath(key, keyBase);
- *
- * return "not changed"; }
- *
- * protected ContentManager initContentManager(String key) { return
- * ContentManager.getContentManager(getPathToMedia()); } }
- */
-
-}
More information about the jboss-svn-commits
mailing list