1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.exoplatform.ecm.webui.component.explorer.rightclick.manager;
19
20
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.regex.Matcher;
27
28 import javax.jcr.Node;
29 import javax.jcr.PathNotFoundException;
30
31 import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace;
32 import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
33 import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea;
34 import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotInTrashFilter;
35 import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotTrashHomeNodeFilter;
36 import org.exoplatform.ecm.webui.component.explorer.control.listener.UIWorkingAreaActionListener;
37 import org.exoplatform.ecm.webui.utils.Utils;
38 import org.exoplatform.ecm.webui.viewer.VideoAudioViewer;
39 import org.exoplatform.web.application.ApplicationMessage;
40 import org.exoplatform.webui.config.annotation.ComponentConfig;
41 import org.exoplatform.webui.config.annotation.EventConfig;
42 import org.exoplatform.webui.core.UIApplication;
43 import org.exoplatform.webui.event.Event;
44 import org.exoplatform.webui.ext.UIExtensionManager;
45 import org.exoplatform.webui.ext.filter.UIExtensionFilter;
46 import org.exoplatform.webui.ext.filter.UIExtensionFilters;
47 import org.exoplatform.webui.ext.manager.UIAbstractManager;
48 import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent;
49
50
51
52
53
54
55
56 @ComponentConfig(
57 events = {
58 @EventConfig(listeners = PlayMediaComponent.PlayMediaActionListener.class)
59 }
60 )
61 public class PlayMediaComponent extends UIAbstractManagerComponent {
62
63 private static final List<UIExtensionFilter> FILTERS
64 = Arrays.asList(new UIExtensionFilter[]{ new IsNotInTrashFilter(),
65 new IsNotTrashHomeNodeFilter() });
66 @UIExtensionFilters
67 public List<UIExtensionFilter> getFilters() {
68 return FILTERS;
69 }
70
71 private boolean accept(Node node) throws Exception {
72 if (!node.isNodeType(Utils.NT_FILE)) return false;
73 String mimeType = node.getNode(Utils.JCR_CONTENT).getProperty(Utils.JCR_MIMETYPE).getString();
74 UIExtensionManager manager = getApplicationComponent(UIExtensionManager.class);
75 Map<String, Object> context = new HashMap<String, Object>();
76 context.put(Utils.MIME_TYPE, mimeType);
77 if (manager.accept(Utils.FILE_VIEWER_EXTENSION_TYPE, "VideoAudio", context)) {
78 return true;
79 }
80 return false;
81 }
82
83 public static class PlayMediaActionListener extends UIWorkingAreaActionListener<PlayMediaComponent> {
84 public void processEvent(Event<PlayMediaComponent> event) throws Exception {
85 PlayMediaComponent playMedia = event.getSource();
86 UIJCRExplorer uiExplorer = playMedia.getAncestorOfType(UIJCRExplorer.class);
87 UIWorkingArea uiWorkingArea = playMedia.getParent();
88 UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class);
89 UIApplication uiApp = uiWorkingArea.getAncestorOfType(UIApplication.class);
90 uiDocumentWorkspace.removeChildById("PlayMedia");
91 String srcPath = event.getRequestContext().getRequestParameter(OBJECTID);
92 Matcher matcher = null;
93 String wsName = null;
94 Node tempNode = null;
95 if(srcPath.indexOf(";") > -1) {
96 String[] paths = srcPath.split(";");
97 List<Node> nodes = new ArrayList<Node>();
98 for(String path : paths) {
99 matcher = UIWorkingArea.FILE_EXPLORER_URL_SYNTAX.matcher(path);
100 if (matcher.find()) {
101 wsName = matcher.group(1);
102 srcPath = matcher.group(2);
103 } else {
104 throw new IllegalArgumentException("The ObjectId is invalid '"+ srcPath + "'");
105 }
106 tempNode = uiExplorer.getNodeByPath(srcPath, uiExplorer.getSessionByWorkspace(wsName));
107 if (playMedia.accept(tempNode)) nodes.add(tempNode);
108 if (nodes.size() == 0) {
109 uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.unavaiable-supported-media-file",
110 null,ApplicationMessage.WARNING));
111
112 return;
113 }
114 }
115 VideoAudioViewer uiViewer = uiDocumentWorkspace.addChild(VideoAudioViewer.class, null, "PlayMedia");
116 uiViewer.setPresentNodes(nodes);
117 uiViewer.setRepository(uiExplorer.getRepositoryName());
118 uiDocumentWorkspace.setRenderedChild(VideoAudioViewer.class);
119 } else {
120 matcher = UIWorkingArea.FILE_EXPLORER_URL_SYNTAX.matcher(srcPath);
121 if (matcher.find()) {
122 wsName = matcher.group(1);
123 srcPath = matcher.group(2);
124 } else {
125 throw new IllegalArgumentException("The ObjectId is invalid '"+ srcPath + "'");
126 }
127 try {
128
129 uiExplorer.setSelectNode(wsName, srcPath);
130 } catch(PathNotFoundException path) {
131 uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.path-not-found-exception",
132 null,ApplicationMessage.WARNING));
133
134 return;
135 }
136 }
137
138 event.getRequestContext().addUIComponentToUpdateByAjax(uiDocumentWorkspace);
139 }
140 }
141
142
143 @Override
144 public Class<? extends UIAbstractManager> getUIAbstractManagerClass() {
145 return null;
146 }
147
148 }