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