Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java =================================================================== diff -u -r41de4a8b5ff40c43e8eaadc76a33ebce112d6801 -r7aa77bcecb501c019e15d8dfe06d7d3542c37460 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java (.../ToolContentHandler.java) (revision 41de4a8b5ff40c43e8eaadc76a33ebce112d6801) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java (.../ToolContentHandler.java) (revision 7aa77bcecb501c019e15d8dfe06d7d3542c37460) @@ -24,6 +24,7 @@ /* $$Id$$ */ package org.lamsfoundation.lams.contentrepository.client; +import java.io.IOException; import java.io.InputStream; import java.util.Set; @@ -262,8 +263,39 @@ return nodeKey; } - /** + * Save content in repository into local file by given toFileName. + * + *

+ * If the toFileName is null, file name use original file name instead + * and file save path will be system temporary directory. + * + * @param uuid + * @param toFileName file name to save. Using the original file name instead if null value given. + * @throws ItemNotFoundException + * @throws RepositoryCheckedException + * @throws IOException + */ + public void saveFile(Long uuid, String toFileName) throws ItemNotFoundException, RepositoryCheckedException, IOException { + try { + try { + getRepositoryService().saveFile(getTicket(false), uuid, null, toFileName); + } catch (AccessDeniedException e) { + log.warn("Unable to access repository to add copy node "+uuid + +"AccessDeniedException: "+e.getMessage()+" Retrying login."); + getRepositoryService().saveFile(getTicket(false), uuid, null, toFileName); + } + } catch (ItemNotFoundException e) { + log.warn("Unable to to save node "+uuid + +" as the node cannot be found. Repository Exception: "+e.getMessage()+" Retry not possible."); + throw e; + } catch (RepositoryCheckedException e) { + log.warn("Unable to to save node "+uuid + +"Repository Exception: "+e.getMessage()+" Retry not possible."); + throw e; + } + } + /** * Copy an entry in the content repository. * * @param uuid id of the file node. Mandatory Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java =================================================================== diff -u -r41de4a8b5ff40c43e8eaadc76a33ebce112d6801 -r7aa77bcecb501c019e15d8dfe06d7d3542c37460 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java (.../IRepositoryService.java) (revision 41de4a8b5ff40c43e8eaadc76a33ebce112d6801) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/IRepositoryService.java (.../IRepositoryService.java) (revision 7aa77bcecb501c019e15d8dfe06d7d3542c37460) @@ -24,6 +24,7 @@ /* $$Id$$ */ package org.lamsfoundation.lams.contentrepository.service; +import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.SortedMap; @@ -361,7 +362,7 @@ public void logout(ITicket ticket) throws AccessDeniedException; /** Get a complete list of all nodes in the workspace and their - * version histories. + * version histories. *

* Warning: Once a workspace gets a lot of nodes, this will be * a very very expensive call!!!!! @@ -370,4 +371,18 @@ * @return SortedMap key Long uuid, value IVersionDetail version history */ public SortedMap getNodeList(ITicket ticket) throws AccessDeniedException ; + /** + * Save current version of a node to local file by given file name. If the toFileName is + * null, file name use original file name instead and file save path will be system temporary directory. + *

+ * So far, it only support FILENODE format content. + * + * @param ticket ticket issued on login. Identifies tool and workspace - mandatory + * @param uuid id of the file/package - mandatory + * @param version desired version - if null gets latest version + * + * @param toFileName the local file name with directory information. + */ + public void saveFile(ITicket ticket, Long uuid, Long versionId, String toFileName) + throws RepositoryCheckedException, AccessDeniedException, ItemNotFoundException, IOException; } Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java =================================================================== diff -u -r41de4a8b5ff40c43e8eaadc76a33ebce112d6801 -r7aa77bcecb501c019e15d8dfe06d7d3542c37460 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java (.../SimpleRepository.java) (revision 41de4a8b5ff40c43e8eaadc76a33ebce112d6801) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/service/SimpleRepository.java (.../SimpleRepository.java) (revision 7aa77bcecb501c019e15d8dfe06d7d3542c37460) @@ -24,7 +24,12 @@ /* $$Id$$ */ package org.lamsfoundation.lams.contentrepository.service; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -43,6 +48,7 @@ import org.lamsfoundation.lams.contentrepository.FileException; import org.lamsfoundation.lams.contentrepository.ICredentials; import org.lamsfoundation.lams.contentrepository.ITicket; +import org.lamsfoundation.lams.contentrepository.IValue; import org.lamsfoundation.lams.contentrepository.IVersionedNode; import org.lamsfoundation.lams.contentrepository.IVersionedNodeAdmin; import org.lamsfoundation.lams.contentrepository.InvalidParameterException; @@ -59,6 +65,8 @@ import org.lamsfoundation.lams.contentrepository.WorkspaceNotFoundException; import org.lamsfoundation.lams.contentrepository.dao.ICredentialDAO; import org.lamsfoundation.lams.contentrepository.dao.IWorkspaceDAO; +import org.lamsfoundation.lams.util.FileUtil; +import org.lamsfoundation.lams.util.FileUtilException; /** @@ -607,8 +615,48 @@ +e.getMessage(), e); } } - /* (non-Javadoc) + * @see org.lamsfoundation.lams.contentrepository.IRepository#saveFile(org.lamsfoundation.lams.contentrepository.ITicket, java.lang.Long, java.lang.String, java.lang.String, java.lang.String) + */ + public void saveFile(ITicket ticket, Long uuid, Long versionId, String toFileName) throws AccessDeniedException, + ItemNotFoundException, IOException, RepositoryCheckedException { + try { + IVersionedNode node = nodeFactory.getNode(ticket.getWorkspaceId(), uuid, versionId); + if(!node.isNodeType(NodeType.FILENODE)) + throw new RepositoryCheckedException("Unsupported node type " + +node.getNodeType()+". Node Data is "+node.toString(),null); + + if(node == null) + throw new ItemNotFoundException("Unable find File node by uuid [" + uuid + "]"); + + InputStream is = node.getFile(); + if(toFileName == null){ + IValue prop = node.getProperty(PropertyName.FILENAME); + toFileName = prop != null ? prop.getString() : null; + FileUtil.createDirectory(FileUtil.TEMP_DIR); + toFileName = FileUtil.TEMP_DIR + File.separator + toFileName; + } + OutputStream os = new FileOutputStream(toFileName); + byte[] out = new byte[8 * 1024]; + int len = -1; + while((len = is.read(out)) != -1){ + os.write(out,0,len); + } + os.close(); + is.close(); + } catch (FileException e) { + // if this is thrown, then it is bug - nothing external should cause it. + throw new RepositoryRuntimeException("Internal error: unable to save node. " + +e.getMessage(), e); + } catch (ValueFormatException e) { + throw new RepositoryRuntimeException("Internal error: unable to save node. " + +e.getMessage(), e); + } catch (FileUtilException e) { + throw new RepositoryRuntimeException("Internal error: unable to save node. " + +e.getMessage(), e); + } + } + /* (non-Javadoc) * @see org.lamsfoundation.lams.contentrepository.IRepository#updatePackageItem(org.lamsfoundation.lams.contentrepository.ITicket, java.lang.Long, java.lang.String, java.lang.String, java.lang.String) */ public String[] deleteNode(ITicket ticket, Long uuid)