1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.wcm.webui.clv;
18
19 import java.text.DateFormat;
20 import java.text.SimpleDateFormat;
21 import java.util.Calendar;
22 import java.util.HashMap;
23 import java.util.LinkedList;
24 import java.util.List;
25 import java.util.Locale;
26 import java.util.Map;
27 import java.util.Map.Entry;
28 import java.util.MissingResourceException;
29
30 import javax.jcr.Node;
31 import javax.jcr.PathNotFoundException;
32 import javax.jcr.RepositoryException;
33 import javax.portlet.PortletPreferences;
34 import javax.portlet.PortletRequest;
35
36 import org.apache.commons.lang.StringUtils;
37 import org.exoplatform.commons.utils.PageList;
38 import org.exoplatform.container.PortalContainer;
39 import org.exoplatform.ecm.utils.text.Text;
40 import org.exoplatform.ecm.utils.lock.LockUtil;
41 import org.exoplatform.portal.mop.SiteType;
42 import org.exoplatform.portal.webui.container.UIContainer;
43 import org.exoplatform.portal.webui.util.Util;
44 import org.exoplatform.resolver.ResourceResolver;
45 import org.exoplatform.services.cms.documents.TrashService;
46 import org.exoplatform.services.cms.folksonomy.NewFolksonomyService;
47 import org.exoplatform.services.ecm.publication.PublicationService;
48 import org.exoplatform.services.jcr.access.PermissionType;
49 import org.exoplatform.services.jcr.core.ExtendedNode;
50 import org.exoplatform.services.log.ExoLogger;
51 import org.exoplatform.services.log.Log;
52 import org.exoplatform.services.wcm.core.NodeLocation;
53 import org.exoplatform.services.wcm.core.WebSchemaConfigService;
54 import org.exoplatform.services.wcm.friendly.FriendlyService;
55 import org.exoplatform.services.wcm.publication.PublicationDefaultStates;
56 import org.exoplatform.services.wcm.publication.WCMComposer;
57 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
58 import org.exoplatform.services.wcm.webcontent.WebContentSchemaHandler;
59 import org.exoplatform.wcm.webui.Utils;
60 import org.exoplatform.wcm.webui.administration.UIEditingForm;
61 import org.exoplatform.wcm.webui.paginator.UICustomizeablePaginator;
62 import org.exoplatform.wcm.webui.reader.ContentReader;
63 import org.exoplatform.web.application.ApplicationMessage;
64 import org.exoplatform.web.application.JavascriptManager;
65 import org.exoplatform.web.url.navigation.NavigationResource;
66 import org.exoplatform.web.url.navigation.NodeURL;
67 import org.exoplatform.webui.application.WebuiRequestContext;
68 import org.exoplatform.webui.application.portlet.PortletRequestContext;
69 import org.exoplatform.webui.config.annotation.ComponentConfig;
70 import org.exoplatform.webui.config.annotation.ComponentConfigs;
71 import org.exoplatform.webui.config.annotation.EventConfig;
72 import org.exoplatform.webui.core.UIPageIterator;
73 import org.exoplatform.webui.core.lifecycle.Lifecycle;
74 import org.exoplatform.webui.event.Event;
75 import org.exoplatform.webui.event.EventListener;
76
77
78
79
80
81
82
83
84 @SuppressWarnings("deprecation")
85 @ComponentConfigs( {
86 @ComponentConfig(lifecycle = Lifecycle.class, events = {
87 @EventConfig(listeners = UICLVPresentation.RefreshActionListener.class),
88 @EventConfig(listeners = UICLVPresentation.DeleteContentActionListener.class,
89 confirm = "UICLVPresentation.msg.confirm-delete"),
90 @EventConfig(listeners = UICLVPresentation.FastPublishActionListener.class) }),
91 @ComponentConfig(type = UICustomizeablePaginator.class,
92 events = @EventConfig(listeners = UICustomizeablePaginator.ShowPageActionListener.class)) })
93 public class UICLVPresentation extends UIContainer {
94
95 public static final String defaultScvParam = "content-id";
96
97 private static final Log LOG = ExoLogger.getLogger(UICLVPresentation.class.getName());
98
99
100 private String templatePath;
101
102
103 private ResourceResolver resourceResolver;
104
105
106 private UICustomizeablePaginator uiPaginator;
107
108
109 private DateFormat dateFormatter = null;
110
111
112 private Map<String, String> tagStyles = null;
113
114
115
116
117 public UICLVPresentation() {
118 }
119
120
121
122
123
124
125
126
127 public void init(ResourceResolver resourceResolver, PageList dataPageList) throws Exception {
128
129 String paginatorTemplatePath = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_PAGINATOR_TEMPLATE);
130 this.templatePath = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_DISPLAY_TEMPLATE);
131
132 this.resourceResolver = resourceResolver;
133 uiPaginator = addChild(UICustomizeablePaginator.class, null, null);
134 uiPaginator.setTemplatePath(paginatorTemplatePath);
135 uiPaginator.setResourceResolver(resourceResolver);
136 uiPaginator.setPageList(dataPageList);
137 Locale locale = Util.getPortalRequestContext().getLocale();
138 dateFormatter = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.MEDIUM,
139 SimpleDateFormat.MEDIUM,
140 locale);
141 }
142
143 public List<CategoryBean> getCategories() throws Exception {
144 String fullPath = this.getAncestorOfType(UICLVPortlet.class).getFolderPath();
145 return getCategories(fullPath, "exo:taxonomy", 0);
146
147 }
148
149 public List<CategoryBean> getCategories(String primaryType) throws Exception {
150 String fullPath = this.getAncestorOfType(UICLVPortlet.class).getFolderPath();
151 return getCategories(fullPath, primaryType, 0);
152 }
153
154 public List<CategoryBean> getCategories(boolean withChildren) throws Exception {
155 String fullPath = this.getAncestorOfType(UICLVPortlet.class).getFolderPath();
156 return getCategories(fullPath, "exo:taxonomy", 0, withChildren);
157 }
158
159 public List<CategoryBean> getCategories(String fullPath, String primaryType, int depth) throws Exception {
160 return getCategories(fullPath, primaryType, depth, true);
161 }
162
163 public List<CategoryBean> getCategories(String fullPath, String primaryType, int depth, boolean withChildren) throws Exception {
164 if (fullPath == null || fullPath.length() == 0) {
165 return null;
166 }
167 WCMComposer wcmComposer = getApplicationComponent(WCMComposer.class);
168 HashMap<String, String> filters = new HashMap<String, String>();
169 filters.put(WCMComposer.FILTER_MODE, Utils.getCurrentMode());
170
171 String orderType = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_ORDER_TYPE);
172 String orderBy = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_ORDER_BY);
173
174
175 filters.put(WCMComposer.FILTER_ORDER_BY, orderBy);
176 filters.put(WCMComposer.FILTER_ORDER_TYPE, orderType);
177 filters.put(WCMComposer.FILTER_LANGUAGE, Util.getPortalRequestContext()
178 .getLocale()
179 .getLanguage());
180
181 filters.put(WCMComposer.FILTER_PRIMARY_TYPE, primaryType);
182
183 String clvBy = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_SHOW_CLV_BY);
184
185
186 String paramPath = Util.getPortalRequestContext().getRequestParameter(clvBy);
187
188 NodeLocation nodeLocation = NodeLocation.getNodeLocationByExpression(fullPath);
189
190 List<Node> nodes = wcmComposer.getContents(nodeLocation.getWorkspace(),
191 nodeLocation.getPath(),
192 filters,
193 WCMCoreUtils.getUserSessionProvider());
194 List<CategoryBean> categories = new LinkedList<CategoryBean>();
195 for (Node node : nodes) {
196 String title = getTitle(node);
197 String url = getCategoryURL(node);
198 String path = node.getPath();
199 long total = (node.hasProperty("exo:total")) ? node.getProperty("exo:total")
200 .getValue()
201 .getLong() : 0;
202 boolean isSelected = paramPath != null && paramPath.endsWith(path);
203 CategoryBean cat = new CategoryBean(node.getName(),
204 node.getPath(),
205 title,
206 url,
207 isSelected,
208 depth,
209 total);
210 NodeLocation catLocation = NodeLocation.getNodeLocationByNode(node);
211 if (withChildren) {
212 List<CategoryBean> childs = getCategories(catLocation.toString(), primaryType, depth + 1);
213 if (childs != null && childs.size() > 0)
214 cat.setChilds(childs);
215 }
216
217 categories.add(cat);
218
219 }
220
221 return categories;
222
223 }
224
225 public String getTagHtmlStyle(long tagCount) throws Exception {
226 for (Entry<String, String> entry : getTagStyles().entrySet()) {
227 if (checkTagRate(tagCount, entry.getKey()))
228 return entry.getValue();
229 }
230 return "";
231 }
232
233 private Map<String, String> getTagStyles() throws Exception {
234 if (tagStyles == null) {
235 NewFolksonomyService folksonomyService = getApplicationComponent(NewFolksonomyService.class);
236 String workspace = "dms-system";
237 tagStyles = new HashMap<String, String>();
238 for (Node tag : folksonomyService.getAllTagStyle(workspace)) {
239 tagStyles.put(tag.getProperty("exo:styleRange").getValue().getString(),
240 tag.getProperty("exo:htmlStyle").getValue().getString());
241 }
242 }
243 return tagStyles;
244 }
245
246 private boolean checkTagRate(long numOfDocument, String range) throws Exception {
247 String[] vals = StringUtils.split(range, "..");
248 int minValue = Integer.parseInt(vals[0]);
249 int maxValue;
250 if (vals[1].equals("*")) {
251 maxValue = Integer.MAX_VALUE;
252 } else {
253 maxValue = Integer.parseInt(vals[1]);
254 }
255 if (minValue <= numOfDocument && numOfDocument < maxValue)
256 return true;
257 return false;
258 }
259
260
261
262
263
264
265
266
267 public String getCategoryURL(Node node) throws Exception {
268 String link = null;
269 PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance();
270 PortletRequest portletRequest = portletRequestContext.getRequest();
271 NodeLocation nodeLocation = NodeLocation.getNodeLocationByNode(node);
272 String baseURI = portletRequest.getScheme() + "://" + portletRequest.getServerName() + ":"
273 + String.format("%s", portletRequest.getServerPort());
274 String basePath = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_TARGET_PAGE);
275 String clvBy = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_SHOW_CLV_BY);
276 if (clvBy == null || clvBy.length() == 0)
277 clvBy = UICLVPortlet.DEFAULT_SHOW_CLV_BY;
278
279 String params = nodeLocation.getRepository() + ":" + nodeLocation.getWorkspace() +":"+ node.getPath();
280
281 NodeURL nodeURL = Util.getPortalRequestContext().createURL(NodeURL.TYPE);
282 NavigationResource resource = new NavigationResource(SiteType.PORTAL,
283 Util.getPortalRequestContext()
284 .getPortalOwner(), basePath);
285 nodeURL.setResource(resource).setQueryParameterValue(clvBy, params);
286 link = baseURI + nodeURL.toString();
287
288 FriendlyService friendlyService = getApplicationComponent(FriendlyService.class);
289 link = friendlyService.getFriendlyUri(link);
290
291 return link;
292 }
293
294
295
296
297
298
299
300 public boolean isShowField(String field) {
301 String visible = Utils.getPortletPreference(field);
302 return (visible != null) ? Boolean.parseBoolean(visible) : false;
303 }
304
305
306
307
308
309
310
311 public boolean showPaginator() throws Exception {
312 String itemsPerPage = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_ITEMS_PER_PAGE);
313 int totalItems = uiPaginator.getTotalItems();
314 if (totalItems > Integer.parseInt(itemsPerPage)) {
315 return true;
316 }
317 return false;
318 }
319
320
321
322
323
324 public String getTemplate() {
325 return templatePath;
326 }
327
328
329
330
331
332
333
334 public ResourceResolver getTemplateResourceResolver(WebuiRequestContext context, String template) {
335 return resourceResolver;
336 }
337
338
339
340
341
342
343
344
345 public String getTitle(Node node) throws Exception {
346 String title = null;
347 if (node.hasProperty("exo:title")) {
348 title = node.getProperty("exo:title").getValue().getString();
349 } else if (node.hasNode("jcr:content")) {
350 Node content = node.getNode("jcr:content");
351 if (content.hasProperty("dc:title")) {
352 try {
353 title = content.getProperty("dc:title").getValues()[0].getString();
354 } catch (Exception ex) {
355
356 }
357 }
358 }
359 if (title == null) {
360 if (node.isNodeType("nt:frozenNode")) {
361 String uuid = node.getProperty("jcr:frozenUuid").getString();
362 Node originalNode = node.getSession().getNodeByUUID(uuid);
363 title = originalNode.getName();
364 } else {
365 title = node.getName();
366 }
367
368 }
369 return ContentReader.getXSSCompatibilityContent(title);
370 }
371
372
373
374
375
376
377
378
379 public String getSummary(Node node) throws Exception {
380 String desc = null;
381 if (node.hasProperty("exo:summary")) {
382 desc = node.getProperty("exo:summary").getValue().getString();
383 } else if (node.hasNode("jcr:content")) {
384 Node content = node.getNode("jcr:content");
385 if (content.hasProperty("dc:description")) {
386 try {
387 desc = ContentReader.getXSSCompatibilityContent(content.getProperty("dc:description").getValues()[0].getString());
388 } catch (Exception ex) {
389 return null;
390 }
391 }
392 }
393 return desc;
394 }
395 public static String getInlineEditingField(Node orgNode, String propertyName, String defaultValue, String inputType,
396 String idGenerator, String cssClass, boolean isGenericProperty, String... arguments) throws Exception {
397 return org.exoplatform.ecm.webui.utils.Utils.getInlineEditingField(orgNode, propertyName,
398 defaultValue, inputType, idGenerator, cssClass, isGenericProperty, arguments);
399 }
400 public String getSummaryField(Node node) throws Exception {
401 String desc = null;
402 if (node.hasProperty("exo:summary")) {
403 return "exo:summary";
404 } else if (node.hasNode("jcr:content")) {
405 Node content = node.getNode("jcr:content");
406 if (content.hasProperty("dc:description")) {
407 try {
408 desc = content.getProperty("dc:description").getValues()[0].getString();
409 return "jcr:content/dc:description";
410 } catch (Exception ex) {
411 return null;
412 }
413 }
414 }
415 return desc;
416 }
417
418
419
420
421
422
423
424 public String getURL(Node node) throws Exception {
425 String link = null;
426 NodeLocation nodeLocation = NodeLocation.getNodeLocationByNode(node);
427 String basePath = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_TARGET_PAGE);
428 String scvWith = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_SHOW_SCV_WITH);
429 if (scvWith == null || scvWith.length() == 0)
430 scvWith = UICLVPortlet.DEFAULT_SHOW_SCV_WITH;
431
432 StringBuffer sb = new StringBuffer();
433 sb.append("/")
434 .append(nodeLocation.getRepository())
435 .append("/")
436 .append(nodeLocation.getWorkspace());
437 if (node.isNodeType("nt:frozenNode")) {
438 String uuid = node.getProperty("jcr:frozenUuid").getString();
439 Node originalNode = node.getSession().getNodeByUUID(uuid);
440 sb.append(originalNode.getPath());
441 } else {
442 sb.append(node.getPath());
443 }
444 String param = sb.toString();
445 param = Text.escapeIllegalJcrChars(param);
446 NodeURL nodeURL = Util.getPortalRequestContext().createURL(NodeURL.TYPE);
447 NavigationResource resource = new NavigationResource(SiteType.PORTAL,
448 Util.getPortalRequestContext()
449 .getPortalOwner(), basePath);
450 nodeURL.setResource(resource).setQueryParameterValue(scvWith, param);
451
452 String fullPath = this.getAncestorOfType(UICLVPortlet.class).getFolderPathParamValue();
453 if (fullPath != null) {
454 String clvBy = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_SHOW_CLV_BY);
455 nodeURL.setQueryParameterValue(clvBy, fullPath);
456 }
457
458 link = nodeURL.toString();
459 FriendlyService friendlyService = getApplicationComponent(FriendlyService.class);
460 link = friendlyService.getFriendlyUri(link);
461
462 return link;
463 }
464
465
466
467
468
469
470
471
472 public String getWebdavURL(Node node) throws Exception {
473 NodeLocation nodeLocation = NodeLocation.getNodeLocationByNode(node);
474 String repository = nodeLocation.getRepository();
475 String workspace = nodeLocation.getWorkspace();
476
477 FriendlyService friendlyService = getApplicationComponent(FriendlyService.class);
478 String link = "#";
479
480 String portalName = PortalContainer.getCurrentPortalContainerName();
481 String restContextName = PortalContainer.getCurrentRestContextName();
482 if (node.isNodeType("nt:frozenNode")) {
483 String uuid = node.getProperty("jcr:frozenUuid").getString();
484 Node originalNode = node.getSession().getNodeByUUID(uuid);
485 link = "/" + portalName + "/" + restContextName + "/jcr/" + repository + "/"
486 + workspace + originalNode.getPath() + "?version=" + node.getParent().getName();
487 } else {
488 link = "/" + portalName + "/" + restContextName + "/jcr/" + repository + "/"
489 + workspace + node.getPath();
490 }
491
492 return friendlyService.getFriendlyUri(link);
493
494 }
495
496
497
498
499
500
501
502
503 public String getAuthor(Node node) throws Exception {
504 if (node.hasProperty("exo:owner")) {
505 String ownerId = node.getProperty("exo:owner").getValue().getString();
506 return ownerId;
507 }
508 return null;
509 }
510
511
512
513
514
515
516
517
518 public String getCreatedDate(Node node) throws Exception {
519 if (node.hasProperty("exo:dateCreated")) {
520 Calendar calendar = node.getProperty("exo:dateCreated").getValue().getDate();
521 if (calendar!=null) {
522 return dateFormatter.format(calendar.getTime());
523 }
524 }
525 return null;
526 }
527
528
529
530
531
532
533
534
535 public String getModifiedDate(Node node) throws Exception {
536 if (node.hasProperty("exo:dateModified")) {
537 Calendar calendar = node.getProperty("exo:dateModified").getValue().getDate();
538 return dateFormatter.format(calendar.getTime());
539 }
540 return null;
541 }
542
543
544
545
546
547
548
549 public String getContentIcon(Node node) {
550 try {
551 if (node.isNodeType("nt:frozenNode")) {
552 String uuid = node.getProperty("jcr:frozenUuid").getString();
553 Node originalNode = node.getSession().getNodeByUUID(uuid);
554 return org.exoplatform.ecm.webui.utils.Utils.getNodeTypeIcon(originalNode, "uiIcon16x16");
555 }
556 return org.exoplatform.ecm.webui.utils.Utils.getNodeTypeIcon(node, "uiIcon16x16");
557 } catch (RepositoryException e) {
558 Utils.createPopupMessage(this,
559 "UIMessageBoard.msg.get-content-icon",
560 null,
561 ApplicationMessage.ERROR);
562 }
563 return null;
564 }
565
566 public String getHeader() {
567 String header = this.getAncestorOfType(UICLVPortlet.class).getHeader();
568 if(header == null)
569 header = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_HEADER);
570 return header;
571 }
572
573 public UIPageIterator getUIPageIterator() {
574 return uiPaginator;
575 }
576
577 public List getCurrentPageData() throws Exception {
578 return NodeLocation.getNodeListByLocationList(uiPaginator.getCurrentPageData());
579 }
580
581 public void setDateTimeFormat(String format) {
582 ((SimpleDateFormat) dateFormatter).applyPattern(format);
583 }
584
585 public String getEditLink(Node node, boolean isEditable, boolean isNew) {
586 return Utils.getEditLink(node, isEditable, isNew);
587 }
588
589 public boolean isShowEdit(Node node) {
590 if (Utils.isShowQuickEdit()) {
591 try {
592 Node parent = node.getParent();
593 ((ExtendedNode) node).checkPermission(PermissionType.SET_PROPERTY);
594 ((ExtendedNode) parent).checkPermission(PermissionType.ADD_NODE);
595 } catch (Exception e) {
596 return false;
597 }
598 return true;
599 }
600 return false;
601 }
602
603 public boolean isViewMode() {
604 return Utils.getCurrentMode().equals(WCMComposer.MODE_LIVE);
605 }
606
607
608
609
610
611
612
613 public String getIllustrativeImage(Node node) {
614 WebSchemaConfigService schemaConfigService = getApplicationComponent(WebSchemaConfigService.class);
615 WebContentSchemaHandler contentSchemaHandler = schemaConfigService.getWebSchemaHandlerByType(WebContentSchemaHandler.class);
616 Node illustrativeImage = null;
617 String uri = null;
618 try {
619 illustrativeImage = contentSchemaHandler.getIllustrationImage(node);
620 uri = WCMCoreUtils.generateImageURI(illustrativeImage, null);
621 } catch (PathNotFoundException ex) {
622
623
624 } catch (Exception e) {
625 if (LOG.isWarnEnabled()) {
626 LOG.warn(e.getMessage(), e);
627 }
628 }
629 return uri;
630 }
631
632 public boolean isShowRssLink() {
633 if (getUIPageIterator().getAvailable() == 0) {
634 return false;
635 }
636 PortletPreferences portletPreferences = Utils.getAllPortletPreferences();
637 String currentApplicationMode = portletPreferences.getValue(UICLVPortlet.PREFERENCE_APPLICATION_TYPE, null);
638 if (currentApplicationMode.equals(UICLVPortlet.APPLICATION_CLV_BY_QUERY))
639 return false;
640
641 return isShowField(UICLVPortlet.PREFERENCE_SHOW_RSSLINK)
642 && (this.getAncestorOfType(UICLVPortlet.class).getFolderPathParamValue() != null
643 || UICLVPortlet.DISPLAY_MODE_AUTOMATIC.equals(Utils.getPortletPreference(UICLVPortlet.PREFERENCE_DISPLAY_MODE)));
644 }
645
646 public String getFastPublicLink(Node viewNode) {
647 String fastPublishLink = null;
648 try {
649 fastPublishLink = event("FastPublish", NodeLocation.getExpressionByNode(viewNode));
650 } catch (Exception e) {
651 if (LOG.isWarnEnabled()) {
652 LOG.warn(e.getMessage());
653 }
654 }
655 return fastPublishLink;
656 }
657
658
659
660
661
662
663 public String getRssLink() {
664 String portal = PortalContainer.getCurrentPortalContainerName();
665 String rest = PortalContainer.getCurrentRestContextName();
666 String server = Util.getPortalRequestContext().getRequest().getRequestURL().toString();
667 int lastIndex = server.indexOf(portal);
668 server = server.substring(0, lastIndex-1) + Util.getPortalRequestContext().getPortalURI();
669 String fullPath = this.getAncestorOfType(UICLVPortlet.class).getFolderPathParamValue();
670 if (fullPath == null || fullPath.length() == 0)
671 fullPath = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_ITEM_PATH);
672 if (fullPath == null)
673 return "/" + portal + "/" + rest + "&siteName=" + Util.getUIPortal().getSiteKey().getName() + "&orderBy="
674 + Utils.getPortletPreference(UICLVPortlet.PREFERENCE_ORDER_BY) + "&orderType="
675 + Utils.getPortletPreference(UICLVPortlet.PREFERENCE_ORDER_TYPE) + "&detailPage="
676 + Utils.getPortletPreference(UICLVPortlet.PREFERENCE_TARGET_PAGE) + "&detailParam="
677 + Utils.getPortletPreference(UICLVPortlet.PREFERENCE_SHOW_SCV_WITH);
678 String[] repoWsPath = fullPath.split(":");
679 return "/" + portal + "/" + rest + "/feed/rss?repository=" + repoWsPath[0] + "&workspace="
680 + repoWsPath[1] + "&server=" + server + "&siteName=" + Util.getUIPortal().getSiteKey().getName()
681 + "&folderPath=" + repoWsPath[2] + "&orderBy="
682 + Utils.getPortletPreference(UICLVPortlet.PREFERENCE_ORDER_BY)
683 + "&orderType="
684 + Utils.getPortletPreference(UICLVPortlet.PREFERENCE_ORDER_TYPE)
685 +
686
687
688 "&detailPage=" + Utils.getPortletPreference(UICLVPortlet.PREFERENCE_TARGET_PAGE)
689 + "&detailParam=" + Utils.getPortletPreference(UICLVPortlet.PREFERENCE_SHOW_SCV_WITH);
690 }
691
692
693
694
695
696
697
698
699
700 public String addQuickEditDiv(String cssClass, Node viewNode) throws Exception {
701 StringBuffer sb = new StringBuffer();
702 String id = this.getClass().getSimpleName() + System.currentTimeMillis();
703 PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance();
704 sb.append("<div id=\""+id+"\" class=\"" + cssClass + " \">");
705 if (Utils.isShowQuickEdit()) {
706 sb.append(" <div class=\"edittingContent\" style=\" z-index: 5\">");
707 sb.append(" <div class=\"edittingToolBar clearfix\" >");
708
709 sb.append(" <div class=\"btn-group\" >");
710
711 if (isShowEdit(viewNode) && !LockUtil.isLocked(viewNode)) {
712 String strEditBundle = "Edit in the Content Explorer";
713 try {
714 strEditBundle = portletRequestContext.getApplicationResourceBundle()
715 .getString("UICLVPresentation.action.edit");
716 } catch (MissingResourceException e) {
717 if (LOG.isWarnEnabled()) {
718 LOG.warn(e.getMessage());
719 }
720 }
721 if (org.exoplatform.wcm.webui.utils.Utils.isShowFastPublish(viewNode)) {
722 String fastPublishLink = event("FastPublish", NodeLocation.getExpressionByNode(viewNode));
723 String strFastPublishBundle = "Publish";
724 try {
725 strFastPublishBundle = portletRequestContext.getApplicationResourceBundle()
726 .getString("UICLVPresentation.action.publish");
727 } catch (MissingResourceException e) {
728 if (LOG.isWarnEnabled()) {
729 LOG.warn(e.getMessage());
730 }
731 }
732 sb.append(" <a class=\"btn\" href=\"" + fastPublishLink + "\" rel=\"tooltip\" data-placement=\"left\" title=\"" + strFastPublishBundle + "\">");
733 sb.append(" <i class=\"uiIconEcmsPublish\" ></i>");
734 sb.append(" </a>");
735 }
736 String contentEditLink = getEditLink(viewNode, true, false);
737 sb.append(" <a class=\"btn\" onclick = 'eXo.ecm.CLV.addURL(this)' href=\"" + contentEditLink + "\" rel=\"tooltip\" data-placement=\"left\" title=\"" + strEditBundle + "\">");
738 sb.append(" <i class=\"uiIconEdit\"></i>");
739 sb.append(" </a>");
740 } else {
741 sb.append(" <a class=\"btn\" >");
742 sb.append(" <i class=\"uiIconEcmsLock\" ></i>");
743 sb.append(" </a>");
744 }
745
746 if (Utils.isShowDelete(viewNode)) {
747 String contentDeleteLink = event("DeleteContent", NodeLocation.getExpressionByNode(viewNode));
748 String strDeleteBundle = "Delete";
749 try {
750 strDeleteBundle = portletRequestContext.getApplicationResourceBundle()
751 .getString("UICLVPresentation.action.delete");
752 } catch (MissingResourceException e) {
753 if (LOG.isWarnEnabled()) {
754 LOG.warn(e.getMessage());
755 }
756 }
757 sb.append(" <a class=\"btn\" href=\"" + contentDeleteLink + "\" rel=\"tooltip\" data-placement=\"left\" title=\"" + strDeleteBundle + "\">");
758 sb.append(" <i class=\"uiIconRemove\"></i>");
759 sb.append(" </a>");
760 }
761
762 sb.append(" </div>");
763
764 if (viewNode.hasProperty("publication:currentState")) {
765 PublicationService publicationService = WCMCoreUtils.getService(PublicationService.class);
766 String state = publicationService.getCurrentState(viewNode);
767 String stateLabel="";
768 try {
769 stateLabel = portletRequestContext.getApplicationResourceBundle()
770 .getString("PublicationStates." + state);
771 } catch (MissingResourceException e) {
772 if (LOG.isWarnEnabled()) {
773 LOG.warn(e.getMessage());
774 }
775 }
776 sb.append("<div class=\"edittingCurrentState pull-left\">");
777 sb.append("<span class=\""+state+"Text\">");
778 if(PublicationDefaultStates.PUBLISHED.equals(state)) sb.append("<i class=\"uiIconTick\"></i>");
779 sb.append(stateLabel + "</span>");
780 sb.append(" </div>");
781 }
782
783 sb.append(" </div>");
784 sb.append(" </div>");
785
786 }
787 String className = cssClass + " " + this.getAncestorOfType(UICLVPortlet.class).getName();
788 String hoverClass = Utils.isShowQuickEdit() ? " containerHoverClassInner" : "";
789 JavascriptManager jsManager = portletRequestContext.getJavascriptManager();
790 jsManager.getRequireJS()
791 .require("SHARED/jquery", "gj")
792 .addScripts("gj('#" + id
793 + "').mouseenter( function() {eXo.ecm.WCMUtils.changeStyleClass('" + id + "','"
794 + className + " " + hoverClass + "');});")
795 .addScripts("gj('#" + id
796 + "').mouseleave( function() {eXo.ecm.WCMUtils.changeStyleClass('" + id + "',"
797 + "'" + className + "');});");
798 return sb.toString();
799 }
800
801 public String getBackLink (String currentPath) {
802 String preferencePath = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_ITEM_PATH);
803 String targetPage = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_TARGET_PAGE);
804 NodeURL nodeURL = Util.getPortalRequestContext().createURL(NodeURL.TYPE);
805 NavigationResource resource = new NavigationResource(SiteType.PORTAL,
806 Util.getPortalRequestContext()
807 .getPortalOwner(), targetPage);
808 nodeURL.setResource(resource);
809
810 if (currentPath.contains(preferencePath)) {
811 String treePath = currentPath.substring(preferencePath.length() + 1);
812 String[] treeNodes = treePath.split("/");
813
814 if (treeNodes.length > 1) {
815 String paramPath = currentPath.substring(0, currentPath.lastIndexOf("/"));
816 String clvBy = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_SHOW_CLV_BY);
817 nodeURL.setQueryParameterValue(clvBy, paramPath);
818 }
819 }
820
821 return nodeURL.toString();
822 }
823
824
825
826
827
828
829
830
831
832
833
834 public static class RefreshActionListener extends EventListener<UICLVPresentation> {
835
836
837
838
839
840
841 public void execute(Event<UICLVPresentation> event) throws Exception {
842 UICLVPresentation clvPresentation = event.getSource();
843 clvPresentation.getAncestorOfType(UICLVContainer.class).onRefresh(event);
844 }
845 }
846
847 public static class DeleteContentActionListener extends EventListener<UICLVPresentation> {
848
849
850
851
852
853
854
855 public void execute(Event<UICLVPresentation> event) throws Exception {
856 String itemPath = event.getRequestContext().getRequestParameter(OBJECTID);
857 Node node = NodeLocation.getNodeByExpression(itemPath);
858 Node parent = node.getParent();
859
860 TrashService trashService = WCMCoreUtils.getService(TrashService.class);
861 trashService.moveToTrash(node, WCMCoreUtils.getUserSessionProvider());
862
863 parent.getSession().save();
864 event.getRequestContext().getJavascriptManager().getRequireJS().addScripts("location.reload(true);");
865 }
866 }
867
868 public static class FastPublishActionListener extends EventListener<UICLVPresentation> {
869
870
871
872
873
874
875
876 public void execute(Event<UICLVPresentation> event) throws Exception {
877 UICLVPresentation contentListPresentation = event.getSource();
878 String nodePath = event.getRequestContext().getRequestParameter(OBJECTID);
879 Node node = NodeLocation.getNodeByExpression(Text.escapeIllegalJcrChars(nodePath));
880 PublicationService publicationService = WCMCoreUtils.getService(PublicationService.class);
881 if (node.isLocked()) {
882 node.getSession().addLockToken(LockUtil.getLockToken(node));
883 }
884 HashMap<String, String> context = new HashMap<String, String>();
885 publicationService.changeState(node, "published", context);
886 event.getRequestContext().getJavascriptManager().getRequireJS().addScripts("location.reload(true);");
887
888 }
889 }
890 }