[kune-commits] r911 - in trunk/src:
main/java/org/ourproject/kune/docs/client
main/java/org/ourproject/kune/docs/client/cnt/reader
main/java/org/ourproject/kune/docs/client/cnt/reader/ui
main/java/org/ourproject/kune/platf/client/ui/download
main/java/org/ourproject/kune/platf/server/manager/impl
main/java/org/ourproject/kune/workspace/client/entitylogo
test/java/org/ourproject/kune/platf/server/manager/impl
vjrj
vjrj at ourproject.org
Wed Oct 15 16:12:57 CEST 2008
Author: vjrj
Date: 2008-10-15 16:12:54 +0200 (Wed, 15 Oct 2008)
New Revision: 911
Added:
trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/FileParams.java
trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/ImageSize.java
Removed:
trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/FileConstants.java
Modified:
trunk/src/main/java/org/ourproject/kune/docs/client/DocumentClientModule.java
trunk/src/main/java/org/ourproject/kune/docs/client/cnt/reader/DocumentReaderPresenter.java
trunk/src/main/java/org/ourproject/kune/docs/client/cnt/reader/DocumentReaderView.java
trunk/src/main/java/org/ourproject/kune/docs/client/cnt/reader/ui/DocumentReaderPanel.java
trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/FileDownloadUtils.java
trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/FileDownloadManager.java
trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/FileUploadManager.java
trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/FileUtils.java
trunk/src/main/java/org/ourproject/kune/workspace/client/entitylogo/EntityLogoPanel.java
trunk/src/test/java/org/ourproject/kune/platf/server/manager/impl/FileUtilsTest.java
Log:
Incomplete - task Image thumbs/icons in client
Modified: trunk/src/main/java/org/ourproject/kune/docs/client/DocumentClientModule.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/docs/client/DocumentClientModule.java 2008-10-15 03:14:33 UTC (rev 910)
+++ trunk/src/main/java/org/ourproject/kune/docs/client/DocumentClientModule.java 2008-10-15 14:12:54 UTC (rev 911)
@@ -58,77 +58,84 @@
@Override
public void onLoad() {
- register(ToolGroup.class, new Factory<DocumentClientTool>(DocumentClientTool.class) {
- public DocumentClientTool create() {
- $(DocumentClientActions.class);
- return new DocumentClientTool($(I18nUITranslationService.class), $(ToolSelector.class),
- $(WsThemePresenter.class), $(WorkspaceSkeleton.class), $$(DocumentContext.class),
- $$(ContentServiceAsync.class), $(ContentActionRegistry.class),
- $(DragDropContentRegistry.class), $(ContentIconsRegistry.class));
- }
- });
+ register(ToolGroup.class, new Factory<DocumentClientTool>(DocumentClientTool.class) {
+ @Override
+ public DocumentClientTool create() {
+ $(DocumentClientActions.class);
+ return new DocumentClientTool($(I18nUITranslationService.class), $(ToolSelector.class),
+ $(WsThemePresenter.class), $(WorkspaceSkeleton.class), $$(DocumentContext.class),
+ $$(ContentServiceAsync.class), $(ContentActionRegistry.class),
+ $(DragDropContentRegistry.class), $(ContentIconsRegistry.class));
+ }
+ });
- register(ToolGroup.class, new Factory<DocumentClientActions>(DocumentClientActions.class) {
- public DocumentClientActions create() {
- return new DocumentClientActions($(I18nUITranslationService.class), $(ContextNavigator.class),
- $(Session.class), $(StateManager.class), $$(ContentServiceAsync.class),
- $$(GroupServiceAsync.class), $$(FileUploader.class), $(ContentActionRegistry.class),
- $(ContextActionRegistry.class), $$(FileDownloadUtils.class), $(EntityLogo.class),
- $$(TextEditor.class), $(KuneErrorHandler.class), $(DocumentContent.class));
- }
- });
+ register(ToolGroup.class, new Factory<DocumentClientActions>(DocumentClientActions.class) {
+ @Override
+ public DocumentClientActions create() {
+ return new DocumentClientActions($(I18nUITranslationService.class), $(ContextNavigator.class),
+ $(Session.class), $(StateManager.class), $$(ContentServiceAsync.class),
+ $$(GroupServiceAsync.class), $$(FileUploader.class), $(ContentActionRegistry.class),
+ $(ContextActionRegistry.class), $$(FileDownloadUtils.class), $(EntityLogo.class),
+ $$(TextEditor.class), $(KuneErrorHandler.class), $(DocumentContent.class));
+ }
+ });
- register(ToolGroup.class, new Factory<DocumentContent>(DocumentContent.class) {
- public DocumentContent create() {
- final ActionToolbarPanel<StateToken> contentNavigatorToolbar = new ActionToolbarPanel<StateToken>(
- ActionToolbarPanel.Position.content, $$(ActionManager.class), $(WorkspaceSkeleton.class));
- final ActionToolbar<StateToken> toolbar = new ActionToolbarPresenter<StateToken>(
- contentNavigatorToolbar);
+ register(ToolGroup.class, new Factory<DocumentContent>(DocumentContent.class) {
+ @Override
+ public DocumentContent create() {
+ final ActionToolbarPanel<StateToken> contentNavigatorToolbar = new ActionToolbarPanel<StateToken>(
+ ActionToolbarPanel.Position.content, $$(ActionManager.class), $(WorkspaceSkeleton.class));
+ final ActionToolbar<StateToken> toolbar = new ActionToolbarPresenter<StateToken>(
+ contentNavigatorToolbar);
- final DocumentContentPresenter presenter = new DocumentContentPresenter($(StateManager.class),
- $(Session.class), $$(DocumentReader.class), $$(TextEditor.class), $$(FolderViewer.class),
- toolbar, $(ContentActionRegistry.class));
- final DocumentContentPanel panel = new DocumentContentPanel($(WorkspaceSkeleton.class));
- presenter.init(panel);
- return presenter;
- }
- });
+ final DocumentContentPresenter presenter = new DocumentContentPresenter($(StateManager.class),
+ $(Session.class), $$(DocumentReader.class), $$(TextEditor.class), $$(FolderViewer.class),
+ toolbar, $(ContentActionRegistry.class));
+ final DocumentContentPanel panel = new DocumentContentPanel($(WorkspaceSkeleton.class));
+ presenter.init(panel);
+ return presenter;
+ }
+ });
- register(Singleton.class, new Factory<AdminContext>(AdminContext.class) {
- public AdminContext create() {
- final AdminContextPresenter presenter = new AdminContextPresenter($(Session.class),
- $(StateManager.class), $$(TagsSummary.class), $$(ContentServiceAsync.class),
- $(EntityTitle.class), $(EntitySubTitle.class));
- final AdminContextView view = new AdminContextPanel(presenter, $(I18nUITranslationService.class));
- presenter.init(view);
- return presenter;
- }
- });
+ register(Singleton.class, new Factory<AdminContext>(AdminContext.class) {
+ @Override
+ public AdminContext create() {
+ final AdminContextPresenter presenter = new AdminContextPresenter($(Session.class),
+ $(StateManager.class), $$(TagsSummary.class), $$(ContentServiceAsync.class),
+ $(EntityTitle.class), $(EntitySubTitle.class));
+ final AdminContextView view = new AdminContextPanel(presenter, $(I18nUITranslationService.class));
+ presenter.init(view);
+ return presenter;
+ }
+ });
- register(ToolGroup.class, new Factory<DocumentContext>(DocumentContext.class) {
- public DocumentContext create() {
- final DocumentContextPresenter presenter = new DocumentContextPresenter($(StateManager.class),
- $$(ContextNavigator.class), $$(AdminContext.class));
- final DocumentContextPanel panel = new DocumentContextPanel($(WorkspaceSkeleton.class));
- presenter.init(panel);
- return presenter;
- }
- });
+ register(ToolGroup.class, new Factory<DocumentContext>(DocumentContext.class) {
+ @Override
+ public DocumentContext create() {
+ final DocumentContextPresenter presenter = new DocumentContextPresenter($(StateManager.class),
+ $$(ContextNavigator.class), $$(AdminContext.class));
+ final DocumentContextPanel panel = new DocumentContextPanel($(WorkspaceSkeleton.class));
+ presenter.init(panel);
+ return presenter;
+ }
+ });
- register(Singleton.class, new Factory<DocumentReader>(DocumentReader.class) {
- public DocumentReader create() {
- final DocumentReaderView view = new DocumentReaderPanel($(WorkspaceSkeleton.class));
- final DocumentReaderPresenter presenter = new DocumentReaderPresenter($(Session.class), view);
- return presenter;
- }
- });
+ register(Singleton.class, new Factory<DocumentReader>(DocumentReader.class) {
+ @Override
+ public DocumentReader create() {
+ final DocumentReaderView view = new DocumentReaderPanel($(WorkspaceSkeleton.class));
+ final DocumentReaderPresenter presenter = new DocumentReaderPresenter(view, $$(FileDownloadUtils.class));
+ return presenter;
+ }
+ });
- register(Singleton.class, new Factory<FolderViewer>(FolderViewer.class) {
- public FolderViewer create() {
- final FolderViewerView view = new FolderViewerPanel();
- final FolderViewerPresenter presenter = new FolderViewerPresenter(view);
- return presenter;
- }
- });
+ register(Singleton.class, new Factory<FolderViewer>(FolderViewer.class) {
+ @Override
+ public FolderViewer create() {
+ final FolderViewerView view = new FolderViewerPanel();
+ final FolderViewerPresenter presenter = new FolderViewerPresenter(view);
+ return presenter;
+ }
+ });
}
}
Modified: trunk/src/main/java/org/ourproject/kune/docs/client/cnt/reader/DocumentReaderPresenter.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/docs/client/cnt/reader/DocumentReaderPresenter.java 2008-10-15 03:14:33 UTC (rev 910)
+++ trunk/src/main/java/org/ourproject/kune/docs/client/cnt/reader/DocumentReaderPresenter.java 2008-10-15 14:12:54 UTC (rev 911)
@@ -24,15 +24,18 @@
import org.ourproject.kune.platf.client.View;
import org.ourproject.kune.platf.client.dto.BasicMimeTypeDTO;
import org.ourproject.kune.platf.client.dto.StateToken;
-import org.ourproject.kune.platf.client.state.Session;
+import org.ourproject.kune.platf.client.ui.download.FileDownloadUtils;
+import org.ourproject.kune.platf.client.ui.download.ImageSize;
+import com.calclab.suco.client.ioc.Provider;
+
public class DocumentReaderPresenter implements DocumentReader {
private final DocumentReaderView view;
- private final Session session;
+ private final Provider<FileDownloadUtils> downloadProvider;
- public DocumentReaderPresenter(final Session session, final DocumentReaderView view) {
- this.session = session;
+ public DocumentReaderPresenter(final DocumentReaderView view, final Provider<FileDownloadUtils> downloadProvider) {
this.view = view;
+ this.downloadProvider = downloadProvider;
}
public View getView() {
@@ -43,10 +46,10 @@
final BasicMimeTypeDTO mimeType) {
if (typeId.equals(DocumentClientTool.TYPE_UPLOADEDFILE)) {
if (mimeType != null) {
- final String url = "/kune/servlets/FileDownloadManager?token=" + token + "&hash="
- + session.getUserHash();
+ FileDownloadUtils fileDownloadUtils = downloadProvider.get();
if (mimeType.getType().equals("image")) {
- view.setContent("<img src=\"" + url + "\">");
+ view.showImage(fileDownloadUtils.getImageUrl(token), fileDownloadUtils.getImageResizedUrl(token,
+ ImageSize.sized));
} else if (mimeType.toString().equals("text/plain") || mimeType.toString().equals("application/pdf")) {
view.setContent(text);
} else {
Modified: trunk/src/main/java/org/ourproject/kune/docs/client/cnt/reader/DocumentReaderView.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/docs/client/cnt/reader/DocumentReaderView.java 2008-10-15 03:14:33 UTC (rev 910)
+++ trunk/src/main/java/org/ourproject/kune/docs/client/cnt/reader/DocumentReaderView.java 2008-10-15 14:12:54 UTC (rev 911)
@@ -26,4 +26,6 @@
public void setContent(String content);
+ public void showImage(String imageUrl, String imageResizedUrl);
+
}
Modified: trunk/src/main/java/org/ourproject/kune/docs/client/cnt/reader/ui/DocumentReaderPanel.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/docs/client/cnt/reader/ui/DocumentReaderPanel.java 2008-10-15 03:14:33 UTC (rev 910)
+++ trunk/src/main/java/org/ourproject/kune/docs/client/cnt/reader/ui/DocumentReaderPanel.java 2008-10-15 14:12:54 UTC (rev 911)
@@ -23,20 +23,47 @@
import org.ourproject.kune.docs.client.cnt.reader.DocumentReaderView;
import org.ourproject.kune.workspace.client.skel.WorkspaceSkeleton;
+import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.Image;
+import com.google.gwt.user.client.ui.Widget;
public class DocumentReaderPanel implements DocumentReaderView {
private final WorkspaceSkeleton ws;
public DocumentReaderPanel(final WorkspaceSkeleton ws) {
- this.ws = ws;
+ this.ws = ws;
}
public void setContent(final String content) {
- final HTML html = new HTML(content);
- html.setStyleName("kune-Content-Main");
- html.addStyleName("kune-Margin-7-trbl");
- ws.getEntityWorkspace().setContent(html);
+ final HTML html = new HTML(content);
+ setDefStyle(html);
+ ws.getEntityWorkspace().setContent(html);
}
+
+ public void showImage(String imageUrl, String imageResizedUrl) {
+ final Image imgOrig = new Image(imageUrl);
+ final Image imgResized = new Image(imageResizedUrl);
+ setDefStyle(imgOrig);
+ setDefStyle(imgResized);
+ imgOrig.addStyleName("kune-pointer");
+ imgResized.addStyleName("kune-pointer");
+ imgResized.addClickListener(new ClickListener() {
+ public void onClick(Widget sender) {
+ ws.getEntityWorkspace().setContent(imgOrig);
+ }
+ });
+ imgOrig.addClickListener(new ClickListener() {
+ public void onClick(Widget sender) {
+ ws.getEntityWorkspace().setContent(imgResized);
+ }
+ });
+ ws.getEntityWorkspace().setContent(imgResized);
+ }
+
+ private void setDefStyle(final Widget widget) {
+ widget.setStyleName("kune-Content-Main");
+ widget.addStyleName("kune-Margin-7-trbl");
+ }
}
Deleted: trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/FileConstants.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/FileConstants.java 2008-10-15 03:14:33 UTC (rev 910)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/FileConstants.java 2008-10-15 14:12:54 UTC (rev 911)
@@ -1,7 +0,0 @@
-package org.ourproject.kune.platf.client.ui.download;
-
-public interface FileConstants {
- final String ICON_SUFFIX = ".ico.";
- final String SIZED_SUFFIX = ".sized.";
- final String THUMB_SUFFIX = ".thumb.";
-}
Modified: trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/FileDownloadUtils.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/FileDownloadUtils.java 2008-10-15 03:14:33 UTC (rev 910)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/FileDownloadUtils.java 2008-10-15 14:12:54 UTC (rev 911)
@@ -13,22 +13,26 @@
private final Session session;
public FileDownloadUtils(final Session session) {
- this.session = session;
+ this.session = session;
}
public void downloadFile(final StateToken token) {
- final String url = calculateUrl(token, true);
- DOM.setElementAttribute(RootPanel.get("__download").getElement(), "src", url);
+ final String url = calculateUrl(token, true);
+ DOM.setElementAttribute(RootPanel.get("__download").getElement(), "src", url);
}
+ public String getImageResizedUrl(final StateToken token, ImageSize imageSize) {
+ return calculateUrl(token, false) + "&" + FileParams.IMGSIZE + "=" + imageSize;
+ }
+
public String getImageUrl(final StateToken token) {
- return calculateUrl(token, false);
+ return calculateUrl(token, false);
}
private String calculateUrl(final StateToken token, final boolean download) {
- final String url = DOWNLOADSERVLET + "?token=" + token + "&hash=" + session.getUserHash() + "&download="
- + (download ? "true" : "false");
- return url;
+ final String url = DOWNLOADSERVLET + "?" + FileParams.TOKEN + "=" + token + "&" + FileParams.HASH + "="
+ + session.getUserHash() + "&" + FileParams.DOWNLOAD + "=" + (download ? "true" : "false");
+ return url;
}
}
Copied: trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/FileParams.java (from rev 910, trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/FileConstants.java)
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/FileConstants.java 2008-10-15 03:14:33 UTC (rev 910)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/FileParams.java 2008-10-15 14:12:54 UTC (rev 911)
@@ -0,0 +1,8 @@
+package org.ourproject.kune.platf.client.ui.download;
+
+public interface FileParams {
+ final String HASH = "hash";
+ final String TOKEN = "token";
+ final String DOWNLOAD = "download";
+ final String IMGSIZE = "imgsize";
+}
Property changes on: trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/FileParams.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/ImageSize.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/ImageSize.java 2008-10-15 03:14:33 UTC (rev 910)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/download/ImageSize.java 2008-10-15 14:12:54 UTC (rev 911)
@@ -0,0 +1,5 @@
+package org.ourproject.kune.platf.client.ui.download;
+
+public enum ImageSize {
+ sized, thumb, ico
+}
\ No newline at end of file
Modified: trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/FileDownloadManager.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/FileDownloadManager.java 2008-10-15 03:14:33 UTC (rev 910)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/FileDownloadManager.java 2008-10-15 14:12:54 UTC (rev 911)
@@ -15,6 +15,8 @@
import org.ourproject.kune.platf.client.dto.StateToken;
import org.ourproject.kune.platf.client.errors.ContentNotFoundException;
+import org.ourproject.kune.platf.client.ui.download.FileParams;
+import org.ourproject.kune.platf.client.ui.download.ImageSize;
import org.ourproject.kune.platf.server.access.AccessRol;
import org.ourproject.kune.platf.server.auth.ActionLevel;
import org.ourproject.kune.platf.server.auth.Authenticated;
@@ -42,67 +44,78 @@
KuneProperties kuneProperties;
public void returnFile(final String filename, final OutputStream out) throws FileNotFoundException, IOException {
- InputStream in = null;
- try {
- in = new BufferedInputStream(new FileInputStream(filename));
- final byte[] buf = new byte[4 * 1024]; // 4K buffer
- int bytesRead;
- while ((bytesRead = in.read(buf)) != -1) {
- out.write(buf, 0, bytesRead);
- }
- } finally {
- if (in != null) {
- in.close();
- }
- }
+ InputStream in = null;
+ try {
+ in = new BufferedInputStream(new FileInputStream(filename));
+ final byte[] buf = new byte[4 * 1024]; // 4K buffer
+ int bytesRead;
+ while ((bytesRead = in.read(buf)) != -1) {
+ out.write(buf, 0, bytesRead);
+ }
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
}
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException,
- IOException {
+ IOException {
- final String userHash = req.getParameter("hash");
- final StateToken stateToken = new StateToken(req.getParameter("token"));
- final String downloadS = req.getParameter("download");
- final boolean download = downloadS != null && downloadS.equals("true") ? true : false;
- final Content cnt = getContentForDownload(userHash, stateToken);
+ final String userHash = req.getParameter(FileParams.HASH);
+ final StateToken stateToken = new StateToken(req.getParameter(FileParams.TOKEN));
+ final String downloadS = req.getParameter(FileParams.DOWNLOAD);
+ String imageSizeS = req.getParameter(FileParams.IMGSIZE);
+ final ImageSize imgsize = imageSizeS == null ? null : ImageSize.valueOf(imageSizeS);
+ final boolean download = downloadS != null && downloadS.equals("true") ? true : false;
- final String absDir = kuneProperties.get(KuneProperties.UPLOAD_LOCATION) + FileUtils.toDir(stateToken);
- final String filename = cnt.getFilename();
- final String absFilename = absDir + filename;
+ final Content cnt = getContentForDownload(userHash, stateToken);
- doBuildResp(resp, absFilename, cnt.getTitle(), cnt.getMimeType(), FileUtils
- .getFileNameExtension(filename, true), download);
+ final String absDir = kuneProperties.get(KuneProperties.UPLOAD_LOCATION) + FileUtils.toDir(stateToken);
+ String filename = cnt.getFilename();
+ String extension = FileUtils.getFileNameExtension(filename, true);
+ BasicMimeType mimeType = cnt.getMimeType();
+
+ if (mimeType.getType().equals("image")) {
+ String imgsizePrefix = imgsize == null ? "" : "." + imgsize;
+ String filenameWithoutExtension = FileUtils.getFileNameWithoutExtension(filename, extension);
+ filename = filenameWithoutExtension + imgsizePrefix + extension;
+ }
+
+ final String absFilename = absDir + filename;
+
+ doBuildResp(resp, absFilename, cnt.getTitle(), mimeType, extension, download);
}
private void doBuildResp(final HttpServletResponse resp, final String filename, final String otherName,
- final BasicMimeType mimeType, final String extension, final boolean download) throws FileNotFoundException,
- IOException {
- final File file = new File(filename);
+ final BasicMimeType mimeType, final String extension, final boolean download) throws FileNotFoundException,
+ IOException {
+ final File file = new File(filename);
- resp.setContentLength((int) file.length());
- if (mimeType == null || download) {
- resp.setContentType("application/x-download");
- } else if (mimeType.getType().equals("image") || mimeType.toString().equals("text/plain")) {
- resp.setContentType(mimeType.toString());
- } else {
- resp.setContentType("application/x-download");
- }
- resp.setHeader("Content-Disposition", "attachment; filename=\"" + otherName + extension + "\"");
+ resp.setContentLength((int) file.length());
+ if (mimeType == null || download) {
+ resp.setContentType("application/x-download");
+ } else if (mimeType.getType().equals("image")) {
+ resp.setContentType(mimeType.toString());
+ } else {
+ resp.setContentType("application/x-download");
+ }
+ resp.setHeader("Content-Disposition", "attachment; filename=\"" + otherName + extension + "\"");
- final OutputStream out = resp.getOutputStream();
- returnFile(filename, out);
+ final OutputStream out = resp.getOutputStream();
+ returnFile(filename, out);
}
@Authenticated(mandatory = false)
@Authorizated(accessRolRequired = AccessRol.Viewer, actionLevel = ActionLevel.content)
private Content getContentForDownload(final String userHash, final StateToken stateToken) throws ServletException {
- try {
- return contentManager.find(ContentUtils.parseId(stateToken.getDocument()));
- } catch (final ContentNotFoundException e) {
- // what response to send in this case ?
- throw new ServletException();
- }
+ try {
+ return contentManager.find(ContentUtils.parseId(stateToken.getDocument()));
+ } catch (final ContentNotFoundException e) {
+ // what response to send in this case ?
+ throw new ServletException();
+ }
}
}
Modified: trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/FileUploadManager.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/FileUploadManager.java 2008-10-15 03:14:33 UTC (rev 910)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/FileUploadManager.java 2008-10-15 14:12:54 UTC (rev 911)
@@ -24,7 +24,7 @@
import org.ourproject.kune.docs.server.DocumentServerTool;
import org.ourproject.kune.platf.client.dto.StateToken;
import org.ourproject.kune.platf.client.services.I18nTranslationService;
-import org.ourproject.kune.platf.client.ui.download.FileConstants;
+import org.ourproject.kune.platf.client.ui.download.ImageSize;
import org.ourproject.kune.platf.client.ui.upload.FileUploader;
import org.ourproject.kune.platf.server.UserSession;
import org.ourproject.kune.platf.server.access.AccessRol;
@@ -70,7 +70,7 @@
@Override
@SuppressWarnings( { "unchecked", "deprecation" })
- protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException,
+ protected void doPost(final HttpServletRequest req, final HttpServletResponse response) throws ServletException,
IOException {
JSONObject jsonResponse = createSuccessResponse();
@@ -122,10 +122,13 @@
e.printStackTrace();
}
- final Writer w = new OutputStreamWriter(resp.getOutputStream());
+ final Writer w = new OutputStreamWriter(response.getOutputStream());
+ response.setCharacterEncoding("utf-8");
+ response.setContentType("text/html");
+ // response.setContentType("text/json");
w.write(jsonResponse.toString());
w.close();
- resp.setStatus(HttpServletResponse.SC_OK);
+ response.setStatus(HttpServletResponse.SC_OK);
}
@Authenticated
@@ -205,9 +208,9 @@
String fileOrig = absDir + filename;
String withoutExtension = FileUtils.getFileNameWithoutExtension(filename, extension);
- String resizeName = absDir + withoutExtension + FileConstants.SIZED_SUFFIX + extension;
- String thumbName = absDir + withoutExtension + FileConstants.THUMB_SUFFIX + extension;
- String iconName = absDir + withoutExtension + FileConstants.ICON_SUFFIX + extension;
+ String resizeName = absDir + withoutExtension + "." + ImageSize.sized + "." + extension;
+ String thumbName = absDir + withoutExtension + "." + ImageSize.thumb + "." + extension;
+ String iconName = absDir + withoutExtension + "." + ImageSize.ico + "." + extension;
int resizeWidth = Integer.parseInt(kuneProperties.get(KuneProperties.IMAGES_RESIZEWIDTH));
int thumbSize = Integer.parseInt(kuneProperties.get(KuneProperties.IMAGES_THUMBSIZE));
Modified: trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/FileUtils.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/FileUtils.java 2008-10-15 03:14:33 UTC (rev 910)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/FileUtils.java 2008-10-15 14:12:54 UTC (rev 911)
@@ -16,59 +16,60 @@
* @return
*/
public static String getFileNameExtension(final String filename, final boolean withDot) {
- // also we can use FilenameUtils
- if (filename == null) {
- return "";
- }
- final int dotIndex = filename.lastIndexOf(".");
- if (dotIndex == -1 || dotIndex == 0) {
- return "";
- } else {
- if (withDot) {
- final String ext = filename.substring(dotIndex);
- return ext.length() == 1 ? "" : ext;
- } else {
- return filename.substring(dotIndex + 1);
- }
- }
+ // also we can use FilenameUtils
+ if (filename == null) {
+ return "";
+ }
+ final int dotIndex = filename.lastIndexOf(".");
+ if (dotIndex == -1 || dotIndex == 0) {
+ return "";
+ } else {
+ if (withDot) {
+ final String ext = filename.substring(dotIndex);
+ return ext.length() == 1 ? "" : ext;
+ } else {
+ return filename.substring(dotIndex + 1);
+ }
+ }
}
public static String getFileNameWithoutExtension(final String fileName, final String extension) {
- final int extlength = extension.length();
- if (extlength > 0) {
- return fileName.substring(0, fileName.length() - extlength - 1);
- } else {
- return fileName;
- }
+ final int extlength = extension.length();
+ if (extlength > 0) {
+ boolean withDot = extension.charAt(0) == '.';
+ return fileName.substring(0, fileName.length() - extlength - (withDot ? 0 : 1));
+ } else {
+ return fileName;
+ }
}
public static String getNextSequentialFileName(final String fileName) {
- final int lastSpace = fileName.lastIndexOf(" ");
- if (lastSpace != -1) {
- final String suffix = fileName.substring(lastSpace + 1);
- try {
- final Integer i = new Integer(suffix);
- return fileName.substring(0, lastSpace + 1) + (i + 1);
- } catch (final NumberFormatException e) {
- }
- }
- return fileName + " 1";
+ final int lastSpace = fileName.lastIndexOf(" ");
+ if (lastSpace != -1) {
+ final String suffix = fileName.substring(lastSpace + 1);
+ try {
+ final Integer i = new Integer(suffix);
+ return fileName.substring(0, lastSpace + 1) + (i + 1);
+ } catch (final NumberFormatException e) {
+ }
+ }
+ return fileName + " 1";
}
public static String getNextSequentialFileName(final String fileName, boolean preserveExtension) {
- if (!preserveExtension) {
- return getNextSequentialFileName(fileName);
- }
- final int dotIndex = fileName.lastIndexOf(".");
- if (dotIndex == -1 || dotIndex == 0) {
- return getNextSequentialFileName(fileName);
- } else {
- final String ext = fileName.substring(dotIndex);
- return getNextSequentialFileName(fileName.substring(0, dotIndex)) + ext;
- }
+ if (!preserveExtension) {
+ return getNextSequentialFileName(fileName);
+ }
+ final int dotIndex = fileName.lastIndexOf(".");
+ if (dotIndex == -1 || dotIndex == 0) {
+ return getNextSequentialFileName(fileName);
+ } else {
+ final String ext = fileName.substring(dotIndex);
+ return getNextSequentialFileName(fileName.substring(0, dotIndex)) + ext;
+ }
}
public static String toDir(final StateToken stateToken) {
- return SLASH + stateToken.getGroup() + SLASH + stateToken.getTool() + SLASH + stateToken.getFolder() + SLASH;
+ return SLASH + stateToken.getGroup() + SLASH + stateToken.getTool() + SLASH + stateToken.getFolder() + SLASH;
}
}
Modified: trunk/src/main/java/org/ourproject/kune/workspace/client/entitylogo/EntityLogoPanel.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/workspace/client/entitylogo/EntityLogoPanel.java 2008-10-15 03:14:33 UTC (rev 910)
+++ trunk/src/main/java/org/ourproject/kune/workspace/client/entitylogo/EntityLogoPanel.java 2008-10-15 14:12:54 UTC (rev 911)
@@ -42,59 +42,59 @@
public class EntityLogoPanel extends SimplePanel implements EntityLogoView {
class EntityTextLogo extends VerticalPanel {
- private static final int GROUP_NAME_LIMIT_SIZE = 90;
- private static final String LOGO_SMALL_FONT_SIZE = "108%";
- private static final String LOGO_DEFAULT_FONT_SIZE = "167%";
- private final Label defTextLogoLabel;
- private final Hyperlink defTextPutYourLogoHL;
- private final HorizontalPanel putYourLogoHP;
+ private static final int GROUP_NAME_LIMIT_SIZE = 90;
+ private static final String LOGO_SMALL_FONT_SIZE = "108%";
+ private static final String LOGO_DEFAULT_FONT_SIZE = "167%";
+ private final Label defTextLogoLabel;
+ private final Hyperlink defTextPutYourLogoHL;
+ private final HorizontalPanel putYourLogoHP;
- public EntityTextLogo() {
- // Initialize
- super();
- defTextLogoLabel = new Label();
- final HTML expandCell = new HTML("<b></b>");
- putYourLogoHP = new HorizontalPanel();
- defTextPutYourLogoHL = new Hyperlink();
+ public EntityTextLogo() {
+ // Initialize
+ super();
+ defTextLogoLabel = new Label();
+ final HTML expandCell = new HTML("<b></b>");
+ putYourLogoHP = new HorizontalPanel();
+ defTextPutYourLogoHL = new Hyperlink();
- // Layout
- add(defTextLogoLabel);
- add(putYourLogoHP);
- putYourLogoHP.add(expandCell);
- putYourLogoHP.add(defTextPutYourLogoHL);
+ // Layout
+ add(defTextLogoLabel);
+ add(putYourLogoHP);
+ putYourLogoHP.add(expandCell);
+ putYourLogoHP.add(defTextPutYourLogoHL);
- // Set properties
- defTextPutYourLogoHL.setText(i18n.t("Put Your Logo Here"));
- defTextPutYourLogoHL.addClickListener(new ClickListener() {
- public void onClick(final Widget sender) {
- final InfoDialog infoDialog = new InfoDialog(
- "Configure your group logo",
- "Howto configure your group logo",
- "For configure your group's logo just add an image to your group contents and select it as your group's logo (see menu 'File'). Whe are working into a more direct way to do that.",
- i18n.t("Ok"), false, false, 300, 200);
- infoDialog.show();
- }
- });
- expandCell.setWidth("100%");
- putYourLogoHP.setCellWidth(expandCell, "100%");
- // TODO: link to configure the logo
- setStylePrimaryName("k-entitytextlogo");
- setDefaultText("");
- }
+ // Set properties
+ defTextPutYourLogoHL.setText(i18n.t("Put Your Logo Here"));
+ defTextPutYourLogoHL.addClickListener(new ClickListener() {
+ public void onClick(final Widget sender) {
+ final InfoDialog infoDialog = new InfoDialog(
+ "Configure your group logo",
+ "Howto configure your group logo",
+ "For configure your group's logo just add an image to your group contents and select it as your group's logo (see menu 'File'). Whe are working into a more direct way to do that.",
+ i18n.t("Ok"), false, false, 300, 200);
+ infoDialog.show();
+ }
+ });
+ expandCell.setWidth("100%");
+ putYourLogoHP.setCellWidth(expandCell, "100%");
+ // TODO: link to configure the logo
+ setStylePrimaryName("k-entitytextlogo");
+ setDefaultText("");
+ }
- public void setDefaultText(final String text) {
- if (text.length() > GROUP_NAME_LIMIT_SIZE) {
- DOM.setStyleAttribute(defTextLogoLabel.getElement(), "fontSize", LOGO_SMALL_FONT_SIZE);
- } else {
- DOM.setStyleAttribute(defTextLogoLabel.getElement(), "fontSize", LOGO_DEFAULT_FONT_SIZE);
- }
- defTextLogoLabel.setText(text);
+ public void setDefaultText(final String text) {
+ if (text.length() > GROUP_NAME_LIMIT_SIZE) {
+ DOM.setStyleAttribute(defTextLogoLabel.getElement(), "fontSize", LOGO_SMALL_FONT_SIZE);
+ } else {
+ DOM.setStyleAttribute(defTextLogoLabel.getElement(), "fontSize", LOGO_DEFAULT_FONT_SIZE);
+ }
+ defTextLogoLabel.setText(text);
- }
+ }
- public void setPutYourLogoVisible(final boolean visible) {
- putYourLogoHP.setVisible(visible);
- }
+ public void setPutYourLogoVisible(final boolean visible) {
+ putYourLogoHP.setVisible(visible);
+ }
}
@@ -103,52 +103,52 @@
private EntityTextLogo entityTextLogo;
private final I18nTranslationService i18n;
- private final Provider<FileDownloadUtils> dowloadProvider;
+ private final Provider<FileDownloadUtils> downloadProvider;
public EntityLogoPanel(final I18nTranslationService i18n, final WorkspaceSkeleton ws,
- final Provider<FileDownloadUtils> dowloadProvider) {
- this.i18n = i18n;
- this.dowloadProvider = dowloadProvider;
- ws.addToEntityMainHeader(this);
+ final Provider<FileDownloadUtils> dowloadProvider) {
+ this.i18n = i18n;
+ this.downloadProvider = dowloadProvider;
+ ws.addToEntityMainHeader(this);
}
public void setLogo(final StateToken stateToken, final boolean clipped) {
- clear();
- final String imageUrl = dowloadProvider.get().getImageUrl(stateToken);
- Image logo;
- if (clipped) {
- logo = new Image(imageUrl, 0, 0, LOGO_ICON_DEFAULT_WIDTH, LOGO_ICON_DEFAULT_HEIGHT);
- } else {
+ clear();
+ final String imageUrl = downloadProvider.get().getImageUrl(stateToken);
+ Image logo;
+ if (clipped) {
+ logo = new Image(imageUrl, 0, 0, LOGO_ICON_DEFAULT_WIDTH, LOGO_ICON_DEFAULT_HEIGHT);
+ } else {
- logo = new Image(imageUrl);
- logo.setWidth("" + LOGO_ICON_DEFAULT_WIDTH);
- logo.setHeight("" + LOGO_ICON_DEFAULT_HEIGHT);
- }
- add(logo);
+ logo = new Image(imageUrl);
+ logo.setWidth("" + LOGO_ICON_DEFAULT_WIDTH);
+ logo.setHeight("" + LOGO_ICON_DEFAULT_HEIGHT);
+ }
+ add(logo);
}
public void setLogo(final String groupName) {
- clear();
- add(getEntityTextLogo());
- entityTextLogo.setDefaultText(groupName);
+ clear();
+ add(getEntityTextLogo());
+ entityTextLogo.setDefaultText(groupName);
}
public void setPutYourLogoVisible(final boolean visible) {
- getEntityTextLogo().setPutYourLogoVisible(visible);
+ getEntityTextLogo().setPutYourLogoVisible(visible);
}
public void setTheme(final WsTheme oldTheme, final WsTheme newTheme) {
- if (oldTheme != null) {
- getEntityTextLogo().removeStyleDependentName(oldTheme.toString());
- }
- getEntityTextLogo().addStyleDependentName(newTheme.toString());
+ if (oldTheme != null) {
+ getEntityTextLogo().removeStyleDependentName(oldTheme.toString());
+ }
+ getEntityTextLogo().addStyleDependentName(newTheme.toString());
}
private EntityTextLogo getEntityTextLogo() {
- if (entityTextLogo == null) {
- this.entityTextLogo = new EntityTextLogo();
- }
- return entityTextLogo;
+ if (entityTextLogo == null) {
+ this.entityTextLogo = new EntityTextLogo();
+ }
+ return entityTextLogo;
}
}
Modified: trunk/src/test/java/org/ourproject/kune/platf/server/manager/impl/FileUtilsTest.java
===================================================================
--- trunk/src/test/java/org/ourproject/kune/platf/server/manager/impl/FileUtilsTest.java 2008-10-15 03:14:33 UTC (rev 910)
+++ trunk/src/test/java/org/ourproject/kune/platf/server/manager/impl/FileUtilsTest.java 2008-10-15 14:12:54 UTC (rev 911)
@@ -11,88 +11,98 @@
@Test
public void dotFileRetSeq1() {
- assertEquals("." + SIMPLE_FILE_NAME + " 1", FileUtils.getNextSequentialFileName("." + SIMPLE_FILE_NAME, true));
+ assertEquals("." + SIMPLE_FILE_NAME + " 1", FileUtils.getNextSequentialFileName("." + SIMPLE_FILE_NAME, true));
}
@Test
public void dotFileRetSeq1IgnoreExt() {
- assertEquals("." + SIMPLE_FILE_NAME + " 1", FileUtils.getNextSequentialFileName("." + SIMPLE_FILE_NAME, false));
+ assertEquals("." + SIMPLE_FILE_NAME + " 1", FileUtils.getNextSequentialFileName("." + SIMPLE_FILE_NAME, false));
}
@Test
public void getExtensionBasic() {
- assertEquals("someext", FileUtils.getFileNameExtension("file.name.with.someext", false));
+ assertEquals("someext", FileUtils.getFileNameExtension("file.name.with.someext", false));
}
@Test
public void getExtensionWithDot() {
- assertEquals("", FileUtils.getFileNameExtension("file name with no ext.", false));
+ assertEquals("", FileUtils.getFileNameExtension("file name with no ext.", false));
}
@Test
public void getExtensionWithDotBasic() {
- assertEquals(".someext", FileUtils.getFileNameExtension("file.name.with.someext", true));
+ assertEquals(".someext", FileUtils.getFileNameExtension("file.name.with.someext", true));
}
@Test
public void getExtensionWithDotWithFinalDot() {
- assertEquals("", FileUtils.getFileNameExtension("file name with no ext.", true));
+ assertEquals("", FileUtils.getFileNameExtension("file name with no ext.", true));
}
@Test
public void getExtensionWithDotWithInitialDot() {
- assertEquals("", FileUtils.getFileNameExtension(".file name with no ext", true));
+ assertEquals("", FileUtils.getFileNameExtension(".file name with no ext", true));
}
@Test
public void getExtensionWithInitialDot() {
- assertEquals("", FileUtils.getFileNameExtension(".file name with no ext", false));
+ assertEquals("", FileUtils.getFileNameExtension(".file name with no ext", false));
}
@Test
public void testFileNameWExtensionSimple() {
- assertEquals("test", FileUtils.getFileNameWithoutExtension("test.txt", "txt"));
+ assertEquals("test", FileUtils.getFileNameWithoutExtension("test.txt", "txt"));
}
@Test
+ public void testFileNameWExtensionSimpleWithDot() {
+ assertEquals("test", FileUtils.getFileNameWithoutExtension("test.txt", ".txt"));
+ }
+
+ @Test
public void testFileNameWithoutExtension() {
- assertEquals("test", FileUtils.getFileNameWithoutExtension("test", ""));
+ assertEquals("test", FileUtils.getFileNameWithoutExtension("test", ""));
}
@Test
+ public void testFileNameWNoExtensionWithDot() {
+ assertEquals("test.", FileUtils.getFileNameWithoutExtension("test.", ""));
+ }
+
+ @Test
public void testGetFilenameExtNull() {
- assertEquals("", FileUtils.getFileNameExtension(null, true));
+ assertEquals("", FileUtils.getFileNameExtension(null, true));
}
@Test
public void testIfSeq101return102() {
- assertEquals(SIMPLE_FILE_NAME + " 102", FileUtils.getNextSequentialFileName(SIMPLE_FILE_NAME + " 101"));
+ assertEquals(SIMPLE_FILE_NAME + " 102", FileUtils.getNextSequentialFileName(SIMPLE_FILE_NAME + " 101"));
}
@Test
public void testIfSeq1return2() {
- assertEquals(SIMPLE_FILE_NAME + " 2", FileUtils.getNextSequentialFileName(SIMPLE_FILE_NAME + " 1"));
+ assertEquals(SIMPLE_FILE_NAME + " 2", FileUtils.getNextSequentialFileName(SIMPLE_FILE_NAME + " 1"));
}
@Test
public void testIfSeq1WithExtreturn2WithExt() {
- assertEquals(SIMPLE_FILE_NAME + " 2" + EXT, FileUtils.getNextSequentialFileName(SIMPLE_FILE_NAME + " 1" + EXT,
- true));
+ assertEquals(SIMPLE_FILE_NAME + " 2" + EXT, FileUtils.getNextSequentialFileName(SIMPLE_FILE_NAME + " 1" + EXT,
+ true));
}
@Test
public void testNoSeqReturn1() {
- assertEquals(SIMPLE_FILE_NAME + " 1", FileUtils.getNextSequentialFileName(SIMPLE_FILE_NAME));
+ assertEquals(SIMPLE_FILE_NAME + " 1", FileUtils.getNextSequentialFileName(SIMPLE_FILE_NAME));
}
@Test
public void testNoSeqWithExtNotTakedIntoAccountReturn1() {
- assertEquals(SIMPLE_FILE_NAME + EXT + " 1", FileUtils.getNextSequentialFileName(SIMPLE_FILE_NAME + EXT, false));
+ assertEquals(SIMPLE_FILE_NAME + EXT + " 1", FileUtils.getNextSequentialFileName(SIMPLE_FILE_NAME + EXT, false));
}
@Test
public void testNoSeqWithExtReturn1WithExt() {
- assertEquals(SIMPLE_FILE_NAME + " 1" + EXT, FileUtils.getNextSequentialFileName(SIMPLE_FILE_NAME + EXT, true));
+ assertEquals(SIMPLE_FILE_NAME + " 1" + EXT, FileUtils.getNextSequentialFileName(SIMPLE_FILE_NAME + EXT, true));
}
}
More information about the kune-commits
mailing list