r1378 - in xwiki-apps/gelc/gelcv1/trunk/gelcplugins: . src/main/java/org/gelc/xwiki/plugins src/main/java/org/gelc/xwiki/plugins/assets src/main/java/org/gelc/xwiki/plugins/licence src/test/cactus src/test/cactus/org src/test/cactus/org/gelc src/test/cactus/org/gelc/xwiki src/test/cactus/org/gelc/xwiki/plugins src/test/cactus/org/gelc/xwiki/plugins/assets src/test/cactus/org/gelc/xwiki/plugins/assets/cactus src/test/java/org/gelc/xwiki/plugins src/test/java/org/gelc/xwiki/plugins/assets
Jeremi Joslin
jeremi at users.forge.objectweb.org
Tue Oct 10 19:43:19 CEST 2006
Author: jeremi
Date: 2006-10-10 19:43:18 +0200 (Tue, 10 Oct 2006)
New Revision: 1378
Added:
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/Asset.java
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/assets/AssetManagerPluginApi.java
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/licence/
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/licence/Licence.java
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/cactus/org/
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/cactus/org/gelc/
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/cactus/org/gelc/xwiki/
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/cactus/org/gelc/xwiki/plugins/
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/cactus/org/gelc/xwiki/plugins/assets/
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/cactus/org/gelc/xwiki/plugins/assets/cactus/
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/cactus/org/gelc/xwiki/plugins/assets/cactus/AssetManagerPluginTest.java
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/assets/
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginTest.java
Modified:
xwiki-apps/gelc/gelcv1/trunk/gelcplugins/gelcplugins.iml
Log:
[GELC]
Add the asset Manager
Modified: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/gelcplugins.iml
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/gelcplugins.iml 2006-10-10 17:42:45 UTC (rev 1377)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/gelcplugins.iml 2006-10-10 17:43:18 UTC (rev 1378)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4" relativePaths="true" type="JAVA_MODULE">
<component name="ModuleRootManager" />
- <component name="NewModuleRootManager">
+ <component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/../build/gelc/WEB-INF/classes" />
<exclude-output />
<output-test url="file://$MODULE_DIR$/../build/gelctest" />
Added: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/Asset.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/Asset.java 2006-10-10 17:42:45 UTC (rev 1377)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/Asset.java 2006-10-10 17:43:18 UTC (rev 1378)
@@ -0,0 +1,43 @@
+/*
+ * 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.assets;
+
+import com.xpn.xwiki.api.Document;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.doc.XWikiAttachment;
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+
+public class Asset extends Document {
+ public Asset(XWikiDocument doc, XWikiContext context) {
+ super(doc, context);
+ }
+
+ public void addAttachment(InputStream iStream, String name) throws XWikiException, IOException {
+ XWikiAttachment att = addAttachment(name, iStream);
+ doc.saveAttachmentContent(att, context);
+ }
+}
Property changes on: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/Asset.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: 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-10 17:42:45 UTC (rev 1377)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetConstant.java 2006-10-10 17:43:18 UTC (rev 1378)
@@ -0,0 +1,28 @@
+package org.gelc.xwiki.plugins.assets;
+
+
+public interface AssetConstant {
+ public final static String PLUGIN_NAME = "asset_manager";
+
+ public final static int ASSET_STATUS_ADDTIONAL_FRAMEWORK_SELECTED = 0;
+ public final static int ASSET_STATUS_FRAMEWORK_ITEM_SELECTED = 1;
+ public final static int ASSET_STATUS_ATTACHEMENT = 2;
+ public final static int ASSET_STATUS_EXTERNAL_LINK = 3;
+ public final static int ASSET_STATUS_LICENCE = 4;
+ public final static int ASSET_STATUS_SIZE = 5;
+
+ public final static String ASSET_TEMPORARY_SPACE = "AssetTemp";
+
+
+ public final static String FRAMEWORK_ASSET_CLASS_FULLNAME = "XWiki.FrameworkItemAssetClass";
+ public final static String FRAMEWORK_ASSET_CLASS_NAME = "FrameworkItemAssetClass";
+
+ public final static String CLASS_FRAMEWORK_ITEM = "framework_item";
+
+
+ public final static String EXTERNAL_ASSET_CLASS_FULLNAME = "XWiki.ExternalAssetClass";
+ public final static String EXTERNAL_ASSET_CLASS_NAME = "ExternalAssetClass";
+
+ public final static String EXTERNAL_ASSET_LINK = "link";
+
+}
Property changes on: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetConstant.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: 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-10 17:42:45 UTC (rev 1377)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPlugin.java 2006-10-10 17:43:18 UTC (rev 1378)
@@ -0,0 +1,233 @@
+/*
+ * 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.assets;
+
+import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.api.Api;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.objects.classes.BaseClass;
+import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
+import com.xpn.xwiki.plugin.XWikiPluginInterface;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+public class AssetManagerPlugin extends XWikiDefaultPlugin implements XWikiPluginInterface, AssetConstant{
+
+ public AssetManagerPlugin(String name, String className, XWikiContext context) {
+ super(name, className, context);
+ }
+
+ public void virtualInit(XWikiContext context){
+ try {
+ initClasses(context);
+ } catch (XWikiException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+
+ public void init(XWikiContext context){
+ try {
+ initClasses(context);
+ } catch (XWikiException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+
+ public String getName() {
+ return PLUGIN_NAME;
+ }
+
+ public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) {
+ return new AssetManagerPluginApi((AssetManagerPlugin) plugin, context);
+ }
+
+ public Asset createAssetDocument(String assetName, XWikiContext context) throws XWikiException {
+ String pageName = 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);
+ if (res.get(ASSET_STATUS_ATTACHEMENT).equals(0) && res.get(ASSET_STATUS_EXTERNAL_LINK).equals(0))
+ return false;
+ if (res.get(ASSET_STATUS_FRAMEWORK_ITEM_SELECTED).equals(0))
+ return false;
+ return true;
+ }
+
+ public Map getStatusList(Asset asset, XWikiContext context) {
+ Map res = new HashMap();
+ if (asset.getAttachmentList().size() == 0)
+ res.put(ASSET_STATUS_ATTACHEMENT, 0);
+ else
+ res.put(ASSET_STATUS_ATTACHEMENT, 1);
+ if (getExternalAsset(asset, context).size() == 0)
+ res.put(ASSET_STATUS_EXTERNAL_LINK, 0);
+ else
+ res.put(ASSET_STATUS_EXTERNAL_LINK, 1);
+ res.put(ASSET_STATUS_ADDTIONAL_FRAMEWORK_SELECTED, 0);
+ if (getMasterFrameworkItems(asset, context).size() == 0)
+ res.put(ASSET_STATUS_FRAMEWORK_ITEM_SELECTED, 0);
+ else
+ res.put(ASSET_STATUS_FRAMEWORK_ITEM_SELECTED, 1);
+ res.put(ASSET_STATUS_LICENCE, 0);
+ return res;
+ }
+
+ public boolean getStatus(Asset asset, int statusCode, XWikiContext context) {
+ Map status = getStatusList(asset, context);
+ return !status.get(statusCode).equals(0);
+ }
+
+ public void addAttachment(InputStream iStream, String name, Asset asset, XWikiContext context) throws XWikiException, IOException {
+ asset.addAttachment(iStream, name);
+ }
+
+ private void initClasses(XWikiContext context) throws XWikiException {
+ initFrameworkItemAssetClass(context);
+ initExternalAssetClass(context);
+ }
+
+ private void initFrameworkItemAssetClass(XWikiContext context) throws XWikiException {
+ XWikiDocument doc;
+ XWiki xwiki = context.getWiki();
+ boolean needsUpdate = false;
+
+ try {
+ doc = xwiki.getDocument(FRAMEWORK_ASSET_CLASS_FULLNAME, context);
+ } catch (Exception e) {
+ doc = new XWikiDocument();
+ doc.setSpace("XWiki");
+ doc.setName(FRAMEWORK_ASSET_CLASS_NAME);
+ needsUpdate = true;
+ }
+
+ BaseClass bclass = doc.getxWikiClass();
+ bclass.setName(FRAMEWORK_ASSET_CLASS_FULLNAME);
+ needsUpdate |= bclass.addTextField(CLASS_FRAMEWORK_ITEM, "framework Item", 500);
+
+ String content = doc.getContent();
+ if ((content==null)||(content.equals(""))) {
+ needsUpdate = true;
+ doc.setContent("1 " + FRAMEWORK_ASSET_CLASS_FULLNAME);
+ }
+
+ if (needsUpdate)
+ xwiki.saveDocument(doc, context);
+ }
+
+ private void initExternalAssetClass(XWikiContext context) throws XWikiException {
+ XWikiDocument doc;
+ XWiki xwiki = context.getWiki();
+ boolean needsUpdate = false;
+
+ try {
+ doc = xwiki.getDocument(EXTERNAL_ASSET_CLASS_FULLNAME, context);
+ } catch (Exception e) {
+ doc = new XWikiDocument();
+ doc.setSpace("XWiki");
+ doc.setName(EXTERNAL_ASSET_CLASS_NAME);
+ needsUpdate = true;
+ }
+
+ BaseClass bclass = doc.getxWikiClass();
+ bclass.setName(EXTERNAL_ASSET_CLASS_FULLNAME);
+ needsUpdate |= bclass.addTextField(EXTERNAL_ASSET_LINK, "external Link", 500);
+
+ String content = doc.getContent();
+ if ((content==null)||(content.equals(""))) {
+ needsUpdate = true;
+ doc.setContent("1 " + EXTERNAL_ASSET_CLASS_FULLNAME);
+ }
+
+ if (needsUpdate)
+ xwiki.saveDocument(doc, context);
+ }
+
+
+ public boolean addFrameworkItem(Asset asset, String fullName, XWikiContext context) throws XWikiException {
+ List items = getMasterFrameworkItems(asset, context);
+ if (items.contains(fullName))
+ return false;
+ com.xpn.xwiki.api.Object obj = asset.newObject(FRAMEWORK_ASSET_CLASS_FULLNAME);
+ obj.set(CLASS_FRAMEWORK_ITEM, fullName);
+ return true;
+ }
+
+ public List getMasterFrameworkItems(Asset asset, XWikiContext context) {
+ Vector v = asset.getObjects(FRAMEWORK_ASSET_CLASS_FULLNAME);
+ List items = new ArrayList();
+ Iterator it = v.iterator();
+ while(it.hasNext())
+ {
+ com.xpn.xwiki.api.Object obj = (com.xpn.xwiki.api.Object) it.next();
+ if(obj.get(CLASS_FRAMEWORK_ITEM) != null)
+ items.add(obj.get(CLASS_FRAMEWORK_ITEM));
+ }
+ return items;
+ }
+
+ public List getExternalAsset(Asset asset, XWikiContext context) {
+ Vector v = asset.getObjects(EXTERNAL_ASSET_CLASS_FULLNAME);
+ List items = new ArrayList();
+ Iterator it = v.iterator();
+ while(it.hasNext())
+ {
+ com.xpn.xwiki.api.Object obj = (com.xpn.xwiki.api.Object) it.next();
+ if(obj.get(EXTERNAL_ASSET_LINK) != null)
+ items.add(obj.get(EXTERNAL_ASSET_LINK));
+ }
+ return items;
+ }
+
+ public boolean addExternalAsset(Asset asset, String link, XWikiContext context) throws XWikiException {
+ List items = getMasterFrameworkItems(asset, context);
+ if (items.contains(link))
+ return false;
+ com.xpn.xwiki.api.Object obj = asset.newObject(EXTERNAL_ASSET_CLASS_FULLNAME);
+ obj.set(EXTERNAL_ASSET_LINK, link);
+ return true;
+ }
+}
Property changes on: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPlugin.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginApi.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginApi.java 2006-10-10 17:42:45 UTC (rev 1377)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginApi.java 2006-10-10 17:43:18 UTC (rev 1378)
@@ -0,0 +1,106 @@
+/*
+ * 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.assets;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.api.Api;
+import com.xpn.xwiki.web.XWikiRequest;
+import org.gelc.xwiki.plugins.licence.Licence;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+
+public class AssetManagerPluginApi extends Api {
+ private AssetManagerPlugin assetManagerPlugin;
+ public AssetManagerPluginApi(XWikiContext context) {
+ super(context);
+ }
+
+ public AssetManagerPluginApi(AssetManagerPlugin assetManagerPlugin, XWikiContext context) {
+ super(context);
+ this.assetManagerPlugin = assetManagerPlugin;
+ }
+
+ public Asset createAssetDocument(String assetName) throws XWikiException {
+ return assetManagerPlugin.createAssetDocument(assetName, context);
+ }
+
+ public Asset getAssetDocument(String assetName) {
+ return null;
+ }
+
+ public void addAttachment(InputStream iStream, String name, Asset asset) throws IOException, XWikiException {
+ assetManagerPlugin.addAttachment(iStream, name, asset, context);
+ }
+
+ public boolean isComplet(Asset asset){
+ return assetManagerPlugin.isComplet(asset, context);
+ }
+
+ public Map getStatusList(Asset asset){
+ return assetManagerPlugin.getStatusList(asset, context);
+ }
+
+ public boolean copyAsset(Asset fromAsset, Asset toAsset){
+ return false;
+ }
+
+ public String fromRequest(XWikiRequest request){
+ return null;
+ }
+
+ public boolean getStatus(Asset asset, int status){
+ return assetManagerPlugin.getStatus(asset, status, context);
+ }
+
+ public void setLicence(Licence licence){
+
+ }
+
+ public boolean addFrameworkItem(Asset asset, String fullName) throws XWikiException {
+ return assetManagerPlugin.addFrameworkItem(asset, fullName, context);
+ }
+
+ public List getMasterFrameworkItems(Asset asset){
+ return assetManagerPlugin.getMasterFrameworkItems(asset, context);
+ }
+
+ public List getAdditionalFrameworkItems(){
+ return null;
+ }
+
+ public boolean addExternalAsset(Asset asset, String link) throws XWikiException {
+ return assetManagerPlugin.addExternalAsset(asset, link, context);
+ }
+
+ public List getExternalAsset(Asset asset){
+ return assetManagerPlugin.getExternalAsset(asset, context);
+ }
+
+
+
+
+}
Property changes on: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginApi.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/licence/Licence.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/licence/Licence.java 2006-10-10 17:42:45 UTC (rev 1377)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/licence/Licence.java 2006-10-10 17:43:18 UTC (rev 1378)
@@ -0,0 +1,11 @@
+package org.gelc.xwiki.plugins.licence;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: jeremi
+ * Date: Oct 4, 2006
+ * Time: 10:22:17 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class Licence {
+}
Property changes on: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/licence/Licence.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/cactus/org/gelc/xwiki/plugins/assets/cactus/AssetManagerPluginTest.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/cactus/org/gelc/xwiki/plugins/assets/cactus/AssetManagerPluginTest.java 2006-10-10 17:42:45 UTC (rev 1377)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/cactus/org/gelc/xwiki/plugins/assets/cactus/AssetManagerPluginTest.java 2006-10-10 17:43:18 UTC (rev 1378)
@@ -0,0 +1,10 @@
+package org.gelc.xwiki.plugins.assets.cactus;
+
+import junit.framework.TestCase;
+
+public class AssetManagerPluginTest extends TestCase {
+
+ public void testAddAsset(){
+
+ }
+}
Property changes on: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/cactus/org/gelc/xwiki/plugins/assets/cactus/AssetManagerPluginTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginTest.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginTest.java 2006-10-10 17:42:45 UTC (rev 1377)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginTest.java 2006-10-10 17:43:18 UTC (rev 1378)
@@ -0,0 +1,149 @@
+/*
+ * 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.assets;
+
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.test.HibernateTestCase;
+import com.xpn.xwiki.web.XWikiServletURLFactory;
+import org.gelc.xwiki.plugins.framework.FrameworkManagerPluginAPI;
+import org.gelc.xwiki.plugins.framework.FrameworkItem;
+import org.gelc.xwiki.plugins.framework.Framework;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+
+
+public class AssetManagerPluginTest extends HibernateTestCase {
+ public static String FRAMEWORK_NAME = "testFramework";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ getXWiki().getPluginManager().addPlugin("framework_manager","org.gelc.xwiki.plugins.framework.FrameworkManagerPlugin", getXWikiContext());
+ getXWiki().getPluginManager().addPlugin("assets_manager","org.gelc.xwiki.plugins.assets.AssetManagerPlugin", getXWikiContext());
+
+ getXWikiContext().setURLFactory(new XWikiServletURLFactory(new URL("http://www.xwiki.org/"), "xwiki/" , "bin/"));
+
+ }
+
+ public void testAddAsset() throws IOException, XWikiException {
+ AssetManagerPluginApi amng = (AssetManagerPluginApi) xwiki.getPluginApi(AssetConstant.PLUGIN_NAME, context);
+ assertNotNull("The plugin is not on the list of plugins", amng);
+ Asset asset = amng.createAssetDocument("test Asset");
+ assertNotNull(asset);
+ assertEquals("test Asset", asset.getTitle());
+
+ assertEquals(AssetConstant.ASSET_TEMPORARY_SPACE, asset.getSpace());
+
+ assertFalse(amng.getStatus(asset, AssetConstant.ASSET_STATUS_ATTACHEMENT));
+ assertFalse(amng.getStatus(asset, AssetConstant.ASSET_STATUS_EXTERNAL_LINK));
+ assertFalse(amng.getStatus(asset, AssetConstant.ASSET_STATUS_ADDTIONAL_FRAMEWORK_SELECTED));
+ assertFalse(amng.getStatus(asset, AssetConstant.ASSET_STATUS_FRAMEWORK_ITEM_SELECTED));
+ assertFalse(amng.getStatus(asset, AssetConstant.ASSET_STATUS_LICENCE));
+ assertFalse(amng.isComplet(asset));
+
+ byte[] content = "content test".getBytes();
+ amng.addAttachment(new ByteArrayInputStream(content), "att1", asset);
+
+ assertTrue(amng.getStatus(asset, AssetConstant.ASSET_STATUS_ATTACHEMENT));
+ assertFalse(amng.getStatus(asset, AssetConstant.ASSET_STATUS_EXTERNAL_LINK));
+ assertFalse(amng.getStatus(asset, AssetConstant.ASSET_STATUS_ADDTIONAL_FRAMEWORK_SELECTED));
+ assertFalse(amng.getStatus(asset, AssetConstant.ASSET_STATUS_FRAMEWORK_ITEM_SELECTED));
+ assertFalse(amng.getStatus(asset, AssetConstant.ASSET_STATUS_LICENCE));
+ assertFalse(amng.isComplet(asset));
+
+ importFramework();
+
+ FrameworkItem item = getFrameworkItem();
+ assertNotNull(item);
+
+ amng.addFrameworkItem(asset, item.getFullName());
+
+ List items = amng.getMasterFrameworkItems(asset);
+ assertNotNull(items);
+ assertEquals(1, items.size());
+ String itemName = (String) items.get(0);
+ assertEquals(item.getFullName(), itemName);
+
+ assertTrue(amng.getStatus(asset, AssetConstant.ASSET_STATUS_ATTACHEMENT));
+ assertFalse(amng.getStatus(asset, AssetConstant.ASSET_STATUS_EXTERNAL_LINK));
+ assertFalse(amng.getStatus(asset, AssetConstant.ASSET_STATUS_ADDTIONAL_FRAMEWORK_SELECTED));
+ assertTrue(amng.getStatus(asset, AssetConstant.ASSET_STATUS_FRAMEWORK_ITEM_SELECTED));
+ assertFalse(amng.getStatus(asset, AssetConstant.ASSET_STATUS_LICENCE));
+ assertTrue(amng.isComplet(asset));
+
+ amng.addExternalAsset(asset, "test");
+ amng.addExternalAsset(asset, "test2");
+
+ List links = amng.getExternalAsset(asset);
+ assertNotNull(links);
+ assertEquals(2, links.size());
+
+ assertTrue(amng.getStatus(asset, AssetConstant.ASSET_STATUS_ATTACHEMENT));
+ assertTrue(amng.getStatus(asset, AssetConstant.ASSET_STATUS_EXTERNAL_LINK));
+ assertFalse(amng.getStatus(asset, AssetConstant.ASSET_STATUS_ADDTIONAL_FRAMEWORK_SELECTED));
+ assertTrue(amng.getStatus(asset, AssetConstant.ASSET_STATUS_FRAMEWORK_ITEM_SELECTED));
+ assertFalse(amng.getStatus(asset, AssetConstant.ASSET_STATUS_LICENCE));
+ assertTrue(amng.isComplet(asset));
+
+ }
+
+ public FrameworkItem getFrameworkItem() throws XWikiException {
+ FrameworkManagerPluginAPI fmng = (FrameworkManagerPluginAPI) xwiki.getPluginApi("framework_manager", context);
+ Framework fmk = fmng.getFramework(FRAMEWORK_NAME);
+ assertNotNull(fmk);
+
+ List children = fmng.getChildren(fmk);
+ assertNotNull(children);
+
+ return (FrameworkItem) children.get(1);
+
+ }
+
+ public void testAddAssetSameName() throws XWikiException {
+ AssetManagerPluginApi amng = (AssetManagerPluginApi) xwiki.getPluginApi(AssetConstant.PLUGIN_NAME, context);
+ assertNotNull("The plugin is not on the list of plugins", amng);
+ Asset asset = amng.createAssetDocument("test Asset");
+ assertNotNull(asset);
+ asset.save();
+
+
+ Asset asset2 = amng.createAssetDocument("test Asset");
+ assertNotNull(asset2);
+
+ assertTrue(asset.getSpace().equals(asset2.getSpace()));
+ assertFalse(asset.getName().equals(asset2.getName()));
+ }
+
+ private void importFramework() throws FileNotFoundException, XWikiException {
+ File xmlFile = new File(getClass().getResource("/framework_Arizona.xml").getFile());
+ InputStream iStream = new FileInputStream(xmlFile);
+ FrameworkManagerPluginAPI fmng = (FrameworkManagerPluginAPI) xwiki.getPluginApi("framework_manager", context);
+ assertNotNull("The plugin is not on the list of plugins", fmng);
+ assertTrue(fmng.importFramework(FRAMEWORK_NAME, iStream));
+ }
+}
Property changes on: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Xwiki-notifications
mailing list