Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #11039: making the display of PDF attached files (via a permalinkURL) possible without breaking out the Silverpeas's navigation. #1013

Merged
merged 1 commit into from Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions core-war/src/main/java/org/silverpeas/web/servlets/GoToFile.java
Expand Up @@ -30,8 +30,12 @@
import org.silverpeas.core.contribution.attachment.model.SimpleDocumentPK;
import org.silverpeas.core.util.StringUtil;
import org.silverpeas.core.util.URLUtil;
import org.silverpeas.core.viewer.model.DocumentView;
import org.silverpeas.core.viewer.service.ViewService;
import org.silverpeas.core.viewer.service.ViewerContext;
import org.silverpeas.core.web.util.ClientBrowserUtil;
import org.silverpeas.core.web.util.servlet.GoTo;
import org.silverpeas.core.webapi.viewer.DocumentViewEntity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -46,7 +50,7 @@ public class GoToFile extends GoTo {

@Override
public String getDestination(String objectId, HttpServletRequest req,
HttpServletResponse res) throws Exception {
HttpServletResponse res) {
SimpleDocument attachment = AttachmentServiceProvider.getAttachmentService().
searchDocumentById(new SimpleDocumentPK(objectId), getContentLanguage(req));
if (attachment == null) {
Expand All @@ -56,11 +60,16 @@ public String getDestination(String objectId, HttpServletRequest req,
String foreignId = attachment.getForeignId();

if (isUserLogin(req) && attachment.canBeAccessedBy(UserDetail.getCurrentRequester())) {
res.setCharacterEncoding(CharEncoding.UTF_8);
res.setContentType(format("{0}; charset=utf-8", attachment.getContentType()));
String fileName = ClientBrowserUtil.rfc2047EncodeFilename(req, attachment.getFilename());
res.setHeader("Content-Disposition", format("inline; filename=\"{0}\"", fileName));
return URLUtil.getFullApplicationURL(req) + encodeFilename(attachment.getAttachmentURL());
if (attachment.isContentPdf()) {
final DocumentView view = ViewService.get().getDocumentView(ViewerContext.from(attachment));
return URLUtil.getServerURL(req) + DocumentViewEntity.createFrom(view).getViewerUri();
} else {
res.setCharacterEncoding(CharEncoding.UTF_8);
res.setContentType(format("{0}; charset=utf-8", attachment.getContentType()));
String fileName = ClientBrowserUtil.rfc2047EncodeFilename(req, attachment.getFilename());
res.setHeader("Content-Disposition", format("inline; filename=\"{0}\"", fileName));
return URLUtil.getFullApplicationURL(req) + encodeFilename(attachment.getAttachmentURL());
}
}

if (StringUtil.isDefined(req.getParameter("ComponentId"))) {
Expand Down
10 changes: 2 additions & 8 deletions core-war/src/main/webapp/util/javaScript/silverpeas-view.js
Expand Up @@ -155,10 +155,7 @@

// Player
$documentViewer.embedPlayer({
url : sp.ajaxRequest(view.viewerUri)
.withParam('documentId', view.documentId)
.withParam('language', view.language)
.getUrl(),
url : view.viewerUri,
width : view.width,
height : view.height
});
Expand Down Expand Up @@ -202,10 +199,7 @@

// Player
$documentViewer.embedPlayer({
url : sp.ajaxRequest(view.viewerUri)
.withParam('documentId', view.documentId)
.withParam('language', view.language)
.getUrl(),
url : view.viewerUri,
width : view.width,
height : view.height
});
Expand Down
Expand Up @@ -94,6 +94,7 @@ private DocumentViewEntity(final DocumentView documentView) {
}
viewerUri += "fp";
}
viewerUri += "?documentId=" + documentId + "&language=" + language;
}

protected DocumentViewEntity() {
Expand Down