001
014
015 package com.liferay.portlet.documentlibrary.context;
016
017 import com.liferay.portal.freemarker.FreeMarkerUtil;
018 import com.liferay.portal.kernel.bean.BeanParamUtil;
019 import com.liferay.portal.kernel.exception.PortalException;
020 import com.liferay.portal.kernel.exception.SystemException;
021 import com.liferay.portal.kernel.language.UnicodeLanguageUtil;
022 import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
023 import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
024 import com.liferay.portal.kernel.portlet.LiferayWindowState;
025 import com.liferay.portal.kernel.repository.model.FileEntry;
026 import com.liferay.portal.kernel.repository.model.FileVersion;
027 import com.liferay.portal.kernel.servlet.BrowserSnifferUtil;
028 import com.liferay.portal.kernel.servlet.taglib.ui.DeleteMenuItem;
029 import com.liferay.portal.kernel.servlet.taglib.ui.JavascriptMenuItem;
030 import com.liferay.portal.kernel.servlet.taglib.ui.JavascriptToolbarItem;
031 import com.liferay.portal.kernel.servlet.taglib.ui.JavascriptUIItem;
032 import com.liferay.portal.kernel.servlet.taglib.ui.MenuItem;
033 import com.liferay.portal.kernel.servlet.taglib.ui.ToolbarItem;
034 import com.liferay.portal.kernel.servlet.taglib.ui.URLMenuItem;
035 import com.liferay.portal.kernel.servlet.taglib.ui.URLToolbarItem;
036 import com.liferay.portal.kernel.servlet.taglib.ui.URLUIItem;
037 import com.liferay.portal.kernel.util.Constants;
038 import com.liferay.portal.kernel.util.HtmlUtil;
039 import com.liferay.portal.kernel.util.JavaConstants;
040 import com.liferay.portal.kernel.util.ParamUtil;
041 import com.liferay.portal.kernel.util.StringBundler;
042 import com.liferay.portal.kernel.util.StringPool;
043 import com.liferay.portal.kernel.util.TextFormatter;
044 import com.liferay.portal.theme.PortletDisplay;
045 import com.liferay.portal.theme.ThemeDisplay;
046 import com.liferay.portal.util.PortalUtil;
047 import com.liferay.portal.util.PortletKeys;
048 import com.liferay.portal.util.PropsValues;
049 import com.liferay.portal.util.WebKeys;
050 import com.liferay.portlet.PortletURLUtil;
051 import com.liferay.portlet.documentlibrary.DLPortletInstanceSettings;
052 import com.liferay.portlet.documentlibrary.context.helper.FileEntryDisplayContextHelper;
053 import com.liferay.portlet.documentlibrary.context.helper.FileVersionDisplayContextHelper;
054 import com.liferay.portlet.documentlibrary.context.util.JSPRenderer;
055 import com.liferay.portlet.documentlibrary.model.DLFileEntryConstants;
056 import com.liferay.portlet.documentlibrary.model.DLFileEntryMetadata;
057 import com.liferay.portlet.documentlibrary.model.DLFileVersion;
058 import com.liferay.portlet.documentlibrary.service.DLFileEntryMetadataLocalServiceUtil;
059 import com.liferay.portlet.documentlibrary.util.DLUtil;
060 import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
061 import com.liferay.portlet.dynamicdatamapping.storage.Fields;
062 import com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil;
063 import com.liferay.portlet.trash.util.TrashUtil;
064 import com.liferay.taglib.security.PermissionsURLTag;
065
066 import java.io.IOException;
067
068 import java.util.ArrayList;
069 import java.util.Collections;
070 import java.util.HashMap;
071 import java.util.List;
072 import java.util.Map;
073 import java.util.UUID;
074
075 import javax.portlet.PortletRequest;
076 import javax.portlet.PortletResponse;
077 import javax.portlet.PortletURL;
078
079 import javax.servlet.ServletException;
080 import javax.servlet.http.HttpServletRequest;
081 import javax.servlet.http.HttpServletResponse;
082
083
086 public abstract class BaseDefaultDLViewFileVersionDisplayContext
087 implements DLViewFileVersionDisplayContext {
088
089 public BaseDefaultDLViewFileVersionDisplayContext(
090 HttpServletRequest request, HttpServletResponse response,
091 FileVersion fileVersion)
092 throws PortalException {
093
094 _request = request;
095 _fileVersion = fileVersion;
096
097 FileEntry fileEntry = null;
098
099 if (fileVersion != null) {
100 fileEntry = fileVersion.getFileEntry();
101 }
102
103 _fileEntry = fileEntry;
104
105 _folderId = BeanParamUtil.getLong(_fileEntry, request, "folderId");
106
107 _themeDisplay = (ThemeDisplay)request.getAttribute(
108 WebKeys.THEME_DISPLAY);
109
110 _fileEntryDisplayContextHelper = new FileEntryDisplayContextHelper(
111 _themeDisplay.getPermissionChecker(), _fileEntry);
112 _fileVersionDisplayContextHelper = new FileVersionDisplayContextHelper(
113 fileVersion);
114 }
115
116 @Override
117 public List<DDMStructure> getDDMStructures() throws PortalException {
118 if (_fileVersionDisplayContextHelper.isDLFileVersion()) {
119 DLFileVersion dlFileVersion =
120 (DLFileVersion)_fileVersion.getModel();
121
122 return dlFileVersion.getDDMStructures();
123 }
124
125 return Collections.emptyList();
126 }
127
128 @Override
129 public Fields getFields(DDMStructure ddmStructure) throws PortalException {
130 DLFileEntryMetadata dlFileEntryMetadata =
131 DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata(
132 ddmStructure.getStructureId(), _fileVersion.getFileVersionId());
133
134 return StorageEngineUtil.getFields(
135 dlFileEntryMetadata.getDDMStorageId());
136 }
137
138 @Override
139 public List<MenuItem> getMenuItems() throws PortalException {
140 List<MenuItem> menuItems = new ArrayList<>();
141
142 if (_isShowActions()) {
143 buildMenuItems(menuItems);
144 }
145
146 return menuItems;
147 }
148
149 @Override
150 public List<ToolbarItem> getToolbarItems() throws PortalException {
151 List<ToolbarItem> toolbarItems = new ArrayList<>();
152
153 _addDownloadToolbarItem(toolbarItems);
154
155 _addOpenInMsOfficeToolbarItem(toolbarItems);
156
157 _addEditToolbarItem(toolbarItems);
158
159 _addMoveToolbarItem(toolbarItems);
160
161 _addCheckoutToolbarItem(toolbarItems);
162
163 _addCancelCheckoutToolbarItem(toolbarItems);
164
165 _addCheckinToolbarItem(toolbarItems);
166
167 _addPermissionsToolbarItem(toolbarItems);
168
169 _addMoveToTheRecycleBinToolbarItem(toolbarItems);
170
171 _addDeleteToolbarItem(toolbarItems);
172
173 return toolbarItems;
174 }
175
176 @Override
177 public UUID getUuid() {
178 return _UUID;
179 }
180
181 @Override
182 public boolean isAssetMetadataVisible() {
183 PortletDisplay portletDisplay = _themeDisplay.getPortletDisplay();
184
185 String portletName = portletDisplay.getPortletName();
186
187 if (portletName.equals(PortletKeys.ASSET_PUBLISHER) ||
188 portletName.equals(PortletKeys.DOCUMENT_LIBRARY) ||
189 portletName.equals(PortletKeys.DOCUMENT_LIBRARY_ADMIN) ||
190 portletName.equals(PortletKeys.MEDIA_GALLERY_DISPLAY) ||
191 portletName.equals(PortletKeys.DOCUMENT_LIBRARY_DISPLAY) ||
192 portletName.equals(PortletKeys.MY_WORKFLOW_INSTANCES) ||
193 portletName.equals(PortletKeys.MY_WORKFLOW_TASKS) ||
194 portletName.equals(PortletKeys.TRASH)) {
195
196 return true;
197 }
198
199 return ParamUtil.getBoolean(_request, "showAssetMetadata");
200 }
201
202 @Override
203 public boolean isCancelCheckoutDocumentButtonVisible()
204 throws PortalException {
205
206 return _fileEntryDisplayContextHelper.
207 isCancelCheckoutDocumentButtonVisible();
208 }
209
210 @Override
211 public boolean isCheckinButtonVisible() throws PortalException {
212 return _fileEntryDisplayContextHelper.isCheckinButtonVisible();
213 }
214
215 @Override
216 public boolean isCheckoutDocumentButtonVisible() throws PortalException {
217 return _fileEntryDisplayContextHelper.isCheckoutDocumentButtonVisible();
218 }
219
220 @Override
221 public boolean isDeleteButtonVisible() throws PortalException {
222 if (_fileEntryDisplayContextHelper.isFileEntryDeletable() &&
223 !_isFileEntryTrashable()) {
224
225 return true;
226 }
227
228 return false;
229 }
230
231 @Override
232 public boolean isDownloadButtonVisible() throws PortalException {
233 return _fileEntryDisplayContextHelper.hasViewPermission();
234 }
235
236 @Override
237 public boolean isEditButtonVisible() throws PortalException {
238 return _fileEntryDisplayContextHelper.isUpdatable();
239 }
240
241 @Override
242 public boolean isMoveButtonVisible() throws PortalException {
243 return _fileEntryDisplayContextHelper.isUpdatable();
244 }
245
246 @Override
247 public boolean isMoveToTheRecycleBinButtonVisible() throws PortalException {
248 if (!isDeleteButtonVisible() &&
249 _fileEntryDisplayContextHelper.isFileEntryDeletable()) {
250
251 return true;
252 }
253
254 return false;
255 }
256
257 @Override
258 public boolean isOpenInMsOfficeButtonVisible() throws PortalException {
259 if (_fileEntryDisplayContextHelper.hasViewPermission() &&
260 _fileVersionDisplayContextHelper.isMsOffice() &&
261 _isWebDAVEnabled() && _isIEOnWin32()) {
262
263 return true;
264 }
265
266 return false;
267 }
268
269 @Override
270 public boolean isPermissionsButtonVisible() throws PortalException {
271 return _fileEntryDisplayContextHelper.hasPermissionsPermission();
272 }
273
274 @Override
275 public boolean isViewButtonVisible() throws PortalException {
276 return _fileEntryDisplayContextHelper.hasViewPermission();
277 }
278
279 @Override
280 public boolean isViewOriginalFileButtonVisible() throws PortalException {
281 return _fileEntryDisplayContextHelper.hasViewPermission();
282 }
283
284 @Override
285 public void renderPreview(
286 HttpServletRequest request, HttpServletResponse response)
287 throws IOException, ServletException {
288
289 JSPRenderer jspRenderer = new JSPRenderer(
290 "/html/portlet/document_library/view_file_entry_preview.jsp");
291
292 jspRenderer.setAttribute(
293 WebKeys.DOCUMENT_LIBRARY_FILE_VERSION, _fileVersion);
294
295 jspRenderer.render(request, response);
296 }
297
298 protected void addCancelCheckoutMenuItem(List<MenuItem> menuItems)
299 throws PortalException {
300
301 if (!isCancelCheckoutDocumentButtonVisible()) {
302 return;
303 }
304
305 _addURLUIItem(
306 new URLMenuItem(), menuItems, "icon-remove",
307 DLUIItemKeys.CANCEL_CHECKOUT, "cancel-checkout[document]",
308 _getActionURL(
309 "/document_library/edit_file_entry",
310 Constants.CANCEL_CHECKOUT));
311 }
312
313 protected void addCheckinMenuItem(List<MenuItem> menuItems)
314 throws PortalException {
315
316 if (!isCheckinButtonVisible()) {
317 return;
318 }
319
320 _addURLUIItem(
321 new URLMenuItem(), menuItems, "icon-lock", DLUIItemKeys.CHECKIN,
322 "checkin",
323 _getActionURL(
324 "/document_library/edit_file_entry", Constants.CHECKIN));
325 }
326
327 protected void addCheckoutMenuItem(List<MenuItem> menuItems)
328 throws PortalException {
329
330 if (!isCheckoutDocumentButtonVisible()) {
331 return;
332 }
333
334 _addURLUIItem(
335 new URLMenuItem(), menuItems, "icon-unlock", DLUIItemKeys.CHECKOUT,
336 "checkout[document]",
337 _getActionURL(
338 "/document_library/edit_file_entry", Constants.CHECKOUT));
339 }
340
341 protected void addDeleteMenuItem(List<MenuItem> menuItems)
342 throws PortalException {
343
344 if (isDeleteButtonVisible()) {
345 DeleteMenuItem deleteMenuItem = new DeleteMenuItem();
346
347 deleteMenuItem.setKey(DLUIItemKeys.DELETE);
348 deleteMenuItem.setURL(
349 _getActionURL(
350 "/document_library/edit_file_entry", Constants.DELETE));
351
352 menuItems.add(deleteMenuItem);
353 }
354 else if (isMoveToTheRecycleBinButtonVisible()) {
355 DeleteMenuItem deleteMenuItem = new DeleteMenuItem();
356
357 deleteMenuItem.setKey(DLUIItemKeys.DELETE);
358 deleteMenuItem.setTrash(true);
359 deleteMenuItem.setURL(
360 _getActionURL(
361 "/document_library/edit_file_entry",
362 Constants.MOVE_TO_TRASH));
363
364 menuItems.add(deleteMenuItem);
365 }
366 }
367
368 protected void addDownloadMenuItem(List<MenuItem> menuItems)
369 throws PortalException {
370
371 if (!isDownloadButtonVisible()) {
372 return;
373 }
374
375 String label = TextFormatter.formatStorageSize(
376 _fileEntry.getSize(), _themeDisplay.getLocale());
377
378 label = _themeDisplay.translate("download") + " (" + label + ")";
379
380 String url = DLUtil.getDownloadURL(
381 _fileEntry, _fileVersion, _themeDisplay, StringPool.BLANK, false,
382 true);
383
384 URLMenuItem urlMenuItem = _addURLUIItem(
385 new URLMenuItem(), menuItems, "icon-download",
386 DLUIItemKeys.DOWNLOAD, label, url);
387
388 urlMenuItem.setTarget("_blank");
389 }
390
391 protected void addEditMenuItem(List<MenuItem> menuItems)
392 throws PortalException {
393
394 if (!isEditButtonVisible()) {
395 return;
396 }
397
398 PortletURL portletURL = _getRenderURL(
399 "/document_library/edit_file_entry");
400
401 portletURL.setParameter("backURL", _getCurrentURL());
402
403 _addURLUIItem(
404 new URLMenuItem(), menuItems, "icon-edit", DLUIItemKeys.EDIT,
405 "edit", portletURL.toString());
406 }
407
408 protected void addMoveMenuItem(List<MenuItem> menuItems)
409 throws PortalException {
410
411 if (!isMoveButtonVisible()) {
412 return;
413 }
414
415 LiferayPortletResponse liferayPortletResponse =
416 _getLiferayPortletResponse();
417
418 PortletURL portletURL = liferayPortletResponse.createRenderURL();
419
420 portletURL.setParameter(
421 "struts_action", "/document_library/move_entry");
422
423 PortletURL redirectURL = liferayPortletResponse.createRenderURL();
424
425 redirectURL.setParameter("struts_action", "/document_library/view");
426 redirectURL.setParameter("folderId", String.valueOf(_folderId));
427
428 portletURL.setParameter("redirect", redirectURL.toString());
429
430 portletURL.setParameter(
431 "fileEntryIds", String.valueOf(_fileEntry.getFileEntryId()));
432
433 _addURLUIItem(
434 new URLMenuItem(), menuItems, "icon-move", DLUIItemKeys.MOVE,
435 "move", portletURL.toString());
436 }
437
438 protected void addOpenInMsOfficeMenuItem(List<MenuItem> menuItems)
439 throws PortalException {
440
441 if (!isOpenInMsOfficeButtonVisible()) {
442 return;
443 }
444
445 String webDavURL = DLUtil.getWebDavURL(
446 _themeDisplay, _fileEntry.getFolder(), _fileEntry,
447 PropsValues.
448 DL_FILE_ENTRY_OPEN_IN_MS_OFFICE_MANUAL_CHECK_IN_REQUIRED,
449 true);
450
451 String onClick = getNamespace() + "openDocument('" + webDavURL + "');";
452
453 JavascriptMenuItem javascriptMenuItem = _addJavascriptUIItem(
454 new JavascriptMenuItem(), menuItems, "icon-file-alt",
455 DLUIItemKeys.OPEN_IN_MS_OFFICE, "open-in-ms-office", onClick);
456
457 Map<String, String> context = new HashMap<>();
458
459 context.put(
460 "errorMessage", UnicodeLanguageUtil.get(
461 _request,
462 "cannot-open-the-requested-document-due-to-the-following-" +
463 "reason"));
464 context.put("namespace", getNamespace());
465
466 String javaScript = _processFreeMarkerTemplate(
467 "/com/liferay/portlet/documentlibrary/context/dependencies" +
468 "open_in_ms_office_js.ftl",
469 context);
470
471 javascriptMenuItem.setJavascript(javaScript);
472 }
473
474 protected void addPermissionsMenuItem(List<MenuItem> menuItems)
475 throws PortalException {
476
477 if (!isPermissionsButtonVisible()) {
478 return;
479 }
480
481 String url = null;
482
483 try {
484 url = PermissionsURLTag.doTag(
485 null, DLFileEntryConstants.getClassName(),
486 HtmlUtil.unescape(_fileEntry.getTitle()), null,
487 String.valueOf(_fileEntry.getFileEntryId()),
488 LiferayWindowState.POP_UP.toString(), null, _request);
489 }
490 catch (Exception e) {
491 throw new SystemException("Unable to create permissions URL", e);
492 }
493
494 URLMenuItem urlMenuItem = _addURLUIItem(
495 new URLMenuItem(), menuItems, "icon-lock", DLUIItemKeys.PERMISSIONS,
496 "permissions", url);
497
498 urlMenuItem.setMethod("get");
499 urlMenuItem.setUseDialog(true);
500 }
501
502 protected abstract void buildMenuItems(List<MenuItem> menuItems)
503 throws PortalException;
504
505 protected String getNamespace() {
506 LiferayPortletResponse liferayPortletResponse =
507 _getLiferayPortletResponse();
508
509 return liferayPortletResponse.getNamespace();
510 }
511
512 protected String getSubmitFormJavascript(String cmd, String redirect) {
513 StringBundler sb = new StringBundler(18);
514
515 sb.append("document.");
516 sb.append(getNamespace());
517 sb.append("fm.");
518 sb.append(getNamespace());
519 sb.append(Constants.CMD);
520 sb.append(".value = '");
521 sb.append(cmd);
522 sb.append("';");
523
524 if (redirect != null) {
525 sb.append("document.");
526 sb.append(getNamespace());
527 sb.append("fm.");
528 sb.append(getNamespace());
529 sb.append("redirect.value = '");
530 sb.append(redirect);
531 sb.append("';");
532 }
533
534 sb.append("submitForm(document.");
535 sb.append(getNamespace());
536 sb.append("fm);");
537
538 return sb.toString();
539 }
540
541 private void _addCancelCheckoutToolbarItem(List<ToolbarItem> toolbarItems)
542 throws PortalException {
543
544 if (!isCancelCheckoutDocumentButtonVisible()) {
545 return;
546 }
547
548 _addJavascriptUIItem(
549 new JavascriptToolbarItem(), toolbarItems, "icon-undo",
550 DLUIItemKeys.CANCEL_CHECKOUT,
551 UnicodeLanguageUtil.get(_request, "cancel-checkout[document]"),
552 getSubmitFormJavascript(Constants.CANCEL_CHECKOUT, null));
553 }
554
555 private void _addCheckinToolbarItem(List<ToolbarItem> toolbarItems)
556 throws PortalException {
557
558 if (!isCheckinButtonVisible()) {
559 return;
560 }
561
562 _addJavascriptUIItem(
563 new JavascriptToolbarItem(), toolbarItems, "icon-lock",
564 DLUIItemKeys.CHECKIN, UnicodeLanguageUtil.get(_request, "checkin"),
565 getSubmitFormJavascript(Constants.CHECKIN, null));
566 }
567
568 private void _addCheckoutToolbarItem(List<ToolbarItem> toolbarItems)
569 throws PortalException {
570
571 if (!isCheckoutDocumentButtonVisible()) {
572 return;
573 }
574
575 _addJavascriptUIItem(
576 new JavascriptToolbarItem(), toolbarItems, "icon-unlock",
577 DLUIItemKeys.CHECKOUT,
578 UnicodeLanguageUtil.get(_request, "checkout[document]"),
579 getSubmitFormJavascript(Constants.CHECKOUT, null));
580 }
581
582 private void _addDeleteToolbarItem(List<ToolbarItem> toolbarItems)
583 throws PortalException {
584
585 if (!isDeleteButtonVisible()) {
586 return;
587 }
588
589 LiferayPortletResponse liferayPortletResponse =
590 _getLiferayPortletResponse();
591
592 PortletURL portletURL = liferayPortletResponse.createRenderURL();
593
594 portletURL.setParameter("struts_action", "/document_library/view");
595 portletURL.setParameter(
596 "folderId", String.valueOf(_fileEntry.getFolderId()));
597
598 StringBundler sb = new StringBundler(5);
599
600 sb.append("if (confirm('");
601 sb.append(
602 UnicodeLanguageUtil.get(
603 _request, "are-you-sure-you-want-to-delete-this"));
604 sb.append("')) {");
605 sb.append(
606 getSubmitFormJavascript(Constants.DELETE, portletURL.toString()));
607 sb.append("}");
608
609 _addJavascriptUIItem(
610 new JavascriptToolbarItem(), toolbarItems, "icon-remove",
611 DLUIItemKeys.DELETE, UnicodeLanguageUtil.get(_request, "delete"),
612 sb.toString());
613 }
614
615 private void _addDownloadToolbarItem(List<ToolbarItem> toolbarItems)
616 throws PortalException {
617
618 if (!isDownloadButtonVisible()) {
619 return;
620 }
621
622 _addURLUIItem(
623 new URLToolbarItem(), toolbarItems, "icon-download",
624 DLUIItemKeys.DOWNLOAD,
625 UnicodeLanguageUtil.get(_request, "download"),
626 DLUtil.getDownloadURL(
627 _fileEntry, _fileVersion, _themeDisplay, StringPool.BLANK));
628 }
629
630 private void _addEditToolbarItem(List<ToolbarItem> toolbarItems)
631 throws PortalException {
632
633 if (!isEditButtonVisible()) {
634 return;
635 }
636
637 PortletURL portletURL = _getRenderURL(
638 "/document_library/edit_file_entry");
639
640 _addURLUIItem(
641 new URLToolbarItem(), toolbarItems, "icon-edit", DLUIItemKeys.EDIT,
642 UnicodeLanguageUtil.get(_request, "edit"), portletURL.toString());
643 }
644
645 private <T extends JavascriptUIItem> T _addJavascriptUIItem(
646 T javascriptUIItem, List<? super T> javascriptUIItems, String icon,
647 String key, String label, String onClick ) {
648
649 javascriptUIItem.setIcon(icon);
650 javascriptUIItem.setKey(key);
651 javascriptUIItem.setLabel(label);
652 javascriptUIItem.setOnClick(onClick);
653
654 javascriptUIItems.add(javascriptUIItem);
655
656 return javascriptUIItem;
657 }
658
659 private void _addMoveToolbarItem(List<ToolbarItem> toolbarItems)
660 throws PortalException {
661
662 if (!isMoveButtonVisible()) {
663 return;
664 }
665
666 PortletURL portletURL = _getRenderURL("/document_library/move_entry");
667
668 _addURLUIItem(
669 new URLToolbarItem(), toolbarItems, "icon-move", DLUIItemKeys.MOVE,
670 UnicodeLanguageUtil.get(_request, "move"), portletURL.toString());
671 }
672
673 private void _addMoveToTheRecycleBinToolbarItem(
674 List<ToolbarItem> toolbarItems)
675 throws PortalException {
676
677 if (!isMoveToTheRecycleBinButtonVisible()) {
678 return;
679 }
680
681 LiferayPortletResponse liferayPortletResponse =
682 _getLiferayPortletResponse();
683
684 PortletURL portletURL = liferayPortletResponse.createRenderURL();
685
686 portletURL.setParameter("struts_action", "/document_library/view");
687 portletURL.setParameter(
688 "folderId", String.valueOf(_fileEntry.getFolderId()));
689
690 _addJavascriptUIItem(
691 new JavascriptToolbarItem(), toolbarItems, "icon-trash",
692 DLUIItemKeys.MOVE_TO_THE_RECYCLE_BIN,
693 UnicodeLanguageUtil.get(_request, "move-to-the-recycle-bin"),
694 getSubmitFormJavascript(
695 Constants.MOVE_TO_TRASH, portletURL.toString()));
696 }
697
698 private void _addOpenInMsOfficeToolbarItem(List<ToolbarItem> toolbarItems)
699 throws PortalException {
700
701 if (!isOpenInMsOfficeButtonVisible()) {
702 return;
703 }
704
705 String webDavURL = DLUtil.getWebDavURL(
706 _themeDisplay, _fileEntry.getFolder(), _fileEntry,
707 PropsValues.
708 DL_FILE_ENTRY_OPEN_IN_MS_OFFICE_MANUAL_CHECK_IN_REQUIRED);
709
710 StringBundler sb = new StringBundler(4);
711
712 sb.append(getNamespace());
713 sb.append("openDocument('");
714 sb.append(webDavURL);
715 sb.append("');");
716
717 _addJavascriptUIItem(
718 new JavascriptToolbarItem(), toolbarItems, "icon-file-alt",
719 DLUIItemKeys.OPEN_IN_MS_OFFICE,
720 UnicodeLanguageUtil.get(_request, "open-in-ms-office"),
721 sb.toString());
722 }
723
724 private void _addPermissionsToolbarItem(List<ToolbarItem> toolbarItems)
725 throws PortalException {
726
727 if (!isPermissionsButtonVisible()) {
728 return;
729 }
730
731 String permissionsURL = null;
732
733 try {
734 permissionsURL = PermissionsURLTag.doTag(
735 null, DLFileEntryConstants.getClassName(),
736 HtmlUtil.unescape(_fileEntry.getTitle()), null,
737 String.valueOf(_fileEntry.getFileEntryId()),
738 LiferayWindowState.POP_UP.toString(), null, _request
739 );
740 }
741 catch (Exception e) {
742 throw new SystemException("Unable to create permissions URL", e);
743 }
744
745 StringBundler sb = new StringBundler(6);
746
747 sb.append("Liferay.Util.openWindow({");
748 sb.append("title: '");
749 sb.append(UnicodeLanguageUtil.get(_request, "permissions"));
750 sb.append("', uri: '");
751 sb.append(permissionsURL);
752 sb.append("'});");
753
754 _addJavascriptUIItem(
755 new JavascriptToolbarItem(), toolbarItems, "icon-lock",
756 DLUIItemKeys.PERMISSIONS,
757 UnicodeLanguageUtil.get(_request, "permissions"), sb.toString());
758 }
759
760 private <T extends URLUIItem> T _addURLUIItem(
761 T urlUIItem, List<? super T> urlUIItems, String icon, String key,
762 String label, String url ) {
763
764 urlUIItem.setIcon(icon);
765 urlUIItem.setKey(key);
766 urlUIItem.setLabel(label);
767 urlUIItem.setURL(url);
768
769 urlUIItems.add(urlUIItem);
770
771 return urlUIItem;
772 }
773
774 private String _getActionURL(String strutsAction, String cmd) {
775 LiferayPortletResponse liferayPortletResponse =
776 _getLiferayPortletResponse();
777
778 PortletURL portletURL = liferayPortletResponse.createActionURL();
779
780 portletURL.setParameter("struts_action", strutsAction);
781 portletURL.setParameter(Constants.CMD, cmd);
782 portletURL.setParameter("redirect", _getCurrentURL());
783 portletURL.setParameter(
784 "fileEntryId", String.valueOf(_fileEntry.getFileEntryId()));
785
786 return portletURL.toString();
787 }
788
789 private String _getCurrentURL() {
790 if (_currentURL != null) {
791 return _currentURL;
792 }
793
794 LiferayPortletRequest liferayPortletRequest =
795 _getLiferayPortletRequest();
796
797 LiferayPortletResponse liferayPortletResponse =
798 _getLiferayPortletResponse();
799
800 PortletURL portletURL = PortletURLUtil.getCurrent(
801 liferayPortletRequest, liferayPortletResponse);
802
803 _currentURL = portletURL.toString();
804
805 return _currentURL;
806 }
807
808 private DLActionsDisplayContext _getDLActionsDisplayContext()
809 throws PortalException {
810
811 if (_dlActionsDisplayContext != null) {
812 return _dlActionsDisplayContext;
813 }
814
815 PortletDisplay portletDisplay = _themeDisplay.getPortletDisplay();
816
817 String portletId = portletDisplay.getId();
818
819 if (portletId.equals(PortletKeys.PORTLET_CONFIGURATION)) {
820 portletId = ParamUtil.getString(_request, "portletResource");
821 }
822
823 DLPortletInstanceSettings dlPortletInstanceSettings =
824 DLPortletInstanceSettings.getInstance(
825 _themeDisplay.getLayout(), portletId);
826
827 _dlActionsDisplayContext = new DLActionsDisplayContext(
828 _request, dlPortletInstanceSettings);
829
830 return _dlActionsDisplayContext;
831 }
832
833 private LiferayPortletRequest _getLiferayPortletRequest() {
834 PortletRequest portletRequest = (PortletRequest)_request.getAttribute(
835 JavaConstants.JAVAX_PORTLET_REQUEST);
836
837 return PortalUtil.getLiferayPortletRequest(portletRequest);
838 }
839
840 private LiferayPortletResponse _getLiferayPortletResponse() {
841 PortletResponse portletResponse =
842 (PortletResponse)_request.getAttribute(
843 JavaConstants.JAVAX_PORTLET_RESPONSE);
844
845 return PortalUtil.getLiferayPortletResponse(portletResponse);
846 }
847
848 private PortletURL _getRenderURL(String strutsAction) {
849 LiferayPortletResponse liferayPortletResponse =
850 _getLiferayPortletResponse();
851
852 PortletURL portletURL = liferayPortletResponse.createRenderURL();
853
854 portletURL.setParameter("struts_action", strutsAction);
855 portletURL.setParameter("redirect", _getCurrentURL());
856 portletURL.setParameter(
857 "fileEntryId", String.valueOf(_fileEntry.getFileEntryId()));
858
859 return portletURL;
860 }
861
862 private boolean _isFileEntryTrashable() throws PortalException {
863 if (_fileEntryDisplayContextHelper.isDLFileEntry() &&
864 _isTrashEnabled()) {
865
866 return true;
867 }
868
869 return false;
870 }
871
872 private boolean _isIEOnWin32() {
873 if (_ieOnWin32 == null) {
874 _ieOnWin32 = BrowserSnifferUtil.isIeOnWin32(_request);
875 }
876
877 return _ieOnWin32;
878 }
879
880 private boolean _isShowActions() throws PortalException {
881 DLActionsDisplayContext dlActionsDisplayContext =
882 _getDLActionsDisplayContext();
883
884 return dlActionsDisplayContext.isShowActions();
885 }
886
887 private boolean _isTrashEnabled() throws PortalException {
888 if (_trashEnabled == null) {
889 _trashEnabled = TrashUtil.isTrashEnabled(
890 _themeDisplay.getScopeGroupId());
891 }
892
893 return _trashEnabled;
894 }
895
896 private boolean _isWebDAVEnabled() {
897 PortletDisplay portletDisplay = _themeDisplay.getPortletDisplay();
898
899 return portletDisplay.isWebDAVEnabled();
900 }
901
902 private String _processFreeMarkerTemplate(
903 String name, Map<String, String> context) {
904
905 try {
906 return FreeMarkerUtil.process(name, context);
907 }
908 catch (Exception e) {
909 throw new SystemException(
910 "Unable to process Freemarker template", e);
911 }
912 }
913
914 private static final UUID _UUID = UUID.fromString(
915 "85F6C50E-3893-4E32-9D63-208528A503FA");
916
917 private String _currentURL;
918 private DLActionsDisplayContext _dlActionsDisplayContext;
919 private final FileEntry _fileEntry;
920 private final FileEntryDisplayContextHelper _fileEntryDisplayContextHelper;
921 private final FileVersion _fileVersion;
922 private final FileVersionDisplayContextHelper
923 _fileVersionDisplayContextHelper;
924 private final long _folderId;
925 private Boolean _ieOnWin32;
926 private final HttpServletRequest _request;
927 private final ThemeDisplay _themeDisplay;
928 private Boolean _trashEnabled;
929
930 }