Ticket #630: fixed
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@77214 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
88b3f0c75e
commit
e7c4b0a82b
15
pom.xml
15
pom.xml
|
@ -96,6 +96,21 @@
|
|||
<version>[1.3.0-SNAPSHOT, 1.6.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- USE THIS FOR RELEASE -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.gcube.portlets.user</groupId> -->
|
||||
<!-- <artifactId>home-library</artifactId> -->
|
||||
<!-- <version>[4.3.0-SNAPSHOT, 5.0.0-SNAPSHOT)</version> -->
|
||||
<!-- <scope>provided</scope> -->
|
||||
<!-- </dependency> -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.gcube.portlets.user</groupId> -->
|
||||
<!-- <artifactId>home-library-jcr</artifactId> -->
|
||||
<!-- <version>[1.3.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> -->
|
||||
<!-- <scope>provided</scope> -->
|
||||
<!-- </dependency> -->
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
|
|
|
@ -1276,6 +1276,9 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
|||
|
||||
final FileModel fileModel = openUrlEvent.getSourceFileModel();
|
||||
|
||||
if(fileModel==null)
|
||||
return;
|
||||
|
||||
rpcWorkspaceService.getUrlById(fileModel.getIdentifier(), fileModel.getGXTFolderItemType().equals(GXTFolderItemTypeEnum.URL_DOCUMENT), false, new AsyncCallback<GWTWorkspaceItem>() {
|
||||
|
||||
@Override
|
||||
|
@ -1292,17 +1295,19 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
|||
|
||||
if(fileModel.getGXTFolderItemType().equals(GXTFolderItemTypeEnum.URL_DOCUMENT)){
|
||||
new WindowOpenUrl(((GWTUrlDocument) result).getUrl(), "_blank", "");
|
||||
System.out.println("Url Open " + ((GWTUrlDocument) result).getUrl());
|
||||
GWT.log("URL_DOCUMENT Open " + ((GWTUrlDocument) result).getUrl());
|
||||
}
|
||||
else{
|
||||
new WindowOpenUrl(((GWTExternalUrl) result).getUrl(), "_blank", "");
|
||||
System.out.println("Url Open " + ((GWTExternalUrl) result).getUrl());
|
||||
GWT.log("ExternalUrl Open " + ((GWTExternalUrl) result).getUrl());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// com.google.gwt.user.client.Window.open(ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE+"?id="+fileModel.getIdentifier()+"&viewContent=true", fileModel.getName(), "");
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.extjs.gxt.ui.client.widget.Dialog;
|
|||
import com.extjs.gxt.ui.client.widget.form.TextArea;
|
||||
import com.extjs.gxt.ui.client.widget.form.TextField;
|
||||
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
|
@ -48,6 +49,14 @@ public class DialogAddUrl extends Dialog {
|
|||
setButtons(Dialog.OKCANCEL);
|
||||
// this.getButtonById(Dialog.CANCEL).setText("Reset");
|
||||
|
||||
|
||||
Label labetInfo = new Label();
|
||||
// labetInfo.setText("If you want create an http/ftp uri, you must include one of this prefix: \"http://\" or \"ftp://\"");
|
||||
// labetInfo.setText("An correct URL for document directly displayable through browser must have the following form - http://host.name/path");
|
||||
// labetInfo.setText("An correct URL must have the following form http://host.name/path");
|
||||
labetInfo.setText("A correct url (for a document displayable directly through the browser) has the following form - http://host.name/path");
|
||||
|
||||
|
||||
txtName = new TextField<String>();
|
||||
txtName.setAllowBlank(false);
|
||||
// txt.setMinLength(2);
|
||||
|
@ -86,6 +95,7 @@ public class DialogAddUrl extends Dialog {
|
|||
|
||||
txtUrl.setFieldLabel(ConstantsExplorer.DIALOG_URL);
|
||||
txtUrl.setAllowBlank(false);
|
||||
txtUrl.setEmptyText("http://host.name/path");
|
||||
// txtUrl.setRegex("^http\\://[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(/\\S*)?$");
|
||||
|
||||
|
||||
|
@ -116,11 +126,15 @@ public class DialogAddUrl extends Dialog {
|
|||
}
|
||||
});
|
||||
|
||||
setFocusWidget(txtUrl);
|
||||
|
||||
|
||||
|
||||
add(txtUrl);
|
||||
add(txtName);
|
||||
add(textAreaDescription);
|
||||
add(labetInfo);
|
||||
|
||||
setFocusWidget(txtName);
|
||||
this.show();
|
||||
}
|
||||
|
||||
|
|
|
@ -269,10 +269,20 @@ public class DownloadServlet extends HttpServlet{
|
|||
case EXTERNAL_URL:{
|
||||
try{
|
||||
ExternalUrl externalUrl = (ExternalUrl)folderItem;
|
||||
|
||||
//ADDED 20/06/2013
|
||||
String itemName = MimeTypeUtil.getNameWithExtension(externalUrl.getName(), "text/uri-list");
|
||||
String contentDisposition = (viewContent)?"inline":"attachment";
|
||||
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
||||
|
||||
// //ADDED 20/06/2013
|
||||
// String itemName = externalUrl.getName() + ".uri";
|
||||
// String contentDisposition = (viewContent)?"inline":"attachment";
|
||||
// resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
||||
|
||||
resp.setContentType("text/uri-list");
|
||||
resp.setContentLength((int) externalUrl.getLength());
|
||||
|
||||
|
||||
//MODIFIED 22-05-2013 CLOSE STREAM
|
||||
StringReader sr = new StringReader(externalUrl.getUrl());
|
||||
OutputStream out = resp.getOutputStream();
|
||||
|
@ -513,13 +523,21 @@ public class DownloadServlet extends HttpServlet{
|
|||
|
||||
System.out.println("start");
|
||||
|
||||
is = GCUBEStorage.getRemoteFile("/Home/test.user/Workspace3d660604-03ef-49eb-89c3-4c73f8a47914");
|
||||
// is = GCUBEStorage.getRemoteFile("/Home/test.user/Workspace3d660604-03ef-49eb-89c3-4c73f8a47914");
|
||||
|
||||
try{
|
||||
|
||||
Workspace ws = HomeLibrary.getHomeManagerFactory().getHomeManager().getHome("test.user", GCUBEScope.getScope("/gcube/devsec")).getWorkspace();
|
||||
Workspace ws = HomeLibrary.getHomeManagerFactory().getHomeManager().getHome("francesco.mangiacrapa", GCUBEScope.getScope("/gcube/devsec")).getWorkspace();
|
||||
//
|
||||
// ExternalFile f = (ExternalFile) ws.getItem("61c6d01c-72f3-44b6-88da-6b9b486ef391");
|
||||
// ExternalFile f = (ExternalFile) ws.getItem("907ce8ef-5c0b-4601-83ac-215d1f432f6b");
|
||||
|
||||
WorkspaceItem wsItem = ws.getItem("907ce8ef-5c0b-4601-83ac-215d1f432f6b");
|
||||
|
||||
|
||||
System.out.println("metadata info recovered from HL: [ID: "+wsItem.getId() +", name: "+wsItem.getName()+"]");
|
||||
|
||||
|
||||
|
||||
|
||||
FileOutputStream out = new FileOutputStream(new File("/tmp/bla"));
|
||||
// byte[] buffer = new byte[1024];
|
||||
|
@ -528,7 +546,10 @@ public class DownloadServlet extends HttpServlet{
|
|||
// out.write(buffer, 0, len);
|
||||
// }
|
||||
|
||||
// is = f.getData();
|
||||
System.out.println("cast as external file");
|
||||
ExternalFile f = (ExternalFile) wsItem;
|
||||
|
||||
is = f.getData();
|
||||
|
||||
IOUtils.copy(is, out);
|
||||
is.close();
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.portlets.user.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||
import org.gcube.portlets.user.homelibrary.jcr.repository.external.GCUBEStorage;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* @Jun 18, 2013
|
||||
*
|
||||
*/
|
||||
public class DonwloadServletTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
InputStream is = null;
|
||||
|
||||
System.out.println("start");
|
||||
|
||||
is = GCUBEStorage.getRemoteFile("/Home/francesco.mangiacrapa/Workspace284ee688-e6fb-4080-bbcb-cc7c8cc5c381");
|
||||
|
||||
try {
|
||||
|
||||
// Workspace ws = HomeLibrary
|
||||
// .getHomeManagerFactory()
|
||||
// .getHomeManager()
|
||||
// .getHome("francesco.mangiacrapa",
|
||||
// GCUBEScope.getScope("/gcube/devsec"))
|
||||
// .getWorkspace();
|
||||
// //
|
||||
// ExternalFile f = (ExternalFile) ws.getItem("8ad4e104-0f34-413e-a88c-e754a81104e7");
|
||||
//
|
||||
FileOutputStream out = new FileOutputStream(new File("/tmp/bla"));
|
||||
// // byte[] buffer = new byte[1024];
|
||||
// // int len;
|
||||
// // while ((len = is.read(buffer)) != -1) {
|
||||
// // out.write(buffer, 0, len);
|
||||
// // }
|
||||
//
|
||||
|
||||
|
||||
// is = f.getData();
|
||||
|
||||
|
||||
IOUtils.copy(is, out);
|
||||
is.close();
|
||||
|
||||
out.close();
|
||||
|
||||
// System.out.println("Sleeping");
|
||||
// Thread.sleep(20000);
|
||||
// System.out.println("Alive");
|
||||
|
||||
System.out.println("end");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.scope.GCUBEScope.MalformedScopeExpressionException;
|
||||
import org.gcube.portlets.user.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.portlets.user.homelibrary.home.HomeManagerFactory;
|
||||
import org.gcube.portlets.user.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
import org.gcube.portlets.user.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.portlets.user.homelibrary.home.exceptions.UserNotFoundException;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceFolder;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.WrongDestinationException;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.folder.FolderItem;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.ExternalImage;
|
||||
import org.gcube.portlets.user.homelibrary.util.MimeTypeUtil;
|
||||
import org.gcube.portlets.user.homelibrary.util.WorkspaceUtil;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* @Jun 20, 2013
|
||||
*
|
||||
*/
|
||||
public class UploadServletTest {
|
||||
|
||||
public static void main(String[] args) throws InternalErrorException, MalformedScopeExpressionException, WorkspaceFolderNotFoundException, HomeNotFoundException, UserNotFoundException, InsufficientPrivilegesException, ItemAlreadyExistException, WrongDestinationException, IOException {
|
||||
|
||||
// HomeManagerFactory factory = HomeLibrary.getHomeManagerFactory();
|
||||
// Workspace workspace = factory.getHomeManager().getHome("francesco.mangiacrapa",GCUBEScope.getScope("/gcube/devsec")).getWorkspace();
|
||||
|
||||
Workspace workspace = HomeLibrary
|
||||
.getHomeManagerFactory()
|
||||
.getHomeManager()
|
||||
.getHome("francesco.mangiacrapa",
|
||||
GCUBEScope.getScope("/gcube/devsec"))
|
||||
.getWorkspace();
|
||||
|
||||
String filePath = "/home/francesco-mangiacrapa/Desktop/icongeoexplorer";
|
||||
|
||||
String fileName = "testupload.txt";
|
||||
|
||||
String fullPath = filePath+"/"+fileName;
|
||||
|
||||
// String newFilePath = "/home/francesco-mangiacrapa/Desktop/icongeoexplorer/testupload.txt";
|
||||
|
||||
// String name = "TestReplaceContentImage";
|
||||
|
||||
// ExternalPDFFile file = workspace.createExternalPDFFile(name, "", null, new FileInputStream(new File(filePath)),
|
||||
// workspace.getRoot().getId());
|
||||
|
||||
WorkspaceFolder root = workspace.getRoot();
|
||||
// ExternalImage file = (ExternalImage) root.find(name);
|
||||
|
||||
|
||||
//UPLOAD FILE
|
||||
String contentType = MimeTypeUtil.getMimeType(new BufferedInputStream(new FileInputStream(new File(fullPath))));
|
||||
|
||||
String itemName = WorkspaceUtil.getUniqueName(fileName, root);
|
||||
System.out.println("Storing data....");
|
||||
System.out.println("content type "+contentType);
|
||||
System.out.println("itemName "+itemName);
|
||||
|
||||
ExternalFile file = (ExternalFile) WorkspaceUtil.createExternalFile(root, itemName, "", contentType, new FileInputStream(new File(fullPath)));
|
||||
|
||||
System.out.println("Storing data - OK" + "File [id: "+file.getId() + ", name: "+file.getName()+"]");
|
||||
//
|
||||
// System.out.println("File mimeType" + file.getMimeType());
|
||||
// System.out.println("File size" + file.getLength());
|
||||
//
|
||||
|
||||
//
|
||||
// file.setData(new FileInputStream(new File(newFilePath)));
|
||||
// System.out.println("New File mimeType" + file.getMimeType());
|
||||
// System.out.println("New File size" + file.getLength());
|
||||
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
System.out.println("Recovering data");
|
||||
InputStream inputStream = file.getData();
|
||||
// write the inputStream to a FileOutputStream
|
||||
OutputStream out = new FileOutputStream(new File("/home/francesco-mangiacrapa/Desktop/result"));
|
||||
|
||||
int read = 0;
|
||||
byte[] bytes = new byte[1024];
|
||||
|
||||
while ((read = inputStream.read(bytes)) != -1) {
|
||||
out.write(bytes, 0, read);
|
||||
}
|
||||
|
||||
inputStream.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
System.out.println("Recovering data - OK");
|
||||
|
||||
// File file = new File("/home/gioia/Desktop/test");
|
||||
// InputStream is = new FileInputStream(file);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue