r1385 - in xwiki-apps/gelc/gelcv1/trunk: gelc/src/main/web/WEB-INF gelcplugins/src/main/java/org/gelc/xwiki/plugins gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets gelcplugins/src/main/java/org/gelc/xwiki/plugins/framework gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime gelcplugins/src/test/java/org/gelc/xwiki/plugins gelcplugins/src/test/java/org/gelc/xwiki/plugins/mime
Jeremi Joslin
jeremi at users.forge.objectweb.org
Thu Oct 12 18:18:19 CEST 2006
Author: jeremi
Date: 2006-10-12 18:18:18 +0200 (Thu, 12 Oct 2006)
New Revision: 1385
Added:
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeType.java
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypeConstant.java
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypePlugin.java
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypePluginAPI.java
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/mime/
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/mime/MimeTypePluginTest.java
Modified:
xwiki-apps/gelc/gelcv1/trunk/gelc/src/main/web/WEB-INF/hibernate.cfg.xml
xwiki-apps/gelc/gelcv1/trunk/gelc/src/main/web/WEB-INF/xwiki.cfg
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetConstant.java
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPlugin.java
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/framework/FrameworkConstant.java
Log:
[GELC]
* add the Mime type Manager
* refactor some code in the assetManager
* add the XWiki class AssetClass
Modified: xwiki-apps/gelc/gelcv1/trunk/gelc/src/main/web/WEB-INF/hibernate.cfg.xml
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelc/src/main/web/WEB-INF/hibernate.cfg.xml 2006-10-12 16:12:30 UTC (rev 1384)
+++ xwiki-apps/gelc/gelcv1/trunk/gelc/src/main/web/WEB-INF/hibernate.cfg.xml 2006-10-12 16:18:18 UTC (rev 1385)
@@ -1,40 +1,40 @@
-<?xml version='1.0' encoding='utf-8'?>
-<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
- "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
-<hibernate-configuration>
- <session-factory>
- <property name="show_sql">false</property>
- <property name="use_outer_join">true</property>
-
- <property name="dbcp.defaultAutoCommit">false</property>
- <property name="dbcp.maxActive">50</property>
- <property name="dbcp.maxIdle">5</property>
- <property name="dbcp.maxWait">30000</property>
- <property name="dbcp.whenExhaustedAction">1</property>
- <property name="dbcp.ps.whenExhaustedAction">1</property>
- <property name="dbcp.ps.maxActive">20</property>
- <property name="dbcp.ps.maxWait">120000</property>
- <property name="dbcp.ps.maxIdle">20</property>
-
- <!--
- <property name="connection.url">jdbc:hsqldb:file:c:/dev/java/xwiki/release/xwikionjetty/db/xwiki_db;shutdown=true;ifexists=true</property>
- <property name="connection.username">sa</property>
- <property name="connection.password"></property>
- <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
- <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
- -->
-
- <property name="connection.url">jdbc:mysql://localhost/xwiki</property>
- <property name="connection.username">xwiki</property>
- <property name="connection.password">gelc</property>
- <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
-
- <property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
- <property name="connection.pool_size">2</property>
- <property name="statement_cache.size">2</property>
- <property name="jdbc.batch_size">0</property>
- <!-- Mapping files -->
- <mapping resource="xwiki.hbm.xml"/>
- </session-factory>
-</hibernate-configuration>
+<?xml version='1.0' encoding='utf-8'?>
+<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
+ "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+<hibernate-configuration>
+ <session-factory>
+ <property name="show_sql">false</property>
+ <property name="use_outer_join">true</property>
+
+ <property name="dbcp.defaultAutoCommit">false</property>
+ <property name="dbcp.maxActive">50</property>
+ <property name="dbcp.maxIdle">5</property>
+ <property name="dbcp.maxWait">30000</property>
+ <property name="dbcp.whenExhaustedAction">1</property>
+ <property name="dbcp.ps.whenExhaustedAction">1</property>
+ <property name="dbcp.ps.maxActive">20</property>
+ <property name="dbcp.ps.maxWait">120000</property>
+ <property name="dbcp.ps.maxIdle">20</property>
+
+ <!--
+ <property name="connection.url">jdbc:hsqldb:file:c:/dev/java/xwiki/release/xwikionjetty/db/xwiki_db;shutdown=true;ifexists=true</property>
+ <property name="connection.username">sa</property>
+ <property name="connection.password"></property>
+ <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
+ <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
+ -->
+
+ <property name="connection.url">jdbc:mysql://localhost/gelc?useServerPrepStmts=false</property>
+ <property name="connection.username">gelc</property>
+ <property name="connection.password">gelc</property>
+ <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
+ <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
+
+ <property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
+ <property name="connection.pool_size">2</property>
+ <property name="statement_cache.size">2</property>
+ <property name="jdbc.batch_size">0</property>
+ <!-- Mapping files -->
+ <mapping resource="xwiki.hbm.xml"/>
+ </session-factory>
+</hibernate-configuration>
Modified: xwiki-apps/gelc/gelcv1/trunk/gelc/src/main/web/WEB-INF/xwiki.cfg
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelc/src/main/web/WEB-INF/xwiki.cfg 2006-10-12 16:12:30 UTC (rev 1384)
+++ xwiki-apps/gelc/gelcv1/trunk/gelc/src/main/web/WEB-INF/xwiki.cfg 2006-10-12 16:18:18 UTC (rev 1385)
@@ -20,7 +20,7 @@
xwiki.store.cache=1
xwiki.store.cache.capacity=100
xwiki.monitor=1
-xwiki.plugins=com.xpn.xwiki.monitor.api.MonitorPlugin,com.xpn.xwiki.plugin.packaging.PackagePlugin,com.xpn.xwiki.plugin.query.QueryPlugin,com.xpn.xwiki.plugin.fileupload.FileUploadPlugin,com.xpn.xwiki.plugin.image.ImagePlugin,org.gelc.xwiki.plugins.assets.AssetManagerPlugin,org.gelc.xwiki.plugins.framework.FrameworkManagerPlugin,com.xpn.xwiki.plugin.userdirectory.UserDirectoryPlugin,com.xpn.xwiki.plugin.usertools.XWikiUserManagementToolsImpl
+xwiki.plugins=com.xpn.xwiki.monitor.api.MonitorPlugin,com.xpn.xwiki.plugin.packaging.PackagePlugin,com.xpn.xwiki.plugin.query.QueryPlugin,com.xpn.xwiki.plugin.fileupload.FileUploadPlugin,com.xpn.xwiki.plugin.image.ImagePlugin,org.gelc.xwiki.plugins.assets.AssetManagerPlugin,org.gelc.xwiki.plugins.framework.FrameworkManagerPlugin,com.xpn.xwiki.plugin.userdirectory.UserDirectoryPlugin,com.xpn.xwiki.plugin.usertools.XWikiUserManagementToolsImpl,org.gelc.xwiki.plugins.mime.MimeTypePlugin
# This parameter allows XWiki to operate in Hosting mode
# allowing to create multiple wikis having their own database
Modified: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetConstant.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetConstant.java 2006-10-12 16:12:30 UTC (rev 1384)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetConstant.java 2006-10-12 16:18:18 UTC (rev 1385)
@@ -19,7 +19,14 @@
public final static String CLASS_FRAMEWORK_ITEM = "framework_item";
+ public final static String ASSET_CLASS_FULLNAME = "XWiki.AssetClass";
+ public final static String ASSET_CLASS_NAME = "AssetClass";
+ public final static String ASSET_ITEM_MIME_TYPE = "mimeType";
+ public final static String ASSET_ITEM_CATEGORY = "category";
+
+
+
public final static String EXTERNAL_ASSET_CLASS_FULLNAME = "XWiki.ExternalAssetClass";
public final static String EXTERNAL_ASSET_CLASS_NAME = "ExternalAssetClass";
Modified: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPlugin.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPlugin.java 2006-10-12 16:12:30 UTC (rev 1384)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPlugin.java 2006-10-12 16:18:18 UTC (rev 1385)
@@ -29,6 +29,7 @@
import com.xpn.xwiki.objects.classes.BaseClass;
import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
import com.xpn.xwiki.plugin.XWikiPluginInterface;
+import org.gelc.xwiki.plugins.mime.MimeTypePlugin;
import java.io.IOException;
import java.io.InputStream;
@@ -49,7 +50,6 @@
try {
initClasses(context);
} catch (XWikiException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
@@ -57,7 +57,6 @@
try {
initClasses(context);
} catch (XWikiException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
@@ -70,23 +69,13 @@
}
public Asset createAssetDocument(String assetName, XWikiContext context) throws XWikiException {
- String pageName = getUniquePageName(ASSET_TEMPORARY_SPACE, assetName, context);
+ String pageName = context.getWiki().getUniquePageName(ASSET_TEMPORARY_SPACE, assetName, context);
Asset asset = (Asset) context.getWiki().getDocument(ASSET_TEMPORARY_SPACE, pageName, context).newDocument(Asset.class.getName(), context);
asset.setTitle(assetName);
asset.setCustomClass(Asset.class.getName());
return asset;
}
- private String getUniquePageName(String space, String assetName, XWikiContext context){
- String pageName = context.getWiki().clearName(assetName, context);
- if (context.getWiki().exists(space + "." + pageName, context)){
- int i = 0;
- while (context.getWiki().exists(space + "." + pageName + "_" + i, context))
- i++;
- return pageName + "_" + i;
- }
- return pageName;
- }
public boolean isComplet(Asset asset, XWikiContext context) {
Map res = getStatusList(asset, context);
@@ -128,6 +117,7 @@
private void initClasses(XWikiContext context) throws XWikiException {
initFrameworkItemAssetClass(context);
initExternalAssetClass(context);
+ initAssetClass(context);
}
private void initFrameworkItemAssetClass(XWikiContext context) throws XWikiException {
@@ -158,6 +148,35 @@
xwiki.saveDocument(doc, context);
}
+ private void initAssetClass(XWikiContext context) throws XWikiException {
+ XWikiDocument doc;
+ XWiki xwiki = context.getWiki();
+ boolean needsUpdate = false;
+
+ try {
+ doc = xwiki.getDocument(ASSET_CLASS_FULLNAME, context);
+ } catch (Exception e) {
+ doc = new XWikiDocument();
+ doc.setSpace("XWiki");
+ doc.setName(ASSET_CLASS_NAME);
+ needsUpdate = true;
+ }
+
+ BaseClass bclass = doc.getxWikiClass();
+ bclass.setName(ASSET_CLASS_FULLNAME);
+ needsUpdate |= bclass.addTextField(ASSET_ITEM_MIME_TYPE, "mimeType", 50);
+ needsUpdate |= bclass.addDBListField(ASSET_ITEM_CATEGORY, "category", MimeTypePlugin.getCategoriesListHsql());
+
+ String content = doc.getContent();
+ if ((content==null)||(content.equals(""))) {
+ needsUpdate = true;
+ doc.setContent("1 " + ASSET_CLASS_FULLNAME);
+ }
+
+ if (needsUpdate)
+ xwiki.saveDocument(doc, context);
+ }
+
private void initExternalAssetClass(XWikiContext context) throws XWikiException {
XWikiDocument doc;
XWiki xwiki = context.getWiki();
@@ -174,7 +193,7 @@
BaseClass bclass = doc.getxWikiClass();
bclass.setName(EXTERNAL_ASSET_CLASS_FULLNAME);
- needsUpdate |= bclass.addTextField(EXTERNAL_ASSET_LINK, "external Link", 500);
+ needsUpdate |= bclass.addTextField(EXTERNAL_ASSET_LINK, "external Link", 200);
String content = doc.getContent();
if ((content==null)||(content.equals(""))) {
Modified: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/framework/FrameworkConstant.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/framework/FrameworkConstant.java 2006-10-12 16:12:30 UTC (rev 1384)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/framework/FrameworkConstant.java 2006-10-12 16:18:18 UTC (rev 1385)
@@ -21,13 +21,6 @@
*/
package org.gelc.xwiki.plugins.framework;
-/**
- * Created by IntelliJ IDEA.
- * User: jeremi
- * Date: Sep 27, 2006
- * Time: 11:15:30 AM
- * To change this template use File | Settings | File Templates.
- */
public interface FrameworkConstant {
public final static String PLUGIN_NAME = "framework_manager";
Added: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeType.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeType.java 2006-10-12 16:12:30 UTC (rev 1384)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeType.java 2006-10-12 16:18:18 UTC (rev 1385)
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * 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.
+ *
+ * @author jeremi
+ */
+package org.gelc.xwiki.plugins.mime;
+
+import com.xpn.xwiki.api.Document;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.XWikiContext;
+
+public class MimeType extends Document {
+ public MimeType(XWikiDocument doc, XWikiContext context) {
+ super(doc, context);
+ }
+
+ public String getCategory(){
+ return (String) get(MimeTypeConstant.MIMETYPE_ITEM_CATEGORY);
+ }
+
+ public String getMimeType(){
+ return (String) get(MimeTypeConstant.MIMETYPE_ITEM_MIME_TYPE);
+ }
+}
Property changes on: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeType.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypeConstant.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypeConstant.java 2006-10-12 16:12:30 UTC (rev 1384)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypeConstant.java 2006-10-12 16:18:18 UTC (rev 1385)
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * 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.
+ *
+ * @author jeremi
+ */
+package org.gelc.xwiki.plugins.mime;
+
+
+public interface MimeTypeConstant {
+ public final static String PLUGIN_NAME = "mime_type";
+
+ public final static String MIMETYPE_SPACE = "MimeType";
+
+ public final static String MIMETYPE_CLASS_FULLNAME = "XWiki.MimeTypeClass";
+ public final static String MIMETYPE_CLASS_NAME = "MimeTypeClass";
+ public final static String MIMETYPE_ITEM_MIME_TYPE = "mimeType";
+ public final static String MIMETYPE_ITEM_CATEGORY = "category";
+ public final static String MIMETYPE_ITEM_EXTENSION = "extension";
+}
Property changes on: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypeConstant.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypePlugin.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypePlugin.java 2006-10-12 16:12:30 UTC (rev 1384)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypePlugin.java 2006-10-12 16:18:18 UTC (rev 1385)
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * 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.
+ *
+ * @author jeremi
+ */
+package org.gelc.xwiki.plugins.mime;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.objects.classes.BaseClass;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.api.Object;
+import com.xpn.xwiki.api.Api;
+import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
+import com.xpn.xwiki.plugin.XWikiPluginInterface;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.gelc.xwiki.plugins.mdfw.MetaDataFrameworkPlugin;
+
+import java.util.List;
+import java.util.Iterator;
+import java.util.ArrayList;
+
+
+public class MimeTypePlugin extends XWikiDefaultPlugin implements XWikiPluginInterface, MimeTypeConstant {
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(MetaDataFrameworkPlugin.class);
+
+
+ public MimeTypePlugin(String name, String className, XWikiContext context) {
+ super(name, className, context);
+ }
+
+ public String getName() {
+ return PLUGIN_NAME;
+ }
+
+ public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) {
+ return new MimeTypePluginAPI((MimeTypePlugin) plugin, context);
+ }
+
+ public void virtualInit(XWikiContext context){
+ try {
+ initClasses(context);
+ } catch (XWikiException e) {
+
+ }
+ }
+
+ public void init(XWikiContext context){
+ try {
+ initClasses(context);
+ } catch (XWikiException e) {
+
+ }
+ }
+
+ public void add(String mimeType, String category, String extension, XWikiContext context) throws XWikiException {
+ String pageName = context.getWiki().getUniquePageName(MIMETYPE_SPACE, mimeType, context);
+ MimeType doc = (MimeType) context.getWiki().getDocument(MIMETYPE_SPACE, pageName, context).newDocument(MimeType.class.getName(), context);
+ doc.setCustomClass(MimeType.class.getName());
+ Object obj = doc.newObject(MIMETYPE_CLASS_FULLNAME);
+ doc.use(obj);
+ doc.set(MIMETYPE_ITEM_MIME_TYPE, mimeType);
+ doc.set(MIMETYPE_ITEM_CATEGORY, category);
+ doc.set(MIMETYPE_ITEM_EXTENSION, extension);
+ doc.save();
+ }
+
+ public MimeType getCategoryByMimetype(String mimeType, XWikiContext context) throws XWikiException {
+ String hql = ", BaseObject as obj, StringProperty as prop where obj.name=doc.fullName"
+ + " and obj.className='" + MIMETYPE_CLASS_FULLNAME + "' and prop.id.id = obj.id "
+ + "and prop.id.name = '" + MIMETYPE_ITEM_MIME_TYPE + "' and prop.value='" + mimeType + "'";
+ List list = context.getWiki().getStore().searchDocumentsNames(hql, context);
+ if (list.size() > 0)
+ return (MimeType) context.getWiki().getDocument((String) list.get(0), context).newDocument(context);
+ return null;
+ }
+
+ public MimeType getCategoryByExtension(String extension, XWikiContext context) throws XWikiException {
+ String hql = ", BaseObject as obj, StringProperty as prop where obj.name=doc.fullName"
+ + " and obj.className='" + MIMETYPE_CLASS_FULLNAME + "' and prop.id.id = obj.id "
+ + "and prop.id.name = '" + MIMETYPE_ITEM_EXTENSION + "' and prop.value='" + extension + "'";
+ List list = context.getWiki().getStore().searchDocumentsNames(hql, context);
+ if (list.size() > 0)
+ return (MimeType) context.getWiki().getDocument((String) list.get(0), context).newDocument(context);
+ return null;
+ }
+
+ public List getCategories(XWikiContext context) throws XWikiException {
+ String hql = ", BaseObject as obj, StringProperty as prop where obj.name=doc.fullName"
+ + " and obj.className='" + MIMETYPE_CLASS_FULLNAME + "' and prop.id.id = obj.id "
+ + " and prop.id.name = '" + MIMETYPE_ITEM_CATEGORY + "' "
+ + " group by prop.value";
+ List list = context.getWiki().getStore().searchDocumentsNames(hql, context);
+ List categs = new ArrayList();
+ Iterator it = list.iterator();
+ while(it.hasNext()){
+ MimeType doc = (MimeType) context.getWiki().getDocument((String) it.next(), context).newDocument(context);
+ categs.add(doc.getCategory());
+ }
+
+ return categs;
+ }
+
+ private void initClasses(XWikiContext context) throws XWikiException {
+ initMimeTypeClass(context);
+ }
+
+
+ public static String getCategoriesListHsql(){
+ String hql = "select prop.value from BaseObject as obj, StringProperty as prop where "
+ + " obj.className='" + MIMETYPE_CLASS_FULLNAME + "' and prop.id.id = obj.id "
+ + " and prop.id.name = '" + MIMETYPE_ITEM_CATEGORY + "' "
+ + " group by prop.value";
+ return hql;
+ }
+
+ private void initMimeTypeClass(XWikiContext context) throws XWikiException {
+ XWikiDocument doc;
+ XWiki xwiki = context.getWiki();
+ boolean needsUpdate = false;
+
+ try {
+ doc = xwiki.getDocument(MIMETYPE_CLASS_FULLNAME, context);
+ } catch (Exception e) {
+ doc = new XWikiDocument();
+ doc.setSpace("XWiki");
+ doc.setName(MIMETYPE_CLASS_NAME);
+ needsUpdate = true;
+ }
+
+ BaseClass bclass = doc.getxWikiClass();
+ bclass.setName(MIMETYPE_CLASS_FULLNAME);
+ needsUpdate |= bclass.addTextField(MIMETYPE_ITEM_MIME_TYPE, "Mime type", 50);
+ needsUpdate |= bclass.addTextField(MIMETYPE_ITEM_CATEGORY, "Category", 50);
+ needsUpdate |= bclass.addTextField(MIMETYPE_ITEM_EXTENSION, "extension", 50);
+
+
+ String content = doc.getContent();
+ if ((content==null)||(content.equals(""))) {
+ needsUpdate = true;
+ doc.setContent("1 " + MIMETYPE_CLASS_FULLNAME);
+ }
+
+ if (needsUpdate)
+ xwiki.saveDocument(doc, context);
+ }
+}
Property changes on: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypePlugin.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypePluginAPI.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypePluginAPI.java 2006-10-12 16:12:30 UTC (rev 1384)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypePluginAPI.java 2006-10-12 16:18:18 UTC (rev 1385)
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * 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.
+ *
+ * @author jeremi
+ */
+package org.gelc.xwiki.plugins.mime;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.api.Api;
+
+import java.util.List;
+
+
+public class MimeTypePluginAPI extends Api {
+ MimeTypePlugin plugin;
+
+ public MimeTypePluginAPI(MimeTypePlugin plugin, XWikiContext context) {
+ super(context);
+ this.plugin = plugin;
+ }
+
+ public void add(String mimeType, String category, String extension) throws XWikiException {
+ plugin.add(mimeType, category, extension, context);
+ }
+
+ public MimeType getCategoryByMimetype(String mimeType) throws XWikiException {
+ return plugin.getCategoryByMimetype(mimeType, context);
+ }
+
+ public MimeType getCategoryByExtension(String mimeType) throws XWikiException {
+ return plugin.getCategoryByExtension(mimeType, context);
+ }
+
+ public List getCategories() throws XWikiException {
+ return plugin.getCategories(context);
+ }
+
+}
Property changes on: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mime/MimeTypePluginAPI.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/mime/MimeTypePluginTest.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/mime/MimeTypePluginTest.java 2006-10-12 16:12:30 UTC (rev 1384)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/mime/MimeTypePluginTest.java 2006-10-12 16:18:18 UTC (rev 1385)
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * 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.
+ *
+ * @author jeremi
+ */
+package org.gelc.xwiki.plugins.mime;
+
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.test.HibernateTestCase;
+import com.xpn.xwiki.web.XWikiServletURLFactory;
+
+import java.net.URL;
+
+
+public class MimeTypePluginTest extends HibernateTestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ getXWiki().getPluginManager().addPlugin(MimeTypeConstant.PLUGIN_NAME,"org.gelc.xwiki.plugins.mime.MimeTypePlugin", getXWikiContext());
+
+ getXWikiContext().setURLFactory(new XWikiServletURLFactory(new URL("http://www.xwiki.org/"), "xwiki/" , "bin/"));
+ }
+
+ public void testAddMimeType() throws XWikiException {
+ MimeTypePluginAPI mtmng = (MimeTypePluginAPI) xwiki.getPluginApi(MimeTypeConstant.PLUGIN_NAME, context);
+ mtmng.add("image/gif", "picture(photo)", "gif");
+ mtmng.add("image/jpeg", "picture(photo)", "jpg");
+ mtmng.add("application/msword", "document", "doc");
+
+ assertEquals("document", mtmng.getCategoryByExtension("doc").getCategory());
+ assertEquals("document", mtmng.getCategoryByMimetype("application/msword").getCategory());
+
+ assertEquals("picture(photo)", mtmng.getCategoryByExtension("gif").getCategory());
+ assertEquals("picture(photo)", mtmng.getCategoryByMimetype("image/jpeg").getCategory());
+
+ assertEquals(2, mtmng.getCategories().size());
+ }
+}
Property changes on: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/mime/MimeTypePluginTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Xwiki-notifications
mailing list