list = handler.getFileNodes();
+ for(FileNodeInfo fileNode:list){
+ log.debug("Tool attachement file is going to save : " + fileNode.getFileUuid());
+ toolContentHandler.saveFile(fileNode.getFileUuid(),toolPath+File.separator+fileNode.getFileUuid());
+ }
+ list.clear();
+ } catch (ItemNotFoundException e) {
+ throw new ExportToolContentException(e);
+ } catch (RepositoryCheckedException e) {
+ throw new ExportToolContentException(e);
+ } catch (IOException e) {
+ throw new ExportToolContentException(e);
+ } catch (FileUtilException e) {
+ throw new ExportToolContentException(e);
+ } finally{
+ if(fileHandleClassList != null)
+ fileHandleClassList.clear();
+ }
+
+ }
+ public void registerFileHandleClass(String fileNodeClassName,String fileUuidFieldName, String fileVersionFieldName){
+ fileHandleClassList.add(this.new FileHandleClassInfo(fileNodeClassName,fileUuidFieldName,fileVersionFieldName));
+
+ }
//******************************************************************
// ApplicationContextAware method implementation
//******************************************************************
@@ -113,9 +321,15 @@
}
private String getFullPath(String path, String file){
- return path + File.separator + file;
+ if(path.endsWith(File.separator))
+ return path + file;
+ else
+ return path + File.separator + file;
}
-
+ private Object findToolService(Tool tool) throws NoSuchBeanDefinitionException
+ {
+ return applicationContext.getBean(tool.getServiceName());
+ }
//******************************************************************
// Spring injection properties set/get
//******************************************************************
@@ -125,4 +339,12 @@
public void setActivityDAO(ActivityDAO activityDAO) {
this.activityDAO = activityDAO;
}
+ public ToolDAO getToolDAO() {
+ return toolDAO;
+ }
+ public void setToolDAO(ToolDAO toolDAO) {
+ this.toolDAO = toolDAO;
+ }
+
+
}
Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/IExportToolContentService.java
===================================================================
diff -u -rbebb1babe03164359747ae3b7abac81d05ea7d6c -rf17ef475206dfa5950b19434ec135b157201c987
--- lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/IExportToolContentService.java (.../IExportToolContentService.java) (revision bebb1babe03164359747ae3b7abac81d05ea7d6c)
+++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/IExportToolContentService.java (.../IExportToolContentService.java) (revision f17ef475206dfa5950b19434ec135b157201c987)
@@ -24,14 +24,55 @@
/* $Id$ */
package org.lamsfoundation.lams.learningdesign.service;
-
+import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler;
+/**
+ * Export tool content service provides ability to export learning design and its relative activities' tool content.
+ *
+ * @author Steve.Ni
+ * @version $Revision$
+ */
public interface IExportToolContentService {
/**
- * Export given learning design tool content. It includes all tools content in this learning design.
+ * Export given learning design tool content. It includes all tools content
+ * in this learning design.
*
* @param learningDesignId
* @return
* @throws ExportToolContentException
*/
- String exportToolContent(Long learningDesignId) throws ExportToolContentException;
+ String exportLearningDesign(Long learningDesignId) throws ExportToolContentException;
+ /**
+ * Export tool content.
+ *
+ * @param toolContentId the tool content ID.
+ * @param toolContentObj The POJO object to descript the tool content which need to export
+ * @param toolContentHandler need be used when this tool has any items in LAMS repository to be exported.
+ * @param toPath the target local file system directory to put tool.xml and its attached files or package.
+ *
+ * @throws ExportToolContentException
+ */
+ void exportToolContent(Long toolContentId, Object toolContentObj, IToolContentHandler toolContentHandler, String toPath)
+ throws ExportToolContentException;
+
+ /**
+ * Register access class and relative method for item in LAMS repository. For example, there is POJO to refer to
+ * a tool offline instruction files:
+ *
+ *
+ * public class ShareResourceToolFile{
+ * private Long fileUuid;
+ * private Long fileVersionId;
+ * ...
+ * //set&get methods
+ * }
+ *
+ *
+ *
+ * Tool must call this method to tell export service to get item by this fileUuid and fileVersionId properties.
+ *
+ * @param fileNodeClassName The POJO class name for repository item reference
+ * @param fileUuidFieldName The POJO properties name for get fileUuid. There must be a get method to access this property.
+ * @param fileVersionFieldName The POJO properties name for get fileVersion. There must be a get method to access this property.
+ */
+ void registerFileHandleClass(String fileNodeClassName,String fileUuidFieldName, String fileVersionFieldName);
}
Index: lams_common/src/java/org/lamsfoundation/lams/tool/ToolContentManager.java
===================================================================
diff -u -r6a4cc1cba568d6ed7af70248ad7f89b757e8f468 -rf17ef475206dfa5950b19434ec135b157201c987
--- lams_common/src/java/org/lamsfoundation/lams/tool/ToolContentManager.java (.../ToolContentManager.java) (revision 6a4cc1cba568d6ed7af70248ad7f89b757e8f468)
+++ lams_common/src/java/org/lamsfoundation/lams/tool/ToolContentManager.java (.../ToolContentManager.java) (revision f17ef475206dfa5950b19434ec135b157201c987)
@@ -103,15 +103,15 @@
* @throws DataMissingException if no tool content matches the toolSessionId
* @throws ToolException if any other error occurs
*/
- public String exportToolContent(Long toolContentId)
+ public void exportToolContent(Long toolContentId, String toPath)
throws DataMissingException, ToolException;
/**
* Import the XML fragment for the tool's content, along with any files needed
* for the content.
* @throws ToolException if any other error occurs
*/
- public String importToolContent(Long toolContentId, String reference, String directory)
+ public void importToolContent(Object toolContnetPOJO)
throws ToolException;
Index: lams_common/src/java/org/lamsfoundation/lams/util/FileUtil.java
===================================================================
diff -u -r34b959260a0f8f8285793a4481a95ca3580eabc5 -rf17ef475206dfa5950b19434ec135b157201c987
--- lams_common/src/java/org/lamsfoundation/lams/util/FileUtil.java (.../FileUtil.java) (revision 34b959260a0f8f8285793a4481a95ca3580eabc5)
+++ lams_common/src/java/org/lamsfoundation/lams/util/FileUtil.java (.../FileUtil.java) (revision f17ef475206dfa5950b19434ec135b157201c987)
@@ -288,4 +288,48 @@
}
return dumpFilename;
}
+ /**
+ * get file name from a string which may include directory information.
+ * For example : "c:\\dir\\ndp\\pp.txt"; will return pp.txt.?
+ * If file has no path infomation, then just return input fileName.
+ *
+ */
+ public static String getFileName(String fileName){
+ if(fileName == null)
+ return "";
+
+ fileName = fileName.trim();
+
+ int dotPos = fileName.lastIndexOf(File.separatorChar);
+ if (dotPos == -1){
+ //just for window OS: it also can use "/" as file separatorChar.
+ dotPos = fileName.lastIndexOf("/");
+ if(dotPos == -1)
+ return fileName;
+ }
+ return fileName.substring(dotPos + 1, fileName.length());
+
+ }
+ /**
+ * Get file directory info.
+ * @param fileName with path info.
+ * @return return only path info with the given fileName
+ */
+ public static String getFileDirectory(String fileName){
+ if(fileName == null)
+ return "";
+
+ fileName = fileName.trim();
+
+ int dotPos = fileName.lastIndexOf(File.separatorChar);
+ if (dotPos == -1){
+ //just for window OS: it also can use "/" as file separatorChar.
+ dotPos = fileName.lastIndexOf("/");
+ if(dotPos == -1)
+ return fileName;
+ }
+ //return the last char is '/'
+ return fileName.substring(0,dotPos+1);
+
+ }
}