file_name
stringlengths
6
86
file_path
stringlengths
45
249
content
stringlengths
47
6.26M
file_size
int64
47
6.26M
language
stringclasses
1 value
extension
stringclasses
1 value
repo_name
stringclasses
767 values
repo_stars
int64
8
14.4k
repo_forks
int64
0
1.17k
repo_open_issues
int64
0
788
repo_created_at
stringclasses
767 values
repo_pushed_at
stringclasses
767 values
UIViewMetadataContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/info/UIViewMetadataContainer.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.info; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UITabPane; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jan 25, 2007 * 1:59:57 PM */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/UIViewMetadataContainer.gtmpl", events = { @EventConfig(listeners = UIViewMetadataContainer.SelectTabActionListener.class) }) public class UIViewMetadataContainer extends UITabPane { private boolean hasMoreOneMetaData; public UIViewMetadataContainer() throws Exception { } /** * @return the hasMoreOneMetaData */ public boolean isHasMoreOneMetaData() { return hasMoreOneMetaData; } /** * @param hasMoreOneMetaData the hasMoreOneMetaData to set */ public void setHasMoreOneMetaData(boolean hasMoreOneMetaData) { this.hasMoreOneMetaData = hasMoreOneMetaData; } public static class SelectTabActionListener extends EventListener<UITabPane> { public void execute(Event<UITabPane> event) throws Exception { WebuiRequestContext context = event.getRequestContext(); String renderTab = context.getRequestParameter(UIComponent.OBJECTID); if (renderTab == null) return; event.getSource().setSelectedTab(renderTab); WebuiRequestContext parentContext = (WebuiRequestContext) context.getParentAppRequestContext(); if (parentContext != null) { parentContext.setResponseComplete(true); } else { context.setResponseComplete(true); } event.getRequestContext().addUIComponentToUpdateByAjax(event.getSource()); } } }
2,745
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIViewMetadataManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/info/UIViewMetadataManager.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.info; import javax.jcr.Node; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jan 30, 2007 * 9:27:48 AM */ @ComponentConfig(lifecycle = UIContainerLifecycle.class) public class UIViewMetadataManager extends UIContainer implements UIPopupComponent { final static public String METADATAS_POPUP = "metadataForm" ; public UIViewMetadataManager() throws Exception { addChild(UIViewMetadataContainer.class, null, null) ; } public Node getViewNode(String nodeType) throws Exception { return getAncestorOfType(UIJCRExplorer.class).getViewNode(nodeType) ; } public void initMetadataFormPopup(String nodeType) throws Exception { removeChildById(METADATAS_POPUP) ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, METADATAS_POPUP) ; uiPopup.setShowMask(true); uiPopup.setWindowSize(650, 300); UIViewMetadataForm uiForm = createUIComponent(UIViewMetadataForm.class, null, null) ; uiForm.getChildren().clear() ; uiForm.setNodeType(nodeType) ; uiForm.setIsNotEditNode(true) ; UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ; Node currentNode = uiExplorer.getCurrentNode() ; uiForm.setWorkspace(currentNode.getSession().getWorkspace().getName()) ; uiForm.setStoredPath(currentNode.getPath()) ; // uiForm.setPropertyNode(getViewNode(nodeType)) ; uiForm.setChildPath(getViewNode(nodeType).getPath()) ; uiPopup.setUIComponent(uiForm) ; uiPopup.setRendered(true); uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public void activate() {} public void deActivate() {} }
2,813
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIViewRelationList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/info/UIViewRelationList.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.info ; import java.util.ArrayList; import java.util.List; import javax.jcr.Node; import javax.jcr.Session; import javax.jcr.Value; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Pham Tuan * phamtuanchip@yahoo.de * September 19, 2006 */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/UIViewRelationList.gtmpl", events = {@EventConfig(listeners = UIViewRelationList.CloseActionListener.class)} ) public class UIViewRelationList extends UIContainer{ public UIViewRelationList() throws Exception { } public List<Node> getRelations() throws Exception { UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ; Session session = uiExplorer.getSession() ; List<Node> relations = new ArrayList<Node>() ; Value[] vals = null ; try { vals = uiExplorer.getCurrentNode().getProperty("exo:relation").getValues() ; }catch (Exception e) { return relations ;} for(Value val : vals) { String uuid = val.getString(); Node node = session.getNodeByUUID(uuid) ; relations.add(node) ; } return relations ; } static public class CloseActionListener extends EventListener<UIViewRelationList> { public void execute(Event<UIViewRelationList> event) throws Exception { } } }
2,438
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIRelationsList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/info/UIRelationsList.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.info; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : nqhungvn * nguyenkequanghung@yahoo.com * July 3, 2006 * 10:07:15 AM */ @ComponentConfig( events = { @EventConfig(listeners = UIRelationsList.AddRelationActionListener.class), @EventConfig(listeners = UIRelationsList.CancelActionListener.class) } ) public class UIRelationsList extends UIContainer { public UIRelationsList() throws Exception { } @SuppressWarnings("unused") static public class AddRelationActionListener extends EventListener<UIRelationsList> { public void execute(Event<UIRelationsList> event) throws Exception { } } @SuppressWarnings("unused") static public class CancelActionListener extends EventListener<UIRelationsList> { public void execute(Event<UIRelationsList> event) throws Exception { } } }
1,874
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIViewMetadataTemplate.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/info/UIViewMetadataTemplate.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.info; import java.util.List; import javax.jcr.Node; import org.exoplatform.services.log.Log; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.utils.PermissionUtil; import org.exoplatform.resolver.ResourceResolver; import org.exoplatform.services.cms.metadata.MetadataService; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.exception.MessageException; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jan 25, 2007 * 2:05:40 PM */ @ComponentConfig( events = { @EventConfig(listeners = UIViewMetadataTemplate.EditPropertyActionListener.class), @EventConfig(listeners = UIViewMetadataTemplate.CancelActionListener.class) } ) public class UIViewMetadataTemplate extends UIContainer { private String documentType_ ; private static final Log LOG = ExoLogger.getLogger(UIViewMetadataTemplate.class.getName()); public UIViewMetadataTemplate() throws Exception { } public void setTemplateType(String type) {documentType_ = type ;} public String getViewTemplatePath() { MetadataService metadataService = getApplicationComponent(MetadataService.class) ; try { return metadataService.getMetadataPath(documentType_, false) ; } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } } return null ; } public String getTemplate() { return getViewTemplatePath() ; } @SuppressWarnings("unused") public ResourceResolver getTemplateResourceResolver(WebuiRequestContext context, String template) { //return getAncestorOfType(UIJCRExplorer.class).getJCRTemplateResourceResolver(); getAncestorOfType(UIJCRExplorer.class).newJCRTemplateResourceResolver() ; return getAncestorOfType(UIJCRExplorer.class).getJCRTemplateResourceResolver(); } public Node getViewNode(String nodeType) throws Exception { return getAncestorOfType(UIJCRExplorer.class).getViewNode(nodeType) ; } public List<String> getMultiValues(Node node, String name) throws Exception { return getAncestorOfType(UIJCRExplorer.class).getMultiValues(node, name) ; } static public class EditPropertyActionListener extends EventListener<UIViewMetadataTemplate> { public void execute(Event<UIViewMetadataTemplate> event) throws Exception { UIViewMetadataTemplate uiViewTemplate = event.getSource() ; String nodeType = event.getRequestContext().getRequestParameter(OBJECTID) ; UIViewMetadataManager uiMetaManager = uiViewTemplate.getAncestorOfType(UIViewMetadataManager.class) ; UIJCRExplorer uiExplorer = uiViewTemplate.getAncestorOfType(UIJCRExplorer.class) ; UIApplication uiApp = uiViewTemplate.getAncestorOfType(UIApplication.class); Node currentNode = uiExplorer.getCurrentNode(); if (!PermissionUtil.canSetProperty(currentNode)) { throw new MessageException(new ApplicationMessage("UIViewMetadataTemplate.msg.access-denied", null, ApplicationMessage.WARNING)) ; } if (!currentNode.isCheckedOut()) { uiApp.addMessage(new ApplicationMessage("UIActionBar.msg.node-checkedin", null)); return; } uiMetaManager.initMetadataFormPopup(nodeType) ; UIViewMetadataContainer uiContainer = uiViewTemplate.getParent() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiContainer.getParent()) ; } } static public class CancelActionListener extends EventListener<UIViewMetadataTemplate> { public void execute(Event<UIViewMetadataTemplate> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class) ; uiExplorer.cancelAction() ; } } }
5,131
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIReferencesList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/info/UIReferencesList.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.info; import java.util.ArrayList; import java.util.List; import javax.jcr.Node; import javax.jcr.PropertyIterator; import javax.jcr.Session; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.core.ManageableRepository; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIGrid; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : nqhungvn * nguyenkequanghung@yahoo.com * July 3, 2006 * 10:07:15 AM * Edit: lxchiati 2006/10/16 * Edit: phamtuan Oct 27, 2006 */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/popup/info/UIReferencesList.gtmpl", events = { @EventConfig (listeners = UIReferencesList.CloseActionListener.class)} ) public class UIReferencesList extends UIGrid implements UIPopupComponent{ /** The log. */ private static final Log LOG = ExoLogger.getLogger(UIReferencesList.class.getName()); private static String[] REFERENCES_BEAN_FIELD = {"workspace", "path"} ; public UIReferencesList() throws Exception {} public void activate() { try { configure("workspace", REFERENCES_BEAN_FIELD, null) ; updateGrid(); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } public void deActivate() {} public void updateGrid() throws Exception { ListAccess<ReferenceBean> referenceList = new ListAccessImpl<ReferenceBean>(ReferenceBean.class, getReferences()); LazyPageList<ReferenceBean> dataPageList = new LazyPageList<ReferenceBean>(referenceList, 10); getUIPageIterator().setPageList(dataPageList); } private List<ReferenceBean> getReferences() throws Exception { List<ReferenceBean> referBeans = new ArrayList<ReferenceBean>() ; RepositoryService repositoryService = getApplicationComponent(RepositoryService.class) ; UIJCRExplorer uiJCRExplorer = getAncestorOfType(UIJCRExplorer.class) ; Node currentNode = uiJCRExplorer.getCurrentNode() ; String uuid = currentNode.getUUID() ; ManageableRepository repository = repositoryService.getCurrentRepository(); Session session = null ; for(String workspace : repository.getWorkspaceNames()) { session = repository.getSystemSession(workspace) ; try{ Node lookupNode = session.getNodeByUUID(uuid) ; PropertyIterator iter = lookupNode.getReferences() ; if(iter != null) { while(iter.hasNext()) { Node refNode = iter.nextProperty().getParent() ; referBeans.add(new ReferenceBean(workspace, refNode.getPath())) ; } } } catch(Exception e) { if (LOG.isWarnEnabled()) { LOG.warn(e.getMessage()); } } session.logout() ; } return referBeans ; } static public class CloseActionListener extends EventListener<UIReferencesList> { public void execute(Event<UIReferencesList> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class) ; uiExplorer.cancelAction() ; } } public class ReferenceBean { private String workspace_ ; private String path_ ; public ReferenceBean ( String workspace, String path) { workspace_ = workspace ; path_ = path ; } public String getPath() { return path_ ;} public void setPath(String path) { this.path_ = path ;} public String getWorkspace() { return workspace_ ;} public void setWorkspace(String workspace) { this.workspace_ = workspace ;} } }
4,942
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIPermissionForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/info/UIPermissionForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.info; import java.security.AccessControlException; import java.util.ArrayList; import java.util.List; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import org.exoplatform.ecm.permission.info.UIPermissionInputSet; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorerPortlet; import org.exoplatform.ecm.webui.core.UIPermissionFormBase; import org.exoplatform.ecm.webui.core.UIPermissionManagerBase; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.ecm.webui.utils.PermissionUtil; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.jcr.access.PermissionType; import org.exoplatform.services.jcr.core.ExtendedNode; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "classpath:groovy/wcm/webui/core/UIPermissionForm.gtmpl", events = { @EventConfig(listeners = UIPermissionForm.SaveActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionForm.ResetActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionForm.CloseActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionForm.SelectUserActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionForm.SelectMemberActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionForm.AddAnyActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionInputSet.OnChangeActionListener.class) } ) public class UIPermissionForm extends UIPermissionFormBase implements UISelectable { public UIPermissionForm() throws Exception { super(); } static public class SaveActionListener extends EventListener<UIPermissionForm> { public void execute(Event<UIPermissionForm> event) throws Exception { UIPermissionForm uiForm = event.getSource(); UIJCRExplorer uiExplorer = uiForm.getAncestorOfType(UIJCRExplorer.class); Node currentNode = uiExplorer.getCurrentNode(); UIPermissionManagerBase uiParent = uiForm.getParent(); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); String userOrGroup = uiForm.getChild(UIPermissionInputSet.class).getUIStringInput( UIPermissionInputSet.FIELD_USERORGROUP).getValue(); List<String> permsList = new ArrayList<String>(); List<String> permsRemoveList = new ArrayList<String>(); uiExplorer.addLockToken(currentNode); if (!currentNode.isCheckedOut()) { uiApp.addMessage(new ApplicationMessage("UIActionBar.msg.node-checkedin", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); return; } for (String perm : PermissionType.ALL) { if (uiForm.getUICheckBoxInput(perm) != null && uiForm.getUICheckBoxInput(perm).isChecked()) permsList.add(perm); else { permsRemoveList.add(perm); } } //check both ADD_NODE and SET_PROPERTY if (uiForm.getUICheckBoxInput(PermissionType.ADD_NODE).isChecked()) { if(!permsList.contains(PermissionType.SET_PROPERTY)) permsList.add(PermissionType.SET_PROPERTY); } //uncheck both ADD_NODE and SET_PROPERTY if (!uiForm.getUICheckBoxInput(PermissionType.ADD_NODE).isChecked()) { if(!permsRemoveList.contains(PermissionType.SET_PROPERTY)) permsRemoveList.add(PermissionType.SET_PROPERTY); } //------------------ if (Utils.isNameEmpty(userOrGroup)) { uiApp.addMessage(new ApplicationMessage("UIPermissionForm.msg.userOrGroup-required", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); return; } if (permsList.size() == 0) { uiApp.addMessage(new ApplicationMessage("UIPermissionForm.msg.checkbox-require", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); return; } String[] permsArray = permsList.toArray(new String[permsList.size()]); ExtendedNode node = (ExtendedNode) currentNode; if (PermissionUtil.canChangePermission(node)) { if (node.canAddMixin("exo:privilegeable")){ node.addMixin("exo:privilegeable"); String nodeOwner = Utils.getNodeOwner(node); if (nodeOwner != null) { node.setPermission(nodeOwner, PermissionType.ALL); } } for (String perm : permsRemoveList) { try { node.removePermission(userOrGroup, perm); } catch (AccessDeniedException ade) { uiApp.addMessage(new ApplicationMessage("UIPermissionForm.msg.access-denied", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); return; } catch (AccessControlException accessControlException) { uiApp.addMessage(new ApplicationMessage("UIPermissionForm.msg.access-denied", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); return; } } try { if(PermissionUtil.canChangePermission(node)) node.setPermission(userOrGroup, permsArray); node.save(); } catch (AccessDeniedException ade) { uiApp.addMessage(new ApplicationMessage("UIPermissionForm.msg.access-denied", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); return; } catch (AccessControlException accessControlException) { uiApp.addMessage(new ApplicationMessage("UIPermissionForm.msg.access-denied", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); return; } uiParent.getChild(UIPermissionInfo.class).updateGrid(1); if (uiExplorer.getRootNode().equals(node)) { if (!PermissionUtil.canRead(currentNode)) { uiForm.getAncestorOfType(UIJCRExplorerPortlet.class).reloadWhenBroken(uiExplorer); return; } } } else { uiApp.addMessage(new ApplicationMessage("UIPermissionForm.msg.not-change-permission", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); return; } // Update symlinks uiForm.updateSymlinks(uiForm.getCurrentNode()); currentNode.getSession().save(); uiForm.refresh(); uiExplorer.setIsHidePopup(true); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); } } public void doSelect(String selectField, Object value) { try { ExtendedNode node = (ExtendedNode)this.getCurrentNode(); checkAll(false); fillForm(value.toString(), node); lockForm(value.toString().equals(getExoOwner(node))); getUIStringInput(selectField).setValue(value.toString()); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } } } static public class CloseActionListener extends EventListener<UIPermissionForm> { public void execute(Event<UIPermissionForm> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); uiExplorer.cancelAction(); } } public Node getCurrentNode() throws Exception { return this.getAncestorOfType(UIJCRExplorer.class).getCurrentNode(); } }
9,244
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIPermissionInfo.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/info/UIPermissionInfo.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.info; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorerPortlet; import org.exoplatform.ecm.webui.core.UIPermissionInfoBase; import org.exoplatform.ecm.webui.utils.PermissionUtil; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.link.LinkManager; import org.exoplatform.services.cms.link.LinkUtils; import org.exoplatform.services.jcr.access.PermissionType; import org.exoplatform.services.jcr.core.ExtendedNode; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.security.IdentityConstants; import org.exoplatform.services.wcm.core.NodetypeConstant; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIGrid; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import java.util.List; @ComponentConfig(lifecycle = UIContainerLifecycle.class, events = { @EventConfig(listeners = UIPermissionInfo.DeleteActionListener.class, confirm = "UIPermissionInfo.msg.confirm-delete-permission"), @EventConfig(listeners = UIPermissionInfo.EditActionListener.class) }) public class UIPermissionInfo extends UIPermissionInfoBase { public UIPermissionInfo() throws Exception { super(); } private static final Log LOG = ExoLogger.getLogger(UIPermissionInfo.class.getName()); static public class DeleteActionListener extends EventListener<UIPermissionInfo> { public void execute(Event<UIPermissionInfo> event) throws Exception { UIPermissionInfo uicomp = event.getSource() ; UIJCRExplorer uiJCRExplorer = uicomp.getAncestorOfType(UIJCRExplorer.class) ; Node currentNode = uiJCRExplorer.getCurrentNode() ; uiJCRExplorer.addLockToken(currentNode); ExtendedNode node = (ExtendedNode)currentNode; String owner = IdentityConstants.SYSTEM ; int iSystemOwner = 0; if (uicomp.getExoOwner(node) != null) owner = uicomp.getExoOwner(node); if (owner.equals(IdentityConstants.SYSTEM)) iSystemOwner = -1; UIApplication uiApp = uicomp.getAncestorOfType(UIApplication.class) ; if (uicomp.getSizeOfListPermission() < 2 + iSystemOwner) { uiApp.addMessage(new ApplicationMessage("UIPermissionInfo.msg.no-permission-remove", null, ApplicationMessage.WARNING)); return; } String name = event.getRequestContext().getRequestParameter(OBJECTID) ; if(!currentNode.isCheckedOut()) { uiApp.addMessage(new ApplicationMessage("UIActionBar.msg.node-checkedin", null, ApplicationMessage.WARNING)) ; return ; } String nodeOwner = Utils.getNodeOwner(node); if(name.equals(nodeOwner)) { uiApp.addMessage(new ApplicationMessage("UIPermissionInfo.msg.no-permission-remove", null, ApplicationMessage.WARNING)) ; return ; } if(PermissionUtil.canChangePermission(node)) { if(node.canAddMixin("exo:privilegeable")) { node.addMixin("exo:privilegeable"); node.setPermission(nodeOwner,PermissionType.ALL); } try { node.removePermission(name) ; node.save() ; } catch(AccessDeniedException ace) { node.getSession().refresh(false) ; uiApp.addMessage(new ApplicationMessage("UIPermissionInfo.msg.access-denied", null, ApplicationMessage.WARNING)) ; return ; } if(uiJCRExplorer.getRootNode().equals(node)) { if(!PermissionUtil.canRead(currentNode)) { uiJCRExplorer.getAncestorOfType(UIJCRExplorerPortlet.class).reloadWhenBroken(uiJCRExplorer) ; return ; } } node.getSession().save() ; } else { uiApp.addMessage(new ApplicationMessage("UIPermissionInfo.msg.no-permission-tochange", null, ApplicationMessage.WARNING)) ; return ; } UIPopupContainer uiPopup = uicomp.getAncestorOfType(UIPopupContainer.class) ; if(!PermissionUtil.canRead(node)) { uiJCRExplorer.setSelectNode(LinkUtils.getParentPath(uiJCRExplorer.getCurrentPath())); uiPopup.deActivate() ; } else { uicomp.updateGrid(uicomp.getChild(UIGrid.class).getUIPageIterator().getCurrentPage()); event.getRequestContext().addUIComponentToUpdateByAjax(uicomp.getParent()) ; } Node realNode = uiJCRExplorer.getRealCurrentNode(); LinkManager linkManager = uiJCRExplorer.getApplicationComponent(LinkManager.class); if (linkManager.isLink(realNode)) { // Reset the permissions linkManager.updateLink(realNode, currentNode); } if(currentNode.isNodeType(NodetypeConstant.MIX_REFERENCEABLE)){ List<Node> symlinks = linkManager.getAllLinks(currentNode, "exo:symlink"); for (Node symlink : symlinks) { try { linkManager.updateLink(symlink, currentNode); } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn(e.getMessage()); } } } } currentNode.getSession().save(); uiJCRExplorer.setIsHidePopup(true) ; if(!PermissionUtil.canRead(currentNode)){ uiPopup.cancelPopupAction(); uiJCRExplorer.refreshExplorer(currentNode.getSession().getRootNode(), true); }else { uiJCRExplorer.refreshExplorer(currentNode, false); } event.getRequestContext().addUIComponentToUpdateByAjax(uiJCRExplorer) ; } } public Node getCurrentNode() throws Exception { return this.getAncestorOfType(UIJCRExplorer.class).getCurrentNode(); } }
7,039
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIAddTag.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UIAddTag.java
/* * Copyright (C) 2003-2008 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIComponent; /** * Created by The eXo Platform SARL * Author : Nguyen Anh Vu * anhvurz90@gmail.com * Nov 27, 2009 * 4:08:24 PM */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/popup/action/UIAddTag.gtmpl" ) public class UIAddTag extends UIComponent { private static String[] ACTIONS = {"AddTag"}; public UIAddTag() { super(); } public String[] getActions() { return ACTIONS; } }
1,318
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITaggingForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UITaggingForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import org.exoplatform.ecm.jcr.model.Preference; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.sidebar.UISideBar; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.folksonomy.NewFolksonomyService; import org.exoplatform.services.jcr.core.ManageableRepository; import org.exoplatform.services.jcr.ext.common.SessionProvider; import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.web.application.RequestContext; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.*; import javax.jcr.Node; import java.util.*; /** * Created by The eXo Platform SARL Author : Dang Van Minh * minh.dang@exoplatform.com Jan 12, 2007 11:56:51 AM */ @ComponentConfig(lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UITaggingForm.AddTagActionListener.class), @EventConfig(listeners = UITaggingForm.EditActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UITaggingForm.RemoveActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UITaggingForm.CancelActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UITaggingForm.ChangeActionListener.class, phase = Phase.DECODE) }) public class UITaggingForm extends UIForm { final static public String TAG_NAME_LIST = "tagNameList"; final static public String TAG_NAMES = "names"; final static public String TAG_SCOPES = "tagScopes"; final static public String LINKED_TAGS = "linked"; final static public String LINKED_TAGS_SET = "tagSet"; private static final String USER_FOLKSONOMY_ALIAS = "userPrivateFolksonomy"; private static final String GROUP_FOLKSONOMY_ALIAS = "folksonomy"; private static final String GROUPS_ALIAS = "groupsPath"; final static public String PUBLIC_TAG_NODE_PATH = "exoPublicTagNode"; public UITaggingForm() throws Exception { UIFormInputSetWithActionForTaggingForm uiInputSet = new UIFormInputSetWithActionForTaggingForm(LINKED_TAGS_SET); uiInputSet.addUIFormInput(new UIFormStringInput(TAG_NAMES, TAG_NAMES, null)); uiInputSet.addUIFormInput(new UIFormTextAreaInput(TAG_NAME_LIST, TAG_NAME_LIST, null)); RequestContext context = RequestContext.getCurrentInstance(); ResourceBundle res = context.getApplicationResourceBundle(); List<SelectItemOption<String>> tagScopes = new ArrayList<SelectItemOption<String>>(); /* Only Public tag enabled in PLF 4 tagScopes.add(new SelectItemOption<String>(res.getString("UITaggingForm.label." + Utils.PRIVATE), Utils.PRIVATE)); */ tagScopes.add(new SelectItemOption<String>(res.getString("UITaggingForm.label." + Utils.PUBLIC), Utils.PUBLIC)); /* * Disable Group and Site tag tagScopes.add(new * SelectItemOption<String>(res.getString("UITaggingForm.label." + * Utils.GROUP), Utils.GROUP)); tagScopes.add(new * SelectItemOption<String>(res.getString("UITaggingForm.label." + * Utils.SITE), Utils.SITE)); */ UIFormSelectBox box = new UIFormSelectBox(TAG_SCOPES, TAG_SCOPES, tagScopes); box.setOnChange("Change"); uiInputSet.addUIFormInput(box); box.setSelectedValues(new String[] { Utils.PUBLIC }); box.setRendered(false); uiInputSet.addUIFormInput(new UIFormInputInfo(LINKED_TAGS, LINKED_TAGS, null)); uiInputSet.setIntroduction(TAG_NAMES, "UITaggingForm.introduction.tagName"); addUIComponentInput(uiInputSet); uiInputSet.setIsView(false); super.setActions(new String[] {"Cancel" }); } public void activate() throws Exception { String workspace = WCMCoreUtils.getRepository().getConfiguration().getDefaultWorkspaceName(); NewFolksonomyService folksonomyService = WCMCoreUtils.getService(NewFolksonomyService.class); StringBuilder linkedTags = new StringBuilder(); Set<String> linkedTagSet = new HashSet<String>(); String tagScope = this.getUIFormSelectBox(TAG_SCOPES).getValue(); Node currentNode = getAncestorOfType(UIJCRExplorer.class).getCurrentNode(); getAncestorOfType(UIJCRExplorer.class).setTagScope(getIntValue(tagScope)); for (Node tag : folksonomyService.getLinkedTagsOfDocumentByScope(getIntValue(tagScope), getStrValue(tagScope, currentNode), currentNode, workspace)) { linkedTagSet.add(tag.getName()); } List<String> linkedTagList = new ArrayList<String>(linkedTagSet); Collections.sort(linkedTagList); for (String tagName : linkedTagList) { if (linkedTags.length() > 0) linkedTags = linkedTags.append(","); linkedTags.append(tagName); } UIFormInputSetWithAction uiLinkedInput = getChildById(LINKED_TAGS_SET); uiLinkedInput.setInfoField(LINKED_TAGS, linkedTags.toString()); //check if current user can remove tag NewFolksonomyService newFolksonomyService = WCMCoreUtils.getService(NewFolksonomyService.class); List<String> memberships = Utils.getMemberships(); String[] actionsForTags = newFolksonomyService.canEditTag(this.getIntValue(tagScope), memberships) ? new String[] {"Edit", "Remove"} : null; uiLinkedInput.setActionInfo(LINKED_TAGS, actionsForTags); uiLinkedInput.setIsShowOnly(true); uiLinkedInput.setIsDeleteOnly(false); } public void deActivate() throws Exception { } public int getIntValue(String scope) { if (Utils.PUBLIC.equals(scope)) return NewFolksonomyService.PUBLIC; else if (Utils.GROUP.equals(scope)) return NewFolksonomyService.GROUP; else if (Utils.PRIVATE.equals(scope)) return NewFolksonomyService.PRIVATE; return NewFolksonomyService.SITE; } public List<String> getAllTagNames() throws Exception { String workspace = WCMCoreUtils.getRepository().getConfiguration().getDefaultWorkspaceName(); NewFolksonomyService folksonomyService = getApplicationComponent(NewFolksonomyService.class); String tagScope = this.getUIFormSelectBox(TAG_SCOPES).getValue(); Node currentNode = getAncestorOfType(UIJCRExplorer.class).getCurrentNode(); return folksonomyService.getAllTagNames(workspace, getIntValue(tagScope), getStrValue(tagScope, currentNode)); } @Override public void processRender(WebuiRequestContext context) throws Exception { // context.getJavascriptManager().importJavascript("eXo.ecm.ECMUtils", // "/ecm-wcm-extension/javascript/"); context.getJavascriptManager().require("SHARED/ecm-utils", "ecmutil"). addScripts("ecmutil.ECMUtils.disableAutocomplete('UITaggingForm');"); super.processRender(context); } private String getStrValue(String scope, Node node) throws Exception { StringBuilder ret = new StringBuilder(); if (Utils.PRIVATE.equals(scope)) ret.append(node.getSession().getUserID()); else if (Utils.GROUP.equals(scope)) { for (String group : Utils.getGroups()) ret.append(group).append(';'); ret.deleteCharAt(ret.length() - 1); } else if (Utils.PUBLIC.equals(scope)) { NodeHierarchyCreator nodeHierarchyCreator = getApplicationComponent(NodeHierarchyCreator.class); ret.append(nodeHierarchyCreator.getJcrPath(PUBLIC_TAG_NODE_PATH)); } return ret.toString(); } static public class AddTagActionListener extends EventListener<UITaggingForm> { public void execute(Event<UITaggingForm> event) throws Exception { UITaggingForm uiForm = event.getSource(); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); String workspace = uiForm.getAncestorOfType(UIJCRExplorer.class) .getRepository() .getConfiguration() .getDefaultWorkspaceName(); String tagName = uiForm.getUIStringInput(TAG_NAMES).getValue(); NewFolksonomyService newFolksonomyService = uiForm.getApplicationComponent(NewFolksonomyService.class); UIJCRExplorer uiExplorer = uiForm.getAncestorOfType(UIJCRExplorer.class); Node currentNode = uiExplorer.getCurrentNode(); uiExplorer.addLockToken(currentNode); if (tagName == null || tagName.trim().length() == 0) { uiApp.addMessage(new ApplicationMessage("UITaggingForm.msg.tag-name-empty", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return; } String[] tagNames; tagNames = tagName.split(","); List<String> listTagNames = new ArrayList<String>(tagNames.length); List<String> listTagNamesClone = new ArrayList<String>(tagNames.length); if (tagName.contains(",")) { for (String tName : tagNames) { listTagNames.add(tName.trim()); listTagNamesClone.add(tName.trim()); } for (String tag : listTagNames) { listTagNamesClone.remove(tag); if (listTagNamesClone.contains(tag)) { continue; } listTagNamesClone.add(tag); } } else { listTagNames.add(tagName.trim()); listTagNamesClone.add(tagName.trim()); } for (String t : listTagNames) { if (t.trim().length() == 0) { listTagNamesClone.remove(t); continue; } if (t.trim().length() > 30) { listTagNamesClone.remove(t); continue; } for (String filterChar : Utils.SPECIALCHARACTER) { if (t.contains(filterChar)) { listTagNamesClone.remove(t); } } } if(listTagNamesClone.size() == 0) { uiApp.addMessage(new ApplicationMessage("UITaggingForm.msg.tagName-empty-or-invalid", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return; } String tagScope = uiForm.getUIFormSelectBox(TAG_SCOPES).getValue(); List<Node> tagList = newFolksonomyService.getLinkedTagsOfDocumentByScope(uiForm.getIntValue(tagScope), uiForm.getStrValue(tagScope, currentNode), uiExplorer.getCurrentNode(), workspace); for (Node tag : tagList) { for (String t : listTagNames) { if (t.equals(tag.getName())) { listTagNamesClone.remove(t); } } } if(listTagNamesClone.size() > 0) addTagToNode(tagScope, currentNode, listTagNamesClone.toArray(new String[listTagNamesClone.size()]), uiForm); uiForm.activate(); Preference preferences = uiExplorer.getPreference(); if (preferences.isShowSideBar()) { UISideBar uiSideBar = uiExplorer.findFirstComponentOfType(UISideBar.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiSideBar); } uiForm.getUIStringInput(TAG_NAMES).setValue(null); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); } private void addTagToNode(String scope, Node currentNode, String[] tagNames, UITaggingForm uiForm) throws Exception { NewFolksonomyService newFolksonomyService = uiForm.getApplicationComponent(NewFolksonomyService.class); ManageableRepository manageableRepo = WCMCoreUtils.getRepository(); NodeHierarchyCreator nodeHierarchyCreator = uiForm.getApplicationComponent(NodeHierarchyCreator.class); String workspace = manageableRepo.getConfiguration().getDefaultWorkspaceName(); List<String> groups = Utils.getGroups(); String[] roles = groups.toArray(new String[groups.size()]); String publicTagNodePath = nodeHierarchyCreator.getJcrPath(PUBLIC_TAG_NODE_PATH); if (Utils.PUBLIC.equals(scope)) newFolksonomyService.addPublicTag(publicTagNodePath, tagNames, currentNode, workspace); // else if (SITE.equals(scope)) // newFolksonomyService.addSiteTag(siteName, treePath, tagNames, // currentNode, repository, workspace); else if (Utils.GROUP.equals(scope)) newFolksonomyService.addGroupsTag(tagNames, currentNode, workspace, roles); else if (Utils.PRIVATE.equals(scope)) { String userName = currentNode.getSession().getUserID(); newFolksonomyService.addPrivateTag(tagNames, currentNode, workspace, userName); } } } static public class CancelActionListener extends EventListener<UITaggingForm> { public void execute(Event<UITaggingForm> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); uiExplorer.cancelAction(); } } static public class RemoveActionListener extends EventListener<UITaggingForm> { public void execute(Event<UITaggingForm> event) throws Exception { UITaggingForm uiForm = event.getSource(); UIJCRExplorer uiExplorer = uiForm.getAncestorOfType(UIJCRExplorer.class); NewFolksonomyService newFolksonomyService = uiForm.getApplicationComponent(NewFolksonomyService.class); String tagScope = uiForm.getUIFormSelectBox(TAG_SCOPES).getValue(); List<String> memberships = Utils.getMemberships(); if (!newFolksonomyService.canEditTag(uiForm.getIntValue(tagScope), memberships)) { UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.editTagAccessDenied", null, ApplicationMessage.WARNING)); return; } Node currentNode = uiExplorer.getCurrentNode(); String tagName = event.getRequestContext().getRequestParameter(OBJECTID); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); if (!Utils.isNameValid(tagName, Utils.SPECIALCHARACTER)) { uiApp.addMessage(new ApplicationMessage("UITaggingForm.msg.tagName-invalid", null, ApplicationMessage.WARNING)); return; } removeTagFromNode(tagScope, currentNode, tagName, uiForm); uiForm.activate(); Preference preferences = uiExplorer.getPreference(); if (preferences.isShowSideBar()) { UISideBar uiSideBar = uiExplorer.findFirstComponentOfType(UISideBar.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiSideBar); } event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); } public void removeTagFromNode(String scope, Node currentNode, String tagName, UITaggingForm uiForm) throws Exception { NewFolksonomyService newFolksonomyService = uiForm.getApplicationComponent(NewFolksonomyService.class); NodeHierarchyCreator nodeHierarchyCreator = uiForm.getApplicationComponent(NodeHierarchyCreator.class); String userName = currentNode.getSession().getUserID(); String workspace = WCMCoreUtils.getRepository().getConfiguration().getDefaultWorkspaceName(); String tagPath; if (Utils.PUBLIC.equals(scope)) { tagPath = newFolksonomyService.getDataDistributionType().getDataNode( (Node)(WCMCoreUtils.getUserSessionProvider().getSession(workspace, WCMCoreUtils.getRepository()).getItem( nodeHierarchyCreator.getJcrPath(PUBLIC_TAG_NODE_PATH))), tagName).getPath(); newFolksonomyService.removeTagOfDocument(tagPath, currentNode, workspace); } else if (Utils.PRIVATE.equals(scope)) { Node userFolksonomyNode = getUserFolksonomyFolder(userName, uiForm); tagPath = newFolksonomyService.getDataDistributionType().getDataNode(userFolksonomyNode, tagName).getPath(); newFolksonomyService.removeTagOfDocument(tagPath, currentNode, workspace); } else if (Utils.GROUP.equals(scope)) { String groupsPath = nodeHierarchyCreator.getJcrPath(GROUPS_ALIAS); String folksonomyPath = nodeHierarchyCreator.getJcrPath(GROUP_FOLKSONOMY_ALIAS); Node groupsNode = getNode(workspace, groupsPath); for (String role : Utils.getGroups()) { tagPath = newFolksonomyService.getDataDistributionType().getDataNode(groupsNode.getNode(role).getNode(folksonomyPath), tagName).getPath(); newFolksonomyService.removeTagOfDocument(tagPath, currentNode, workspace); } } } private Node getNode(String workspace, String path) throws Exception { SessionProvider sessionProvider = WCMCoreUtils.getUserSessionProvider(); return (Node) sessionProvider.getSession(workspace, WCMCoreUtils.getRepository()).getItem(path); } private Node getUserFolksonomyFolder(String userName, UITaggingForm uiForm) throws Exception { NodeHierarchyCreator nodeHierarchyCreator = uiForm.getApplicationComponent(NodeHierarchyCreator.class); Node userNode = nodeHierarchyCreator.getUserNode(WCMCoreUtils.getUserSessionProvider(), userName); String folksonomyPath = nodeHierarchyCreator.getJcrPath(USER_FOLKSONOMY_ALIAS); return userNode.getNode(folksonomyPath); } } static public class ChangeActionListener extends EventListener<UITaggingForm> { public void execute(Event<UITaggingForm> event) throws Exception { UITaggingForm uiForm = event.getSource(); uiForm.activate(); } } static public class EditActionListener extends EventListener<UITaggingForm> { public void execute(Event<UITaggingForm> event) throws Exception { UITaggingForm uiForm = event.getSource(); NewFolksonomyService newFolksonomyService = uiForm.getApplicationComponent(NewFolksonomyService.class); String tagScope = uiForm.getUIFormSelectBox(TAG_SCOPES).getValue(); List<String> memberships = Utils.getMemberships(); if (!newFolksonomyService.canEditTag(uiForm.getIntValue(tagScope), memberships)) { UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.editTagAccessDenied", null, ApplicationMessage.WARNING)); return; } ((UITaggingFormContainer) uiForm.getParent()).edit(event); } } }
21,668
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UICategoryForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UICategoryForm.java
/*************************************************************************** * Copyright (C) 2003-2009 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. * **************************************************************************/ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.nodetype.ConstraintViolationException; import javax.jcr.nodetype.NodeDefinition; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.form.validator.ECMNameValidator; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.services.jcr.util.Text; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.wcm.webui.Utils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.exception.MessageException; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.validator.MandatoryValidator; @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UICategoryForm.SaveActionListener.class), @EventConfig(listeners = UICategoryForm.CancelActionListener.class, phase=Phase.DECODE) } ) public class UICategoryForm extends UIForm implements UIPopupComponent { final static public String FIELD_NAME = "name"; final static public String FIELD_TYPE = "type"; final static private Log LOG = ExoLogger.getLogger(UICategoryForm.class.getName()); public void activate() { try { addUIFormInput(new UIFormStringInput(FIELD_NAME, FIELD_NAME, null).addValidator(MandatoryValidator.class).addValidator(ECMNameValidator.class)); setActions(new String[] { "Save", "Cancel" }); getUIStringInput(FIELD_NAME).setValue(null); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } public void deActivate() {} static public class SaveActionListener extends EventListener<UICategoryForm> { public void execute(Event<UICategoryForm> event) throws Exception { UICategoryForm uiFolderForm = event.getSource(); UIJCRExplorer uiExplorer = uiFolderForm.getAncestorOfType(UIJCRExplorer.class); UIApplication uiApp = uiFolderForm.getAncestorOfType(UIApplication.class); String title = uiFolderForm.getUIStringInput(FIELD_NAME).getValue(); String name = Utils.cleanString(title); Node node = uiExplorer.getCurrentNode(); if (uiExplorer.nodeIsLocked(node)) { uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.node-locked", null)); return; } if (name == null || name.length() == 0) { uiApp.addMessage(new ApplicationMessage("UIFolderForm.msg.name-invalid", null)); return; } String type = "exo:taxonomy"; try { Node newNode = node.addNode(Text.escapeIllegalJcrChars(name), type); if (newNode.canAddMixin("exo:rss-enable")) { newNode.addMixin("exo:rss-enable"); newNode.setProperty("exo:title", title); } node.save(); node.getSession().save(); uiExplorer.updateAjax(event); } catch(ConstraintViolationException cve) { Object[] arg = { type }; throw new MessageException(new ApplicationMessage("UIFolderForm.msg.constraint-violation", arg, ApplicationMessage.WARNING)); } catch(AccessDeniedException accessDeniedException) { uiApp.addMessage(new ApplicationMessage("UIFolderForm.msg.repository-exception-permission", null, ApplicationMessage.WARNING)); return; } catch(RepositoryException re) { String key = ""; NodeDefinition[] definitions = node.getPrimaryNodeType().getChildNodeDefinitions(); for (NodeDefinition def : definitions) { if (node.hasNode(name) || !def.allowsSameNameSiblings()) { key = "UIFolderForm.msg.not-allow-sameNameSibling"; } else { key = "UIFolderForm.msg.repository-exception"; } } uiApp.addMessage(new ApplicationMessage(key, null, ApplicationMessage.WARNING)); return ; } catch(NumberFormatException nume) { String key = "UIFolderForm.msg.numberformat-exception"; uiApp.addMessage(new ApplicationMessage(key, null, ApplicationMessage.WARNING)); return ; } catch (Exception e) { JCRExceptionManager.process(uiApp, e); if (LOG.isErrorEnabled()) { LOG.error("Error when create category node", e); } return; } } } static public class CancelActionListener extends EventListener<UICategoryForm> { public void execute(Event<UICategoryForm> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); uiExplorer.cancelAction(); } } }
6,376
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITaggingFormContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UITaggingFormContainer.java
/* * Copyright (C) 2003-2008 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import org.exoplatform.ecm.jcr.model.Preference; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.sidebar.UISideBar; import org.exoplatform.services.cms.folksonomy.NewFolksonomyService; import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import javax.jcr.Node; import java.util.List; /** * Created by The eXo Platform SARL * Author : Nguyen Anh Vu * anhvurz90@gmail.com * Dec 10, 2009 * 4:56:12 PM */ @ComponentConfig( lifecycle = UIContainerLifecycle.class, template = "system:/groovy/portal/webui/container/UIContainer.gtmpl" ) public class UITaggingFormContainer extends UIContainer implements UIPopupComponent { private static final Log LOG = ExoLogger.getLogger(UITaggingFormContainer.class.getName()); public void activate() { try { UITaggingForm uiForm = addChild(UITaggingForm.class, null, null); uiForm.activate(); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } @Override public void processRender(WebuiRequestContext context) throws Exception { getChild(UITaggingForm.class).activate(); super.processRender(context); } public void deActivate() { } private void initTaggingFormPopup(Node selectedTag) throws Exception { removeChildById("TagPopup") ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, "TagPopup") ; uiPopup.setShowMask(true); uiPopup.setWindowSize(600, 200) ; UITagForm uiForm = createUIComponent(UITagForm.class, null, null) ; uiForm.setTag(selectedTag) ; uiPopup.setUIComponent(uiForm) ; uiPopup.setRendered(true) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public Node getSelectedTag(String tagName) throws Exception { NewFolksonomyService newFolksonomyService = getApplicationComponent(NewFolksonomyService.class) ; NodeHierarchyCreator nodeHierarchyCreator = getApplicationComponent(NodeHierarchyCreator.class); UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); UITaggingForm uiTaggingForm = getChild(UITaggingForm.class); String workspace = uiExplorer.getRepository().getConfiguration().getDefaultWorkspaceName(); String userName = WCMCoreUtils.getRemoteUser(); String tagScope = uiTaggingForm.getUIFormSelectBox(UITaggingForm.TAG_SCOPES).getValue(); int scope = uiTaggingForm.getIntValue(tagScope); uiExplorer.setTagScope(scope); String publicTagNodePath = nodeHierarchyCreator.getJcrPath(UITaggingForm.PUBLIC_TAG_NODE_PATH); List<Node> tagList = (scope == NewFolksonomyService.PUBLIC) ? newFolksonomyService.getAllPublicTags(publicTagNodePath, workspace) : newFolksonomyService.getAllPrivateTags(userName); for (Node tag : tagList) if (tag.getName().equals(tagName)) return tag; return null; } public void edit(Event<? extends UIComponent> event) throws Exception { UITaggingFormContainer uiTaggingFormContainer = this; String selectedName = event.getRequestContext().getRequestParameter(OBJECTID); Node selectedTag = uiTaggingFormContainer.getSelectedTag(selectedName); uiTaggingFormContainer.initTaggingFormPopup(selectedTag); UIJCRExplorer uiExplorer = uiTaggingFormContainer.getAncestorOfType(UIJCRExplorer.class); Preference preferences = uiExplorer.getPreference(); if (preferences.isShowSideBar()) { UISideBar uiSideBar = uiExplorer.findFirstComponentOfType(UISideBar.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiSideBar); } event.getRequestContext().addUIComponentToUpdateByAjax(uiTaggingFormContainer); } static public class EditActionListener extends EventListener<UITaggingFormContainer> { public void execute(Event<UITaggingFormContainer> event) throws Exception { UITaggingFormContainer uiTaggingFormContainer = event.getSource(); String selectedName = event.getRequestContext().getRequestParameter(OBJECTID); Node selectedTag = uiTaggingFormContainer.getSelectedTag(selectedName); uiTaggingFormContainer.initTaggingFormPopup(selectedTag); UIJCRExplorer uiExplorer = uiTaggingFormContainer.getAncestorOfType(UIJCRExplorer.class); Preference preferences = uiExplorer.getPreference(); if (preferences.isShowSideBar()) { UISideBar uiSideBar = uiExplorer.findFirstComponentOfType(UISideBar.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiSideBar); } event.getRequestContext().addUIComponentToUpdateByAjax(uiTaggingFormContainer); } } }
6,074
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITagForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UITagForm.java
/* * Copyright (C) 2003-2008 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import org.exoplatform.ecm.jcr.model.Preference; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.sidebar.UISideBar; import org.exoplatform.ecm.webui.component.explorer.sidebar.UITagExplorer; import org.exoplatform.ecm.webui.form.validator.ECMNameValidator; import org.exoplatform.services.cms.folksonomy.NewFolksonomyService; import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator; import org.exoplatform.services.wcm.core.NodeLocation; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.validator.MandatoryValidator; import javax.jcr.Node; import java.util.List; /** * Created by The eXo Platform SARL * Author : Nguyen Anh Vu * anhvurz90@gmail.com * Nov 27, 2009 * 5:03:28 PM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UITagForm.UpdateTagActionListener.class), @EventConfig(listeners = UITagForm.CancelActionListener.class, phase = Phase.DECODE) } ) public class UITagForm extends UIForm { final static public String TAG_NAME = "tagName" ; final static public String PUBLIC_TAG_NODE_PATH = "exoPublicTagNode"; private NodeLocation selectedTag_ ; private String oldTagPath_; private String oldName_; public UITagForm() throws Exception { addUIFormInput(new UIFormStringInput(TAG_NAME, TAG_NAME, null).addValidator(MandatoryValidator.class) .addValidator(ECMNameValidator.class)) ; } public Node getTag() { return NodeLocation.getNodeByLocation(selectedTag_); } public void setTag(Node selectedTag) throws Exception { selectedTag_ = NodeLocation.getNodeLocationByNode(selectedTag); if (selectedTag != null) { oldTagPath_ = selectedTag_.getPath(); oldName_ = NodeLocation.getNodeByLocation(selectedTag_).getName(); getUIStringInput(TAG_NAME).setValue(oldName_); } } static public class UpdateTagActionListener extends EventListener<UITagForm> { public void execute(Event<UITagForm> event) throws Exception { UITagForm uiForm = event.getSource() ; UIJCRExplorer uiExplorer = uiForm.getAncestorOfType(UIJCRExplorer.class); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class) ; String workspace = uiForm.getAncestorOfType(UIJCRExplorer.class) .getRepository() .getConfiguration() .getDefaultWorkspaceName(); String userName = WCMCoreUtils.getRemoteUser(); int scope = uiExplorer.getTagScope(); NewFolksonomyService newFolksonomyService = uiForm.getApplicationComponent(NewFolksonomyService.class) ; String tagName = uiForm.getUIStringInput(TAG_NAME).getValue().trim(); if(tagName.trim().length() > 20) { uiApp.addMessage(new ApplicationMessage("UITaggingForm.msg.tagName-too-long", null, ApplicationMessage.WARNING)); return; } try { // add new tag if (uiForm.getTag() == null) { if (scope == NewFolksonomyService.PRIVATE) { newFolksonomyService.addPrivateTag(new String[] { tagName }, null, workspace, userName); } if (scope == NewFolksonomyService.PUBLIC) { NodeHierarchyCreator nodeHierarchyCreator = uiForm.getApplicationComponent(NodeHierarchyCreator.class); String publicTagNodePath = nodeHierarchyCreator.getJcrPath(PUBLIC_TAG_NODE_PATH); newFolksonomyService.addPublicTag(publicTagNodePath, new String[] { tagName }, null, workspace); } } // rename tag else { if (!existTag(tagName, workspace, scope, uiForm, userName)) { NodeHierarchyCreator nodeHierarchyCreator = uiForm.getApplicationComponent(NodeHierarchyCreator.class); // if (scope == NewFolksonomyService.PRIVATE) { // Node newTagNode = newFolksonomyService.modifyPrivateTagName(uiForm.oldTagPath_, tagName, workspace, userName); // uiExplorer.setTagPath(newTagNode.getPath()); // } else { //always public tags String publicTagNodePath = nodeHierarchyCreator.getJcrPath(PUBLIC_TAG_NODE_PATH); Node newTagNode = newFolksonomyService.modifyPublicTagName(uiForm.oldTagPath_, tagName, workspace, publicTagNodePath); if (uiExplorer.getTagPaths().contains(uiForm.oldTagPath_)) { uiExplorer.removeTagPath(uiForm.oldTagPath_); uiExplorer.setTagPath(newTagNode.getPath()); } // } } else if (!tagName.equals(uiForm.oldName_)) { uiApp.addMessage(new ApplicationMessage("UITagForm.msg.NameAlreadyExist", null, ApplicationMessage.WARNING)); } } UIEditingTagsForm uiEdit = uiForm.getAncestorOfType(UIEditingTagsForm.class) ; if (uiEdit != null) { uiEdit.getChild(UIEditingTagList.class).updateGrid(); } } catch(Exception e) { String key = "UITagStyleForm.msg.error-update" ; uiApp.addMessage(new ApplicationMessage(key, null, ApplicationMessage.WARNING)); return ; } UIPopupWindow uiPopup = uiForm.getAncestorOfType(UIPopupWindow.class) ; uiPopup.setShow(false) ; Preference preferences = uiExplorer.getPreference(); if (preferences.isShowSideBar()) { UISideBar uiSideBar = uiExplorer.findFirstComponentOfType(UISideBar.class); uiSideBar.getChild(UITagExplorer.class).updateTagList(); event.getRequestContext().addUIComponentToUpdateByAjax(uiSideBar); } event.getRequestContext().addUIComponentToUpdateByAjax(uiPopup.getParent()) ; } private boolean existTag(String tagName, String workspace, int scope, UITagForm uiForm, String userName) throws Exception { NewFolksonomyService newFolksonomyService = uiForm.getApplicationComponent(NewFolksonomyService.class) ; NodeHierarchyCreator nodeHierarchyCreator = uiForm.getApplicationComponent(NodeHierarchyCreator.class); String publicTagNodePath = nodeHierarchyCreator.getJcrPath(PUBLIC_TAG_NODE_PATH); List<Node> tagList = (scope == NewFolksonomyService.PUBLIC) ? newFolksonomyService.getAllPublicTags(publicTagNodePath, workspace) : newFolksonomyService.getAllPrivateTags(userName); for (Node tag : tagList) if (tag.getName().equals(tagName)) return true; return false; } } static public class CancelActionListener extends EventListener<UITagForm> { public void execute(Event<UITagForm> event) throws Exception { UITagForm uiForm = event.getSource(); UIPopupWindow uiPopup = uiForm.getAncestorOfType(UIPopupWindow.class) ; uiPopup.setShow(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiPopup.getParent()); } } }
8,781
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIFolderForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UIFolderForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.jcr.AccessDeniedException; import javax.jcr.ItemExistsException; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.nodetype.ConstraintViolationException; import javax.jcr.nodetype.NodeDefinition; import org.apache.commons.lang3.StringUtils; import org.exoplatform.ecm.utils.text.Text; import org.exoplatform.ecm.webui.comparator.ItemOptionNameComparator; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.exception.MessageException; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormSelectBox; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.input.UICheckBoxInput; @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/explorer/popup/action/UIAddFolder.gtmpl", events = { @EventConfig(listeners = UIFolderForm.SaveActionListener.class), @EventConfig(listeners = UIFolderForm.OnChangeActionListener.class), @EventConfig(listeners = UIFolderForm.CancelActionListener.class, phase=Phase.DECODE) } ) public class UIFolderForm extends UIForm implements UIPopupComponent { public static final String FIELD_TITLE_TEXT_BOX = "titleTextBox"; public static final String FIELD_CUSTOM_TYPE_CHECK_BOX = "customTypeCheckBox"; public static final String FIELD_CUSTOM_TYPE_SELECT_BOX = "customTypeSelectBox"; private static final Log LOG = ExoLogger.getLogger(UIFolderForm.class.getName()); private static final String DEFAULT_NAME = "untitled"; private static final String MANAGED_SITES = "Managed Sites"; private String selectedType; /** * Constructor. * * @throws Exception */ public UIFolderForm() throws Exception { // Title checkbox UIFormStringInput titleTextBox = new UIFormStringInput(FIELD_TITLE_TEXT_BOX, FIELD_TITLE_TEXT_BOX, null); this.addUIFormInput(titleTextBox); // Custom type checkbox UICheckBoxInput customTypeCheckBox = new UICheckBoxInput(FIELD_CUSTOM_TYPE_CHECK_BOX, FIELD_CUSTOM_TYPE_CHECK_BOX, false); customTypeCheckBox.setRendered(false); customTypeCheckBox.setLabel("UIFolderForm".concat("label").concat(FIELD_CUSTOM_TYPE_CHECK_BOX)); customTypeCheckBox.setOnChange("OnChange"); this.addUIFormInput(customTypeCheckBox); // Custom type selectbox UIFormSelectBox customTypeSelectBox = new UIFormSelectBox(FIELD_CUSTOM_TYPE_SELECT_BOX, FIELD_CUSTOM_TYPE_SELECT_BOX, null); customTypeSelectBox.setRendered(false); this.addUIFormInput(customTypeSelectBox); // Set action this.setActions(new String[]{"Save", "Cancel"}); } /** * Activate form. */ public void activate() { try { UICheckBoxInput customTypeCheckBox = this.getUICheckBoxInput(FIELD_CUSTOM_TYPE_CHECK_BOX); UIFormSelectBox customTypeSelectBox = this.getUIFormSelectBox(FIELD_CUSTOM_TYPE_SELECT_BOX); // Get allowed folder types in current path UIJCRExplorer uiExplorer = this.getAncestorOfType(UIJCRExplorer.class); List<String> folderTypes = Utils.getAllowedFolderTypesInCurrentPath(uiExplorer.getCurrentNode(), uiExplorer.getDriveData()); // Only render custom type checkbox if at least 2 folder types allowed if (folderTypes.size() > 1) { customTypeCheckBox.setRendered(true); if (MANAGED_SITES.equals(this.getAncestorOfType(UIJCRExplorer.class).getDriveData().getName())) { customTypeCheckBox.setChecked(true); customTypeSelectBox.setRendered(true); this.fillCustomTypeSelectBox(folderTypes); } else { customTypeCheckBox.setChecked(false); customTypeSelectBox.setRendered(false); } } else { customTypeCheckBox.setRendered(false); customTypeSelectBox.setRendered(false); this.setSelectedType(folderTypes.get(0)); } } catch(Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e.getMessage()); } } } public void deActivate() {} /** * Fill data to custom type select box. * * @param folderTypes * @throws Exception */ private void fillCustomTypeSelectBox(List<String> folderTypes) throws Exception { UIFormSelectBox customTypeSelectBox = this.getUIFormSelectBox(FIELD_CUSTOM_TYPE_SELECT_BOX); List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>(); for (String folderType : folderTypes) { String label = this.getLabel(folderType.replace(":", "_")); options.add(new SelectItemOption<String>(label, folderType)); } Collections.sort(options, new ItemOptionNameComparator()); customTypeSelectBox.setOptions(options); } /** * Get selected Folder Type. * * @return the selectedType */ public String getSelectedType() { return selectedType; } /** * Set selected folder type. * * @param selectedType the selectedType to set */ private void setSelectedType(String selectedType) { this.selectedType = selectedType; } public static class OnChangeActionListener extends EventListener<UIFolderForm> { public void execute(Event<UIFolderForm> event) throws Exception { UIFolderForm uiFolderForm = event.getSource(); UICheckBoxInput customTypeCheckBox = uiFolderForm.getUICheckBoxInput(FIELD_CUSTOM_TYPE_CHECK_BOX); UIFormSelectBox customTypeSelectBox = uiFolderForm.getUIFormSelectBox(FIELD_CUSTOM_TYPE_SELECT_BOX); // Allowed folder types UIJCRExplorer uiExplorer = uiFolderForm.getAncestorOfType(UIJCRExplorer.class); List<String> folderTypes = Utils.getAllowedFolderTypesInCurrentPath(uiExplorer.getCurrentNode(), uiExplorer.getDriveData()); // Fill custom type select box if (customTypeCheckBox.isChecked()) { uiFolderForm.fillCustomTypeSelectBox(folderTypes); customTypeSelectBox.setRendered(true); } else { customTypeSelectBox.setRendered(false); } event.getRequestContext().addUIComponentToUpdateByAjax(uiFolderForm); } } static public class SaveActionListener extends EventListener<UIFolderForm> { public void execute(Event<UIFolderForm> event) throws Exception { UIFolderForm uiFolderForm = event.getSource(); UIJCRExplorer uiExplorer = uiFolderForm.getAncestorOfType(UIJCRExplorer.class); UIApplication uiApp = uiFolderForm.getAncestorOfType(UIApplication.class); List<String> folderTypes = Utils.getAllowedFolderTypesInCurrentPath(uiExplorer.getCurrentNode(), uiExplorer.getDriveData()); UICheckBoxInput customTypeCheckBox = uiFolderForm.getUICheckBoxInput(FIELD_CUSTOM_TYPE_CHECK_BOX); UIFormSelectBox customTypeSelectBox = uiFolderForm.getUIFormSelectBox(FIELD_CUSTOM_TYPE_SELECT_BOX); // Get title and name String title = uiFolderForm.getUIStringInput(FIELD_TITLE_TEXT_BOX).getValue(); // Validate input Node currentNode = uiExplorer.getCurrentNode(); if (uiExplorer.nodeIsLocked(currentNode)) { uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.node-locked", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiFolderForm); return; } if(StringUtils.isBlank(title)) { uiApp.addMessage(new ApplicationMessage("UIFolderForm.msg.name-invalid", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiFolderForm); return; } // The name automatically determined from the title according to the current algorithm. String name = Text.escapeIllegalJcrChars(org.exoplatform.services.cms.impl.Utils.cleanString(title)); // Set default name if new title contain no valid character if (StringUtils.isEmpty(name)) { name = DEFAULT_NAME; } // Get selected folder type if (customTypeCheckBox.isRendered()) { if (customTypeCheckBox.isChecked()) { String selectedValue = customTypeSelectBox.getValue(); uiFolderForm.setSelectedType(selectedValue); } else { if (folderTypes.contains(Utils.NT_FOLDER)) { uiFolderForm.setSelectedType(Utils.NT_FOLDER); } else { // Message showing type nt:folder is not enabled, choose other type uiApp.addMessage( new ApplicationMessage("UIFolderForm.msg.ntFolder-not-avaiable", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiFolderForm); return; } } } if (currentNode.hasNode(name)) { uiApp.addMessage( new ApplicationMessage("UIFolderForm.msg.not-allow-sameNameSibling", null, ApplicationMessage.WARNING)); return; } try { // Add node Node addedNode = currentNode.addNode(name, uiFolderForm.getSelectedType()); // Set title if (!addedNode.hasProperty(Utils.EXO_TITLE)) { addedNode.addMixin(Utils.EXO_RSS_ENABLE); } addedNode.setProperty(Utils.EXO_TITLE, title); currentNode.save(); uiExplorer.updateAjax(event); } catch(ConstraintViolationException cve) { Object[] arg = { uiFolderForm.getSelectedType() }; throw new MessageException( new ApplicationMessage("UIFolderForm.msg.constraint-violation", arg, ApplicationMessage.WARNING)); } catch(AccessDeniedException accessDeniedException) { uiApp.addMessage( new ApplicationMessage("UIFolderForm.msg.repository-exception-permission", null, ApplicationMessage.WARNING)); } catch(ItemExistsException re) { uiApp.addMessage( new ApplicationMessage("UIFolderForm.msg.not-allow-sameNameSibling", null, ApplicationMessage.WARNING)); } catch(RepositoryException re) { String key = "UIFolderForm.msg.repository-exception"; NodeDefinition[] definitions = currentNode.getPrimaryNodeType().getChildNodeDefinitions(); boolean isSameNameSiblingsAllowed = false; for (NodeDefinition def : definitions) { if (def.allowsSameNameSiblings()) { isSameNameSiblingsAllowed = true; break; } } if (currentNode.hasNode(name) && !isSameNameSiblingsAllowed) { key = "UIFolderForm.msg.not-allow-sameNameSibling"; } uiApp.addMessage( new ApplicationMessage(key, null, ApplicationMessage.WARNING)); } catch(NumberFormatException nume) { uiApp.addMessage( new ApplicationMessage("UIFolderForm.msg.numberformat-exception", null, ApplicationMessage.WARNING)); } catch (Exception e) { JCRExceptionManager.process(uiApp, e); } } } static public class CancelActionListener extends EventListener<UIFolderForm> { public void execute(Event<UIFolderForm> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); uiExplorer.cancelAction(); } } }
13,267
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIFormInputSetWithActionForTaggingForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UIFormInputSetWithActionForTaggingForm.java
/* * Copyright (C) 2003-2008 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import java.util.List; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.webui.config.annotation.ComponentConfig; /** * Created by The eXo Platform SARL * Author : Nguyen Anh Vu * anhvurz90@gmail.com * Dec 24, 2009 * 5:20:02 PM */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/popup/action/UIFormInputSetWithActionForTaggingForm.gtmpl" ) public class UIFormInputSetWithActionForTaggingForm extends UIFormInputSetWithAction { public UIFormInputSetWithActionForTaggingForm(String name) { super(name); } public String getTagNames() throws Exception { String tags = ""; StringBuffer sb = new StringBuffer(); List<String> tagsList = this.getAncestorOfType(UITaggingForm.class).getAllTagNames(); for (String string : tagsList) { sb.append(string).append(","); } tags = sb.toString(); if(tags.length() > 0) tags = tags.substring(0, tags.length()-1); return tags; } }
1,793
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UICommentForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UICommentForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import org.exoplatform.commons.utils.HTMLSanitizer; import org.exoplatform.ecm.webui.component.explorer.*; import org.exoplatform.services.cms.comments.CommentsService; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.organization.*; import org.exoplatform.services.resources.ResourceBundleService; import org.exoplatform.services.wcm.core.NodeLocation; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.exception.MessageException; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.UIFormTextAreaInput; import org.exoplatform.webui.form.validator.EmailAddressValidator; import javax.jcr.Node; import java.util.Locale; import java.util.ResourceBundle; /** * Created by The eXo Platform SARL Author : Tran The Trong trongtt@gmail.com * Jan 30, 2007 */ @ComponentConfig(lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/explorer/popup/action/UICommentForm.gtmpl", events = { @EventConfig(listeners = UICommentForm.SaveActionListener.class), @EventConfig(listeners = UICommentForm.CancelActionListener.class, phase = Phase.DECODE) }) public class UICommentForm extends UIForm implements UIPopupComponent { final public static String FIELD_EMAIL = "email"; final public static String FIELD_WEBSITE = "website"; final public static String FIELD_COMMENT = "comment"; private static final Log LOG = ExoLogger.getLogger(UICommentForm.class.getName()); private boolean edit; private String nodeCommentPath; private String userName; private NodeLocation document_; public UICommentForm() throws Exception { } public boolean isEdit() { return edit; } public void setEdit(boolean edit) { this.edit = edit; } public String getNodeCommentPath() { return nodeCommentPath; } public void setNodeCommentPath(String nodeCommentPath) { this.nodeCommentPath = nodeCommentPath; } public String getUserName() { return userName; } private void prepareFields() throws Exception { WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance(); userName = requestContext.getRemoteUser(); if (userName == null || userName.length() == 0) { addUIFormInput(new UIFormStringInput(FIELD_EMAIL, FIELD_EMAIL, null).addValidator(EmailAddressValidator.class)); addUIFormInput(new UIFormStringInput(FIELD_WEBSITE, FIELD_WEBSITE, null)); } UIFormTextAreaInput commentField = new UIFormTextAreaInput(FIELD_COMMENT, FIELD_COMMENT, ""); //commentField.addValidator(FckMandatoryValidator.class); addUIFormInput(commentField); Locale locale = WebuiRequestContext.getCurrentInstance().getLocale(); ResourceBundleService resourceBundleService = WCMCoreUtils.getService(ResourceBundleService.class); ResourceBundle resourceBundle = resourceBundleService.getResourceBundle("locale.ecm.dialogs", locale); String placeholder = resourceBundle.getString("UICommentForm.label.placeholder"); requestContext.getJavascriptManager().require("SHARED/uiCommentForm", "commentForm") .addScripts("eXo.ecm.CommentForm.init('" + placeholder.replace("'", "\\'") + "');"); if (isEdit()) { Node comment = getAncestorOfType(UIJCRExplorer.class).getNodeByPath(nodeCommentPath, NodeLocation.getNodeByLocation(document_).getSession()); if (comment.hasProperty("exo:commentContent")) { getChild(UIFormTextAreaInput.class).setValue(comment.getProperty("exo:commentContent").getString()); } } } public void activate() { try { document_ = NodeLocation.getNodeLocationByNode(getAncestorOfType(UIJCRExplorer.class).getCurrentNode()); prepareFields(); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } public void deActivate() { document_ = null; } public Node getDocument() { return NodeLocation.getNodeByLocation(document_); } public void setDocument(Node doc) { document_ = NodeLocation.getNodeLocationByNode(doc); } /** * Overrides method processRender of UIForm, loads javascript module * wcm-webui-extension */ @Override public void processRender(WebuiRequestContext context) throws Exception { context.getJavascriptManager().loadScriptResource("wcm-webui-extension"); super.processRender(context); } public static class CancelActionListener extends EventListener<UICommentForm> { public void execute(Event<UICommentForm> event) throws Exception { event.getSource().getAncestorOfType(UIPopupContainer.class).cancelPopupAction(); } } public static class SaveActionListener extends EventListener<UICommentForm> { public void execute(Event<UICommentForm> event) throws Exception { UICommentForm uiForm = event.getSource(); UIJCRExplorer uiExplorer = uiForm.getAncestorOfType(UIJCRExplorer.class); String comment = uiForm.getChild(UIFormTextAreaInput.class).getValue(); comment = HTMLSanitizer.sanitize(comment); CommentsService commentsService = uiForm.getApplicationComponent(CommentsService.class); if (comment == null || comment.trim().length() == 0) { event.getSource().getAncestorOfType(UIPopupContainer.class).cancelPopupAction(); throw new MessageException(new ApplicationMessage("UICommentForm.msg.content-null", null, ApplicationMessage.WARNING)); } if (uiForm.isEdit()) { try { Node commentNode = uiExplorer.getNodeByPath(uiForm.getNodeCommentPath(), NodeLocation.getNodeByLocation(uiForm.document_).getSession()); commentsService.updateComment(commentNode, comment); } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn(e.getMessage()); } } } else { String userName = event.getRequestContext().getRemoteUser(); String website = null; String email = null; if (userName == null || userName.length() == 0) { userName = "anonymous"; website = uiForm.getUIStringInput(FIELD_WEBSITE).getValue(); email = uiForm.getUIStringInput(FIELD_EMAIL).getValue(); } else { OrganizationService organizationService = WCMCoreUtils.getService(OrganizationService.class); UserProfileHandler profileHandler = organizationService.getUserProfileHandler(); UserHandler userHandler = organizationService.getUserHandler(); User user = userHandler.findUserByName(userName); UserProfile userProfile = profileHandler.findUserProfileByName(userName); if (userProfile != null) website = userProfile.getUserInfoMap().get("user.business-info.online.uri"); else website = ""; email = user.getEmail(); } try { String language = uiExplorer.getChild(UIWorkingArea.class) .getChild(UIDocumentWorkspace.class) .getChild(UIDocumentContainer.class) .getChild(UIDocumentInfo.class) .getLanguage(); commentsService.addComment(NodeLocation.getNodeByLocation(uiForm.document_), userName, email, website, comment, language); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error(e); } } } UIPopupWindow uiPopup = uiExplorer.getChildById("ViewSearch"); if (uiPopup != null) { uiPopup.setShowMask(true); event.getRequestContext().addUIComponentToUpdateByAjax(uiPopup); } uiExplorer.updateAjax(event); } } }
9,554
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIWatchDocumentForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UIWatchDocumentForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; import javax.jcr.Node; import javax.jcr.lock.LockException; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.services.cms.watch.WatchDocumentService; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormRadioBoxInput; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jan 10, 2007 * 2:34:12 PM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/explorer/popup/action/UIWatchDocumentForm.gtmpl", events = { @EventConfig(listeners = UIWatchDocumentForm.WatchActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIWatchDocumentForm.CancelActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIWatchDocumentForm.UnwatchActionListener.class, phase = Phase.DECODE) } ) public class UIWatchDocumentForm extends UIForm implements UIPopupComponent { private static final Log LOG = ExoLogger.getLogger(UIWatchDocumentForm.class.getName()); private static final String NOTIFICATION_TYPE = "notificationType"; private static final String NOTIFICATION_TYPE_BY_EMAIL = "Email"; public UIWatchDocumentForm() throws Exception { List<SelectItemOption<String>> nodifyOptions = new ArrayList<SelectItemOption<String>>(); nodifyOptions.add(new SelectItemOption<String>(NOTIFICATION_TYPE_BY_EMAIL, NOTIFICATION_TYPE_BY_EMAIL)); UIFormRadioBoxInput notificationTypeRadioBoxInput = new UIFormRadioBoxInput(NOTIFICATION_TYPE, NOTIFICATION_TYPE, nodifyOptions); addUIFormInput(notificationTypeRadioBoxInput); } public void activate() { try { if(!isWatching()) setActions(new String[] {"Watch", "Cancel"}); else { setActions(new String[] {"Unwatch", "Cancel"}); UIFormRadioBoxInput notificationTypeRadioBoxInput = this.getChildById(NOTIFICATION_TYPE); notificationTypeRadioBoxInput.setValue(NOTIFICATION_TYPE_BY_EMAIL); notificationTypeRadioBoxInput.setReadOnly(true); } } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } public void deActivate() { } private Node getWatchNode() throws Exception{ return getAncestorOfType(UIJCRExplorer.class).getCurrentNode(); } private String getUserName() { WebuiRequestContext context = WebuiRequestContext.getCurrentInstance(); return context.getRemoteUser(); } private boolean isWatching() throws Exception{ return (WatchDocumentService.NOTIFICATION_BY_EMAIL == this.getNotifyType()); } private int getNotifyType() throws Exception { WatchDocumentService watchService = getApplicationComponent(WatchDocumentService.class); return watchService.getNotificationType(this.getWatchNode(), this.getUserName()); } private void showFinishMessage(Event<UIWatchDocumentForm> event, String messageKey) throws Exception { ResourceBundle res = event.getRequestContext().getApplicationResourceBundle(); UIJCRExplorer uiExplorer = this.getAncestorOfType(UIJCRExplorer.class); uiExplorer.getChild(UIWorkingArea.class).setWCMNotice(res.getString(messageKey)); uiExplorer.updateAjax(event); } private void toogleWatch(Event<UIWatchDocumentForm> event) throws Exception { UIApplication uiApp = this.getAncestorOfType(UIApplication.class); // Add lock token this.getAncestorOfType(UIJCRExplorer.class).addLockToken(this.getWatchNode()); try { WatchDocumentService watchService = WCMCoreUtils.getService(WatchDocumentService.class); if (isWatching()) { watchService.unwatchDocument(this.getWatchNode(), this.getUserName(), WatchDocumentService.NOTIFICATION_BY_EMAIL); this.showFinishMessage(event, "UIWatchDocumentForm.msg.unwatching-successfully"); } else { watchService.watchDocument(this.getWatchNode(), this.getUserName(), WatchDocumentService.NOTIFICATION_BY_EMAIL); this.showFinishMessage(event, "UIWatchDocumentForm.msg.watching-successfully"); } } catch (LockException e) { uiApp.addMessage(new ApplicationMessage("UIWatchDocumentForm.msg.node-is-locked", null, ApplicationMessage.WARNING)); } catch (Exception e) { uiApp.addMessage(new ApplicationMessage("UIWatchDocumentForm.msg.unknown-error", null, ApplicationMessage.ERROR)); } } public static class CancelActionListener extends EventListener<UIWatchDocumentForm> { public void execute(Event<UIWatchDocumentForm> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); uiExplorer.cancelAction(); } } public static class WatchActionListener extends EventListener<UIWatchDocumentForm> { public void execute(Event<UIWatchDocumentForm> event) throws Exception { UIWatchDocumentForm uiForm = event.getSource(); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); // Add lock token uiForm.getAncestorOfType(UIJCRExplorer.class).addLockToken(uiForm.getWatchNode()); // Add watching boolean isNotifyByEmail = NOTIFICATION_TYPE_BY_EMAIL.equalsIgnoreCase(((UIFormRadioBoxInput)uiForm.getChildById(NOTIFICATION_TYPE)).getValue()); if(isNotifyByEmail) { uiForm.toogleWatch(event); } else { uiApp.addMessage(new ApplicationMessage("UIWatchDocumentForm.msg.not-support", null, ApplicationMessage.WARNING)); } } } public static class UnwatchActionListener extends EventListener<UIWatchDocumentForm> { public void execute(Event<UIWatchDocumentForm> event) throws Exception { UIWatchDocumentForm uiForm = event.getSource(); uiForm.toogleWatch(event); } } }
7,681
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIEditingTagsForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UIEditingTagsForm.java
/* * Copyright (C) 2003-2008 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import org.exoplatform.ecm.jcr.model.Preference; import org.exoplatform.ecm.webui.component.explorer.UIDocumentInfo; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.sidebar.UISideBar; import org.exoplatform.ecm.webui.component.explorer.sidebar.UITagExplorer; import org.exoplatform.services.cms.folksonomy.NewFolksonomyService; import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import javax.jcr.Node; import java.util.List; /** * Created by The eXo Platform SARL * Author : Nguyen Anh Vu * anhvurz90@gmail.com * Nov 27, 2009 * 11:13:55 AM */ @ComponentConfig( lifecycle = UIContainerLifecycle.class, template = "system:/groovy/portal/webui/container/UIContainer.gtmpl", events = { @EventConfig(listeners = UIEditingTagsForm.EditTagActionListener.class), @EventConfig(listeners = UIEditingTagsForm.RemoveTagActionListener.class, confirm = "UIEditingTagsForm.msg.confirm-remove") } ) public class UIEditingTagsForm extends UIContainer implements UIPopupComponent { private static final Log LOG = ExoLogger.getLogger(UIEditingTagsForm.class.getName()); private static final String PUBLIC_TAG_NODE_PATH = "exoPublicTagNode"; private static final String USER_FOLKSONOMY_ALIAS = "userPrivateFolksonomy"; public void activate() { try { addChild(UIEditingTagList.class, null, null); getChild(UIEditingTagList.class).updateGrid(); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } public void deActivate() { } @Override public void processRender(WebuiRequestContext context) throws Exception { getChild(UIEditingTagList.class).updateGrid(); super.processRender(context); } public void initTaggingFormPopup(Node selectedTag) throws Exception { removeChildById("TagPopup") ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, "TagPopup") ; uiPopup.setShowMask(true); uiPopup.setWindowSize(600, 200) ; UITagForm uiForm = createUIComponent(UITagForm.class, null, null) ; uiForm.setTag(selectedTag) ; uiPopup.setUIComponent(uiForm) ; uiPopup.setRendered(true) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public Node getSelectedTag(String tagName) throws Exception { NewFolksonomyService newFolksonomyService = getApplicationComponent(NewFolksonomyService.class) ; NodeHierarchyCreator nodeHierarchyCreator = getApplicationComponent(NodeHierarchyCreator.class); UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); String workspace = uiExplorer.getRepository().getConfiguration().getDefaultWorkspaceName(); String userName = WCMCoreUtils.getRemoteUser(); int scope = uiExplorer.getTagScope(); String publicTagNodePath = nodeHierarchyCreator.getJcrPath(PUBLIC_TAG_NODE_PATH); List<Node> tagList = (scope == NewFolksonomyService.PUBLIC) ? newFolksonomyService.getAllPublicTags(publicTagNodePath, workspace) : newFolksonomyService.getAllPrivateTags(userName); for (Node tag : tagList) if (tag.getName().equals(tagName)) return tag; return null; } static public class EditTagActionListener extends EventListener<UIEditingTagsForm> { public void execute(Event<UIEditingTagsForm> event) throws Exception { UIEditingTagsForm uiEditingTagsForm = event.getSource() ; String selectedName = event.getRequestContext().getRequestParameter(OBJECTID) ; Node selectedTag = uiEditingTagsForm.getSelectedTag(selectedName) ; uiEditingTagsForm.initTaggingFormPopup(selectedTag) ; UIJCRExplorer uiExplorer = uiEditingTagsForm.getAncestorOfType(UIJCRExplorer.class); Preference preferences = uiExplorer.getPreference(); if (preferences.isShowSideBar()) { UISideBar uiSideBar = uiExplorer.findFirstComponentOfType(UISideBar.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiSideBar); } event.getRequestContext().addUIComponentToUpdateByAjax(uiEditingTagsForm); } } static public class RemoveTagActionListener extends EventListener<UIEditingTagsForm> { public void execute(Event<UIEditingTagsForm> event) throws Exception { UIEditingTagsForm uiEdit = event.getSource(); UIJCRExplorer uiExplorer = uiEdit.getAncestorOfType(UIJCRExplorer.class); String selectedName = event.getRequestContext().getRequestParameter(OBJECTID); removeTagFromNode(WCMCoreUtils.getRemoteUser(), uiExplorer.getTagScope(), selectedName, uiEdit); uiEdit.getChild(UIEditingTagList.class).updateGrid(); Preference preferences = uiExplorer.getPreference(); if (preferences.isShowSideBar()) { UISideBar uiSideBar = uiExplorer.findFirstComponentOfType(UISideBar.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiSideBar); UIDocumentInfo uiDocumentInfo = uiExplorer.findFirstComponentOfType(UIDocumentInfo.class); if (uiDocumentInfo != null) { uiDocumentInfo.updatePageListData(); uiExplorer.refreshExplorerWithoutClosingPopup(); } } event.getRequestContext().addUIComponentToUpdateByAjax(uiExplorer); } public void removeTagFromNode(String userID, int scope, String tagName, UIEditingTagsForm uiForm) throws Exception { NewFolksonomyService newFolksonomyService = uiForm.getApplicationComponent(NewFolksonomyService.class); NodeHierarchyCreator nodeHierarchyCreator = uiForm.getApplicationComponent(NodeHierarchyCreator.class); String workspace = WCMCoreUtils.getRepository().getConfiguration().getDefaultWorkspaceName(); String tagPath = ""; if (NewFolksonomyService.PUBLIC == scope) { tagPath = newFolksonomyService.getDataDistributionType().getDataNode( (Node)(WCMCoreUtils.getUserSessionProvider().getSession(workspace, WCMCoreUtils.getRepository()).getItem( nodeHierarchyCreator.getJcrPath(PUBLIC_TAG_NODE_PATH))), tagName).getPath(); newFolksonomyService.removeTag(tagPath, workspace); } else if (NewFolksonomyService.PRIVATE == scope) { Node userFolksonomyNode = getUserFolksonomyFolder(userID, uiForm); tagPath = newFolksonomyService.getDataDistributionType().getDataNode(userFolksonomyNode, tagName).getPath(); newFolksonomyService.removeTag(tagPath, workspace); } UIJCRExplorer uiExplorer = uiForm.getAncestorOfType(UIJCRExplorer.class); uiExplorer.removeTagPath(tagPath); uiExplorer.findFirstComponentOfType(UITagExplorer.class).updateTagList(); } private Node getUserFolksonomyFolder(String userName, UIEditingTagsForm uiForm) throws Exception { NodeHierarchyCreator nodeHierarchyCreator = uiForm.getApplicationComponent(NodeHierarchyCreator.class); Node userNode = nodeHierarchyCreator.getUserNode(WCMCoreUtils.getUserSessionProvider(), userName); String folksonomyPath = nodeHierarchyCreator.getJcrPath(USER_FOLKSONOMY_ALIAS); return userNode.getNode(folksonomyPath); } } }
8,615
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIEditingTagList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UIEditingTagList.java
/* * Copyright (C) 2003-2008 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.services.cms.folksonomy.NewFolksonomyService; import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIGrid; import javax.jcr.Node; import java.util.ArrayList; import java.util.List; /** * Created by The eXo Platform SARL * Author : Nguyen Anh Vu * anhvurz90@gmail.com * Nov 27, 2009 * 4:18:12 PM */ @ComponentConfig( template = "system:/groovy/webui/core/UIGrid.gtmpl" ) public class UIEditingTagList extends UIGrid { public UIEditingTagList() throws Exception { super(); getUIPageIterator().setId("TagIterator"); configure("name", BEAN_FIELD, ACTIONS); } private static String[] BEAN_FIELD = {"name"}; private static String[] ACTIONS = {"EditTag", "RemoveTag"}; final static public String PUBLIC_TAG_NODE_PATH = "exoPublicTagNode"; final static public String EXO_TOTAL = "exo:total"; public void updateGrid() throws Exception { NewFolksonomyService newFolksonomyService = getApplicationComponent(NewFolksonomyService.class); UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); NodeHierarchyCreator nodeHierarchyCreator = uiExplorer.getApplicationComponent(NodeHierarchyCreator.class); String workspace = uiExplorer.getRepository().getConfiguration().getDefaultWorkspaceName(); int scope = uiExplorer.getTagScope(); String publicTagNodePath = nodeHierarchyCreator.getJcrPath(PUBLIC_TAG_NODE_PATH); List<Node> tags = (scope == NewFolksonomyService.PRIVATE) ? newFolksonomyService.getAllPrivateTags(WCMCoreUtils.getRemoteUser()) : newFolksonomyService.getAllPublicTags(publicTagNodePath, workspace); List<TagData> tagDataList = new ArrayList<TagData>(); List<String> tagPaths = new ArrayList<String>(); for (Node tag : tags) { tagDataList.add(new TagData(tag.getName())); tagPaths.add(tag.getPath()); } uiExplorer.getTagPaths().retainAll(tagPaths); ListAccess<TagData> tagList = new ListAccessImpl<TagData>(TagData.class, tagDataList); LazyPageList<TagData> dataPageList = new LazyPageList<TagData>(tagList, 10); getUIPageIterator().setPageList(dataPageList); } static public class TagData { private String tagName; public TagData(String tagName) { this.tagName = tagName; } public String getName() { return tagName; } } }
3,529
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIDocumentFormController.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UIDocumentFormController.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import java.security.AccessControlException; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.ResourceBundle; import java.util.TreeMap; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import org.exoplatform.ecm.webui.component.explorer.optionblocks.UIOptionBlockPanel; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.wcm.core.NodeLocation; import org.exoplatform.web.application.RequestContext; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.ext.UIExtension; import org.exoplatform.webui.ext.UIExtensionManager; /** * Created by The eXo Platform SARL * Author : Pham Tuan * phamtuanchip@yahoo.de * Nov 8, 2006 10:16:18 AM */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/UIDocumentFormController.gtmpl" ) public class UIDocumentFormController extends UIContainer implements UIPopupComponent { private static final Log LOG = ExoLogger.getLogger(UIDocumentFormController.class.getName()); private NodeLocation currentNode_ ; private String repository_ ; private String OPTION_BLOCK_EXTENSION_TYPE = "org.exoplatform.ecm.dms.UIOptionBlockPanel"; private List<UIComponent> listExtenstion = new ArrayList<UIComponent>(); private boolean isDisplayOptionPanel = false; public UIDocumentFormController() throws Exception { addChild(UISelectDocumentForm.class, null, null); UIDocumentForm uiDocumentForm = createUIComponent(UIDocumentForm.class, null, null) ; uiDocumentForm.addNew(true); uiDocumentForm.setShowActionsOnTop(true); addChild(uiDocumentForm); uiDocumentForm.setRendered(false); } public void setCurrentNode(Node node) { currentNode_ = NodeLocation.getNodeLocationByNode(node); } public void setRepository(String repository) { repository_ = repository; } public void initPopup(UIComponent uiComp) throws Exception { removeChildById("PopupComponent") ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, "PopupComponent") ; uiPopup.setShowMask(true); uiPopup.setUIComponent(uiComp) ; uiPopup.setWindowSize(640, 300) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public List<String> getListFileType() throws Exception { TemplateService templateService = getApplicationComponent(TemplateService.class) ; return templateService.getCreationableContentTypes(NodeLocation.getNodeByLocation(currentNode_)); } public void bindContentType() throws Exception { Comparator<String> ascComparator = new Comparator<String>() { @Override public int compare(String s1, String s2) { return s1.compareTo(s2) ; } }; Map<String, String> templates = new TreeMap <String, String>(ascComparator); TemplateService templateService = getApplicationComponent(TemplateService.class) ; List<String> acceptableContentTypes = templateService.getCreationableContentTypes(NodeLocation.getNodeByLocation(currentNode_)); if(acceptableContentTypes.size() == 0) return; String userName = Util.getPortalRequestContext().getRemoteUser(); for(String contentType: acceptableContentTypes) { try { String label = templateService.getTemplateLabel(contentType); String templatePath = templateService.getTemplatePathByUser(true, contentType, userName); if ((templatePath != null) && (templatePath.length() > 0)) { templates.put(label, contentType); } } catch (AccessControlException e) { if (LOG.isDebugEnabled()) { LOG.warn(userName + " do not have sufficient permission to access " + contentType + " template."); } } catch (PathNotFoundException e) { if (LOG.isWarnEnabled()) { LOG.warn("Node type template %s does not exist!", contentType); } } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn(e.getMessage()); } } } if(templates.size()>0) { UISelectDocumentForm uiSelectForm = getChild(UISelectDocumentForm.class) ; if (templates.size() > 1) { uiSelectForm.setDocumentTemplates(templates); } else { UIDocumentFormController uiDCFormController = uiSelectForm.getParent() ; UIDocumentForm documentForm = uiDCFormController.getChild(UIDocumentForm.class) ; documentForm.addNew(true); documentForm.getChildren().clear() ; documentForm.resetInterceptors(); documentForm.resetProperties(); documentForm.setContentType(templates.values().iterator().next()); documentForm.setCanChangeType(false); uiSelectForm.setRendered(false); documentForm.setRendered(true); } } } public void init() throws Exception { getChild(UIDocumentForm.class).setRepositoryName(repository_) ; getChild(UIDocumentForm.class).setWorkspace(currentNode_.getWorkspace()) ; getChild(UIDocumentForm.class).setStoredPath(currentNode_.getPath()) ; getChild(UIDocumentForm.class).resetProperties(); } public void activate() { } /** * Remove lock if node is locked for editing */ public void deActivate() { try { UIDocumentForm uiDocumentForm = getChild(UIDocumentForm.class); if (uiDocumentForm != null) { uiDocumentForm.releaseLock(); } } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } @SuppressWarnings("unchecked") @Override public <T extends UIComponent> T setRendered(boolean rendered) { UIComponent res = super.setRendered(rendered); if (rendered == false) { try { deActivate(); } catch (Exception ex) { if (LOG.isErrorEnabled()) { LOG.error("Unknown err:", ex); } } } return (T)res; } @Override public void processRender(WebuiRequestContext context) throws Exception { UIPopupWindow uiPopup = getAncestorOfType(UIPopupWindow.class); if (uiPopup != null && !uiPopup.isShow()) { uiPopup.setShowMask(true); deActivate(); } super.processRender(context); } /* * * This method get Option Block Panel extenstion and add it into this * * */ public void addOptionBlockPanel() throws Exception { UIExtensionManager manager = getApplicationComponent(UIExtensionManager.class); List<UIExtension> extensions = manager.getUIExtensions(OPTION_BLOCK_EXTENSION_TYPE); for (UIExtension extension : extensions) { UIComponent uicomp = manager.addUIExtension(extension, null, this); uicomp.setRendered(false); listExtenstion.add(uicomp); } } /* * This method checks and returns true if the Option Block Panel is configured to display, else it returns false * */ public boolean isHasOptionBlockPanel() { UIExtensionManager manager = getApplicationComponent(UIExtensionManager.class); List<UIExtension> extensions = manager.getUIExtensions(OPTION_BLOCK_EXTENSION_TYPE); if(extensions != null) { return true; } return false; } public void setDisplayOptionBlockPanel(boolean display) { for(UIComponent uicomp : listExtenstion) { uicomp.setRendered(display); } isDisplayOptionPanel = display; } public boolean isDisplayOptionBlockPanel() { return isDisplayOptionPanel; } public void initOptionBlockPanel() throws Exception { if(isHasOptionBlockPanel()) { addOptionBlockPanel(); UIOptionBlockPanel optionBlockPanel = this.getChild(UIOptionBlockPanel.class); if(optionBlockPanel.isHasOptionBlockExtension()) { optionBlockPanel.addOptionBlockExtension(); setDisplayOptionBlockPanel(true); } } } public String getClosingConfirmMsg(String key) { RequestContext context = RequestContext.getCurrentInstance(); ResourceBundle res = context.getApplicationResourceBundle(); return res.getString(key); } }
9,310
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIDocumentForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UIDocumentForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import org.apache.commons.lang3.StringUtils; import org.exoplatform.ecm.utils.lock.LockUtil; import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.ecm.webui.component.explorer.control.action.EditDocumentActionComponent; import org.exoplatform.ecm.webui.form.DialogFormActionListeners; import org.exoplatform.ecm.webui.form.UIDialogForm; import org.exoplatform.ecm.webui.selector.ComponentSelector; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.ecm.webui.tree.selectone.UIOneNodePathSelector; import org.exoplatform.ecm.webui.tree.selectone.UIOneTaxonomySelector; import org.exoplatform.ecm.webui.utils.DialogFormUtil; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.resolver.ResourceResolver; import org.exoplatform.services.cms.BasePath; import org.exoplatform.services.cms.CmsService; import org.exoplatform.services.cms.impl.DMSConfiguration; import org.exoplatform.services.cms.jcrext.activity.ActivityCommonService; import org.exoplatform.services.cms.taxonomy.TaxonomyService; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.jcr.ext.common.SessionProvider; import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator; import org.exoplatform.services.listener.ListenerService; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.wcm.core.NodetypeConstant; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.wcm.webui.reader.ContentReader; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.ComponentConfigs; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIFormInput; import org.exoplatform.webui.form.UIFormInputBase; import org.exoplatform.webui.form.UIFormMultiValueInputSet; import javax.jcr.AccessDeniedException; import javax.jcr.ItemExistsException; import javax.jcr.ItemNotFoundException; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.Value; import javax.jcr.nodetype.ConstraintViolationException; import javax.jcr.version.VersionException; import java.io.Writer; import java.security.AccessControlException; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * Created by The eXo Platform SARL * Author : nqhungvn * nguyenkequanghung@yahoo.com * July 3, 2006 * 10:07:15 AM * Editor : Pham Tuan * phamtuanchip@yahoo.de * Nov 08, 2006 */ @ComponentConfigs( { @ComponentConfig(type = UIFormMultiValueInputSet.class, id = "WYSIWYGRichTextMultipleInputset", events = { @EventConfig(listeners = UIDialogForm.AddActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIFormMultiValueInputSet.RemoveActionListener.class, phase = Phase.DECODE) }), @ComponentConfig(lifecycle = UIFormLifecycle.class, events = { @EventConfig(listeners = UIDocumentForm.SaveActionListener.class), @EventConfig(listeners = UIDocumentForm.SaveAndCloseActionListener.class), @EventConfig(listeners = UIDocumentForm.CloseActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDocumentForm.ChangeTypeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDocumentForm.AddActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDocumentForm.RemoveActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDocumentForm.ShowComponentActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDocumentForm.RemoveReferenceActionListener.class, confirm = "DialogFormField.msg.confirm-delete", phase = Phase.DECODE), @EventConfig(listeners = DialogFormActionListeners.RemoveDataActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = DialogFormActionListeners.ChangeTabActionListener.class, phase = Phase.DECODE) }) }) public class UIDocumentForm extends UIDialogForm implements UIPopupComponent, UISelectable { final static public String FIELD_TAXONOMY = "categories"; final static public String POPUP_TAXONOMY = "PopupComponent"; private List<String> listTaxonomyName = new ArrayList<String>(); private boolean canChangeType = true; private static final Log LOG = ExoLogger.getLogger(UIDocumentForm.class.getName()); public boolean isCanChangeType() { return canChangeType; } public void setCanChangeType(boolean canChangeType) { this.canChangeType = canChangeType; } public UIDocumentForm() throws Exception { setActions(new String[]{"Save", "SaveAndClose", "Close"}); } private String getChangeTypeActionLink () throws Exception { if (!isAddNew || !canChangeType) return ""; WebuiRequestContext context = WebuiRequestContext.getCurrentInstance(); ResourceBundle res = context.getApplicationResourceBundle(); String action = "ChangeType"; String strChangeTypeLabel = res.getString(getName() + ".action." + action); StringBuilder link = new StringBuilder(); link.append("<a onclick=\"") .append(event(action)) .append("\" class=\"changeTypeLink\">(") .append(strChangeTypeLabel) .append(")</a>"); return link.toString(); } public List<String> getlistTaxonomyName() { return listTaxonomyName; } public void setListTaxonomyName(List<String> listTaxonomyNameNew) { listTaxonomyName = listTaxonomyNameNew; } public void releaseLock() throws Exception { if (isEditing()) { super.releaseLock(); } } public String getDMSWorkspace() throws Exception { DMSConfiguration dmsConfig = getApplicationComponent(DMSConfiguration.class); return dmsConfig.getConfig().getSystemWorkspace(); } public Node getRootPathTaxonomy(Node node) throws Exception { try { TaxonomyService taxonomyService = getApplicationComponent(TaxonomyService.class); List<Node> allTaxonomyTrees = taxonomyService.getAllTaxonomyTrees(); for (Node taxonomyTree : allTaxonomyTrees) { if (node.getPath().startsWith(taxonomyTree.getPath())) return taxonomyTree; } return null; } catch (AccessDeniedException accessDeniedException) { return null; } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } UIApplication uiApp = getAncestorOfType(UIApplication.class); Object[] arg = { contentType }; uiApp.addMessage(new ApplicationMessage("UIDocumentForm.msg.not-support", arg, ApplicationMessage.ERROR)); return null; } } @SuppressWarnings("unchecked") public void doSelect(String selectField, Object value) throws Exception { isUpdateSelect = true; UIFormInput formInput = getUIInput(selectField); if(formInput instanceof UIFormInputBase) { ((UIFormInputBase)formInput).setValue(value.toString()); }else if(formInput instanceof UIFormMultiValueInputSet) { UIFormMultiValueInputSet inputSet = (UIFormMultiValueInputSet) formInput; String valueTaxonomy = String.valueOf(value).trim(); List<String> values = (List<String>) inputSet.getValue(); if (!getListTaxonomy().contains(valueTaxonomy)) { getListTaxonomy().add(valueTaxonomy); values.add(getCategoryLabel(valueTaxonomy)); } inputSet.setValue(values); } UIDocumentFormController uiContainer = getParent(); uiContainer.removeChildById(POPUP_TAXONOMY); } public String getTemplate() { TemplateService templateService = getApplicationComponent(TemplateService.class); String userName = Util.getPortalRequestContext().getRemoteUser(); try { if (contentType != null && contentType.length() > 0 && userName != null & userName.length() > 0) { return templateService.getTemplatePathByUser(true, contentType, userName); } return null; } catch (AccessControlException e) { if (LOG.isErrorEnabled()) { LOG.error("AccessControlException: user [" + userName + "] does not have access to the template for content type [" + contentType + "] in repository + [" + repositoryName + "]"); } return null; } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } UIApplication uiApp = getAncestorOfType(UIApplication.class); Object[] arg = { contentType }; uiApp.addMessage(new ApplicationMessage("UIDocumentForm.msg.not-support", arg, ApplicationMessage.ERROR)); return null; } } private String getTemplateLabel() throws Exception { TemplateService templateService = getApplicationComponent(TemplateService.class); return templateService.getTemplateLabel(contentType); } @Override public void processRender(WebuiRequestContext context) throws Exception { context.getJavascriptManager(). require("SHARED/uiDocumentForm", "uiDocumentForm"). addScripts("uiDocumentForm.UIDocForm.UpdateGUI();"). addScripts("uiDocumentForm.UIDocForm.AutoFocus();"); context.getJavascriptManager().loadScriptResource("wcm-webui-extension"); context.getJavascriptManager().addCustomizedOnLoadScript("changeWarning();"); super.processRender(context); } public void processRenderAction() throws Exception { WebuiRequestContext context = WebuiRequestContext.getCurrentInstance(); ResourceBundle res = context.getApplicationResourceBundle(); Writer writer = context.getWriter(); writer.append("<h5 class=\"title uiDialogAction clearfix\" >"); writer.append("<div class=\"dialogAction pull-right\">"); String[] listAction = getActions(); String contextID = "UIDocumentForm_" + System.currentTimeMillis(); String actionLabel; String link; int count = 0; for (String action : listAction) { String btn = (count++ == 0) ? "btn btn-primary" : "btn"; try { actionLabel = res.getString(getName() + ".action." + action); } catch (MissingResourceException e) { actionLabel = action; } link = event(action); writer.append("<button type=\"button\" ") .append("onclick=\"") .append(link) .append("\" class=\"" + btn +"\">") .append(actionLabel) .append("</button>"); } String fullscreen = res.getString(getName() + ".tooltip.FullScreen"); writer.append("<a class=\"actionIcon\" onclick='eXo.webui.UIDocForm.FullScreenToggle(this); return false;'><i ") .append("title=\"").append(fullscreen) .append("\" id=\"") .append(contextID) .append("\" class=\"uiIconEcmsExpand uiIconEcmsLightGray\"></i></a>"); writer.append("</div>"); writer.append("<span class='uiDialogTitle'>" + ContentReader.getXSSCompatibilityContent(getTemplateLabel()) + " " + getChangeTypeActionLink () + "</span>"); writer.append("</h5>"); context.getJavascriptManager().loadScriptResource("uiDocumentForm"); context.getJavascriptManager().addCustomizedOnLoadScript("eXo.webui.UIDocForm.initFullScreenStatus(\"" + contextID + "\");"); } @SuppressWarnings("unused") public ResourceResolver getTemplateResourceResolver(WebuiRequestContext context, String template) { return getAncestorOfType(UIJCRExplorer.class).getJCRTemplateResourceResolver(); } public void activate() {} public void deActivate() {} public Node getCurrentNode() throws Exception { return getAncestorOfType(UIJCRExplorer.class).getCurrentNode(); } public String getLastModifiedDate() throws Exception { return getLastModifiedDate(getCurrentNode()); } public synchronized void renderField(String name) throws Exception { if (FIELD_TAXONOMY.equals(name)) { if (!isAddNew && !isUpdateSelect) { TaxonomyService taxonomyService = getApplicationComponent(TaxonomyService.class); List<Node> listCategories = taxonomyService.getAllCategories(getNode()); Node taxonomyTree; for (Node itemNode : listCategories) { taxonomyTree = getRootPathTaxonomy(itemNode); if (taxonomyTree == null) continue; String categoryPath = itemNode.getPath().replaceAll(taxonomyTree.getPath(), ""); if (!getListTaxonomy().contains(taxonomyTree.getName() + categoryPath)) { if (!listTaxonomyName.contains(getCategoryLabel(taxonomyTree.getName() + categoryPath))) listTaxonomyName.add(getCategoryLabel(taxonomyTree.getName() + categoryPath)); getListTaxonomy().add(taxonomyTree.getName() + categoryPath); } } UIFormMultiValueInputSet uiSet = getChildById(FIELD_TAXONOMY); if (uiSet != null) uiSet.setValue(listTaxonomyName); } } super.renderField(name); } private synchronized List<String> getAddedListCategory(List<String> taxonomyList, List<String> existingList) { List<String> addedList = new ArrayList<String>(); for(String addedCategory : taxonomyList) { if(!existingList.contains(addedCategory)) addedList.add(addedCategory); } return addedList; } private synchronized List<String> getRemovedListCategory(List<String> taxonomyList, List<String> existingList) { List<String> removedList = new ArrayList<String>(); for(String existedCategory : existingList) { if(!taxonomyList.contains(existedCategory)) removedList.add(existedCategory); } return removedList; } public static Node saveDocument (Event <UIDocumentForm> event) throws Exception { UIDocumentForm documentForm = event.getSource(); UIJCRExplorer uiExplorer = documentForm.getAncestorOfType(UIJCRExplorer.class); List inputs = documentForm.getChildren(); UIApplication uiApp = documentForm.getAncestorOfType(UIApplication.class); boolean hasCategories = false; String categoriesPath = ""; TaxonomyService taxonomyService = documentForm.getApplicationComponent(TaxonomyService.class); Boolean hasTitle = false; for (int i = 0; i < inputs.size(); i++) { UIFormInput input = (UIFormInput) inputs.get(i); if ((input.getName() != null) && input.getName().equals("title")) { if(input.getValue() != null) { hasTitle = true; break; } } } if (documentForm.isAddNew() && hasTitle) { for (int i = 0; i < inputs.size(); i++) { UIFormInput input = (UIFormInput) inputs.get(i); if ((input.getName() != null) && input.getName().equals("name")) { String valueName = input.getValue().toString(); if (!Utils.isNameValid(valueName, Utils.SPECIALCHARACTER)) { uiApp.addMessage(new ApplicationMessage("UIFolderForm.msg.name-not-allowed", null, ApplicationMessage.WARNING)); return null; } } } } int index = 0; List<String> listTaxonomy = documentForm.getListTaxonomy(); if (documentForm.isReference) { UIFormMultiValueInputSet uiSet = documentForm.getChildById(FIELD_TAXONOMY); if((uiSet != null) && (uiSet.getName() != null) && uiSet.getName().equals(FIELD_TAXONOMY)) { hasCategories = true; listTaxonomy = (List<String>) uiSet.getValue(); for (String category : listTaxonomy) { categoriesPath = categoriesPath.concat(category).concat(","); } if (listTaxonomy != null && listTaxonomy.size() > 0) { try { for (String categoryPath : listTaxonomy) { index = categoryPath.indexOf("/"); if (index < 0) { taxonomyService.getTaxonomyTree(categoryPath); } else { taxonomyService.getTaxonomyTree(categoryPath.substring(0, index)) .getNode(categoryPath.substring(index + 1)); } } } catch (Exception e) { uiApp.addMessage(new ApplicationMessage("UISelectedCategoriesGrid.msg.non-categories", null, ApplicationMessage.WARNING)); return null; } } } } Map inputProperties = DialogFormUtil.prepareMap(inputs, documentForm.getInputProperties(), documentForm.getInputOptions()); Node newNode = null; String nodeType; Node homeNode; Node currentNode = uiExplorer.getCurrentNode(); if(documentForm.isAddNew()) { UIDocumentFormController uiDFController = documentForm.getParent(); homeNode = currentNode; nodeType = uiDFController.getChild(UIDocumentForm.class).getContentType(); if(homeNode.isLocked()) { homeNode.getSession().addLockToken(LockUtil.getLockToken(homeNode)); } } else { Node documentNode = documentForm.getNode(); for (String removedNode : documentForm.getRemovedNodes()) { documentNode.getNode(removedNode).remove(); } homeNode = currentNode; nodeType = documentNode.getPrimaryNodeType().getName(); if(documentNode.isLocked()) { String lockToken = LockUtil.getLockToken(documentNode); if(lockToken != null && !lockToken.isEmpty()) { documentNode.getSession().addLockToken(lockToken); } } } try { CmsService cmsService = documentForm.getApplicationComponent(CmsService.class); cmsService.getPreProperties().clear(); String addedPath = ""; if(documentForm.isAddNew()) { addedPath = cmsService.storeNode(nodeType, homeNode, inputProperties, true); } else { if(WCMCoreUtils.canAccessParentNode(currentNode)) { addedPath = cmsService.storeNode(nodeType, homeNode.getParent(), inputProperties, false); } else { addedPath = cmsService.storeEditedNode(nodeType, homeNode, inputProperties, documentForm.isAddNew()); } } try { newNode = (Node)currentNode.getSession().getItem(addedPath); //Broadcast the add file activity if(documentForm.isAddNew()) { ListenerService listenerService = WCMCoreUtils.getService(ListenerService.class); ActivityCommonService activityService = WCMCoreUtils.getService(ActivityCommonService.class); if (newNode.getPrimaryNodeType().getName().equals(NodetypeConstant.NT_FILE) && activityService.isBroadcastNTFileEvents(newNode)) { listenerService.broadcast(ActivityCommonService.FILE_CREATED_ACTIVITY, null, newNode); newNode.getSession().save(); } else if(activityService.isAcceptedNode(newNode)) { listenerService.broadcast(ActivityCommonService.NODE_CREATED_ACTIVITY, null, newNode); newNode.getSession().save(); } } if(newNode.isLocked()) { newNode.getSession().addLockToken(LockUtil.getLockToken(newNode)); } List<Node> listTaxonomyTrees = taxonomyService.getAllTaxonomyTrees(); List<Node> listExistedTaxonomy = taxonomyService.getAllCategories(newNode); List<String> listExistingTaxonomy = new ArrayList<String>(); for (Node existedTaxonomy : listExistedTaxonomy) { for (Node taxonomyTrees : listTaxonomyTrees) { if (existedTaxonomy.getPath().contains(taxonomyTrees.getPath())) { listExistingTaxonomy.add(taxonomyTrees.getName() + existedTaxonomy.getPath().substring(taxonomyTrees.getPath().length())); break; } } } if (WCMCoreUtils.canAccessParentNode(currentNode)) { if (hasCategories && !currentNode.getParent().isNodeType("exo:taxonomy")) { for (String removedCate : documentForm.getRemovedListCategory(listTaxonomy, listExistingTaxonomy)) { index = removedCate.indexOf("/"); if (index != -1) { taxonomyService.removeCategory(newNode, removedCate.substring(0, index), removedCate.substring(index + 1)); } else { taxonomyService.removeCategory(newNode, removedCate, ""); } } } } if (hasCategories && (newNode != null) && ((listTaxonomy != null) && (listTaxonomy.size() > 0))){ documentForm.releaseLock(); for(String categoryPath : documentForm.getAddedListCategory(listTaxonomy, listExistingTaxonomy)) { index = categoryPath.indexOf("/"); try { if (index != -1) { taxonomyService.addCategory(newNode, categoryPath.substring(0, index), categoryPath.substring(index + 1)); } else { taxonomyService.addCategory(newNode, categoryPath, ""); } } catch(AccessDeniedException accessDeniedException) { uiApp.addMessage(new ApplicationMessage("AccessControlException.msg", null, ApplicationMessage.WARNING)); } catch (Exception e) { continue; } } } else { List<Value> vals = new ArrayList<Value>(); if (newNode.hasProperty("exo:category")) newNode.setProperty("exo:category", vals.toArray(new Value[vals.size()])); newNode.save(); } uiExplorer.setCurrentPath(newNode.getPath()); uiExplorer.setWorkspaceName(newNode.getSession().getWorkspace().getName()); uiExplorer.refreshExplorer(newNode, true); uiExplorer.updateAjax(event); return newNode; } catch(Exception e) { currentNode.refresh(false); uiExplorer.updateAjax(event); } currentNode.save(); uiExplorer.updateAjax(event); } catch (AccessControlException ace) { throw new AccessDeniedException(ace.getMessage()); } catch(VersionException ve) { uiApp.addMessage(new ApplicationMessage("UIDocumentForm.msg.in-versioning", null, ApplicationMessage.WARNING)); return null; } catch(ItemNotFoundException item) { uiApp.addMessage(new ApplicationMessage("UIDocumentForm.msg.item-not-found", null, ApplicationMessage.WARNING)); return null; } catch(AccessDeniedException accessDeniedException) { uiApp.addMessage(new ApplicationMessage("UIDocumentForm.msg.repository-exception-permission", null, ApplicationMessage.WARNING)); return null; } catch(ItemExistsException existedex) { uiApp.addMessage(new ApplicationMessage("UIDocumentForm.msg.not-allowed-same-name-sibling", null, ApplicationMessage.WARNING)); return null; } catch(ConstraintViolationException constraintViolationException) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error occurrs", constraintViolationException); } uiApp.addMessage(new ApplicationMessage("UIDocumentForm.msg.constraintviolation-exception", null, ApplicationMessage.WARNING)); return null; } catch(RepositoryException repo) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error occurrs", repo); } uiApp.addMessage(new ApplicationMessage("UIDocumentForm.msg.repository-exception", null, ApplicationMessage.WARNING)); return null; } catch(NumberFormatException nume) { String key = "UIDocumentForm.msg.numberformat-exception"; uiApp.addMessage(new ApplicationMessage(key, null, ApplicationMessage.WARNING)); return null; } catch(Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error occurs", e); } String key = "UIDocumentForm.msg.cannot-save"; uiApp.addMessage(new ApplicationMessage(key, null, ApplicationMessage.WARNING)); return null; } finally { documentForm.releaseLock(); } return null; } public static void closeForm (Event<UIDocumentForm> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); if(uiExplorer != null) { UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class); event.getSource().releaseLock(); if (uiDocumentWorkspace.getChild(UIDocumentFormController.class) != null) { uiDocumentWorkspace.removeChild(UIDocumentFormController.class); } else uiExplorer.cancelAction(); uiExplorer.updateAjax(event); } } static public class SaveActionListener extends EventListener<UIDocumentForm> { public void execute(Event<UIDocumentForm> event) throws Exception { UIDocumentForm documentForm = event.getSource(); synchronized (documentForm) { UIJCRExplorer uiExplorer = documentForm.getAncestorOfType(UIJCRExplorer.class); UIApplication uiApp = documentForm.getAncestorOfType(UIApplication.class); Node newNode = UIDocumentForm.saveDocument(event); if (newNode != null) { event.getRequestContext().setAttribute("nodePath",newNode.getPath()); UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class); uiDocumentWorkspace.removeChild(UIDocumentFormController.class); documentForm.setIsUpdateSelect(false); EditDocumentActionComponent.editDocument(event, null, uiExplorer, uiExplorer, uiExplorer.getCurrentNode(), uiApp); } } } } static public class ShowComponentActionListener extends EventListener<UIDocumentForm> { public void execute(Event<UIDocumentForm> event) throws Exception { UIDocumentForm uiForm = event.getSource(); UIDocumentFormController uiContainer = uiForm.getParent(); uiForm.isShowingComponent = true; String fieldName = event.getRequestContext().getRequestParameter(OBJECTID); Map fieldPropertiesMap = uiForm.componentSelectors.get(fieldName); String classPath = (String)fieldPropertiesMap.get("selectorClass"); ClassLoader cl = Thread.currentThread().getContextClassLoader(); Class clazz = Class.forName(classPath, true, cl); String rootPath = (String)fieldPropertiesMap.get("rootPath"); UIComponent uiComp = uiContainer.createUIComponent(clazz, null, null); String selectorParams = (String)fieldPropertiesMap.get("selectorParams"); UIJCRExplorer explorer = uiForm.getAncestorOfType(UIJCRExplorer.class); if (uiComp instanceof UIOneNodePathSelector) { String repositoryName = explorer.getRepositoryName(); SessionProvider provider = explorer.getSessionProvider(); String wsFieldName = (String) fieldPropertiesMap.get("workspaceField"); String wsName = ""; if (wsFieldName != null && wsFieldName.length() > 0) { if (uiForm.<UIFormInputBase> getUIInput(wsFieldName) != null) { wsName = (String) uiForm.<UIFormInputBase> getUIInput(wsFieldName).getValue(); ((UIOneNodePathSelector) uiComp).setIsDisable(wsName, true); } else { wsName = explorer.getCurrentWorkspace(); ((UIOneNodePathSelector) uiComp).setIsDisable(wsName, false); } } if (selectorParams != null) { String[] arrParams = selectorParams.split(","); if (arrParams.length == 4) { ((UIOneNodePathSelector) uiComp).setAcceptedNodeTypesInPathPanel(new String[] { Utils.NT_FILE, Utils.NT_FOLDER, Utils.NT_UNSTRUCTURED, Utils.EXO_TAXONOMY }); wsName = arrParams[1]; rootPath = arrParams[2]; ((UIOneNodePathSelector) uiComp).setIsDisable(wsName, true); if (arrParams[3].indexOf(";") > -1) { ((UIOneNodePathSelector) uiComp).setAcceptedMimeTypes(arrParams[3].split(";")); } else { ((UIOneNodePathSelector) uiComp).setAcceptedMimeTypes(new String[] { arrParams[3] }); } } } if (rootPath == null) rootPath = "/"; ((UIOneNodePathSelector) uiComp).setRootNodeLocation(repositoryName, wsName, rootPath); ((UIOneNodePathSelector) uiComp).setShowRootPathSelect(true); ((UIOneNodePathSelector) uiComp).init(provider); } else if (uiComp instanceof UIOneTaxonomySelector) { NodeHierarchyCreator nodeHierarchyCreator = uiForm.getApplicationComponent(NodeHierarchyCreator.class); String workspaceName = uiForm.getDMSWorkspace(); ((UIOneTaxonomySelector) uiComp).setIsDisable(workspaceName, false); String rootTreePath = nodeHierarchyCreator.getJcrPath(BasePath.TAXONOMIES_TREE_STORAGE_PATH); Session session = explorer.getSessionByWorkspace(workspaceName); Node rootTree = (Node) session.getItem(rootTreePath); NodeIterator childrenIterator = rootTree.getNodes(); while (childrenIterator.hasNext()) { Node childNode = childrenIterator.nextNode(); rootTreePath = childNode.getPath(); break; } ((UIOneTaxonomySelector) uiComp).setRootNodeLocation(uiForm.repositoryName, workspaceName, rootTreePath); ((UIOneTaxonomySelector) uiComp).init(WCMCoreUtils.getSystemSessionProvider()); } uiContainer.initPopup(uiComp); String param = "returnField=" + fieldName; String[] params = selectorParams == null ? new String[] { param } : new String[] { param, "selectorParams=" + selectorParams }; ((ComponentSelector) uiComp).setSourceComponent(uiForm, params); event.getRequestContext().addUIComponentToUpdateByAjax(uiContainer); } } static public class RemoveReferenceActionListener extends EventListener<UIDocumentForm> { public void execute(Event<UIDocumentForm> event) throws Exception { UIDocumentForm uiForm = event.getSource(); uiForm.isRemovePreference = true; String fieldName = event.getRequestContext().getRequestParameter(OBJECTID); uiForm.getUIStringInput(fieldName).setValue(null); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class CloseActionListener extends EventListener<UIDocumentForm> { public void execute(Event<UIDocumentForm> event) throws Exception { UIDocumentForm.closeForm(event); } } static public class ChangeTypeActionListener extends EventListener<UIDocumentForm> { public void execute(Event<UIDocumentForm> event) throws Exception { UIDocumentForm uiDocumentForm = event.getSource(); UIDocumentFormController uiDCFormController = uiDocumentForm.getParent(); UISelectDocumentForm uiSelectForm = uiDCFormController.getChild(UISelectDocumentForm.class); uiSelectForm.setRendered(true); uiDocumentForm.setRendered(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiDCFormController); } } static public class SaveAndCloseActionListener extends EventListener<UIDocumentForm> { public void execute(Event<UIDocumentForm> event) throws Exception { Node newNode = UIDocumentForm.saveDocument(event); if (newNode != null) { event.getRequestContext().setAttribute("nodePath",newNode.getPath()); } UIDocumentForm.closeForm(event); } } static public class AddActionListener extends EventListener<UIDocumentForm> { public void execute(Event<UIDocumentForm> event) throws Exception { UIDocumentForm uiDocumentForm = event.getSource(); UIDocumentFormController uiFormController = uiDocumentForm.getParent(); String clickedField = event.getRequestContext().getRequestParameter(OBJECTID); if (uiDocumentForm.isReference) { uiDocumentForm.setIsUpdateSelect(true); UIApplication uiApp = uiDocumentForm.getAncestorOfType(UIApplication.class); try { UIFormMultiValueInputSet uiSet = uiDocumentForm.getChildById(FIELD_TAXONOMY); if((uiSet != null) && (uiSet.getName() != null) && uiSet.getName().equals(FIELD_TAXONOMY)) { if ((clickedField != null) && (clickedField.equals(FIELD_TAXONOMY))){ UIJCRExplorer uiExplorer = uiDocumentForm.getAncestorOfType(UIJCRExplorer.class); String repository = uiExplorer.getRepositoryName(); if(uiSet.getValue().size() == 0) uiSet.setValue(new ArrayList<Value>()); UIOneTaxonomySelector uiOneTaxonomySelector = uiFormController.createUIComponent(UIOneTaxonomySelector.class, null, null); TaxonomyService taxonomyService = uiDocumentForm.getApplicationComponent(TaxonomyService.class); List<Node> lstTaxonomyTree = taxonomyService.getAllTaxonomyTrees(); if (lstTaxonomyTree.size() == 0) throw new AccessDeniedException(); String workspaceName = lstTaxonomyTree.get(0).getSession().getWorkspace().getName(); uiOneTaxonomySelector.setIsDisable(workspaceName, false); uiOneTaxonomySelector.setRootNodeLocation(repository, workspaceName, lstTaxonomyTree.get(0).getPath()); uiOneTaxonomySelector.setExceptedNodeTypesInPathPanel(new String[] {Utils.EXO_SYMLINK}); uiOneTaxonomySelector.init(uiExplorer.getSystemProvider()); String param = "returnField=" + FIELD_TAXONOMY; uiOneTaxonomySelector.setSourceComponent(uiDocumentForm, new String[]{param}); UIPopupWindow uiPopupWindow = uiFormController.getChildById(POPUP_TAXONOMY); if (uiPopupWindow == null) { uiPopupWindow = uiFormController.addChild(UIPopupWindow.class, null, POPUP_TAXONOMY); } uiPopupWindow.setWindowSize(700, 450); uiPopupWindow.setUIComponent(uiOneTaxonomySelector); uiPopupWindow.setRendered(true); uiPopupWindow.setShow(true); } } event.getRequestContext().addUIComponentToUpdateByAjax(uiFormController); } catch (AccessDeniedException accessDeniedException) { uiApp.addMessage(new ApplicationMessage("Taxonomy.msg.AccessDeniedException", null, ApplicationMessage.WARNING)); return; } catch (Exception e) { JCRExceptionManager.process(uiApp, e); return; } } else { event.getRequestContext().addUIComponentToUpdateByAjax(uiDocumentForm.getParent()); } } } static public class RemoveActionListener extends EventListener<UIDocumentForm> { public void execute(Event<UIDocumentForm> event) throws Exception { UIDocumentForm uiDocumentForm = event.getSource(); String objectid = event.getRequestContext().getRequestParameter(OBJECTID); String idx = objectid.replaceAll(FIELD_TAXONOMY,""); try { int idxInput = Integer.parseInt(idx); uiDocumentForm.getListTaxonomy().remove(idxInput); uiDocumentForm.getlistTaxonomyName().remove(idxInput); uiDocumentForm.setIsUpdateSelect(true); } catch (NumberFormatException ne) { if (LOG.isWarnEnabled()) { LOG.warn(ne.getMessage()); } } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn(e.getMessage()); } } event.getRequestContext().addUIComponentToUpdateByAjax(uiDocumentForm); } } }
38,501
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UISelectDocumentForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UISelectDocumentForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPageIterator; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Pham Tuan * phamtuanchip@yahoo.de * Nov 8, 2006 10:06:40 AM */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/UISelectDocumentFormThumbnailView.gtmpl", events = { @EventConfig(listeners = UISelectDocumentForm.SelectTemplateActionListener.class) } ) public class UISelectDocumentForm extends UIContainer { private final static String DOCUMENT_TEMPLATE_ITERATOR_ID = "DocumentTemplateIterator"; private String uiComponentTemplate; private Map<String, String> documentTemplates = new HashMap<String, String>(); private String repository; private UIPageIterator pageIterator; public UISelectDocumentForm() throws Exception { pageIterator = addChild(UIPageIterator.class, null, DOCUMENT_TEMPLATE_ITERATOR_ID); } public Map<String, String> getDocumentTemplates() { return documentTemplates; } public void setDocumentTemplates(Map<String, String> templates) { this.documentTemplates = templates; } public void updatePageListData() throws Exception { List<String> templateList = new ArrayList<String>(); Iterator<String> iter = getDocumentTemplates().keySet().iterator(); while (iter.hasNext()) { String key = iter.next(); templateList.add(key); } ListAccess<String> nodeAccList = new ListAccessImpl<String>(String.class, templateList); UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); int nodesPerPage = uiExplorer.getPreference().getNodesPerPage(); pageIterator.setPageList(new LazyPageList<String>(nodeAccList, nodesPerPage)); } public String getContentType (String label) { return getDocumentTemplates().get(label); } public String getTemplateIconStylesheet(String contentType) { return contentType.replace(":", "_"); } public List<?> getChildrenList() throws Exception { return pageIterator.getCurrentPageData(); } public String getRepository() { return repository; } public void setRepository(String repository) { this.repository = repository; } public UIPageIterator getContentPageIterator() { return pageIterator; } public String getTemplate() { return uiComponentTemplate != null ? uiComponentTemplate : super.getTemplate(); } public void setTemplate(String template) { this.uiComponentTemplate = template; } static public class SelectTemplateActionListener extends EventListener<UISelectDocumentForm> { public void execute(Event<UISelectDocumentForm> event) throws Exception { String contentType = event.getRequestContext().getRequestParameter(OBJECTID); UISelectDocumentForm uiSelectForm = event.getSource() ; UIDocumentFormController uiDCFormController = uiSelectForm.getParent() ; UIDocumentForm documentForm = uiDCFormController.getChild(UIDocumentForm.class) ; documentForm.addNew(true); documentForm.getChildren().clear() ; documentForm.resetInterceptors(); documentForm.resetProperties(); documentForm.setContentType(contentType); uiSelectForm.setRendered(false); documentForm.setRendered(true); event.getRequestContext().addUIComponentToUpdateByAjax(uiDCFormController.getAncestorOfType(UIWorkingArea.class)); } } }
4,821
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIResourceForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UIResourceForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import java.io.InputStream; import javax.jcr.Node; import javax.jcr.Property; import javax.jcr.RepositoryException; import javax.jcr.Session; import org.exoplatform.ecm.webui.component.explorer.UIDocumentInfo; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.services.wcm.core.NodeLocation; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.UIFormTextAreaInput; import org.exoplatform.webui.form.input.UIUploadInput; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * September 7, 2006 * 14:42:15 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, type = UIResourceForm.class, template = "system:/groovy/webui/form/UIFormWithTitle.gtmpl", events = { @EventConfig(listeners = UIResourceForm.SaveActionListener.class), @EventConfig(listeners = UIResourceForm.BackActionListener.class) } ) public class UIResourceForm extends UIForm { final static public String FIElD_NAME = "name" ; final static public String FIElD_TEXTTOMODIFY = "textToModify" ; final static public String FIElD_FILETOUPLOAD = "fileToUpload" ; private NodeLocation contentNode_ ; private boolean isText_; private Session session_ ; public UIResourceForm() throws Exception { setMultiPart(true) ; addUIFormInput(new UIFormStringInput(FIElD_NAME, FIElD_NAME, null)) ; } public void setContentNode(Node node, Session session) throws RepositoryException { session_ = session ; contentNode_ = NodeLocation.getNodeLocationByNode(node); isText_ = node.getProperty("jcr:mimeType").getString().startsWith("text"); String name = node.getParent().getName() ; getUIStringInput(FIElD_NAME).setValue(name) ; if(isText_) { String contentText = node.getProperty("jcr:data").getString() ; addUIFormInput(new UIFormTextAreaInput(FIElD_TEXTTOMODIFY, FIElD_TEXTTOMODIFY, contentText)) ; }else { getUIStringInput(FIElD_NAME).setReadOnly(true); UIUploadInput uiInput = new UIUploadInput(FIElD_FILETOUPLOAD, FIElD_FILETOUPLOAD); addUIFormInput(uiInput) ; } } public boolean isText() throws RepositoryException { return isText_; } static public class SaveActionListener extends EventListener<UIResourceForm> { public void execute(Event<UIResourceForm> event) throws Exception { UIResourceForm uiResourceForm = event.getSource() ; Node contentNode = NodeLocation.getNodeByLocation(uiResourceForm.contentNode_); Property prop = contentNode.getProperty("jcr:mimeType") ; UIJCRExplorer uiJCRExplorer = uiResourceForm.getAncestorOfType(UIJCRExplorer.class) ; if(prop.getString().startsWith("text")) { String text = uiResourceForm.getUIFormTextAreaInput(FIElD_TEXTTOMODIFY).getValue() ; contentNode.setProperty("jcr:data", text) ; }else { UIUploadInput fileUpload = (UIUploadInput)uiResourceForm.getUIInput(FIElD_FILETOUPLOAD) ; InputStream content = fileUpload.getUploadDataAsStream(fileUpload.getUploadIds()[0]); contentNode.setProperty("jcr:data", content) ; } if(uiResourceForm.session_ != null) uiResourceForm.session_.save() ; else uiJCRExplorer.getSession().save() ; uiResourceForm.setRenderSibling(UIDocumentInfo.class); } } static public class BackActionListener extends EventListener<UIResourceForm> { public void execute(Event<UIResourceForm> event) throws Exception { UIResourceForm uiResourceForm = event.getSource() ; uiResourceForm.setRenderSibling(UIDocumentInfo.class) ; } } }
4,746
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIVoteForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UIVoteForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import javax.jcr.Node; import org.apache.commons.lang3.StringUtils; import org.exoplatform.ecm.webui.component.explorer.UIDocumentInfo; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.cms.voting.VotingService; import org.exoplatform.services.security.ConversationState; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Tran The Trong * trongtt@gmail.com * Jan 30, 2006 * 10:45:01 AM */ @ComponentConfig( template = "app:/groovy/webui/component/UIVoteForm.gtmpl", events = { @EventConfig(listeners = UIVoteForm.VoteActionListener.class), @EventConfig(listeners = UIVoteForm.CancelActionListener.class) } ) public class UIVoteForm extends UIComponent implements UIPopupComponent { public UIVoteForm() throws Exception {} public void activate() {} public void deActivate() {} public double getRating() throws Exception { VotingService votingService = WCMCoreUtils.getService(VotingService.class); UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); UIDocumentInfo uiDocInfo = uiExplorer.findFirstComponentOfType(UIDocumentInfo.class); String currentUser = ConversationState.getCurrent().getIdentity().getUserId(); return votingService.getVoteValueOfUser(uiExplorer.getCurrentNode(), currentUser, uiDocInfo.getLanguage()); } public String getCurrentRatingResourceKey() throws Exception { String voteKey = StringUtils.EMPTY; int voteValue = (int)getRating(); switch (voteValue) { case 1: voteKey = "UIVoteForm.title.normal"; break; case 2: voteKey = "UIVoteForm.title.good"; break; case 3: voteKey = "UIVoteForm.title.verygood"; break; case 4: voteKey = "UIVoteForm.title.excellent"; break; case 5: voteKey = "UIVoteForm.title.best"; break; default: voteKey = "UIVoteForm.title.no-value"; break; } return voteKey; } static public class VoteActionListener extends EventListener<UIVoteForm> { public void execute(Event<UIVoteForm> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class) ; String userName = Util.getPortalRequestContext().getRemoteUser() ; UIDocumentInfo uiDocumentInfo = uiExplorer.findFirstComponentOfType(UIDocumentInfo.class) ; Node currentNode = uiExplorer.getCurrentNode(); uiExplorer.addLockToken(currentNode); String language = uiDocumentInfo.getLanguage() ; double objId = Double.parseDouble(event.getRequestContext().getRequestParameter(OBJECTID)) ; VotingService votingService = uiExplorer.getApplicationComponent(VotingService.class) ; votingService.vote(uiExplorer.getCurrentNode(), objId, userName, language) ; event.getSource().getAncestorOfType(UIPopupContainer.class).cancelPopupAction() ; uiExplorer.updateAjax(event) ; } } static public class CancelActionListener extends EventListener<UIVoteForm> { public void execute(Event<UIVoteForm> event) throws Exception { event.getSource().getAncestorOfType(UIPopupContainer.class).cancelPopupAction() ; } } }
4,577
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UISelectRestorePath.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/actions/UISelectRestorePath.java
/* * Copyright (C) 2003-2008 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.actions; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.lock.LockException; import javax.jcr.nodetype.ConstraintViolationException; import javax.jcr.version.VersionException; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.ecm.webui.tree.selectone.UIOneNodePathSelector; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.documents.TrashService; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.wcm.core.NodeLocation; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormInputSet; import org.exoplatform.webui.form.UIFormStringInput; /** * Created by The eXo Platform SARL * Author : Nguyen Anh Vu * anhvurz90@gmail.com * Mar 4, 2010 * 3:33:41 PM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UISelectRestorePath.SaveActionListener.class), @EventConfig(listeners = UISelectRestorePath.AddActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UISelectRestorePath.CancelActionListener.class, phase = Phase.DECODE) } ) public class UISelectRestorePath extends UIForm implements UIPopupComponent, UISelectable { final static public String FIELD_PATH = "PathNode"; final static public String FORM_INPUT = "formInput"; final static public String POPUP_PATH = "UIPopupPathFoRestore"; final static public String FORM_MESSAGE = "UIFormMessage"; final static public String CHOOSE_PATH_TO_RESTORE_NODE = "ChooseTagToRestoreNode"; private final static Log LOG = ExoLogger.getLogger(UISelectRestorePath.class.getName()); private NodeLocation trashHomeNode; private String repository; private String srcPath; public Node getTrashHomeNode() { return NodeLocation.getNodeByLocation(trashHomeNode); } public void setTrashHomeNode(Node trashHomeNode) { this.trashHomeNode = NodeLocation.getNodeLocationByNode(trashHomeNode); } public String getRepository() { return repository; } public void setRepository(String repository) { this.repository = repository; } public String getSrcPath() { return srcPath; } public void setSrcPath(String srcPath) { this.srcPath = srcPath; } public void activate() { try { UIFormInputSet uiFormInputAction = new UIFormInputSetWithAction("UIFormInputSetWithAction"); UIFormStringInput homePathField = new UIFormStringInput(FORM_INPUT, FORM_INPUT, null); homePathField.setValue(""); homePathField.setReadOnly(true); uiFormInputAction.addUIFormInput(homePathField); uiFormInputAction.setId(FIELD_PATH); ((UIFormInputSetWithAction)uiFormInputAction).setActionInfo(FORM_INPUT, new String[]{"Add"}); this.addUIFormInput(uiFormInputAction); setActions(new String[] {"Save", "Cancel"}); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } public void deActivate() { } public void doSelect(String selectField, Object value) throws Exception { String valueNodeName = String.valueOf(value).trim(); UIFormInputSetWithAction uiFormInputAction = getChild(UIFormInputSetWithAction.class); uiFormInputAction.getChild(UIFormStringInput.class).setValue(valueNodeName); this.getAncestorOfType(UIPopupContainer.class).removeChildById(POPUP_PATH); } static public class CancelActionListener extends EventListener<UISelectRestorePath> { public void execute(Event<UISelectRestorePath> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); uiExplorer.cancelAction(); } } static public class AddActionListener extends EventListener<UISelectRestorePath> { public void execute(Event<UISelectRestorePath> event) throws Exception { UISelectRestorePath uiSelectRestorePath = event.getSource(); UIPopupContainer uiPopupContainer = uiSelectRestorePath.getAncestorOfType(UIPopupContainer.class); UIJCRExplorer uiExplorer = uiSelectRestorePath.getAncestorOfType(UIJCRExplorer.class); String workspaceName = uiExplorer.getCurrentWorkspace(); UIPopupWindow uiPopupWindow = initPopup(uiPopupContainer, POPUP_PATH); UIOneNodePathSelector uiNodePathSelector = uiPopupContainer.createUIComponent(UIOneNodePathSelector.class, null, null); uiNodePathSelector.setIsDisable(workspaceName, false); uiNodePathSelector.setShowRootPathSelect(true); uiNodePathSelector.setRootNodeLocation(uiExplorer.getRepositoryName(), workspaceName, "/"); uiNodePathSelector.setAcceptedNodeTypesInPathPanel(new String[] {Utils.NT_UNSTRUCTURED, Utils.NT_FOLDER}) ; uiNodePathSelector.setAcceptedNodeTypesInTree(new String[] {Utils.NT_UNSTRUCTURED, Utils.NT_FOLDER}); uiNodePathSelector.setExceptedNodeTypesInPathPanel(new String[] {Utils.EXO_TRASH_FOLDER}); uiNodePathSelector.setExceptedNodeTypesInTree(new String[] {Utils.EXO_TRASH_FOLDER}); if(WCMCoreUtils.isAnonim()) { uiNodePathSelector.init(WCMCoreUtils.createAnonimProvider()) ; } else if(workspaceName.equals(getSystemWorkspaceName(uiExplorer))){ uiNodePathSelector.init(WCMCoreUtils.getSystemSessionProvider()) ; } else { uiNodePathSelector.init(WCMCoreUtils.getUserSessionProvider()) ; } String param = "returnField=" + FIELD_PATH; uiNodePathSelector.setSourceComponent(uiSelectRestorePath, new String[]{param}); uiPopupWindow.setUIComponent(uiNodePathSelector); //uiPopupWindow.setRendered(true); uiPopupWindow.setShow(true); event.getRequestContext().addUIComponentToUpdateByAjax(uiPopupContainer); } private String getSystemWorkspaceName(UIJCRExplorer uiExplorer) throws RepositoryException { RepositoryService repositoryService = uiExplorer.getApplicationComponent(RepositoryService.class); return repositoryService.getCurrentRepository().getConfiguration().getSystemWorkspaceName(); } private UIPopupWindow initPopup(UIPopupContainer uiPopupContainer, String id) throws Exception { UIPopupWindow uiPopup = uiPopupContainer.getChildById(id); if (uiPopup == null) { uiPopup = uiPopupContainer.addChild(UIPopupWindow.class, null, id); } uiPopup.setWindowSize(700, 350); uiPopup.setShow(false); uiPopup.setResizable(true); return uiPopup; } } static public class SaveActionListener extends EventListener<UISelectRestorePath> { public void execute(Event<UISelectRestorePath> event) throws Exception { UISelectRestorePath uiSelectRestorePath = event.getSource(); UIJCRExplorer uiExplorer = uiSelectRestorePath.getAncestorOfType(UIJCRExplorer.class); UIApplication uiApp = uiSelectRestorePath.getAncestorOfType(UIApplication.class); String fullRestorePath = uiSelectRestorePath. getChild(UIFormInputSetWithAction.class). getChild(UIFormStringInput.class).getValue(); int colonIndex = fullRestorePath.indexOf(':'); if (colonIndex == -1) return; String restoreWorkspace = fullRestorePath.substring(0, colonIndex); String restorePath = fullRestorePath.substring(colonIndex + 1); Node trashNode = (Node) uiSelectRestorePath.getTrashHomeNode() .getSession() .getItem(uiSelectRestorePath.getSrcPath()); trashNode.setProperty(TrashService.RESTORE_WORKSPACE, restoreWorkspace); trashNode.setProperty(TrashService.RESTORE_PATH, restorePath + (restorePath.endsWith("/") ? "" : '/') + trashNode.getName()); TrashService trashService = uiSelectRestorePath.getApplicationComponent(TrashService.class); try { trashService.restoreFromTrash(uiSelectRestorePath.getSrcPath(), uiExplorer.getSessionProvider()); UIPopupContainer uiPopupContainer = uiExplorer.getChild(UIPopupContainer.class); uiPopupContainer.removeChild(UISelectRestorePath.class); uiExplorer.updateAjax(event); } catch (PathNotFoundException e) { if (LOG.isErrorEnabled()) { LOG.error("Path not found! Maybe, it was removed or path changed, can't restore node :" + trashNode.getPath()); } JCRExceptionManager.process(uiApp, e); } catch (LockException e) { if (LOG.isErrorEnabled()) { LOG.error("node is locked, can't restore node :" + trashNode.getPath()); } JCRExceptionManager.process(uiApp, e); } catch (VersionException e) { if (LOG.isErrorEnabled()) { LOG.error("node is checked in, can't restore node:" + trashNode.getPath()); } JCRExceptionManager.process(uiApp, e); } catch (AccessDeniedException e) { if (LOG.isErrorEnabled()) { LOG.error("access denied, can't restore of node:" + trashNode.getPath()); } JCRExceptionManager.process(uiApp, e); } catch (ConstraintViolationException e) { if (LOG.isErrorEnabled()) { LOG.error("access denied, can't restore of node:" + trashNode.getPath()); } JCRExceptionManager.process(uiApp, e); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("an unexpected error occurs", e); } JCRExceptionManager.process(uiApp, e); } } } }
11,746
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIActionViewTemplate.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIActionViewTemplate.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import javax.jcr.Node; import org.exoplatform.container.xml.PortalContainerInfo; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.resolver.ResourceResolver; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.wcm.core.NodeLocation; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIContainer; /** * Created by The eXo Platform SARL * Author : Pham Tuan * phamtuanchip@yahoo.de * Nov 15, 2006 10:08:29 AM */ @ComponentConfig() public class UIActionViewTemplate extends UIContainer { private String documentType_ ; private NodeLocation node_ ; public void setTemplateNode(Node node) throws Exception { node_ = NodeLocation.getNodeLocationByNode(node); documentType_ = node.getPrimaryNodeType().getName() ; } public String getViewTemplatePath(){ TemplateService templateService = getApplicationComponent(TemplateService.class) ; String userName = Util.getPortalRequestContext().getRemoteUser() ; try { return templateService.getTemplatePathByUser(false, documentType_, userName) ; } catch (Exception e) { return null ; } } public String getPortalName() { PortalContainerInfo containerInfo = WCMCoreUtils.getService(PortalContainerInfo.class) ; return containerInfo.getContainerName() ; } public String getWorkspaceName() throws Exception { return NodeLocation.getNodeByLocation(node_).getSession().getWorkspace().getName() ; } public String getTemplate() { return getViewTemplatePath() ;} public ResourceResolver getTemplateResourceResolver(WebuiRequestContext context, String template) { return getAncestorOfType(UIJCRExplorer.class).getJCRTemplateResourceResolver() ; } public Node getNode() { return NodeLocation.getNodeByLocation(node_); } }
2,910
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIActionContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIActionContainer.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Nov 8, 2006 * 11:22:07 AM */ @ComponentConfig( lifecycle = UIContainerLifecycle.class ) public class UIActionContainer extends UIContainer implements UIPopupComponent { public UIActionContainer() throws Exception { addChild(UIActionTypeForm.class, null, null) ; addChild(UIActionForm.class, null, null) ; } public void activate() { } public void deActivate() { } public void initPopup(UIComponent uiComp) throws Exception { removeChildById("PopupComponent") ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, "PopupComponent") ; uiPopup.setShowMask(true); uiPopup.setUIComponent(uiComp) ; uiPopup.setWindowSize(640, 300) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } }
1,992
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIActivePublication.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIActivePublication.java
/* * Copyright (C) 2003-2008 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import java.util.ArrayList; import java.util.Collection; import java.util.List; import javax.jcr.Node; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.core.UIPagingGrid; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.ecm.publication.AlreadyInPublicationLifecycleException; import org.exoplatform.services.ecm.publication.PublicationPlugin; import org.exoplatform.services.ecm.publication.PublicationPresentationService; import org.exoplatform.services.ecm.publication.PublicationService; import org.exoplatform.services.ecm.publication.plugins.webui.UIPublicationLogList; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.wcm.extensions.publication.lifecycle.authoring.AuthoringPublicationConstant; import org.exoplatform.services.wcm.publication.WCMPublicationService; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; /* * Created by The eXo Platform SAS Author : Anh Do Ngoc anh.do@exoplatform.com * Sep 9, 2008 */ /** * The Class UIActivePublication. */ @ComponentConfig(template = "system:/groovy/ecm/webui/UIGridWithButton.gtmpl", events = { @EventConfig(listeners = UIActivePublication.EnrolActionListener.class), @EventConfig(listeners = UIActivePublication.CancelActionListener.class) }) public class UIActivePublication extends UIPagingGrid implements UIPopupComponent { /** The Constant LIFECYCLE_NAME. */ public final static String LIFECYCLE_NAME = "LifecycleName"; /** The Constant LIFECYCLE_DESC. */ public final static String LIFECYCLE_DESC = "LifecycleDesc"; /** The LIFECYCL e_ fields. */ public static String[] LIFECYCLE_FIELDS = { LIFECYCLE_NAME, LIFECYCLE_DESC }; /** The LIFECYCL e_ action. */ public static String[] LIFECYCLE_ACTION = { "Enrol" }; /** The Constant LIFECYCLE_SELECTED. */ public final static String LIFECYCLE_SELECTED = "LifecycleSelected"; private static final Log LOG = ExoLogger.getLogger(UIActivePublication.class.getName()); /** * Instantiates a new uI active publication. * * @throws Exception the exception */ public UIActivePublication() throws Exception { configure(LIFECYCLE_NAME, LIFECYCLE_FIELDS, LIFECYCLE_ACTION); getUIPageIterator().setId("LifecyclesIterator"); } /** * Gets the actions. * * @return the actions */ public String[] getActions() { return new String[] { "Cancel" }; } /** * Update lifecycles grid. * * @throws Exception the exception */ public void refresh(int currentPage) throws Exception { List<PublicationLifecycleBean> publicationLifecycleBeans = new ArrayList<PublicationLifecycleBean>(); PublicationService publicationService = getApplicationComponent(PublicationService.class); Collection<PublicationPlugin> publicationPlugins = publicationService.getPublicationPlugins() .values(); if (publicationPlugins.size() != 0) { for (PublicationPlugin publicationPlugin : publicationPlugins) { PublicationLifecycleBean lifecycleBean = new PublicationLifecycleBean(); lifecycleBean.setLifecycleName(publicationPlugin.getLifecycleName()); lifecycleBean.setLifecycleDesc(publicationPlugin.getDescription()); publicationLifecycleBeans.add(lifecycleBean); } } ListAccess<PublicationLifecycleBean> beanList = new ListAccessImpl<PublicationLifecycleBean>(PublicationLifecycleBean.class, publicationLifecycleBeans); LazyPageList<PublicationLifecycleBean> dataPageList = new LazyPageList<PublicationLifecycleBean>(beanList, getUIPageIterator().getItemsPerPage()); getUIPageIterator().setPageList(dataPageList); getUIPageIterator().setTotalItems(publicationLifecycleBeans.size()); if (currentPage > getUIPageIterator().getAvailablePage()) getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage()); else getUIPageIterator().setCurrentPage(currentPage); } public void enrolNodeInLifecycle(Node currentNode, String lifecycleName, WebuiRequestContext requestContext) throws Exception { UIJCRExplorer uiJCRExplorer = getAncestorOfType(UIJCRExplorer.class); UIApplication uiApp = getAncestorOfType(UIApplication.class); UIPublicationManager uiPublicationManager = uiJCRExplorer.createUIComponent( UIPublicationManager.class, null, null); uiJCRExplorer.addLockToken(currentNode); Node parentNode = currentNode.getParent(); uiJCRExplorer.addLockToken(parentNode); WCMPublicationService wcmPublicationService = getApplicationComponent(WCMPublicationService.class); PublicationPresentationService publicationPresentationService = getApplicationComponent(PublicationPresentationService.class); try { if(!currentNode.isCheckedOut()) { uiApp.addMessage(new ApplicationMessage("UIActionBar.msg.node-checkedin", null, ApplicationMessage.WARNING)); return; } String siteName = Util.getPortalRequestContext().getPortalOwner(); String remoteUser = Util.getPortalRequestContext().getRemoteUser(); if (AuthoringPublicationConstant.LIFECYCLE_NAME.equals(lifecycleName)) { wcmPublicationService.enrollNodeInLifecycle(currentNode, siteName, remoteUser); } else { wcmPublicationService.enrollNodeInLifecycle(currentNode, lifecycleName); } } catch (AlreadyInPublicationLifecycleException e) { uiApp.addMessage(new ApplicationMessage("UIActivePublication.msg.already-enroled", null, ApplicationMessage.ERROR)); return; } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } uiApp.addMessage(new ApplicationMessage("UIActivePublication.msg.unknow-error", new String[] { e.getMessage() }, ApplicationMessage.ERROR)); return; } // refresh node prevent the situation node is changed in other session currentNode.refresh(true); UIContainer container = createUIComponent(UIContainer.class, null, null); UIForm uiFormPublicationManager = publicationPresentationService.getStateUI(currentNode, container); UIPopupContainer UIPopupContainer = uiJCRExplorer.getChild(UIPopupContainer.class); if(uiFormPublicationManager instanceof UIPopupComponent) { //TODO for future version, we need remove this code //This is special case for wcm which wants to more than 2 tabs in PublicationManager //The uiForm in this case should be a UITabPane or UIFormTabPane and need be an UIPopupComponent UIPopupContainer.activate(uiFormPublicationManager,700,500); }else { uiPublicationManager.addChild(uiFormPublicationManager); uiPublicationManager.addChild(UIPublicationLogList.class, null, null).setRendered(false); UIPublicationLogList uiPublicationLogList = uiPublicationManager.getChild(UIPublicationLogList.class); UIPopupContainer.activate(uiPublicationManager, 700, 500); uiPublicationLogList.setNode(currentNode); uiPublicationLogList.updateGrid(); } } /* * (non-Javadoc) * * @see org.exoplatform.ecm.webui.popup.UIPopupComponent#activate() */ public void activate() { } /* * (non-Javadoc) * * @see org.exoplatform.ecm.webui.popup.UIPopupComponent#deActivate() */ public void deActivate() { } /** * The Class PublicationLifecycleBean. */ public class PublicationLifecycleBean { private String lifecycleName; private String lifecycleDesc; /** * Gets the lifecycle name. * * @return the lifecycle name */ public String getLifecycleName() { return lifecycleName; } /** * Sets the lifecycle name. * * @param lifecycleName the new lifecycle name */ public void setLifecycleName(String lifecycleName) { this.lifecycleName = lifecycleName; } /** * Gets the lifecycle desc. * * @return the lifecycle desc */ public String getLifecycleDesc() { return lifecycleDesc; } /** * Sets the lifecycle desc. * * @param lifecycleDesc the new lifecycle desc */ public void setLifecycleDesc(String lifecycleDesc) { this.lifecycleDesc = lifecycleDesc; } } /** * The listener interface for receiving cancelAction events. The class that is * interested in processing a cancelAction event implements this interface, * and the object created with that class is registered with a component using * the component's <code>addCancelActionListener</code> method. When * the cancelAction event occurs, that object's appropriate * method is invoked. */ public static class CancelActionListener extends EventListener<UIActivePublication> { /* * (non-Javadoc) * * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event) */ public void execute(Event<UIActivePublication> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); uiExplorer.cancelAction(); } } /** * The listener interface for receiving enrolAction events. The class that is * interested in processing a enrolAction event implements this interface, and * the object created with that class is registered with a component using the * component's <code>addEnrolActionListener</code> method. When * the enrolAction event occurs, that object's appropriate * method is invoked. */ public static class EnrolActionListener extends EventListener<UIActivePublication> { /* * (non-Javadoc) * * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event) */ public void execute(Event<UIActivePublication> event) throws Exception { UIActivePublication uiActivePub = event.getSource(); UIJCRExplorer uiJCRExplorer = uiActivePub.getAncestorOfType(UIJCRExplorer.class); String selectedLifecycle = event.getRequestContext().getRequestParameter(OBJECTID); Node currentNode = uiJCRExplorer.getCurrentNode(); uiActivePub.enrolNodeInLifecycle(currentNode, selectedLifecycle,event.getRequestContext()); } } }
12,262
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIRelationManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIRelationManager.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.ecm.webui.tree.selectone.UIOneNodePathSelector; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Oct 18, 2006 * 10:29:16 AM */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/UITabPaneWithAction.gtmpl", events = @EventConfig(listeners = UIRelationManager.CloseActionListener.class) ) public class UIRelationManager extends UIContainer implements UIPopupComponent { final static public String[] ACTIONS = {"Close"} ; public UIRelationManager() throws Exception { addChild(UIRelationsAddedList.class, null, null) ; addChild(UIOneNodePathSelector.class, null, null).setRendered(false) ; } public String[] getActions() { return ACTIONS ; } static public class CloseActionListener extends EventListener<UIRelationManager> { public void execute(Event<UIRelationManager> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class) ; uiExplorer.getCurrentNode().save() ; uiExplorer.setIsHidePopup(false) ; uiExplorer.cancelAction() ; uiExplorer.updateAjax(event); } } public void activate() { } public void deActivate() { } }
2,440
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UICategoriesAddedList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UICategoriesAddedList.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import java.util.ArrayList; import java.util.List; import java.util.MissingResourceException; import javax.jcr.AccessDeniedException; import javax.jcr.ItemExistsException; import javax.jcr.Node; import javax.jcr.RepositoryException; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.ecm.webui.tree.selectone.UIOneTaxonomySelector; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.taxonomy.TaxonomyService; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.wcm.core.NodeLocation; import org.exoplatform.services.wcm.publication.WCMComposer; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPageIterator; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.exception.MessageException; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Oct 18, 2006 * 2:28:18 PM */ @ComponentConfig(template = "app:/groovy/webui/component/explorer/popup/admin/UICategoriesAddedList.gtmpl", events = { @EventConfig(listeners = UICategoriesAddedList.DeleteActionListener.class, confirm = "UICategoriesAddedList.msg.confirm-delete") }) public class UICategoriesAddedList extends UIContainer implements UISelectable { private UIPageIterator uiPageIterator_; private static final Log LOG = ExoLogger.getLogger(UICategoriesAddedList.class.getName()); public UICategoriesAddedList() throws Exception { uiPageIterator_ = addChild(UIPageIterator.class, null, "CategoriesAddedList"); } public UIPageIterator getUIPageIterator() { return uiPageIterator_; } public List getListCategories() throws Exception { return NodeLocation.getNodeListByLocationList(uiPageIterator_.getCurrentPageData()); } public void updateGrid(int currentPage) throws Exception { ListAccess<Object> categoryList = new ListAccessImpl<Object>(Object.class, NodeLocation.getLocationsByNodeList(getCategories())); LazyPageList<Object> objPageList = new LazyPageList<Object>(categoryList, 10); uiPageIterator_.setPageList(objPageList); if (currentPage > getUIPageIterator().getAvailablePage()) getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage()); else getUIPageIterator().setCurrentPage(currentPage); } public List<Node> getCategories() throws Exception { List<Node> listCategories = new ArrayList<Node>(); UIJCRExplorer uiJCRExplorer = getAncestorOfType(UIJCRExplorer.class); TaxonomyService taxonomyService = getApplicationComponent(TaxonomyService.class); List<Node> listNode = getAllTaxonomyTrees(); for(Node itemNode : listNode) { listCategories.addAll(taxonomyService.getCategories(uiJCRExplorer.getCurrentNode(), itemNode.getName())); } return listCategories; } List<Node> getAllTaxonomyTrees() throws RepositoryException { TaxonomyService taxonomyService = getApplicationComponent(TaxonomyService.class); return taxonomyService.getAllTaxonomyTrees(); } String displayCategory(Node node, List<Node> taxonomyTrees) { try { for (Node taxonomyTree : taxonomyTrees) { if (node.getPath().contains(taxonomyTree.getPath())) { return getCategoryLabel(node.getPath().replace(taxonomyTree.getPath(), taxonomyTree.getName())); } } } catch (RepositoryException e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error when "); } } return ""; } private String getCategoryLabel(String resource) { String[] taxonomyPathSplit = resource.split("/"); StringBuilder buildlabel; StringBuilder buildPathlabel = new StringBuilder(); for (int i = 0; i < taxonomyPathSplit.length; i++) { buildlabel = new StringBuilder("eXoTaxonomies"); for (int j = 0; j <= i; j++) { buildlabel.append(".").append(taxonomyPathSplit[j]); } try { buildPathlabel.append(Utils.getResourceBundle(buildlabel.append(".label").toString())).append("/"); } catch (MissingResourceException me) { buildPathlabel.append(taxonomyPathSplit[i]).append("/"); } } return buildPathlabel.substring(0, buildPathlabel.length() - 1); } @SuppressWarnings("unused") public void doSelect(String selectField, Object value) throws Exception { UIJCRExplorer uiJCRExplorer = getAncestorOfType(UIJCRExplorer.class); UICategoryManager uiCategoryManager = getAncestorOfType(UICategoryManager.class); UIOneTaxonomySelector uiOneTaxonomySelector = uiCategoryManager.getChild(UIOneTaxonomySelector.class); String rootTaxonomyName = uiOneTaxonomySelector.getRootTaxonomyName(); TaxonomyService taxonomyService = getApplicationComponent(TaxonomyService.class); try { Node currentNode = uiJCRExplorer.getCurrentNode(); uiJCRExplorer.addLockToken(currentNode); if (rootTaxonomyName.equals(value)) { taxonomyService.addCategory(currentNode, rootTaxonomyName, ""); } else { String[] arrayCategoryPath = String.valueOf(value.toString()).split("/"); StringBuffer categoryPath = new StringBuffer().append("/"); for(int i = 1; i < arrayCategoryPath.length; i++ ) { categoryPath.append(arrayCategoryPath[i]); categoryPath.append("/"); } taxonomyService.addCategory(currentNode, rootTaxonomyName, categoryPath.toString()); } uiJCRExplorer.getCurrentNode().save() ; uiJCRExplorer.getSession().save() ; updateGrid(1) ; setRenderSibling(UICategoriesAddedList.class) ; NodeLocation location = NodeLocation.getNodeLocationByNode(currentNode); WCMComposer composer = WCMCoreUtils.getService(WCMComposer.class); } catch (AccessDeniedException accessDeniedException) { throw new MessageException(new ApplicationMessage("AccessControlException.msg", null, ApplicationMessage.WARNING)); } catch (ItemExistsException item) { throw new MessageException(new ApplicationMessage("UICategoriesAddedList.msg.ItemExistsException", null, ApplicationMessage.WARNING)); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } JCRExceptionManager.process(getAncestorOfType(UIApplication.class), e); } } static public class DeleteActionListener extends EventListener<UICategoriesAddedList> { public void execute(Event<UICategoriesAddedList> event) throws Exception { UICategoriesAddedList uiAddedList = event.getSource(); UIContainer uiManager = uiAddedList.getParent(); UIApplication uiApp = uiAddedList.getAncestorOfType(UIApplication.class); String nodePath = event.getRequestContext().getRequestParameter(OBJECTID); UIJCRExplorer uiExplorer = uiAddedList.getAncestorOfType(UIJCRExplorer.class); Node currentNode = uiExplorer.getCurrentNode(); TaxonomyService taxonomyService = uiAddedList.getApplicationComponent(TaxonomyService.class); try { List<Node> listNode = uiAddedList.getAllTaxonomyTrees(); for(Node itemNode : listNode) { if(nodePath.contains(itemNode.getPath())) { taxonomyService.removeCategory(currentNode, itemNode.getName(), nodePath.substring(itemNode.getPath().length())); break; } } uiAddedList.updateGrid(uiAddedList.getUIPageIterator().getCurrentPage()); } catch(AccessDeniedException ace) { throw new MessageException(new ApplicationMessage("UICategoriesAddedList.msg.access-denied", null, ApplicationMessage.WARNING)) ; } catch(Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } JCRExceptionManager.process(uiApp, e); } uiManager.setRenderedChild("UICategoriesAddedList"); } } }
9,876
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIPublicationManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIPublicationManager.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIContainer; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jun 26, 2008 1:15:45 AM */ @ComponentConfig(template = "classpath:groovy/ecm/webui/UITabPane.gtmpl") public class UIPublicationManager extends UIContainer implements UIPopupComponent{ public UIPublicationManager() throws Exception { } public void activate() { } public void deActivate() { } }
1,399
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIActionListContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIActionListContainer.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import java.util.List; import javax.jcr.Node; import javax.jcr.lock.Lock; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.control.action.EditDocumentActionComponent; import org.exoplatform.ecm.utils.lock.LockUtil; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.lock.LockService; import org.exoplatform.services.organization.MembershipType; import org.exoplatform.services.organization.OrganizationService; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * May 7, 2007 1:35:17 PM */ @ComponentConfig(lifecycle = UIContainerLifecycle.class) public class UIActionListContainer extends UIContainer { public UIActionListContainer() throws Exception { addChild(UIActionList.class, null, null) ; } public void initEditPopup(Node actionNode) throws Exception { removeChildById("editActionPopup") ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, "editActionPopup") ; uiPopup.setShowMask(true); UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ; Node currentNode = uiExplorer.getCurrentNode() ; UIActionForm uiActionForm = createUIComponent(UIActionForm.class, null, "EditFormAction") ; uiActionForm.setWorkspace(currentNode.getSession().getWorkspace().getName()) ; uiActionForm.createNewAction(currentNode, actionNode.getPrimaryNodeType().getName(), false) ; uiActionForm.setIsUpdateSelect(false) ; // uiActionForm.setNode(actionNode) ; uiActionForm.setNodePath(actionNode.getPath()) ; uiActionForm.setCurrentAction(actionNode.getName()); actionNode.refresh(true); // Check document is lock for editing uiActionForm.setIsKeepinglock(false); if (!actionNode.isLocked()) { OrganizationService service = WCMCoreUtils.getService(OrganizationService.class); List<MembershipType> memberships = (List<MembershipType>) service.getMembershipTypeHandler().findMembershipTypes(); synchronized (EditDocumentActionComponent.class) { actionNode.refresh(true); if (!actionNode.isLocked()) { if(actionNode.canAddMixin(Utils.MIX_LOCKABLE)){ actionNode.addMixin(Utils.MIX_LOCKABLE); actionNode.save(); } Lock lock = actionNode.lock(false, false); LockUtil.keepLock(lock); LockService lockService = uiExplorer.getApplicationComponent(LockService.class); List<String> settingLockList = lockService.getAllGroupsOrUsersForLock(); for (String settingLock : settingLockList) { LockUtil.keepLock(lock, settingLock); if (!settingLock.startsWith("*")) continue; String lockTokenString = settingLock; for (MembershipType membership : memberships) { lockTokenString = settingLock.replace("*", membership.getName()); LockUtil.keepLock(lock, lockTokenString); } } actionNode.save(); uiActionForm.setIsKeepinglock(true); } } } // Update data avoid concurrent modification by other session actionNode.refresh(true); // Check again after node is locking by current user or another if (LockUtil.getLockTokenOfUser(actionNode) == null) { Object[] arg = { actionNode.getPath() }; UIApplication uiApp = getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.node-locked-editing", arg, ApplicationMessage.WARNING)); return; } uiActionForm.setIsEditInList(true) ; uiActionForm.setIsKeepinglock(true); uiPopup.setWindowSize(650, 450); uiPopup.setUIComponent(uiActionForm) ; uiPopup.setRendered(true); uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public void initPopup(UIComponent uiComp) throws Exception { removeChildById("PopupComponent") ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, "PopupComponent") ; uiPopup.setShowMask(true); uiPopup.setUIComponent(uiComp) ; uiPopup.setWindowSize(640, 300) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } }
5,508
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIRelationsAddedList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIRelationsAddedList.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import java.util.ArrayList; import java.util.List; import javax.jcr.Node; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.services.cms.relations.RelationsService; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIGrid; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.exception.MessageException; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Oct 18, 2006 * 2:28:18 PM */ @ComponentConfig( lifecycle = UIContainerLifecycle.class, events = { @EventConfig(listeners = UIRelationsAddedList.DeleteActionListener.class, confirm="UIRelationsAddedList.msg.confirm-delete") } ) public class UIRelationsAddedList extends UIContainer implements UISelectable { private static final Log LOG = ExoLogger.getLogger(UIRelationsAddedList.class.getName()); private static String[] RELATE_BEAN_FIELD = {"path"} ; private static String[] ACTION = {"Delete"} ; public UIRelationsAddedList() throws Exception { UIGrid uiGrid = addChild(UIGrid.class, null, "RelateAddedList") ; uiGrid.setDisplayedChars(150); uiGrid.getUIPageIterator().setId("RelateListIterator"); uiGrid.configure("path", RELATE_BEAN_FIELD, ACTION) ; } public void updateGrid(List<Node> nodes, int currentPage) throws Exception { UIGrid uiGrid = getChildById("RelateAddedList"); if (nodes == null) nodes = new ArrayList<Node>(); ListAccess<Node> nodeList = new ListAccessImpl<Node>(Node.class, nodes); LazyPageList<Node> objPageList = new LazyPageList<Node>(nodeList, 10); uiGrid.getUIPageIterator().setPageList(objPageList); if (currentPage > uiGrid.getUIPageIterator().getAvailablePage()) uiGrid.getUIPageIterator().setCurrentPage(uiGrid.getUIPageIterator().getAvailablePage()); else uiGrid.getUIPageIterator().setCurrentPage(currentPage); } @SuppressWarnings("unused") public void doSelect(String selectField, Object value) throws Exception { UIJCRExplorer uiJCRExplorer = getAncestorOfType(UIJCRExplorer.class) ; RelationsService relateService = getApplicationComponent(RelationsService.class) ; String currentFullPath = uiJCRExplorer.getCurrentWorkspace() + ":" + uiJCRExplorer.getCurrentNode().getPath() ; if(value.equals(currentFullPath)) { throw new MessageException(new ApplicationMessage("UIRelationsAddedList.msg.can-not-add-itself", null, ApplicationMessage.WARNING)) ; } try { String wsName = value.toString().substring(0, value.toString().indexOf(":")) ; String path = value.toString().substring(value.toString().indexOf(":") + 1) ; Node currentNode = uiJCRExplorer.getCurrentNode(); uiJCRExplorer.addLockToken(currentNode); relateService.addRelation(currentNode, path, wsName) ; updateGrid(relateService.getRelations(currentNode, WCMCoreUtils.getUserSessionProvider()), 1); setRenderSibling(UIRelationsAddedList.class) ; } catch(Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } } } static public class DeleteActionListener extends EventListener<UIRelationsAddedList> { public void execute(Event<UIRelationsAddedList> event) throws Exception { UIRelationsAddedList uiAddedList = event.getSource() ; UIRelationManager uiManager = uiAddedList.getParent() ; UIApplication uiApp = uiAddedList.getAncestorOfType(UIApplication.class) ; String nodePath = event.getRequestContext().getRequestParameter(OBJECTID) ; RelationsService relationService = uiAddedList.getApplicationComponent(RelationsService.class) ; UIJCRExplorer uiExplorer = uiAddedList.getAncestorOfType(UIJCRExplorer.class) ; Node currentNode = uiExplorer.getCurrentNode(); uiExplorer.addLockToken(currentNode); try { relationService.removeRelation(uiExplorer.getCurrentNode(), nodePath); UIGrid uiGrid = uiAddedList.getChildById("RelateAddedList"); uiAddedList.updateGrid(relationService.getRelations(uiExplorer.getCurrentNode(), WCMCoreUtils.getUserSessionProvider()), uiGrid.getUIPageIterator().getCurrentPage()); } catch(Exception e) { JCRExceptionManager.process(uiApp, e) ; } uiManager.setRenderedChild("UIRelationsAddedList") ; } } }
6,068
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIActionViewContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIActionViewContainer.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Pham Tuan * phamtuanchip@yahoo.de * Nov 15, 2006 11:10:20 AM */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/popup/admin/UITabWithAction.gtmpl", events = { @EventConfig(listeners = UIActionViewContainer.CancelActionListener.class)} ) public class UIActionViewContainer extends UIContainer { private String[] actions_ = new String[] {"Cancel"} ; public String[] getActions() {return actions_ ;} static public class CancelActionListener extends EventListener<UIActionViewContainer> { public void execute(Event<UIActionViewContainer> event) throws Exception { UIActionManager uiActionManager = event.getSource().getAncestorOfType(UIActionManager.class) ; uiActionManager.removeChild(UIActionViewContainer.class) ; uiActionManager.setRenderedChild(UIActionListContainer.class) ; } } }
1,985
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UICategoryManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UICategoryManager.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.tree.selectone.UIOneTaxonomySelector; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Oct 17, 2006 * 10:41:44 AM */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/UITabPaneWithAction.gtmpl", events = @EventConfig(listeners = UICategoryManager.CloseActionListener.class) ) public class UICategoryManager extends UIContainer implements UIPopupComponent { private static final Log LOG = ExoLogger.getLogger(UICategoryManager.class.getName()); final static public String[] ACTIONS = {"Close"} ; public UICategoryManager() throws Exception { addChild(UICategoriesAddedList.class, null, null) ; addChild(UIOneTaxonomySelector.class, null, null).setRendered(false); } public String[] getActions() { return ACTIONS ; } static public class CloseActionListener extends EventListener<UICategoryManager> { public void execute(Event<UICategoryManager> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class) ; uiExplorer.setIsHidePopup(false) ; uiExplorer.cancelAction() ; } } public void activate() { try { getChild(UICategoriesAddedList.class).updateGrid(1); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } public void deActivate() { } }
2,738
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIPropertyForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIPropertyForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import java.io.InputStream; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.GregorianCalendar; import java.util.List; import java.util.Locale; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import javax.jcr.Property; import javax.jcr.PropertyType; import javax.jcr.RepositoryException; import javax.jcr.Value; import javax.jcr.ValueFactory; import javax.jcr.ValueFormatException; import javax.jcr.nodetype.NodeType; import javax.jcr.nodetype.PropertyDefinition; import org.apache.commons.lang3.StringUtils; import org.exoplatform.ecm.webui.form.validator.DateValidator; import org.exoplatform.ecm.webui.form.validator.ECMNameValidator; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.ecm.utils.lock.LockUtil; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormDateTimeInput; import org.exoplatform.webui.form.UIFormInputBase; import org.exoplatform.webui.form.UIFormMultiValueInputSet; import org.exoplatform.webui.form.UIFormSelectBox; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.input.UICheckBoxInput; import org.exoplatform.webui.form.input.UIUploadInput; import org.exoplatform.webui.form.validator.MandatoryValidator; /** * Created by The eXo Platform SARL * Author : phamtuan * phamtuanchip@yahoo.de September 13, 2006 10:07:15 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UIPropertyForm.SaveActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPropertyForm.ChangeTypeActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPropertyForm.AddActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPropertyForm.RemoveActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPropertyForm.CancelActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPropertyForm.ResetActionListener.class) } ) public class UIPropertyForm extends UIForm { final static public String FIELD_PROPERTY = "name"; final static public String FIELD_TYPE = "type"; final static public String FIELD_VALUE = "value"; final static public String FIELD_NAMESPACE = "namespace"; final static public String FIELD_MULTIPLE = "multiple"; final static private String FALSE = "false"; final static private String TRUE = "true"; final static public String PROPERTY_SELECT = "property_select" ; private static final Log LOG = ExoLogger.getLogger(UIPropertyForm.class.getName()); private String propertyName_; private boolean isAddNew_ = true; private boolean isMultiple_ = false; public void init(Node currentNode) throws Exception { setMultiPart(true); List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>(); options.add(new SelectItemOption<String>(PropertyType.TYPENAME_STRING, Integer.toString(PropertyType.STRING))); options.add(new SelectItemOption<String>(PropertyType.TYPENAME_BINARY, Integer.toString(PropertyType.BINARY))); options.add(new SelectItemOption<String>(PropertyType.TYPENAME_BOOLEAN, Integer.toString(PropertyType.BOOLEAN))); options.add(new SelectItemOption<String>(PropertyType.TYPENAME_DATE, Integer.toString(PropertyType.DATE))); options.add(new SelectItemOption<String>(PropertyType.TYPENAME_DOUBLE, Integer.toString(PropertyType.DOUBLE))); options.add(new SelectItemOption<String>(PropertyType.TYPENAME_LONG, Integer.toString(PropertyType.LONG))); options.add(new SelectItemOption<String>(PropertyType.TYPENAME_NAME, Integer.toString(PropertyType.NAME))); options.add(new SelectItemOption<String>(PropertyType.TYPENAME_PATH, Integer.toString(PropertyType.PATH))); options.add(new SelectItemOption<String>(PropertyType.TYPENAME_REFERENCE, Integer.toString(PropertyType.REFERENCE))); List<SelectItemOption<String>> nsOptions = new ArrayList<SelectItemOption<String>>(); List<SelectItemOption<String>> properties = new ArrayList<SelectItemOption<String>>() ; NodeType nodeType = currentNode.getPrimaryNodeType(); if (!nodeType.isNodeType(Utils.NT_UNSTRUCTURED)) { UIFormSelectBox uiPropSelectBox = new UIFormSelectBox(PROPERTY_SELECT, PROPERTY_SELECT, properties); uiPropSelectBox.setOnChange("ChangeType"); addUIFormInput(uiPropSelectBox); } else { addUIFormInput(new UIFormSelectBox(FIELD_NAMESPACE, FIELD_NAMESPACE, nsOptions)); addUIFormInput(new UIFormStringInput(FIELD_PROPERTY, FIELD_PROPERTY, null).addValidator(MandatoryValidator.class) .addValidator(ECMNameValidator.class)); UIFormSelectBox uiSelectBox = new UIFormSelectBox(FIELD_TYPE, FIELD_TYPE, options); uiSelectBox.setOnChange("ChangeType"); addUIFormInput(uiSelectBox); List<SelectItemOption<String>> multipleOpt = new ArrayList<SelectItemOption<String>>(); multipleOpt.add(new SelectItemOption<String>(TRUE, TRUE)); multipleOpt.add(new SelectItemOption<String>(FALSE, FALSE)); UIFormSelectBox uiMultiSelectBox = new UIFormSelectBox(FIELD_MULTIPLE, FIELD_MULTIPLE, multipleOpt); uiMultiSelectBox.setOnChange("ChangeType"); addUIFormInput(uiMultiSelectBox); } initValueField(currentNode); setActions(new String[] { "Save", "Reset", "Cancel" }); } public List<SelectItemOption<String>> getNamespaces() throws Exception { List<SelectItemOption<String>> namespaceOptions = new ArrayList<SelectItemOption<String>>(); String[] namespaces = getApplicationComponent(RepositoryService.class).getCurrentRepository() .getNamespaceRegistry() .getPrefixes(); for(String namespace : namespaces){ namespaceOptions.add(new SelectItemOption<String>(namespace, namespace)); } return namespaceOptions; } public void refresh() throws Exception { reset(); isAddNew_ = true; removeChildById(FIELD_VALUE); Node currentNode = getCurrentNode(); if (currentNode != null){ if (currentNode.isNodeType(Utils.NT_UNSTRUCTURED) ){ getUIStringInput(FIELD_PROPERTY).setReadOnly(!isAddNew_); getUIFormSelectBox(FIELD_NAMESPACE).setDisabled(!isAddNew_); getUIFormSelectBox(FIELD_TYPE).setValue(Integer.toString(PropertyType.STRING)); getUIFormSelectBox(FIELD_TYPE).setDisabled(!isAddNew_); getUIFormSelectBox(FIELD_MULTIPLE).setDisabled(!isAddNew_); }else{ getUIFormSelectBox(PROPERTY_SELECT).setDisabled(!isAddNew_); } } initValueField(currentNode); } private void initValueField(Node currentNode) throws Exception { if(currentNode.isNodeType(Utils.NT_UNSTRUCTURED)){ UIFormMultiValueInputSet uiFormMValue = createUIComponent(UIFormMultiValueInputSet.class, null, null); uiFormMValue.addValidator(MandatoryValidator.class); uiFormMValue.setId(FIELD_VALUE); uiFormMValue.setName(FIELD_VALUE); uiFormMValue.setType(UIFormStringInput.class); addUIFormInput(uiFormMValue); } else{ List<PropertyDefinition> properties = org.exoplatform.services.cms.impl.Utils.getProperties(currentNode); getUIFormSelectBox(PROPERTY_SELECT).setOptions(renderProperties(currentNode)); if(properties!= null && properties.size() > 0) { if(properties.get(0).isMultiple()){ UIFormMultiValueInputSet uiFormMValue = createUIComponent(UIFormMultiValueInputSet.class, null, null); uiFormMValue.addValidator(MandatoryValidator.class); uiFormMValue.setId(FIELD_VALUE); uiFormMValue.setName(FIELD_VALUE); changeMultipleType(uiFormMValue, properties.get(0).getRequiredType()); addUIFormInput(uiFormMValue); }else{ changeSingleType(properties.get(0).getRequiredType()); } } } } private Value createValue(Object value, int type, ValueFactory valueFactory) throws Exception { if(value != null) { switch (type) { case 2: return valueFactory.createValue((InputStream)value); case 3: return valueFactory.createValue(Long.parseLong(value.toString())); case 4: return valueFactory.createValue(Double.parseDouble(value.toString())); case 5: return valueFactory.createValue((GregorianCalendar)value); case 6: return valueFactory.createValue(Boolean.parseBoolean(value.toString())); default: return valueFactory.createValue(value.toString(), type); } } else return null; } private Value[] createValues(List<Object> valueList, int type, ValueFactory valueFactory) throws Exception { Value[] values = new Value[valueList.size()]; for(int i = 0; i < valueList.size(); i++) { values[i] = createValue(valueList.get(i), type, valueFactory); } return values; } protected void lockForm(boolean isLock) { if(isLock) setActions(new String[]{}); else setActions(new String[]{"Save", "Reset", "Cancel"}); Node currentNode; try { currentNode = getCurrentNode(); if (currentNode != null){ if (currentNode.isNodeType(Utils.NT_UNSTRUCTURED) ){ getUIStringInput(FIELD_PROPERTY).setReadOnly(isLock); getUIFormSelectBox(FIELD_NAMESPACE).setDisabled(isLock); getUIFormSelectBox(FIELD_TYPE).setDisabled(isLock); }else{ getUIFormSelectBox(PROPERTY_SELECT).setDisabled(isLock); } } } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } } } private Node getCurrentNode() throws Exception { UIPropertiesManager uiManager = getParent(); return uiManager.getCurrentNode(); } public void loadForm(String propertyName) throws Exception { WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance(); Node currentNode = getCurrentNode(); propertyName_ = propertyName; isAddNew_ = false; if(!currentNode.isNodeType(Utils.NT_UNSTRUCTURED)) { List<SelectItemOption<String>> propertySelected = new ArrayList<SelectItemOption<String>>(); propertySelected.add(new SelectItemOption<String>(propertyName,propertyName)); getUIFormSelectBox(PROPERTY_SELECT).setDisabled(true).setOptions(propertySelected); Property property = currentNode.getProperty(propertyName); isMultiple_ = property.getDefinition().isMultiple(); if(isMultiple_) { removeChildById(FIELD_VALUE); UIFormMultiValueInputSet uiFormMValue = createUIComponent(UIFormMultiValueInputSet.class, null, null); uiFormMValue.addValidator(MandatoryValidator.class); uiFormMValue.setId(FIELD_VALUE); uiFormMValue.setName(FIELD_VALUE); addUIFormInput(uiFormMValue); List<String> listValue = new ArrayList<String>(); for(Value value : property.getValues()) { switch (property.getType()) { case 2: break; case 3: { listValue.add(Long.toString(value.getLong())); break; } case 4: { listValue.add(Double.toString(value.getDouble())); break; } case 5: { DateFormat dateFormat = new SimpleDateFormat(formatDate(requestContext.getLocale())); listValue.add(dateFormat.format(value.getDate().getTime())); break; } case 6: { listValue.add(Boolean.toString(value.getBoolean())); break; } default: { listValue.add(value.getString()); break; } } } changeMultipleType(uiFormMValue, property.getType()); uiFormMValue.setValue(listValue); } else { Value value = property.getValue(); changeSingleType(property.getType()); switch (property.getType()) { case 2: break; case 3: { UIFormStringInput uiForm = getUIStringInput(FIELD_VALUE); uiForm.setValue(Long.toString(value.getLong())); break; } case 4: { UIFormStringInput uiForm = getUIStringInput(FIELD_VALUE); uiForm.setValue(Double.toString(value.getDouble())); break; } case 5: { UIFormDateTimeInput uiFormDateTimeInput = getUIFormDateTimeInput(FIELD_VALUE); DateFormat dateFormat = new SimpleDateFormat(formatDate(requestContext.getLocale())); uiFormDateTimeInput.setValue(dateFormat.format(value.getDate().getTime())); break; } case 6: { UICheckBoxInput uiCheckBoxInput = getUICheckBoxInput(FIELD_VALUE); uiCheckBoxInput.setChecked(value.getBoolean()); break; } default: { UIFormStringInput uiForm = getUIStringInput(FIELD_VALUE); uiForm.setValue(value.getString()); break; } } } } else { String[] propertyInfo = propertyName.split(":"); if(propertyInfo.length == 1){ getUIFormSelectBox(FIELD_NAMESPACE).setDisabled(true).setValue(""); getUIStringInput(FIELD_PROPERTY).setReadOnly(true).setValue(propertyInfo[0]); } else{ getUIFormSelectBox(FIELD_NAMESPACE).setDisabled(true).setValue(propertyInfo[0]); getUIStringInput(FIELD_PROPERTY).setReadOnly(true).setValue(propertyInfo[1]); } Property property = currentNode.getProperty(propertyName); isMultiple_ = property.getDefinition().isMultiple(); if (property.getType() == 0){ getUIFormSelectBox(FIELD_TYPE).setDisabled(true).setValue("1"); } else { getUIFormSelectBox(FIELD_TYPE).setDisabled(true).setValue(Integer.toString(property.getType())); } getUIFormSelectBox(FIELD_MULTIPLE).setDisabled(true).setValue(Boolean.toString(isMultiple_)); if(isMultiple_) { removeChildById(FIELD_VALUE); UIFormMultiValueInputSet uiFormMValue = createUIComponent(UIFormMultiValueInputSet.class, null, null); uiFormMValue.addValidator(MandatoryValidator.class); uiFormMValue.setId(FIELD_VALUE); uiFormMValue.setName(FIELD_VALUE); addUIFormInput(uiFormMValue); List<String> listValue = new ArrayList<String>(); for(Value value : property.getValues()) { switch (property.getType()) { case 2: break; case 3: { listValue.add(Long.toString(value.getLong())); break; } case 4: { listValue.add(Double.toString(value.getDouble())); break; } case 5: { DateFormat dateFormat = new SimpleDateFormat(formatDate(requestContext.getLocale())); listValue.add(dateFormat.format(value.getDate().getTime())); break; } case 6: { listValue.add(Boolean.toString(value.getBoolean())); break; } default: { listValue.add(value.getString()); break; } } } changeMultipleType(uiFormMValue, property.getType()); uiFormMValue.setValue(listValue); } else { Value value = property.getValue(); changeSingleType(property.getType()); switch (property.getType()) { case 2: break; case 3: { UIFormStringInput uiForm = getUIStringInput(FIELD_VALUE); uiForm.setValue(Long.toString(value.getLong())); break; } case 4: { UIFormStringInput uiForm = getUIStringInput(FIELD_VALUE); uiForm.setValue(Double.toString(value.getDouble())); break; } case 5: { UIFormDateTimeInput uiFormDateTimeInput = getUIFormDateTimeInput(FIELD_VALUE); DateFormat dateFormat = new SimpleDateFormat(formatDate(requestContext.getLocale())); uiFormDateTimeInput.setValue(dateFormat.format(value.getDate().getTime())); break; } case 6: { UICheckBoxInput uiCheckBoxInput = getUICheckBoxInput(FIELD_VALUE); uiCheckBoxInput.setChecked(value.getBoolean()); break; } default: { UIFormStringInput uiForm = getUIStringInput(FIELD_VALUE); uiForm.setValue(value.getString()); break; } } } } } private Object processValue(int type) throws Exception { Object value = null; UIComponent uiChild = getChildById(FIELD_VALUE); if(uiChild != null) { if(type == 6) { UICheckBoxInput checkbox = (UICheckBoxInput)uiChild; value = checkbox.isChecked(); } else if(type == 5) { UIFormDateTimeInput dateInput = (UIFormDateTimeInput)uiChild; value = dateInput.getCalendar(); } else if(type == 2) { UIUploadInput binaryInput = (UIUploadInput)uiChild; String uploadId = binaryInput.getUploadIds()[0]; if(binaryInput.getUploadDataAsStream(uploadId) != null) { value = binaryInput.getUploadDataAsStream(uploadId); } } else { UIFormStringInput uiStringInput = (UIFormStringInput)uiChild; value = uiStringInput.getValue(); if (value == null) value = ""; } } return value; } @SuppressWarnings("unchecked") private List<Object> processValues(int type) throws Exception { UIFormMultiValueInputSet multiValueInputSet = getUIInput(FIELD_VALUE); List<Object> valueList = new ArrayList<Object>(); if(type == 6) { for(UIComponent child : multiValueInputSet.getChildren()) { UICheckBoxInput checkbox = (UICheckBoxInput)child; valueList.add(checkbox.isChecked()); } } else if(type == 5) { for(UIComponent child : multiValueInputSet.getChildren()) { UIFormDateTimeInput dateInput = (UIFormDateTimeInput)child; valueList.add(dateInput.getCalendar()); } } else if(type == 2) { for(UIComponent child : multiValueInputSet.getChildren()) { UIUploadInput binaryInput = (UIUploadInput)child; String uploadId = binaryInput.getUploadIds()[0]; if(binaryInput.getUploadDataAsStream(uploadId) != null) { InputStream content = binaryInput.getUploadDataAsStream(uploadId); valueList.add(content); } } } else { valueList = (List<Object>)multiValueInputSet.getValue(); } return valueList; } private void changeMultipleType(UIFormMultiValueInputSet uiFormMultiValue, int type) throws Exception { if(PropertyType.BINARY == type) { uiFormMultiValue.setType(UIUploadInput.class); } else if(PropertyType.BOOLEAN == type) { uiFormMultiValue.setType(UICheckBoxInput.class); } else if(PropertyType.DATE == type) { uiFormMultiValue.setType(UIFormDateTimeInput.class); uiFormMultiValue.addValidator(DateValidator.class); } else { uiFormMultiValue.setType(UIFormStringInput.class); } } private void changeSingleType(int type) throws Exception { removeChildById(FIELD_VALUE); if(PropertyType.BINARY == type) { UIUploadInput uiUploadInput = new UIUploadInput(FIELD_VALUE, FIELD_VALUE); addUIFormInput(uiUploadInput); } else if(PropertyType.BOOLEAN == type) { addUIFormInput(new UICheckBoxInput(FIELD_VALUE, FIELD_VALUE, null)); } else if(PropertyType.DATE == type) { UIFormDateTimeInput uiFormDateTimeInput = new UIFormDateTimeInput(FIELD_VALUE, FIELD_VALUE, null); uiFormDateTimeInput.addValidator(DateValidator.class); addUIFormInput(uiFormDateTimeInput); } else { addUIFormInput(new UIFormStringInput(FIELD_VALUE, FIELD_VALUE, null)); } } static public class ChangeTypeActionListener extends EventListener<UIPropertyForm> { public void execute(Event<UIPropertyForm> event) throws Exception { UIPropertyForm uiForm = (UIPropertyForm) event.getSource(); Node currentNode = uiForm.getCurrentNode(); boolean isMultiple = false; if(currentNode.isNodeType(Utils.NT_UNSTRUCTURED)){ int type = Integer.parseInt(uiForm.getUIFormSelectBox(FIELD_TYPE).getValue()); UIFormSelectBox multiSelect = uiForm.getUIFormSelectBox(FIELD_MULTIPLE); if(multiSelect != null) { if (PropertyType.BOOLEAN == type) { multiSelect.setValue(FALSE); multiSelect.setReadOnly(true); multiSelect.setDisabled(true); } else { multiSelect.setReadOnly(false); multiSelect.setDisabled(false); } } uiForm.removeChildById(FIELD_VALUE); isMultiple = Boolean.parseBoolean(uiForm.getUIFormSelectBox(FIELD_MULTIPLE).getValue()); if(isMultiple) { UIFormMultiValueInputSet uiFormMultiValue = uiForm.createUIComponent(UIFormMultiValueInputSet.class, null, null); uiFormMultiValue.setId(FIELD_VALUE); uiFormMultiValue.setName(FIELD_VALUE); uiForm.changeMultipleType(uiFormMultiValue, type); uiForm.addUIFormInput(uiFormMultiValue); } else { uiForm.changeSingleType(type); } }else{ for(PropertyDefinition property : org.exoplatform.services.cms.impl.Utils.getProperties(currentNode)) { if (property.getName().equals(uiForm.getUIFormSelectBox(PROPERTY_SELECT).getValue())){ isMultiple = property.isMultiple(); int type = property.getRequiredType(); UIFormSelectBox multiSelect = uiForm.getUIFormSelectBox(FIELD_MULTIPLE); if(multiSelect != null) { if (PropertyType.BOOLEAN == type) { multiSelect.setValue(FALSE); multiSelect.setReadOnly(true); multiSelect.setDisabled(true); } else { multiSelect.setReadOnly(false); multiSelect.setDisabled(false); } } uiForm.removeChildById(FIELD_VALUE); if(isMultiple) { UIFormMultiValueInputSet uiFormMultiValue = uiForm.createUIComponent(UIFormMultiValueInputSet.class, null, null); uiFormMultiValue.setId(FIELD_VALUE); uiFormMultiValue.setName(FIELD_VALUE); uiForm.changeMultipleType(uiFormMultiValue, type); uiForm.addUIFormInput(uiFormMultiValue); } else { uiForm.changeSingleType(type); } break; } } } event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); } } static public class SaveActionListener extends EventListener<UIPropertyForm> { public void execute(Event<UIPropertyForm> event) throws Exception { UIPropertyForm uiForm = event.getSource(); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); Node currentNode = uiForm.getCurrentNode(); if(currentNode.isLocked()) { String lockToken = LockUtil.getLockToken(currentNode); if(lockToken != null) currentNode.getSession().addLockToken(lockToken); } if(!currentNode.isCheckedOut()) { uiApp.addMessage(new ApplicationMessage("UIPropertyForm.msg.node-checkedin", null)); return; } boolean isMultiple = false; NodeType nodeType = currentNode.getPrimaryNodeType(); String name = ""; int type = -1; if(uiForm.isAddNew_) { if(!nodeType.isNodeType(Utils.NT_UNSTRUCTURED)) { name = uiForm.getUIFormSelectBox(PROPERTY_SELECT).getValue(); }else{ String namespace = uiForm.getUIFormSelectBox(FIELD_NAMESPACE).getValue(); name = namespace + (StringUtils.isNotBlank(namespace) ? ":" : "") + uiForm.getUIStringInput(FIELD_PROPERTY).getValue(); } if(name != null && name.length() > 0) { //test valid property name try { currentNode.hasProperty(name); } catch (RepositoryException e) { Object[] args = {name}; uiApp.addMessage(new ApplicationMessage("UIPropertyForm.msg.property-name-incorrect", args, ApplicationMessage.WARNING)); UIPropertiesManager uiPropertiesManager = uiForm.getAncestorOfType(UIPropertiesManager.class); uiPropertiesManager.setRenderedChild(UIPropertyForm.class); return; } if(currentNode.hasProperty(name)) { Object[] args = { name }; uiApp.addMessage(new ApplicationMessage("UIPropertyForm.msg.propertyName-exist", args, ApplicationMessage.WARNING)); UIPropertiesManager uiPropertiesManager = uiForm.getAncestorOfType(UIPropertiesManager.class); uiPropertiesManager.setRenderedChild(UIPropertyForm.class); return; } if (nodeType.isNodeType(Utils.NT_UNSTRUCTURED)) { type = Integer.parseInt(uiForm.getUIFormSelectBox(FIELD_TYPE).getValue()); isMultiple = Boolean.parseBoolean(uiForm.getUIFormSelectBox(FIELD_MULTIPLE).getValue()); } else { String propertyName = uiForm.getUIFormSelectBox(PROPERTY_SELECT).getValue(); for (PropertyDefinition property : org.exoplatform.services.cms.impl.Utils.getProperties(currentNode)) { if (property.getName().equals(propertyName)) { type = property.getRequiredType(); isMultiple = property.isMultiple(); break; } } } } } else { name = uiForm.propertyName_; Property property = null; try { property = currentNode.getProperty(name); } catch (PathNotFoundException ex) { uiApp.addMessage(new ApplicationMessage("UIPropertyForm.msg.property-not-exist", new String[] {name})); return; } type = property.getType(); if (type == 0) type = 1; isMultiple = property.getDefinition().isMultiple(); } try { if(name != null) { if(isMultiple) { Value[] values = {}; List<Object> valueList = uiForm.processValues(type); values = uiForm.createValues(valueList, type, currentNode.getSession().getValueFactory()); // if(currentNode.hasProperty(name)) { currentNode.setProperty(name, values); //} } else { Object objValue = uiForm.processValue(type); Value value = uiForm.createValue(objValue, type, currentNode.getSession().getValueFactory()); // if(currentNode.hasProperty(name)) { //setProperty already checks whether the property exists if not it will create a new one as in the description currentNode.setProperty(name, value); // } } } currentNode.save(); currentNode.getSession().save(); } catch(ValueFormatException vf) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", vf); } uiApp.addMessage(new ApplicationMessage("UIPropertyForm.msg.valueFormatEx", null, ApplicationMessage.WARNING)); return; } catch(NumberFormatException nume) { uiApp.addMessage(new ApplicationMessage("UIPropertyForm.msg.number-format-exception", null, ApplicationMessage.WARNING)); return; } catch(Exception e) { uiApp.addMessage(new ApplicationMessage("UIPropertyForm.msg.unknown-error", null, ApplicationMessage.WARNING)); if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } JCRExceptionManager.process(uiApp, e); return; } uiForm.refresh(); UIPropertiesManager uiPropertiesManager = uiForm.getAncestorOfType(UIPropertiesManager.class); uiPropertiesManager.setSelectedTab(1); uiPropertiesManager.setIsEditProperty(false); } } static public class ResetActionListener extends EventListener<UIPropertyForm> { public void execute(Event<UIPropertyForm> event) throws Exception { UIPropertyForm uiForm = event.getSource(); uiForm.refresh(); uiForm.isAddNew_ = true; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); } } static public class CancelActionListener extends EventListener<UIPropertyForm> { public void execute(Event<UIPropertyForm> event) throws Exception { UIPropertyForm uiForm = event.getSource(); UIPropertiesManager uiPropertiesManager = uiForm.getAncestorOfType(UIPropertiesManager.class); uiPropertiesManager.setSelectedTab(1); uiForm.refresh(); uiForm.isAddNew_ = true; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class AddActionListener extends EventListener<UIPropertyForm> { public void execute(Event<UIPropertyForm> event) throws Exception { UIPropertyForm uiForm = event.getSource(); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); } } static public class RemoveActionListener extends EventListener<UIPropertyForm> { public void execute(Event<UIPropertyForm> event) throws Exception { UIPropertyForm uiForm = event.getSource(); UIFormMultiValueInputSet uiSet = uiForm.findFirstComponentOfType(UIFormMultiValueInputSet.class); List<UIComponent> children = uiSet.getChildren(); if(children != null && children.size() > 0) { for(int i = 0; i < children.size(); i ++) { UIFormInputBase<?> uiInput = (UIFormInputBase<?>)children.get(i); uiInput.setId(FIELD_VALUE + String.valueOf(i)); uiInput.setName(FIELD_VALUE + String.valueOf(i)); } } event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); } } public List<SelectItemOption<String>> renderProperties(Node node) throws Exception { List<SelectItemOption<String>> properties = new ArrayList<SelectItemOption<String>>(); NodeType nodetype = node.getPrimaryNodeType() ; Collection<NodeType> types = new ArrayList<NodeType>() ; types.add(nodetype) ; NodeType[] mixins = node.getMixinNodeTypes() ; if (mixins != null) types.addAll(Arrays.asList(mixins)) ; for(NodeType nodeType : types) { for(PropertyDefinition property : nodeType.getPropertyDefinitions()) { String name = property.getName(); if(!name.equals("exo:internalUse") && !property.isProtected() && !node.hasProperty(name)) { properties.add(new SelectItemOption<String>(name,name)); } } } return properties; } // adapt GateIn's UIFormDateTimeInput private String formatDate(Locale locale) { String datePattern = ""; DateFormat dateFormat = SimpleDateFormat.getDateInstance(DateFormat.SHORT, locale); // convert to unique pattern datePattern = ((SimpleDateFormat)dateFormat).toPattern(); if (!datePattern.contains("yy")) { datePattern = datePattern.replaceAll("y", "yy"); } if (!datePattern.contains("yyyy")) { datePattern = datePattern.replaceAll("yy", "yyyy"); } if (!datePattern.contains("dd")) { datePattern = datePattern.replaceAll("d", "dd"); } if (!datePattern.contains("MM")) { datePattern= datePattern.replaceAll("M", "MM"); } return datePattern; } }
34,537
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIPropertyTab.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIPropertyTab.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Set; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.Property; import javax.jcr.PropertyIterator; import javax.jcr.PropertyType; import javax.jcr.Session; import javax.jcr.Value; import javax.jcr.ValueFormatException; import javax.jcr.nodetype.NodeType; import javax.jcr.nodetype.PropertyDefinition; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.utils.PermissionUtil; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * September 13, 2006 * 10:07:15 AM */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/popup/info/UIPropertyTab.gtmpl", events = { @EventConfig(listeners = UIPropertyTab.CloseActionListener.class), @EventConfig(listeners = UIPropertyTab.EditActionListener.class), @EventConfig(listeners = UIPropertyTab.DeleteActionListener.class, confirm="UIPropertyTab.confirm.remove-property") } ) public class UIPropertyTab extends UIContainer { private static String[] PRO_BEAN_FIELD = {"icon", "name", "multiValue", "value", "action"} ; private final static String PRO_KEY_BINARYTYPE = "binary" ; private final static String PRO_KEY_CANNOTGET = "cannotget" ; private static final Log LOG = ExoLogger.getLogger(UIPropertyTab.class.getName()); private Set<String> propertiesName_ = new HashSet<String>(); public String[] getBeanFields() { return PRO_BEAN_FIELD ;} public String[] getActions() {return new String[] {"Close"} ;} private Node getCurrentNode() throws Exception { UIPropertiesManager uiManager = getParent(); return uiManager.getCurrentNode(); } public PropertyIterator getProperties() throws Exception { return getCurrentNode().getProperties() ; } private Set<String> propertiesName() throws Exception { if(propertiesName_.size() == 0) { Node currentNode = getCurrentNode(); NodeType nodetype = currentNode.getPrimaryNodeType() ; Collection<NodeType> types = new ArrayList<NodeType>() ; types.add(nodetype) ; NodeType[] mixins = currentNode.getMixinNodeTypes() ; if (mixins != null) types.addAll(Arrays.asList(mixins)) ; for(NodeType nodeType : types) { for(PropertyDefinition property : nodeType.getPropertyDefinitions()) { propertiesName_.add(property.getName()); } } } return propertiesName_; } public boolean addedByUser(String propertyName) throws Exception { if(propertiesName().contains(propertyName)) return false; return true; } public boolean isCanbeRemoved(String propertyName) throws Exception { Property property = getCurrentNode().getProperty(propertyName); if (property == null || !PermissionUtil.canSetProperty(property.getParent()) || property.getDefinition().isMandatory() || property.getDefinition().isProtected()) return false; return true; } public boolean isCanbeEdit(Property property) throws Exception { if(!PermissionUtil.canSetProperty(property.getParent()) || property.getDefinition().isProtected()) { return false; } return true; } public String getPropertyValue(Property prop) throws Exception { if(prop.getType() == PropertyType.BINARY) return PRO_KEY_BINARYTYPE ; boolean flag = true; try { if(prop.getDefinition() != null && prop.getDefinition().isMultiple()) { Value[] values = prop.getValues(); StringBuilder sB = new StringBuilder(); for (int i = 0; i < values.length; i++) { if (prop.getType() == PropertyType.REFERENCE) { String uuid = values[i].getString(); Node node = this.getNodeByUUID(uuid); if (node == null) { if (i == 0) flag = false; continue; } } if ((i > 0) && flag) sB.append("; "); sB.append(values[i].getString()); flag = true; } return sB.toString(); } return prop.getString() ; } catch(ValueFormatException ve) { return PRO_KEY_CANNOTGET ; } catch(Exception e) { return PRO_KEY_CANNOTGET ; } } public Node getNodeByUUID(String uuid) { Node node = null; try { UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); Session session = uiExplorer.getSession(); node = session.getNodeByUUID(uuid); } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn(e.getMessage()); } } return node; } static public class CloseActionListener extends EventListener<UIPropertyTab> { public void execute(Event<UIPropertyTab> event) throws Exception { event.getSource().getAncestorOfType(UIJCRExplorer.class).cancelAction() ; } } static public class EditActionListener extends EventListener<UIPropertyTab> { public void execute(Event<UIPropertyTab> event) throws Exception { UIPropertyTab uiPropertyTab = event.getSource(); UIPropertiesManager uiManager = uiPropertyTab.getParent(); UIApplication uiApp = uiManager.getAncestorOfType(UIApplication.class); UIJCRExplorer uiExplorer = uiManager.getAncestorOfType(UIJCRExplorer.class); Node currentNode = uiExplorer.getCurrentNode(); if(!PermissionUtil.canSetProperty(currentNode)) { uiApp.addMessage(new ApplicationMessage("UIActionBar.msg.access-denied", null, ApplicationMessage.WARNING)); return; } if(uiExplorer.nodeIsLocked(currentNode)) { Object[] arg = { currentNode.getPath() }; uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.node-locked", arg)); return; } if(!currentNode.isCheckedOut()) { uiApp.addMessage(new ApplicationMessage("UIActionBar.msg.node-checkedin", null)); return; } String propertyName = event.getRequestContext().getRequestParameter(OBJECTID); UIPropertyForm uiForm = uiManager.getChild(UIPropertyForm.class); if(uiForm == null) { uiForm = uiManager.addChild(UIPropertyForm.class, null, null); uiForm.init(currentNode); } uiForm.loadForm(propertyName); uiManager.setIsEditProperty(true); uiManager.setSelectedTab(2); } } static public class DeleteActionListener extends EventListener<UIPropertyTab> { public void execute(Event<UIPropertyTab> event) throws Exception { UIPropertyTab uiPropertyTab = event.getSource(); String propertyName = event.getRequestContext().getRequestParameter(OBJECTID); Node currentNode = uiPropertyTab.getCurrentNode(); UIApplication uiApp = uiPropertyTab.getAncestorOfType(UIApplication.class); try { if(currentNode.hasProperty(propertyName)) currentNode.getProperty(propertyName).remove(); currentNode.save(); UIPropertiesManager uiManager = uiPropertyTab.getParent(); uiManager.setRenderedChild(UIPropertyTab.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiPropertyTab); return; } catch(AccessDeniedException ace) { uiApp.addMessage(new ApplicationMessage("UIActionBar.msg.access-denied", null, ApplicationMessage.WARNING)); return; } catch(Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } return; } } } }
8,800
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIActionForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIActionForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.nodetype.ConstraintViolationException; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.sidebar.UITreeExplorer; import org.exoplatform.ecm.webui.form.UIDialogForm; import org.exoplatform.ecm.webui.nodetype.selector.UINodeTypeSelector; import org.exoplatform.ecm.webui.selector.ComponentSelector; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.ecm.webui.tree.selectone.UIOneNodePathSelector; import org.exoplatform.ecm.webui.utils.DialogFormUtil; import org.exoplatform.ecm.webui.utils.PermissionUtil; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.portal.application.PortalRequestContext; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.resolver.ResourceResolver; import org.exoplatform.services.cms.CmsService; import org.exoplatform.services.cms.JcrInputProperty; import org.exoplatform.services.cms.actions.ActionServiceContainer; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.jcr.ext.common.SessionProvider; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.web.url.navigation.NavigationResource; import org.exoplatform.web.url.navigation.NodeURL; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.ComponentConfigs; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPageIterator; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIFormInputBase; import org.exoplatform.webui.form.UIFormMultiValueInputSet; import org.exoplatform.webui.form.UIFormStringInput; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Nov 8, 2006 * 11:23:50 AM */ @ComponentConfigs( { @ComponentConfig(type = UIFormMultiValueInputSet.class, id = "WYSIWYGRichTextMultipleInputset", events = { @EventConfig(listeners = UIDialogForm.AddActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIFormMultiValueInputSet.RemoveActionListener.class, phase = Phase.DECODE) }), @ComponentConfig(lifecycle = UIFormLifecycle.class, events = { @EventConfig(listeners = UIActionForm.SaveActionListener.class), @EventConfig(listeners = UIDialogForm.OnchangeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIActionForm.BackActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIActionForm.ShowComponentActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIActionForm.AddActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIActionForm.RemoveActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIActionForm.RemoveReferenceActionListener.class, confirm = "DialogFormField.msg.confirm-delete", phase = Phase.DECODE) }) }) public class UIActionForm extends UIDialogForm implements UISelectable { private String parentPath_; private String nodeTypeName_ = null; private boolean isAddNew_; private String scriptPath_ = null; private boolean isEditInList_ = false; private String rootPath_ = null; private String currentAction = null; private static final String EXO_ACTIONS = "exo:actions"; private static final Log LOG = ExoLogger.getLogger(UIActionForm.class.getName()); public String getDriverName() { UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); return uiExplorer.getRepositoryName() + "/" + uiExplorer.getDriveData().getName(); } public UIActionForm() throws Exception { setActions(new String[]{"Save","Back"}); } public void createNewAction(Node parentNode, String actionType, boolean isAddNew) throws Exception { reset(); parentPath_ = parentNode.getPath(); nodeTypeName_ = actionType; isAddNew_ = isAddNew; componentSelectors.clear(); properties.clear(); getChildren().clear(); } private Node getParentNode() throws Exception{ return (Node) getSession().getItem(parentPath_); } /** * @param currentAction the currentAction to set */ public void setCurrentAction(String currentAction) { this.currentAction = currentAction; } /** * @return the currentAction */ public String getCurrentAction() { return currentAction; } public void doSelect(String selectField, Object value) throws Exception { isUpdateSelect = true; UIComponent uicomponent = getChildById(selectField); if (UIFormStringInput.class.isInstance(uicomponent)) ((UIFormStringInput)uicomponent).setValue(value.toString()); else if (UIFormMultiValueInputSet.class.isInstance(uicomponent)) { ((UIFormMultiValueInputSet)uicomponent).setValue((ArrayList<String>)value); } if(isEditInList_) { UIActionManager uiManager = getAncestorOfType(UIActionManager.class); UIActionListContainer uiActionListContainer = uiManager.getChild(UIActionListContainer.class); uiActionListContainer.removeChildById("PopupComponent"); } else { UIActionContainer uiActionContainer = getParent(); uiActionContainer.removeChildById("PopupComponent"); } } public String getCurrentPath() throws Exception { return getAncestorOfType(UIJCRExplorer.class).getCurrentNode().getPath(); } public ResourceResolver getTemplateResourceResolver(WebuiRequestContext context, String template) { return getAncestorOfType(UIJCRExplorer.class).getJCRTemplateResourceResolver(); } public String getTemplate() { return getDialogPath(); } public String getDialogPath() { repositoryName = getAncestorOfType(UIJCRExplorer.class).getRepositoryName(); TemplateService templateService = getApplicationComponent(TemplateService.class); String userName = Util.getPortalRequestContext().getRemoteUser(); String dialogPath = null; if (nodeTypeName_ != null) { try { dialogPath = templateService.getTemplatePathByUser(true, nodeTypeName_, userName); } catch (Exception e){ if (LOG.isWarnEnabled()) { LOG.warn(e.getMessage()); } } } return dialogPath; } public String getRepositoryName() { return repositoryName; } public String getTemplateNodeType() { return nodeTypeName_; } private void setPath(String scriptPath) { UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); if(scriptPath.indexOf(":") < 0) { scriptPath = uiExplorer.getCurrentWorkspace() + ":" + scriptPath; } scriptPath_ = scriptPath; } public String getPath() { return scriptPath_; } public void setRootPath(String rootPath){ rootPath_ = rootPath; } public String getRootPath(){return rootPath_;} public void setIsEditInList(boolean isEditInList) { isEditInList_ = isEditInList; } public void onchange(Event<?> event) throws Exception { if(isEditInList_ || !isAddNew_) { event.getRequestContext().addUIComponentToUpdateByAjax(getParent()); return; } UIActionManager uiManager = getAncestorOfType(UIActionManager.class); uiManager.setRenderedChild(UIActionContainer.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } public void renderField(String name) throws Exception { UIComponent uiInput = findComponentById(name); if ("homePath".equals(name)) { UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ; Node currentNode = uiExplorer.getCurrentNode() ; String homPath = uiExplorer.getCurrentWorkspace() + ":" + currentNode.getPath(); ((UIFormStringInput) uiInput).setValue(homPath); } super.renderField(name); } static public class SaveActionListener extends EventListener<UIActionForm> { private void addInputInfo(Map<String, JcrInputProperty> input, UIActionForm actionForm) throws Exception { String rssUrlKey = "/node/exo:url"; if (input.get(rssUrlKey) == null) return; UIJCRExplorer uiExplorer = actionForm.getAncestorOfType(UIJCRExplorer.class); //drive name UITreeExplorer treeExplorer = uiExplorer.findFirstComponentOfType(UITreeExplorer.class); String driveName = treeExplorer.getDriveName(); //requestUri PortalRequestContext pContext = Util.getPortalRequestContext(); NodeURL nodeURL = pContext.createURL(NodeURL.TYPE); NavigationResource resource = new NavigationResource(Util.getUIPortal().getSelectedUserNode()); nodeURL.setResource(resource); nodeURL.setQueryParameterValue("path", driveName); nodeURL.setSchemeUse(true); input.get(rssUrlKey).setValue(nodeURL.toString()); } public void execute(Event<UIActionForm> event) throws Exception { UIActionForm actionForm = event.getSource(); UIApplication uiApp = actionForm.getAncestorOfType(UIApplication.class); ActionServiceContainer actionServiceContainer = actionForm.getApplicationComponent(ActionServiceContainer.class); UIJCRExplorer uiExplorer = actionForm.getAncestorOfType(UIJCRExplorer.class); String repository = actionForm.getAncestorOfType(UIJCRExplorer.class).getRepositoryName(); Map<String, JcrInputProperty> sortedInputs = DialogFormUtil.prepareMap(actionForm.getChildren(), actionForm.getInputProperties(), actionForm.getInputOptions()); addInputInfo(sortedInputs, actionForm); Node currentNode = uiExplorer.getCurrentNode(); if(!PermissionUtil.canAddNode(currentNode) || !PermissionUtil.canSetProperty(currentNode)) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.no-permission-add", null)); return; } UIFormStringInput homePathInput = actionForm.getUIStringInput("homePath"); if (homePathInput != null) { String targetPath = homePathInput.getValue(); if ((targetPath == null) || (targetPath.length() == 0)) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.homePath-emty", null, ApplicationMessage.WARNING)); return; } } UIFormStringInput targetPathInput = actionForm.getUIStringInput("targetPath"); if (targetPathInput != null) { String targetPath = targetPathInput.getValue(); if ((targetPath == null) || (targetPath.length() == 0)) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.targetPath-emty", null, ApplicationMessage.WARNING)); return; } } String actionName = (String)(sortedInputs.get("/node/exo:name")).getValue(); if (!Utils.isNameValid(actionName, Utils.SPECIALCHARACTER)) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.name-not-allowed", null, ApplicationMessage.WARNING)); return; } Node parentNode = actionForm.getParentNode(); if (actionForm.isAddNew_) { if (parentNode.hasNode(EXO_ACTIONS)) { if (parentNode.getNode(EXO_ACTIONS).hasNode(actionName)) { Object[] args = { actionName }; uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.existed-action", args, ApplicationMessage.WARNING)); return; } } } else if (actionForm.isEditInList_) { if (parentNode.hasNode(EXO_ACTIONS)) { if (parentNode.getNode(EXO_ACTIONS).hasNode(actionName) && !actionName.equals(actionForm.currentAction)) { Object[] args = { actionName }; uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.existed-action", args, ApplicationMessage.WARNING)); return; } } } try{ if (uiExplorer.nodeIsLocked(currentNode)) return; if (!actionForm.isAddNew_) { CmsService cmsService = actionForm.getApplicationComponent(CmsService.class); Node storedHomeNode = actionForm.getNode().getParent(); Node currentActionNode = storedHomeNode.getNode(sortedInputs.get("/node").getValue().toString()); if (uiExplorer.nodeIsLocked(currentActionNode)) return; cmsService.storeNode(actionForm.nodeTypeName_, storedHomeNode, sortedInputs, false); Session session = currentActionNode.getSession(); if (uiExplorer.nodeIsLocked(currentActionNode)) return; // We add LockToken again because CMSService did logout // session cause lost lock information session.move(currentActionNode.getPath(), storedHomeNode.getPath() + "/" + sortedInputs.get("/node/exo:name").getValue().toString()); session.save(); currentNode.getSession().save(); if (actionForm.isEditInList_) { UIActionManager uiManager = actionForm.getAncestorOfType(UIActionManager.class); UIPopupWindow uiPopup = uiManager.findComponentById("editActionPopup"); uiPopup.setShow(false); uiPopup.setRendered(false); uiManager.setDefaultConfig(); actionForm.isEditInList_ = false; //actionForm.isAddNew_ = true; actionForm.setIsOnchange(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); uiExplorer.setIsHidePopup(true); uiExplorer.updateAjax(event); } else { uiExplorer.setIsHidePopup(false); uiExplorer.updateAjax(event); } actionForm.setPath(storedHomeNode.getPath()); actionServiceContainer.removeAction(currentNode, currentActionNode.getName(), repository); //return; } JcrInputProperty rootProp = sortedInputs.get("/node"); if(rootProp == null) { rootProp = new JcrInputProperty(); rootProp.setJcrPath("/node"); rootProp.setValue((sortedInputs.get("/node/exo:name")).getValue()); sortedInputs.put("/node", rootProp); } else { rootProp.setValue((sortedInputs.get("/node/exo:name")).getValue()); } if (parentNode.isNew()) { String[] args = { parentNode.getPath() }; uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.unable-add-action", args)); return; } actionServiceContainer.addAction(parentNode, actionForm.nodeTypeName_, sortedInputs); actionForm.setIsOnchange(false); parentNode.getSession().save(); UIActionManager uiActionManager = actionForm.getAncestorOfType(UIActionManager.class); actionForm.createNewAction(uiExplorer.getCurrentNode(), actionForm.nodeTypeName_, true); UIActionList uiActionList = uiActionManager.findFirstComponentOfType(UIActionList.class); uiActionList.updateGrid(parentNode, uiActionList.getChild(UIPageIterator.class).getCurrentPage()); uiActionManager.setRenderedChild(UIActionListContainer.class); actionForm.reset(); } catch(ConstraintViolationException cex) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.constraintviolation-exception", null, ApplicationMessage.WARNING)); return; } catch(RepositoryException repo) { String key = "UIActionForm.msg.repository-exception"; uiApp.addMessage(new ApplicationMessage(key, null, ApplicationMessage.WARNING)); return; } catch(NumberFormatException nume) { String key = "UIActionForm.msg.numberformat-exception"; uiApp.addMessage(new ApplicationMessage(key, null, ApplicationMessage.WARNING)); return; } catch (NullPointerException nullPointerException) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.unable-add", null, ApplicationMessage.WARNING)); return; } catch (NoSuchFieldException ns) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.lifecycle-invalid", null, ApplicationMessage.WARNING)); return; } catch (Exception e) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.unable-add", null, ApplicationMessage.WARNING)); return; } finally { if (actionForm.isEditInList_) { actionForm.releaseLock(); actionForm.isEditInList_ = false; } } } } @SuppressWarnings("unchecked") static public class ShowComponentActionListener extends EventListener<UIActionForm> { public void execute(Event<UIActionForm> event) throws Exception { UIActionForm uiForm = event.getSource(); UIContainer uiContainer = null; uiForm.isShowingComponent = true; if(uiForm.isEditInList_) { uiContainer = uiForm.getAncestorOfType(UIActionListContainer.class); } else { uiContainer = uiForm.getParent(); } String fieldName = event.getRequestContext().getRequestParameter(OBJECTID); Map fieldPropertiesMap = uiForm.componentSelectors.get(fieldName); String classPath = (String)fieldPropertiesMap.get("selectorClass"); String rootPath = (String)fieldPropertiesMap.get("rootPath"); ClassLoader cl = Thread.currentThread().getContextClassLoader(); Class clazz = Class.forName(classPath, true, cl); UIComponent uiComp = uiContainer.createUIComponent(clazz, null, null); String selectorParams = (String)fieldPropertiesMap.get("selectorParams"); if(uiComp instanceof UIOneNodePathSelector) { UIJCRExplorer explorer = uiForm.getAncestorOfType(UIJCRExplorer.class); String repositoryName = explorer.getRepositoryName(); SessionProvider provider = explorer.getSessionProvider(); String wsFieldName = (String)fieldPropertiesMap.get("workspaceField"); String wsName = explorer.getCurrentWorkspace(); if(wsFieldName != null && wsFieldName.length() > 0) { wsName = (String)uiForm.<UIFormInputBase>getUIInput(wsFieldName).getValue(); ((UIOneNodePathSelector)uiComp).setIsDisable(wsName, true); } if(selectorParams != null) { String[] arrParams = selectorParams.split(","); if(arrParams.length == 4) { ((UIOneNodePathSelector)uiComp).setAcceptedNodeTypesInPathPanel(new String[] {Utils.NT_FILE}); wsName = arrParams[1]; rootPath = arrParams[2]; ((UIOneNodePathSelector)uiComp).setIsDisable(wsName, true); if(arrParams[3].indexOf(";") > -1) { ((UIOneNodePathSelector)uiComp).setAcceptedMimeTypes(arrParams[3].split(";")); } else { ((UIOneNodePathSelector)uiComp).setAcceptedMimeTypes(new String[] {arrParams[3]}); } } } if(rootPath == null) rootPath = "/"; ((UIOneNodePathSelector)uiComp).setRootNodeLocation(repositoryName, wsName, rootPath); ((UIOneNodePathSelector)uiComp).setShowRootPathSelect(true); ((UIOneNodePathSelector)uiComp).init(provider); } else if (uiComp instanceof UINodeTypeSelector) { UIJCRExplorer explorer = uiForm.getAncestorOfType(UIJCRExplorer.class); ((UINodeTypeSelector)uiComp).setRepositoryName(explorer.getRepositoryName()); UIFormMultiValueInputSet uiFormMultiValueInputSet = uiForm.getChildById(fieldName); List values = uiFormMultiValueInputSet.getValue(); ((UINodeTypeSelector)uiComp).init(1, values); } if(uiForm.isEditInList_) ((UIActionListContainer) uiContainer).initPopup(uiComp); else ((UIActionContainer)uiContainer).initPopup(uiComp); String param = "returnField=" + fieldName; String[] params = selectorParams == null ? new String[] { param } : new String[] { param, "selectorParams=" + selectorParams }; ((ComponentSelector)uiComp).setSourceComponent(uiForm, params); if(uiForm.isAddNew_) { UIContainer uiParent = uiContainer.getParent(); uiParent.setRenderedChild(uiContainer.getId()); } event.getRequestContext().addUIComponentToUpdateByAjax(uiContainer); } } static public class RemoveReferenceActionListener extends EventListener<UIActionForm> { public void execute(Event<UIActionForm> event) throws Exception { UIActionForm uiForm = event.getSource(); uiForm.isRemovePreference = true; String fieldName = event.getRequestContext().getRequestParameter(OBJECTID); UIComponent uicomponent = uiForm.getChildById(fieldName); if (UIFormStringInput.class.isInstance(uicomponent)) ((UIFormStringInput)uicomponent).setValue(null); else if (UIFormMultiValueInputSet.class.isInstance(uicomponent)) { ((UIFormMultiValueInputSet)uicomponent).setValue(new ArrayList<String>()); } event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } public static class AddActionListener extends EventListener<UIActionForm> { public void execute(Event<UIActionForm> event) throws Exception { UIActionForm uiForm = event.getSource(); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } public static class RemoveActionListener extends EventListener<UIActionForm> { public void execute(Event<UIActionForm> event) throws Exception { UIActionForm uiForm = event.getSource(); uiForm.isRemoveActionField = true; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class BackActionListener extends EventListener<UIActionForm> { public void execute(Event<UIActionForm> event) throws Exception { UIActionForm uiForm = event.getSource(); UIActionManager uiManager = uiForm.getAncestorOfType(UIActionManager.class); if(uiForm.isAddNew_) { uiManager.setRenderedChild(UIActionListContainer.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } else { if(uiForm.isEditInList_) { uiForm.releaseLock(); uiManager.setRenderedChild(UIActionListContainer.class); uiManager.setDefaultConfig(); UIActionListContainer uiActionListContainer = uiManager.getChild(UIActionListContainer.class); UIPopupWindow uiPopup = uiActionListContainer.findComponentById("editActionPopup"); uiPopup.setShow(false); uiPopup.setRendered(false); uiForm.isEditInList_ = false; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } else { UIJCRExplorer uiExplorer = uiForm.getAncestorOfType(UIJCRExplorer.class); uiExplorer.cancelAction(); } } } } }
25,254
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIImportNode.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIImportNode.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.ResourceBundle; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import javax.jcr.AccessDeniedException; import javax.jcr.ImportUUIDBehavior; import javax.jcr.InvalidSerializedDataException; import javax.jcr.Node; import javax.jcr.Session; import javax.jcr.nodetype.ConstraintViolationException; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.mimetype.DMSMimeTypeResolver; import org.exoplatform.services.jcr.impl.storage.JCRItemExistsException; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.upload.UploadService; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.web.application.RequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormSelectBox; import org.exoplatform.webui.form.input.UIUploadInput; /** * Created by The eXo Platform SARL Author : Dang Van Minh minh.dang@exoplatform.com Oct 5, 2006 */ @ComponentConfig(lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/explorer/popup/admin/UIFormWithMultiRadioBox.gtmpl", events = { @EventConfig(listeners = UIImportNode.ImportActionListener.class), @EventConfig(listeners = UIImportNode.CancelActionListener.class, phase = Phase.DECODE) }) public class UIImportNode extends UIForm implements UIPopupComponent { private static final Log LOG = ExoLogger.getLogger(UIImportNode.class.getName()); public static final String FORMAT = "format"; public static final String FILE_UPLOAD = "upload"; public static final String IMPORT_BEHAVIOR = "behavior"; public static final String VERSION_HISTORY_FILE_UPLOAD = "versionHistory"; public static final String MAPPING_FILE = "mapping.properties"; public UIImportNode() throws Exception { this.setMultiPart(true); // Disabling the size limit since it makes no sense in the import case UIUploadInput uiFileUpload = new UIUploadInput(FILE_UPLOAD, FILE_UPLOAD, 1, 0); addUIFormInput(uiFileUpload); addUIFormInput(new UIFormSelectBox(IMPORT_BEHAVIOR, IMPORT_BEHAVIOR, null)); // Disabling the size limit since it makes no sense in the import case UIUploadInput uiHistoryFileUpload = new UIUploadInput(VERSION_HISTORY_FILE_UPLOAD, VERSION_HISTORY_FILE_UPLOAD, 1, 0); addUIFormInput(uiHistoryFileUpload); } public void activate() { List<SelectItemOption<String>> importBehavior = new ArrayList<SelectItemOption<String>>(); RequestContext context = RequestContext.getCurrentInstance(); ResourceBundle res = context.getApplicationResourceBundle(); importBehavior.add(new SelectItemOption<String>( res.getString("Import.Behavior.type" + Integer.toString(ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW)), Integer.toString(ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW))); importBehavior.add(new SelectItemOption<String>( res.getString("Import.Behavior.type" + Integer.toString(ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING)), Integer.toString(ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING))); importBehavior.add(new SelectItemOption<String>( res.getString("Import.Behavior.type" + Integer.toString(ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING)), Integer.toString(ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING))); importBehavior.add(new SelectItemOption<String>( res.getString("Import.Behavior.type" + Integer.toString(ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW)), Integer.toString(ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW))); getUIFormSelectBox(IMPORT_BEHAVIOR).setOptions(importBehavior); } public void deActivate() { } private boolean validHistoryUploadFile(Event<?> event) throws Exception { UIUploadInput inputHistory = getUIInput(VERSION_HISTORY_FILE_UPLOAD); UIApplication uiApp = getAncestorOfType(UIApplication.class); ZipInputStream zipInputStream = new ZipInputStream(inputHistory.getUploadDataAsStream(inputHistory.getUploadIds()[0])); ZipEntry entry = zipInputStream.getNextEntry(); while(entry != null) { if(entry.getName().equals(MAPPING_FILE)) { zipInputStream.closeEntry(); return true; } zipInputStream.closeEntry(); entry = zipInputStream.getNextEntry(); } zipInputStream.close(); uiApp.addMessage(new ApplicationMessage("UIImportNode.msg.history-invalid-content", null, ApplicationMessage.WARNING)); return false; } private String getMimeType(String fileName) throws Exception { DMSMimeTypeResolver resolver = DMSMimeTypeResolver.getInstance(); return resolver.getMimeType(fileName); } static public class ImportActionListener extends EventListener<UIImportNode> { public void execute(Event<UIImportNode> event) throws Exception { UIImportNode uiImport = event.getSource(); UIJCRExplorer uiExplorer = uiImport.getAncestorOfType(UIJCRExplorer.class); UIApplication uiApp = uiImport.getAncestorOfType(UIApplication.class); UIUploadInput input = uiImport.getUIInput(FILE_UPLOAD); UIUploadInput inputHistory = uiImport.getUIInput(VERSION_HISTORY_FILE_UPLOAD); Node currentNode = uiExplorer.getCurrentNode(); Session session = currentNode.getSession() ; String nodePath = currentNode.getPath(); uiExplorer.addLockToken(currentNode); String inputUploadId = input.getUploadIds()[0]; String inputHistoryUploadId = inputHistory.getUploadIds()[0]; if (input.getUploadResource(inputUploadId) == null) { uiApp.addMessage(new ApplicationMessage("UIImportNode.msg.filename-invalid", null, ApplicationMessage.WARNING)); return; } if(inputHistory.getUploadResource(inputHistoryUploadId) != null) { String mimeTypeHistory = uiImport.getMimeType(inputHistory.getUploadResource(inputHistoryUploadId).getFileName()); if(!mimeTypeHistory.equals("application/zip")) { uiApp.addMessage(new ApplicationMessage("UIImportNode.msg.history-invalid-type", null, ApplicationMessage.WARNING)); return; } if(!uiImport.validHistoryUploadFile(event)) return; } String mimeType = uiImport.getMimeType(input.getUploadResource(inputUploadId).getFileName()); InputStream xmlInputStream = null; if ("text/xml".equals(mimeType)) { xmlInputStream = new BufferedInputStream(input.getUploadDataAsStream(inputUploadId)); } else if ("application/zip".equals(mimeType)) { ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(input.getUploadDataAsStream(inputUploadId))); xmlInputStream = Utils.extractFirstEntryFromZipFile(zipInputStream); } else { uiApp.addMessage(new ApplicationMessage("UIImportNode.msg.mimetype-invalid", null, ApplicationMessage.WARNING)); return; } try { int importBehavior = Integer.parseInt(uiImport.getUIFormSelectBox(IMPORT_BEHAVIOR).getValue()); //Process import session.importXML(nodePath, xmlInputStream, importBehavior); try { session.save(); } catch (ConstraintViolationException e) { session.refresh(false); Object[] args = { uiExplorer.getCurrentNode().getPrimaryNodeType().getName() }; uiApp.addMessage(new ApplicationMessage("UIImportNode.msg.constraint-violation-exception", args, ApplicationMessage.WARNING)); return; } //Process import version history if(inputHistory.getUploadResource(inputHistoryUploadId) != null) { Map<String, String> mapHistoryValue = org.exoplatform.services.cms.impl.Utils.getMapImportHistory(inputHistory.getUploadDataAsStream(inputHistoryUploadId)); org.exoplatform.services.cms.impl.Utils.processImportHistory( currentNode, inputHistory.getUploadDataAsStream(inputHistoryUploadId), mapHistoryValue); } // if an import fails, it's possible when source xml contains errors, // user may fix the fail caused items and save session (JSR-170, 7.3.7 Session Import Methods). // Or user may decide to make a rollback - make Session.refresh(false) // So, we should make rollback in case of error... // see Session.importXML() throws IOException, PathNotFoundException, ItemExistsException, // ConstraintViolationException, VersionException, InvalidSerializedDataException, LockException, RepositoryException // otherwise ECM FileExplolrer crashes as it assume all items were imported correct. uiApp.addMessage(new ApplicationMessage("UIImportNode.msg.import-successful", null)); } catch (AccessDeniedException ace) { session.refresh(false); uiApp.addMessage(new ApplicationMessage("UIImportNode.msg.access-denied", null, ApplicationMessage.WARNING)); return; } catch (ConstraintViolationException con) { session.refresh(false); Object[] args = { uiExplorer.getCurrentNode().getPrimaryNodeType().getName() }; uiApp.addMessage(new ApplicationMessage("UIImportNode.msg.constraint-violation-exception", args, ApplicationMessage.WARNING)); return; } catch (JCRItemExistsException iee) { session.refresh(false); uiApp.addMessage(new ApplicationMessage("UIImportNode.msg.item-exists-exception", new Object[] { iee.getIdentifier() }, ApplicationMessage.WARNING)); return; } catch (InvalidSerializedDataException isde) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", isde); } session.refresh(false); String msg = isde.getMessage(); String position = ""; if (msg != null && msg.indexOf("[") > 0 && msg.indexOf("]") > 0) { position = msg.substring(msg.lastIndexOf("["), msg.lastIndexOf("]")+1); } String fileName = input.getUploadResource(inputUploadId).getFileName(); Object [] args = new Object[] {position, fileName}; ApplicationMessage appMsg = new ApplicationMessage("UIImportNode.msg.xml-invalid", args, ApplicationMessage.WARNING); appMsg.setArgsLocalized(false); uiApp.addMessage(appMsg); return; } catch (Exception ise) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", ise); } session.refresh(false); uiApp.addMessage(new ApplicationMessage("UIImportNode.msg.filetype-error", null, ApplicationMessage.WARNING)); return; } finally { UploadService uploadService = uiImport.getApplicationComponent(UploadService.class) ; uploadService.removeUploadResource(inputUploadId); uploadService.removeUploadResource(inputHistoryUploadId); } uiExplorer.updateAjax(event); } } static public class CancelActionListener extends EventListener<UIImportNode> { public void execute(Event<UIImportNode> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); uiExplorer.cancelAction(); } } }
13,228
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIExportNode.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIExportNode.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; import java.util.UUID; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.Value; import javax.jcr.query.Query; import javax.jcr.query.QueryManager; import javax.jcr.query.QueryResult; import org.apache.commons.lang3.StringUtils; import org.exoplatform.download.DownloadService; import org.exoplatform.download.InputStreamDownloadResource; import org.exoplatform.ecm.utils.text.Text; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.compress.CompressData; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.web.application.RequestContext; import org.exoplatform.web.application.RequireJS; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormInputInfo; import org.exoplatform.webui.form.UIFormRadioBoxInput; import org.exoplatform.webui.form.input.UICheckBoxInput; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Oct 5, 2006 */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/explorer/popup/admin/UIFormWithMultiRadioBox.gtmpl", events = { @EventConfig(listeners = UIExportNode.ExportActionListener.class), @EventConfig(listeners = UIExportNode.ExportHistoryActionListener.class), @EventConfig(listeners = UIExportNode.CancelActionListener.class) } ) public class UIExportNode extends UIForm implements UIPopupComponent { private static final Log LOG = ExoLogger.getLogger(UIExportNode.class.getName()); public static final String NODE_PATH = "nodePath"; public static final String FORMAT = "format"; public static final String ZIP = "zip"; public static final String DOC_VIEW = "docview"; public static final String SYS_VIEW = "sysview"; public static final String VERSION_SQL_QUERY = "select * from mix:versionable where jcr:path like '$0/%' " + "order by exo:dateCreated DESC"; public static final String ROOT_SQL_QUERY = "select * from mix:versionable order by exo:dateCreated DESC"; private boolean isVerionNode_ = false; public UIExportNode() throws Exception { RequestContext context = RequestContext.getCurrentInstance(); ResourceBundle resourceBundle = context.getApplicationResourceBundle(); List<SelectItemOption<String>> formatItem = new ArrayList<SelectItemOption<String>>() ; formatItem.add(new SelectItemOption<String>( resourceBundle.getString("Import.label." + SYS_VIEW), SYS_VIEW)); formatItem.add(new SelectItemOption<String>( resourceBundle.getString("Import.label." + DOC_VIEW), DOC_VIEW)); addUIFormInput(new UIFormInputInfo(NODE_PATH, NODE_PATH, null)) ; addUIFormInput(new UIFormRadioBoxInput(FORMAT, SYS_VIEW, formatItem). setAlign(UIFormRadioBoxInput.VERTICAL_ALIGN)) ; addUIFormInput(new UICheckBoxInput(ZIP, ZIP, null)) ; } public void update(Node node) throws Exception { getUIFormInputInfo(NODE_PATH).setValue(Text.unescapeIllegalJcrChars(node.getPath())) ; } public void activate() { try { update(getAncestorOfType(UIJCRExplorer.class).getCurrentNode()); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } public void deActivate() { } public QueryResult getQueryResult(Node currentNode) throws RepositoryException { QueryManager queryManager = currentNode.getSession().getWorkspace().getQueryManager(); String queryStatement = ""; if(currentNode.getPath().equals("/")) { queryStatement = ROOT_SQL_QUERY; } else { queryStatement = StringUtils.replace(VERSION_SQL_QUERY,"$0",currentNode.getPath()); } Query query = queryManager.createQuery(queryStatement, Query.SQL); return query.execute(); } public String[] getActions() { try { Node currentNode = getAncestorOfType(UIJCRExplorer.class).getCurrentNode(); if(currentNode.isNodeType(Utils.MIX_VERSIONABLE)) isVerionNode_ = true; QueryResult queryResult = getQueryResult(currentNode); if(queryResult.getNodes().getSize() > 0 || isVerionNode_) { return new String[] {"Export", "ExportHistory", "Cancel"}; } } catch(Exception e) { return new String[] {"Export", "Cancel"}; } return new String[] {"Export", "Cancel"}; } private String getHistoryValue(Node node) throws Exception { String versionHistory = node.getProperty("jcr:versionHistory").getValue().getString(); String baseVersion = node.getProperty("jcr:baseVersion").getValue().getString(); Value[] predecessors = node.getProperty("jcr:predecessors").getValues(); StringBuilder historyValue = new StringBuilder(); StringBuilder predecessorsBuilder = new StringBuilder(); for(Value value : predecessors) { if(predecessorsBuilder.length() > 0) predecessorsBuilder.append(",") ; predecessorsBuilder.append(value.getString()); } historyValue.append(node.getUUID()).append("=").append(versionHistory). append(";").append(baseVersion).append(";").append(predecessorsBuilder.toString()); return historyValue.toString(); } /** * Create temp file to allow download a big data * @return file */ private static File getExportedFile(String prefix, String suffix) throws IOException { return File.createTempFile(prefix.concat(UUID.randomUUID().toString()), suffix); } static public class ExportActionListener extends EventListener<UIExportNode> { public void execute(Event<UIExportNode> event) throws Exception { UIExportNode uiExport = event.getSource(); UIJCRExplorer uiExplorer = uiExport.getAncestorOfType(UIJCRExplorer.class); UIApplication uiApp = uiExport.getAncestorOfType(UIApplication.class); File exportedFile = UIExportNode.getExportedFile("export", ".xml"); OutputStream out = new BufferedOutputStream(new FileOutputStream(exportedFile)); InputStream in = new BufferedInputStream(new TempFileInputStream(exportedFile)); CompressData zipService = new CompressData(); DownloadService dservice = uiExport.getApplicationComponent(DownloadService.class); InputStreamDownloadResource dresource; String format = uiExport.<UIFormRadioBoxInput> getUIInput(FORMAT).getValue(); boolean isZip = uiExport.getUICheckBoxInput(ZIP).isChecked(); Node currentNode = uiExplorer.getCurrentNode(); Session session = currentNode.getSession() ; String nodePath = currentNode.getPath(); File zipFile = null; try { if(isZip) { if (format.equals(DOC_VIEW)) session.exportDocumentView(nodePath, out, false, false); else session.exportSystemView(nodePath, out, false, false); out.flush(); out.close(); zipFile = UIExportNode.getExportedFile("data", ".zip"); out = new BufferedOutputStream(new FileOutputStream(zipFile)); zipService.addInputStream(format + ".xml", in); zipService.createZip(out); in.close(); exportedFile.delete(); in = new BufferedInputStream(new TempFileInputStream(zipFile)); dresource = new InputStreamDownloadResource(in, "application/zip"); dresource.setDownloadName(format + ".zip"); } else { if (format.equals(DOC_VIEW)) session.exportDocumentView(nodePath, out, false, false); else session.exportSystemView(nodePath, out, false, false); out.flush(); dresource = new InputStreamDownloadResource(in, "text/xml"); dresource.setDownloadName(format + ".xml"); } String downloadLink = dservice.getDownloadLink(dservice.addDownloadResource(dresource)); RequireJS requireJS = event.getRequestContext().getJavascriptManager().getRequireJS(); requireJS.require("SHARED/ecm-utils", "ecmutil").addScripts("ecmutil.ECMUtils.ajaxRedirect('" + downloadLink + "');"); uiExplorer.cancelAction(); } catch (OutOfMemoryError error) { uiApp.addMessage(new ApplicationMessage("UIExportNode.msg.OutOfMemoryError", null, ApplicationMessage.ERROR)); return; } finally { out.close(); } } } static public class ExportHistoryActionListener extends EventListener<UIExportNode> { public void execute(Event<UIExportNode> event) throws Exception { UIExportNode uiExport = event.getSource() ; UIJCRExplorer uiExplorer = uiExport.getAncestorOfType(UIJCRExplorer.class) ; UIApplication uiApp = uiExport.getAncestorOfType(UIApplication.class); CompressData zipService = new CompressData(); DownloadService dservice = uiExport.getApplicationComponent(DownloadService.class) ; InputStreamDownloadResource dresource ; Node currentNode = uiExplorer.getCurrentNode(); String sysWsName = uiExplorer.getRepository().getConfiguration().getSystemWorkspaceName(); Session session = uiExplorer.getSessionByWorkspace(sysWsName); QueryResult queryResult = uiExport.getQueryResult(currentNode); NodeIterator queryIter = queryResult.getNodes(); String format = uiExport.<UIFormRadioBoxInput>getUIInput(FORMAT).getValue() ; OutputStream out = null; InputStream in = null; List<File> lstExporedFile = new ArrayList<File>(); File exportedFile = null; File zipFile = null; File propertiesFile = UIExportNode.getExportedFile("mapping", ".properties"); OutputStream propertiesBOS = new BufferedOutputStream(new FileOutputStream(propertiesFile)); InputStream propertiesBIS = new BufferedInputStream(new TempFileInputStream(propertiesFile)); try { while(queryIter.hasNext()) { exportedFile = UIExportNode.getExportedFile("data", ".xml"); lstExporedFile.add(exportedFile); out = new BufferedOutputStream(new FileOutputStream(exportedFile)); in = new BufferedInputStream(new TempFileInputStream(exportedFile)); Node node = queryIter.nextNode(); String historyValue = uiExport.getHistoryValue(node); propertiesBOS.write(historyValue.getBytes()); propertiesBOS.write('\n'); if(format.equals(DOC_VIEW)) session.exportDocumentView(node.getVersionHistory().getPath(), out, false, false ); else session.exportSystemView(node.getVersionHistory().getPath(), out, false, false ); out.flush(); zipService.addInputStream(node.getUUID() + ".xml", in); } if(currentNode.isNodeType(Utils.MIX_VERSIONABLE)) { exportedFile = UIExportNode.getExportedFile("data", ".xml"); lstExporedFile.add(exportedFile); out = new BufferedOutputStream(new FileOutputStream(exportedFile)); in = new BufferedInputStream(new TempFileInputStream(exportedFile)); String historyValue = uiExport.getHistoryValue(currentNode); propertiesBOS.write(historyValue.getBytes()); propertiesBOS.write('\n'); if (format.equals(DOC_VIEW)) session.exportDocumentView(currentNode.getVersionHistory().getPath(), out, false, false); else session.exportSystemView(currentNode.getVersionHistory().getPath(), out, false, false); out.flush(); zipService.addInputStream(currentNode.getUUID() + ".xml",in); } propertiesBOS.flush(); zipService.addInputStream("mapping.properties", propertiesBIS); zipFile = UIExportNode.getExportedFile("data", "zip"); in = new BufferedInputStream(new TempFileInputStream(zipFile)); out = new BufferedOutputStream(new FileOutputStream(zipFile)); out.flush(); zipService.createZip(out); dresource = new InputStreamDownloadResource(in, "application/zip") ; dresource.setDownloadName(format + "_versionHistory.zip"); String downloadLink = dservice.getDownloadLink(dservice.addDownloadResource(dresource)) ; RequireJS requireJS = event.getRequestContext().getJavascriptManager().getRequireJS(); requireJS.require("SHARED/ecm-utils", "ecmutil").addScripts("ecmutil.ECMUtils.ajaxRedirect('" + downloadLink + "');"); } catch (OutOfMemoryError error) { uiApp.addMessage(new ApplicationMessage("UIExportNode.msg.OutOfMemoryError", null, ApplicationMessage.ERROR)); return; } finally { propertiesBOS.close(); propertiesBIS.close(); if (out != null) { out.close(); } } } } static public class CancelActionListener extends EventListener<UIExportNode> { public void execute(Event<UIExportNode> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class) ; uiExplorer.cancelAction() ; } } private static class TempFileInputStream extends FileInputStream { private final File file; public TempFileInputStream(File file) throws FileNotFoundException { super(file); this.file = file; try { file.deleteOnExit(); } catch (Exception e) { // ignore me } } } }
15,183
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIActionList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIActionList.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import java.util.ArrayList; import java.util.List; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.component.explorer.UIDocumentContainer; import org.exoplatform.ecm.webui.component.explorer.UIDocumentInfo; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.sidebar.UITreeExplorer; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.services.cms.actions.ActionServiceContainer; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.wcm.core.NodeLocation; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPageIterator; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Nov 8, 2006 * 9:41:56 AM */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/popup/admin/UIActionList.gtmpl", events = { @EventConfig(listeners = UIActionList.ViewActionListener.class), @EventConfig(listeners = UIActionList.DeleteActionListener.class, confirm = "UIActionList.msg.confirm-delete-action"), @EventConfig(listeners = UIActionList.CloseActionListener.class), @EventConfig(listeners = UIActionList.EditActionListener.class) } ) public class UIActionList extends UIContainer { final static public String[] ACTIONS = {"View", "Edit", "Delete"} ; public UIActionList() throws Exception { addChild(UIPageIterator.class, null, "ActionListIterator"); } @SuppressWarnings("unchecked") public void updateGrid(Node node, int currentPage) throws Exception { UIPageIterator uiIterator = getChild(UIPageIterator.class) ; ListAccess<Object> actionList = new ListAccessImpl<Object>(Object.class, NodeLocation.getLocationsByNodeList(getAllActions(node))); LazyPageList<Object> objPageList = new LazyPageList<Object>(actionList, 10); uiIterator.setPageList(objPageList); if(currentPage > uiIterator.getAvailablePage()) uiIterator.setCurrentPage(uiIterator.getAvailablePage()); else uiIterator.setCurrentPage(currentPage); } public String[] getActions() { return ACTIONS ; } public boolean hasActions() throws Exception{ UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ; ActionServiceContainer actionService = getApplicationComponent(ActionServiceContainer.class) ; return actionService.hasActions(uiExplorer.getCurrentNode()); } public List<Node> getAllActions(Node node) { ActionServiceContainer actionService = getApplicationComponent(ActionServiceContainer.class) ; try { return actionService.getActions(node); } catch(Exception e){ return new ArrayList<Node>() ; } } public List getListActions() throws Exception { UIPageIterator uiIterator = getChild(UIPageIterator.class) ; return NodeLocation.getNodeListByLocationList(uiIterator.getCurrentPageData()); } static public class ViewActionListener extends EventListener<UIActionList> { public void execute(Event<UIActionList> event) throws Exception { UIActionList uiActionList = event.getSource() ; String actionName = event.getRequestContext().getRequestParameter(OBJECTID) ; UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class) ; UIActionManager uiActionManager = uiExplorer.findFirstComponentOfType(UIActionManager.class) ; ActionServiceContainer actionService = uiActionList.getApplicationComponent(ActionServiceContainer.class); Node node = actionService.getAction(uiExplorer.getCurrentNode(),actionName); String nodeTypeName = node.getPrimaryNodeType().getName() ; String userName = event.getRequestContext().getRemoteUser() ; TemplateService templateService = uiActionList.getApplicationComponent(TemplateService.class) ; UIApplication uiApp = uiActionList.getAncestorOfType(UIApplication.class) ; try { String path = templateService.getTemplatePathByUser(false, nodeTypeName, userName); if(path == null) { Object[] args = {actionName} ; uiApp.addMessage(new ApplicationMessage("UIActionList.msg.template-null", args, ApplicationMessage.WARNING)) ; return ; } } catch(PathNotFoundException path) { Object[] args = {actionName} ; uiApp.addMessage(new ApplicationMessage("UIActionList.msg.template-empty", args, ApplicationMessage.WARNING)) ; return ; } catch(AccessDeniedException ace) { uiApp.addMessage(new ApplicationMessage("UIActionList.msg.access-denied", null, ApplicationMessage.WARNING)) ; return ; } catch(Exception e) { JCRExceptionManager.process(uiApp, e) ; return ; } if(uiActionManager.getChild(UIActionViewContainer.class) != null) { uiActionManager.removeChild(UIActionViewContainer.class) ; } UIActionViewContainer uiActionViewContainer = uiActionManager.createUIComponent(UIActionViewContainer.class, null, null) ; UIActionViewTemplate uiViewTemplate = uiActionViewContainer.createUIComponent(UIActionViewTemplate.class, null, null) ; uiViewTemplate.setTemplateNode(node) ; uiActionViewContainer.addChild(uiViewTemplate) ; uiActionManager.addChild(uiActionViewContainer) ; uiActionManager.setRenderedChild(UIActionViewContainer.class) ; } } static public class EditActionListener extends EventListener<UIActionList> { public void execute(Event<UIActionList> event) throws Exception { UIActionList uiActionList = event.getSource() ; UIJCRExplorer uiExplorer = uiActionList.getAncestorOfType(UIJCRExplorer.class) ; UIActionListContainer uiActionListContainer = uiActionList.getParent() ; String actionName = event.getRequestContext().getRequestParameter(OBJECTID) ; TemplateService templateService = uiActionList.getApplicationComponent(TemplateService.class) ; String userName = event.getRequestContext().getRemoteUser() ; String repository = uiActionList.getAncestorOfType(UIJCRExplorer.class).getRepositoryName() ; Node currentNode = uiExplorer.getCurrentNode() ; ActionServiceContainer actionService = uiActionList.getApplicationComponent(ActionServiceContainer.class); Node selectedAction = null ; try { selectedAction = actionService.getAction(currentNode,actionName); } catch(PathNotFoundException path) { currentNode.refresh(false) ; UIDocumentContainer uiDocumentContainer = uiExplorer.findFirstComponentOfType(UIDocumentContainer.class) ; UIDocumentInfo uiDocumentInfo = uiDocumentContainer.getChild(UIDocumentInfo.class) ; if(uiExplorer.isShowViewFile()) uiDocumentInfo.setRendered(false) ; else uiDocumentInfo.setRendered(true) ; if(uiExplorer.getPreference().isShowSideBar()) { UITreeExplorer treeExplorer = uiExplorer.findFirstComponentOfType(UITreeExplorer.class); treeExplorer.buildTree(); } selectedAction = actionService.getAction(currentNode,actionName); } String nodeTypeName = selectedAction.getPrimaryNodeType().getName() ; UIApplication uiApp = uiActionList.getAncestorOfType(UIApplication.class) ; try { templateService.getTemplatePathByUser(true, nodeTypeName, userName); } catch(PathNotFoundException path) { Object[] args = {actionName} ; uiApp.addMessage(new ApplicationMessage("UIActionList.msg.template-empty", args, ApplicationMessage.WARNING)) ; return ; } catch(Exception e) { JCRExceptionManager.process(uiApp, e) ; return ; } uiActionListContainer.initEditPopup(selectedAction) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiActionListContainer) ; } } static public class CloseActionListener extends EventListener<UIActionList> { public void execute(Event<UIActionList> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class) ; uiExplorer.setIsHidePopup(false) ; uiExplorer.cancelAction() ; } } static public class DeleteActionListener extends EventListener<UIActionList> { public void execute(Event<UIActionList> event) throws Exception { UIActionList uiActionList = event.getSource() ; UIJCRExplorer uiExplorer = uiActionList.getAncestorOfType(UIJCRExplorer.class) ; ActionServiceContainer actionService = uiActionList.getApplicationComponent(ActionServiceContainer.class) ; String actionName = event.getRequestContext().getRequestParameter(OBJECTID) ; UIActionListContainer uiActionListContainer = uiActionList.getParent() ; UIPopupWindow uiPopup = uiActionListContainer.getChildById("editActionPopup") ; UIApplication uiApp = uiActionList.getAncestorOfType(UIApplication.class) ; if(uiPopup != null && uiPopup.isShow()) { uiPopup.setShowMask(true); uiApp.addMessage(new ApplicationMessage("UIActionList.msg.remove-popup-first", null, ApplicationMessage.WARNING)) ; return ; } if(uiPopup != null && uiPopup.isRendered()) uiActionListContainer.removeChildById("editActionPopup") ; try { actionService.removeAction(uiExplorer.getCurrentNode(), actionName, uiExplorer.getRepositoryName()) ; } catch(AccessDeniedException ace) { uiApp.addMessage(new ApplicationMessage("UIActionList.msg.access-denied", null, ApplicationMessage.WARNING)) ; return ; } UIActionManager uiActionManager = uiExplorer.findFirstComponentOfType(UIActionManager.class) ; uiActionManager.removeChild(UIActionViewContainer.class) ; uiActionList.updateGrid(uiExplorer.getCurrentNode(), uiActionList.getChild(UIPageIterator.class).getCurrentPage()); uiActionManager.setRenderedChild(UIActionListContainer.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiActionManager) ; } } }
12,077
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIActionManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIActionManager.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPageIterator; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupWindow; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Nov 8, 2006 * 9:39:58 AM */ @ComponentConfig(template = "system:/groovy/webui/core/UITabPane.gtmpl") public class UIActionManager extends UIContainer implements UIPopupComponent { private static final Log LOG = ExoLogger.getLogger(UIActionManager.class.getName()); public UIActionManager() throws Exception { addChild(UIActionListContainer.class, null, null); addChild(UIActionContainer.class, null, null).setRendered(false); } public void activate() { try { UIActionTypeForm uiActionTypeForm = findFirstComponentOfType(UIActionTypeForm.class); uiActionTypeForm.update(); UIActionList uiActionList = findFirstComponentOfType(UIActionList.class); uiActionList.updateGrid(getAncestorOfType(UIJCRExplorer.class).getCurrentNode(), uiActionList.getChild(UIPageIterator.class).getCurrentPage()); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } /** * Remove lock if node is locked for editing */ public void deActivate() { try { UIActionForm uiForm = findFirstComponentOfType(UIActionForm.class); if (uiForm != null) { uiForm.releaseLock(); } } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } @Override public void processRender(WebuiRequestContext context) throws Exception { UIPopupWindow uiPopup = getAncestorOfType(UIPopupWindow.class); if (uiPopup != null && !uiPopup.isShow()) { uiPopup.setShowMask(true); deActivate(); } super.processRender(context); } public void setDefaultConfig() throws Exception { UIActionContainer uiActionContainer = getChild(UIActionContainer.class); UIActionTypeForm uiActionType = uiActionContainer.getChild(UIActionTypeForm.class); uiActionType.setDefaultActionType(); Class[] renderClasses = { UIActionTypeForm.class, UIActionForm.class }; uiActionContainer.setRenderedChildrenOfTypes(renderClasses); } }
3,469
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIPropertiesManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIPropertiesManager.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import java.util.List; import javax.jcr.Node; import javax.jcr.nodetype.PropertyDefinition; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * September 17, 2006 * 10:07:15 AM */ @ComponentConfig( template = "system:/groovy/webui/core/UITabPane_New.gtmpl", events = { @EventConfig(listeners = UIPropertiesManager.SelectTabActionListener.class) } ) public class UIPropertiesManager extends UIContainer implements UIPopupComponent { private String selectedPath_ = null; private String wsName_ = null; private boolean isEditProperty = false; private List<PropertyDefinition> properties = null; private String selectedTabId = ""; public UIPropertiesManager() throws Exception { addChild(UIPropertyTab.class, null, null); addChild(UIPropertyForm.class, null, null); setSelectedTab(1); } public String getSelectedTabId() { return selectedTabId; } public void setSelectedTab(String renderTabId) { selectedTabId = renderTabId; } public void setSelectedTab(int index) { selectedTabId = getChild(index - 1).getId(); } public void processRender(WebuiRequestContext context) throws Exception { Node currentNode = getCurrentNode(); properties = org.exoplatform.services.cms.impl.Utils.getProperties(currentNode); if (!isEditProperty && currentNode != null && !currentNode.isNodeType(Utils.NT_UNSTRUCTURED) && (properties == null || properties.size() == 0)) { removeChild(UIPropertyForm.class); } super.processRender(context); } public Node getCurrentNode() throws Exception { UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ; if(uiExplorer != null) { if(selectedPath_ != null) { return uiExplorer.getNodeByPath(selectedPath_, uiExplorer.getSessionByWorkspace(wsName_)); } return uiExplorer.getCurrentNode(); } else return null; } public void setSelectedPath(String selectedPath, String wsName) { selectedPath_ = selectedPath; wsName_ = wsName; } public void activate() { } public void deActivate() {} public void setLockForm(boolean isLockForm) { getChild(UIPropertyForm.class).lockForm(isLockForm) ; } static public class SelectTabActionListener extends EventListener<UIPropertiesManager> { public void execute(Event<UIPropertiesManager> event) throws Exception { WebuiRequestContext context = event.getRequestContext(); String renderTab = context.getRequestParameter(UIComponent.OBJECTID); if (renderTab == null) return; event.getSource().setSelectedTab(renderTab); WebuiRequestContext parentContext = (WebuiRequestContext)context.getParentAppRequestContext(); if (parentContext != null) { parentContext.setResponseComplete(true); } else { context.setResponseComplete(true); } } } public void setIsEditProperty(boolean isEdit) { this.isEditProperty = isEdit; } }
4,466
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIActionTypeForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/popup/admin/UIActionTypeForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.popup.admin; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import javax.jcr.nodetype.NodeType; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.cms.actions.ActionServiceContainer; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormSelectBox; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Nov 8, 2006 * 9:41:47 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/explorer/UIFormWithoutAction.gtmpl", events = @EventConfig(listeners = UIActionTypeForm.ChangeActionTypeActionListener.class) ) public class UIActionTypeForm extends UIForm { final static public String ACTION_TYPE = "actionType" ; final static public String CHANGE_ACTION = "ChangeActionType" ; private List<SelectItemOption<String>> typeList_ ; public String defaultActionType_ ; public UIActionTypeForm() throws Exception { typeList_ = new ArrayList<SelectItemOption<String>>() ; UIFormSelectBox uiSelectBox = new UIFormSelectBox(ACTION_TYPE, ACTION_TYPE, new ArrayList<SelectItemOption<String>>()) ; uiSelectBox.setOnChange(CHANGE_ACTION) ; addUIFormInput(uiSelectBox) ; } private Iterator<NodeType> getCreatedActionTypes() throws Exception { ActionServiceContainer actionService = getApplicationComponent(ActionServiceContainer.class) ; String repository = getAncestorOfType(UIJCRExplorer.class).getRepositoryName() ; return actionService.getCreatedActionTypes(repository).iterator(); } public void setDefaultActionType() throws Exception{ UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ; UIActionContainer uiActionContainer = getParent() ; Node currentNode = uiExplorer.getCurrentNode() ; UIActionForm uiActionForm = uiActionContainer.getChild(UIActionForm.class) ; uiActionForm.createNewAction(currentNode, typeList_.get(0).getValue(), true) ; uiActionForm.setWorkspace(currentNode.getSession().getWorkspace().getName()) ; uiActionForm.setStoredPath(currentNode.getPath()) ; } public void update() throws Exception { Iterator<NodeType> actions = getCreatedActionTypes(); List<String> actionList = new ArrayList<String>(); while(actions.hasNext()){ String action = actions.next().getName(); actionList.add(action); } Collections.sort(actionList); TemplateService templateService = getApplicationComponent(TemplateService.class); String userName = Util.getPortalRequestContext().getRemoteUser(); for(String action : actionList) { try { templateService.getTemplatePathByUser(true, action, userName); typeList_.add(new SelectItemOption<String>(action, action)); } catch (Exception e){ continue; } } getUIFormSelectBox(ACTION_TYPE).setOptions(typeList_) ; defaultActionType_ = typeList_.get(0).getValue(); getUIFormSelectBox(ACTION_TYPE).setValue(defaultActionType_); setDefaultActionType(); } static public class ChangeActionTypeActionListener extends EventListener<UIActionTypeForm> { public void execute(Event<UIActionTypeForm> event) throws Exception { UIActionTypeForm uiActionType = event.getSource() ; UIJCRExplorer uiExplorer = uiActionType.getAncestorOfType(UIJCRExplorer.class) ; Node currentNode = uiExplorer.getCurrentNode() ; String actionType = uiActionType.getUIFormSelectBox(ACTION_TYPE).getValue() ; TemplateService templateService = uiActionType.getApplicationComponent(TemplateService.class) ; String userName = Util.getPortalRequestContext().getRemoteUser() ; UIApplication uiApp = uiActionType.getAncestorOfType(UIApplication.class) ; try { String templatePath = templateService.getTemplatePathByUser(true, actionType, userName) ; if(templatePath == null) { Object[] arg = { actionType } ; uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.access-denied", arg, ApplicationMessage.WARNING)) ; uiActionType.getUIFormSelectBox( UIActionTypeForm.ACTION_TYPE).setValue(uiActionType.defaultActionType_) ; UIActionContainer uiActionContainer = uiActionType.getAncestorOfType(UIActionContainer.class) ; UIActionForm uiActionForm = uiActionContainer.getChild(UIActionForm.class) ; uiActionForm.createNewAction(currentNode, uiActionType.defaultActionType_, true) ; uiActionContainer.setRenderSibling(UIActionContainer.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiActionContainer) ; return ; } } catch(PathNotFoundException path) { Object[] arg = { actionType } ; uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.not-support", arg, ApplicationMessage.WARNING)) ; uiActionType.getUIFormSelectBox( UIActionTypeForm.ACTION_TYPE).setValue(uiActionType.defaultActionType_) ; UIActionContainer uiActionContainer = uiActionType.getAncestorOfType(UIActionContainer.class) ; UIActionForm uiActionForm = uiActionContainer.getChild(UIActionForm.class) ; uiActionForm.createNewAction(currentNode, uiActionType.defaultActionType_, true) ; uiActionContainer.setRenderSibling(UIActionContainer.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiActionContainer) ; } UIActionContainer uiActionContainer = uiActionType.getParent() ; UIActionForm uiActionForm = uiActionContainer.getChild(UIActionForm.class) ; uiActionForm.createNewAction(currentNode, actionType, true) ; uiActionContainer.setRenderSibling(UIActionContainer.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiActionContainer) ; } } }
7,574
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
EditorsOpenManageComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/documents/EditorsOpenManageComponent.java
/* * Copyright (C) 2003-2019 eXo Platform SAS. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.exoplatform.ecm.webui.component.explorer.documents; import java.util.Arrays; import java.util.List; import org.exoplatform.ecm.webui.component.explorer.control.filter.DownloadDocumentFilter; import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; import org.exoplatform.webui.ext.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * The Class EditorsOpenManageComponent creates and displays UINewDocumentForm. */ @ComponentConfig(events = { @EventConfig(listeners = EditorsOpenManageComponent.EditorsOpenActionListener.class) }) public class EditorsOpenManageComponent extends UIAbstractManagerComponent { /** The Constant LOG. */ protected static final Log LOG = ExoLogger.getLogger(EditorsOpenManageComponent.class); /** The Constant FILTERS. */ private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] { new IsAvailableDocumentProviderPresentFilter(), new DownloadDocumentFilter() }); /** * The listener interface for receiving onlyofficeOpenAction events. The class * that is interested in processing a onlyofficeOpenAction event implements * this interface, and the object created with that class is registered with a * component using the component's * <code>addOnlyofficeOpenActionListener</code> method. When the * onlyofficeOpenAction event occurs, that object's appropriate method is * invoked. */ public static class EditorsOpenActionListener extends UIActionBarActionListener<EditorsOpenManageComponent> { /** * {@inheritDoc} */ public void processEvent(Event<EditorsOpenManageComponent> event) throws Exception { // This code will not be invoked } } /** * Gets the filters. * * @return the filters */ @UIExtensionFilters public List<UIExtensionFilter> getFilters() { return FILTERS; } /** * {@inheritDoc} */ @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return null; } }
3,304
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
DocumentEditorsLifecycle.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/documents/DocumentEditorsLifecycle.java
/* * Copyright (C) 2003-2020 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.documents; import java.util.List; import javax.jcr.Node; import javax.jcr.RepositoryException; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.portal.application.PortalRequestContext; import org.exoplatform.services.cms.documents.DocumentEditorProvider; import org.exoplatform.services.cms.documents.DocumentService; import org.exoplatform.services.cms.documents.impl.EditorProvidersHelper; import org.exoplatform.services.cms.documents.impl.EditorProvidersHelper.ProviderInfo; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.security.ConversationState; import org.exoplatform.services.security.Identity; import org.exoplatform.web.application.Application; import org.exoplatform.web.application.ApplicationLifecycle; import org.exoplatform.web.application.RequestContext; import org.exoplatform.web.application.RequestFailure; import org.exoplatform.web.application.RequireJS; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.ws.frameworks.json.impl.JsonException; import org.exoplatform.ws.frameworks.json.impl.JsonGeneratorImpl; import jakarta.servlet.ServletRequest; /** * The Class DocumentEditorsLifecycle. */ public class DocumentEditorsLifecycle implements ApplicationLifecycle<WebuiRequestContext> { /** The Constant USERID_ATTRIBUTE. */ public static final String USERID_ATTRIBUTE = "DocumentEditorsContext.userId"; /** The Constant DOCUMENT_WORKSPACE_ATTRIBUTE. */ public static final String DOCUMENT_WORKSPACE_ATTRIBUTE = "DocumentEditorsContext.document.workspace"; /** The Constant DOCUMENT_PATH_ATTRIBUTE. */ public static final String DOCUMENT_PATH_ATTRIBUTE = "DocumentEditorsContext.document.path"; /** The Constant LOG. */ protected static final Log LOG = ExoLogger.getLogger(DocumentEditorsLifecycle.class); /** The Constant MIX_REFERENCEABLE. */ protected static final String MIX_REFERENCEABLE = "mix:referenceable"; /** The document service. */ protected DocumentService documentService; /** * Instantiates a new DocumentEditorsLifecycle lifecycle. */ public DocumentEditorsLifecycle() { // } /** * {@inheritDoc} */ @Override public void onInit(Application app) throws Exception { // nothing } /** * {@inheritDoc} */ @Override public void onStartRequest(Application app, WebuiRequestContext context) throws Exception { // nothing } /** * {@inheritDoc} */ @Override public void onFailRequest(Application app, WebuiRequestContext context, RequestFailure failureType) { // nothing } /** * {@inheritDoc} */ @Override public void onDestroy(Application app) throws Exception { // nothing } /** * {@inheritDoc} */ @Override public void onEndRequest(Application app, WebuiRequestContext context) throws Exception { RequestContext parentContext = context.getParentAppRequestContext(); UIJCRExplorer explorer = context.getUIApplication().findFirstComponentOfType(UIJCRExplorer.class); if (explorer != null && parentContext != null) { try { String userName = context.getRemoteUser(); Node node = explorer.getCurrentNode(); String nodeWs = node.getSession().getWorkspace().getName(); String nodePath = node.getPath(); if (node.isNodeType(MIX_REFERENCEABLE) && isNotSameUserDocument(userName, nodeWs, nodePath, parentContext)) { if (LOG.isDebugEnabled()) { LOG.debug("Init documents explorer for {}, node: {}:{}, context: {}", userName, nodeWs, nodePath, parentContext); } parentContext.setAttribute(USERID_ATTRIBUTE, userName); parentContext.setAttribute(DOCUMENT_WORKSPACE_ATTRIBUTE, nodeWs); parentContext.setAttribute(DOCUMENT_PATH_ATTRIBUTE, nodePath); initExplorer(context, node.getUUID(), node.getSession().getWorkspace().getName()); } } catch (RepositoryException e) { LOG.error("Couldn't initialize document editors JS module", e); } } else if (LOG.isDebugEnabled()) { LOG.debug("Explorer or portal context not found, explorer: {}, context: {}", explorer, parentContext); } } /** * Gets the servlet request associated with given context. * * @param context the context * @return the servlet request */ protected ServletRequest getServletRequest(WebuiRequestContext context) { try { // First we assume it's PortalRequestContext return context.getRequest(); } catch (ClassCastException e) { // Then try get portlet's parent context RequestContext parentContext = context.getParentAppRequestContext(); if (parentContext != null && PortalRequestContext.class.isAssignableFrom(parentContext.getClass())) { return PortalRequestContext.class.cast(parentContext).getRequest(); } } return null; } /** * Inits the editors module. * * @param context the context * @param fileId the file id * @param workspace the workspace * @throws RepositoryException the repository exception */ protected void initExplorer(WebuiRequestContext context, String fileId, String workspace) throws RepositoryException { Identity identity = ConversationState.getCurrent().getIdentity(); List<DocumentEditorProvider> providers = getDocumentService().getDocumentEditorProviders(); List<ProviderInfo> providersInfo = EditorProvidersHelper.getInstance() .initExplorer(providers, identity, fileId, workspace, context); try { String providersInfoJson = new JsonGeneratorImpl().createJsonArray(providersInfo).toString(); RequireJS require = context.getJavascriptManager().require("SHARED/editorbuttons", "editorbuttons"); require.addScripts("editorbuttons.initExplorer('" + fileId + "', '" + workspace + "', " + providersInfoJson + ");"); } catch (JsonException e) { LOG.warn("Cannot generate JSON for initializing exprorer in editors module. {}", e.getMessage()); } } /** * Checks if is not same user document. * * @param userName the user name * @param nodeWs the node ws * @param nodePath the node path * @param parentContext the parent context * @return true, if is not same user document */ private boolean isNotSameUserDocument(String userName, String nodeWs, String nodePath, RequestContext parentContext) { return !(userName.equals(parentContext.getAttribute(USERID_ATTRIBUTE)) && nodeWs.equals(parentContext.getAttribute(DOCUMENT_WORKSPACE_ATTRIBUTE)) && nodePath.equals(parentContext.getAttribute(DOCUMENT_PATH_ATTRIBUTE))); } /** * Gets the document service. * * @return the document service */ protected DocumentService getDocumentService() { if (documentService == null) { documentService = WebuiRequestContext.getCurrentInstance() .getApplication() .getApplicationServiceContainer() .getComponentInstanceOfType(DocumentService.class); } return documentService; } }
8,091
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
DocumentSelectItemOption.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/documents/DocumentSelectItemOption.java
/* * Copyright (C) 2003-2020 eXo Platform SAS. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.exoplatform.ecm.webui.component.explorer.documents; import org.exoplatform.services.cms.documents.NewDocumentTemplateProvider; import org.exoplatform.webui.core.model.SelectItemOption; /** * The Class DocumentSelectItemOption adds a template provider to SelectItemOption. * * @param <T> the generic type */ public class DocumentSelectItemOption<T> extends SelectItemOption<T> { /** The template provider. */ protected final NewDocumentTemplateProvider templateProvider; /** * Instantiates a new document select item option. * * @param templateProvider the template provider */ public DocumentSelectItemOption(NewDocumentTemplateProvider templateProvider) { super(); this.templateProvider = templateProvider; } /** * Instantiates a new document select item option. * * @param label the label * @param value the value * @param icon the icon * @param templateProvider the template provider */ public DocumentSelectItemOption(String label, T value, String icon, NewDocumentTemplateProvider templateProvider) { super(label, value, icon); this.templateProvider = templateProvider; } /** * Instantiates a new document select item option. * * @param label the label * @param value the value * @param desc the desc * @param icon the icon * @param templateProvider the template provider */ public DocumentSelectItemOption(String label, T value, String desc, String icon, NewDocumentTemplateProvider templateProvider) { super(label, value, desc, icon); this.templateProvider = templateProvider; } /** * Instantiates a new document select item option. * * @param label the label * @param value the value * @param desc the desc * @param icon the icon * @param selected the selected * @param templateProvider the template provider */ public DocumentSelectItemOption(String label, T value, String desc, String icon, boolean selected, NewDocumentTemplateProvider templateProvider) { super(label, value, desc, icon, selected); this.templateProvider = templateProvider; } /** * Instantiates a new document select item option. * * @param label the label * @param value the value * @param templateProvider the template provider */ public DocumentSelectItemOption(String label, T value, NewDocumentTemplateProvider templateProvider) { super(label, value); this.templateProvider = templateProvider; } /** * Instantiates a new document select item option. * * @param value the value * @param templateProvider the template provider */ public DocumentSelectItemOption(T value, NewDocumentTemplateProvider templateProvider) { super(value); this.templateProvider = templateProvider; } /** * Gets the template provider. * * @return the template provider */ public NewDocumentTemplateProvider getTemplateProvider() { return templateProvider; } }
3,808
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
IsAvailableDocumentProviderPresentFilter.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/documents/IsAvailableDocumentProviderPresentFilter.java
/* * Copyright (C) 2003-2020 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.documents; import java.util.Map; import javax.jcr.Node; import org.exoplatform.container.ExoContainerContext; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.services.cms.documents.DocumentEditorProvider; import org.exoplatform.services.cms.documents.DocumentService; import org.exoplatform.services.security.ConversationState; import org.exoplatform.services.security.Identity; import org.exoplatform.webui.ext.filter.UIExtensionAbstractFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilterType; /** * The filter checks if at least one NewDocumentTemplateProvider is registered. */ public class IsAvailableDocumentProviderPresentFilter extends UIExtensionAbstractFilter { /** The Constant MIX_REFERENCEABLE. */ private static final String MIX_REFERENCEABLE = "mix:referenceable"; /** * Instantiates a new checks if is template plugin present filter. */ public IsAvailableDocumentProviderPresentFilter() { this(null); } /** * Instantiates a new checks if is template plugin present filter. * * @param messageKey the message key */ public IsAvailableDocumentProviderPresentFilter(String messageKey) { super(messageKey, UIExtensionFilterType.MANDATORY); } /** * Accept. * * @param context the context * @return true, if successful * @throws Exception the exception */ @Override public boolean accept(Map<String, Object> context) throws Exception { Node node = null; if (context != null) { node = (Node) context.get(Node.class.getName()); } if (node == null) { UIJCRExplorer uiExplorer = (UIJCRExplorer) context.get(UIJCRExplorer.class.getName()); if (uiExplorer != null) { node = uiExplorer.getCurrentNode(); } } if (node != null && node.isNodeType(MIX_REFERENCEABLE)) { DocumentService documentService = ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(DocumentService.class); if (documentService != null) { Identity identity = ConversationState.getCurrent().getIdentity(); String fileId = node.getUUID(); String workspace = node.getSession().getWorkspace().getName(); // Search for available provider which supports the current file for (DocumentEditorProvider provider : documentService.getDocumentEditorProviders()) { if (provider.isAvailableForUser(identity) && provider.isDocumentSupported(fileId, workspace)) { return true; } } } } return false; } /** * On deny. * * @param context the context * @throws Exception the exception */ @Override public void onDeny(Map<String, Object> context) throws Exception { } }
3,553
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINewDocumentForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/documents/UINewDocumentForm.java
/* * Copyright (C) 2003-2019 eXo Platform SAS. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.exoplatform.ecm.webui.component.explorer.documents; import java.util.ArrayList; import java.util.List; import javax.jcr.AccessDeniedException; import javax.jcr.ItemExistsException; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.nodetype.ConstraintViolationException; import javax.jcr.nodetype.NodeDefinition; import org.apache.commons.lang3.StringUtils; import org.exoplatform.ecm.utils.text.Text; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.form.validator.XSSValidator; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.services.cms.documents.DocumentEditorProvider; import org.exoplatform.services.cms.documents.DocumentService; import org.exoplatform.services.cms.documents.NewDocumentTemplate; import org.exoplatform.services.cms.documents.NewDocumentTemplateProvider; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.security.ConversationState; import org.exoplatform.services.security.Identity; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.exception.MessageException; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormSelectBox; import org.exoplatform.webui.form.UIFormStringInput; /** * The UINewDocumentForm is displayed when 'New Document' button was clicked in ECMS Action Bar. */ @ComponentConfig(lifecycle = UIFormLifecycle.class, template = "app:groovy/ecm/webui/UINewDocument.gtmpl", events = { @EventConfig(listeners = UINewDocumentForm.SaveActionListener.class), @EventConfig(listeners = UINewDocumentForm.CancelActionListener.class, phase = Phase.DECODE) }) public class UINewDocumentForm extends UIForm implements UIPopupComponent { /** The Constant FIELD_TITLE_TEXT_BOX. */ public static final String FIELD_TITLE_TEXT_BOX = "titleTextBox"; /** The Constant FIELD_TYPE_SELECT_BOX. */ public static final String FIELD_TYPE_SELECT_BOX = "typeSelectBox"; /** The Constant DEFAULT_NAME. */ private static final String DEFAULT_NAME = "untitled"; /** The Constant LOG. */ protected static final Log LOG = ExoLogger.getLogger(UINewDocumentForm.class.getName()); /** The document service. */ protected DocumentService documentService; /** * Constructor. * */ public UINewDocumentForm() throws Exception{ this.documentService = this.getApplicationComponent(DocumentService.class); // Title textbox UIFormStringInput titleTextBox = new UIFormStringInput(FIELD_TITLE_TEXT_BOX, FIELD_TITLE_TEXT_BOX, null); titleTextBox.addValidator(XSSValidator.class); this.addUIFormInput(titleTextBox); List<NewDocumentTemplateProvider> templateProviders = documentService.getNewDocumentTemplateProviders(); List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>(); Identity identity = ConversationState.getCurrent().getIdentity(); templateProviders.forEach(provider -> { if (provider.getEditor().isAvailableForUser(identity)) { provider.getTemplates().forEach(template -> { DocumentSelectItemOption<String> option = new DocumentSelectItemOption<>(template.getName(), provider); options.add(option); }); } }); UIFormSelectBox typeSelectBox = new UIFormSelectBox(FIELD_TYPE_SELECT_BOX, FIELD_TYPE_SELECT_BOX, options); typeSelectBox.setRendered(true); this.addUIFormInput(typeSelectBox); this.setActions(new String[] { "Save", "Cancel" }); } /** * The listener interface for receiving saveAction events. * The class that is interested in processing a saveAction * event implements this interface, and the object created * with that class is registered with a component using the * component's method. When * the saveAction event occurs, that object's appropriate * method is invoked. */ static public class SaveActionListener extends EventListener<UINewDocumentForm> { /** * {@inheritDoc} */ public void execute(Event<UINewDocumentForm> event) throws Exception { UINewDocumentForm uiDocumentForm = event.getSource(); UIJCRExplorer uiExplorer = uiDocumentForm.getAncestorOfType(UIJCRExplorer.class); UIApplication uiApp = uiDocumentForm.getAncestorOfType(UIApplication.class); Node currentNode = uiExplorer.getCurrentNode(); if (uiExplorer.nodeIsLocked(currentNode)) { uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.node-locked", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiDocumentForm); return; } // Get title String title = uiDocumentForm.getUIStringInput(FIELD_TITLE_TEXT_BOX).getValue(); if (StringUtils.isBlank(title)) { uiApp.addMessage(new ApplicationMessage("UINewDocumentForm.msg.name-invalid", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiDocumentForm); return; } UIFormSelectBox typeSelectBox = uiDocumentForm.getUIFormSelectBox(FIELD_TYPE_SELECT_BOX); List<SelectItemOption<String>> options = typeSelectBox.getOptions(); DocumentSelectItemOption<String> selectedOption = (DocumentSelectItemOption<String>) options.stream() .filter(option -> option.isSelected()) .findFirst() .get(); NewDocumentTemplateProvider templateProvider = selectedOption.getTemplateProvider(); String name = selectedOption.getLabel(); NewDocumentTemplate template = templateProvider.getTemplate(name); DocumentEditorProvider editorProvider = templateProvider.getEditor(); title = getFileName(title, template); Identity identity = ConversationState.getCurrent().getIdentity(); if (editorProvider != null && editorProvider.isAvailableForUser(identity)) { editorProvider.beforeDocumentCreate(template, currentNode.getPath(), title); } Node document = null; try { document = templateProvider.createDocument(currentNode, title, template); } catch (ConstraintViolationException cve) { Object[] arg = { typeSelectBox.getValue() }; throw new MessageException(new ApplicationMessage("UINewDocumentForm.msg.constraint-violation", arg, ApplicationMessage.WARNING)); } catch (AccessDeniedException accessDeniedException) { uiApp.addMessage(new ApplicationMessage("UINewDocumentForm.msg.repository-exception-permission", null, ApplicationMessage.WARNING)); } catch (ItemExistsException re) { uiApp.addMessage(new ApplicationMessage("UINewDocumentForm.msg.not-allow-sameNameSibling", null, ApplicationMessage.WARNING)); } catch (RepositoryException re) { String key = "UINewDocumentForm.msg.repository-exception"; NodeDefinition[] definitions = currentNode.getPrimaryNodeType().getChildNodeDefinitions(); boolean isSameNameSiblingsAllowed = false; for (NodeDefinition def : definitions) { if (def.allowsSameNameSiblings()) { isSameNameSiblingsAllowed = true; break; } } if (currentNode.hasNode(title) && !isSameNameSiblingsAllowed) { key = "UINewDocumentForm.msg.not-allow-sameNameSibling"; } uiApp.addMessage(new ApplicationMessage(key, null, ApplicationMessage.WARNING)); } catch (NumberFormatException nume) { uiApp.addMessage(new ApplicationMessage("UINewDocumentForm.msg.numberformat-exception", null, ApplicationMessage.WARNING)); } catch (Exception e) { JCRExceptionManager.process(uiApp, e); } if (document != null && editorProvider != null && editorProvider.isAvailableForUser(identity)) { editorProvider.onDocumentCreated(document.getSession().getWorkspace().getName(), document.getPath()); } uiExplorer.updateAjax(event); } public String getFileName(String title, NewDocumentTemplate template) { title = Text.escapeIllegalJcrChars(title); if (StringUtils.isEmpty(title)) { title = DEFAULT_NAME; } String extension = template.getExtension(); if (extension == null || extension.trim().isEmpty()) { String path = template.getPath(); if (path.contains(".")) { extension = path.substring(path.lastIndexOf(".")); } } if (!title.endsWith(extension)) { title += extension; } return title; } } /** * The listener interface for receiving cancelAction events. * The class that is interested in processing a cancelAction * event implements this interface, and the object created * with that class is registered with a component using the * component's method. When * the cancelAction event occurs, that object's appropriate * method is invoked. */ static public class CancelActionListener extends EventListener<UINewDocumentForm> { /** * {@inheritDoc} */ public void execute(Event<UINewDocumentForm> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); uiExplorer.cancelAction(); } } /** * Activate. */ @Override public void activate() { // Nothing } /** * De activate. */ @Override public void deActivate() { // Nothing } }
11,525
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
IsNewDocumentTemplatePresentFilter.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/documents/IsNewDocumentTemplatePresentFilter.java
/* * Copyright (C) 2003-2020 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.documents; import java.util.Map; import org.exoplatform.container.ExoContainerContext; import org.exoplatform.services.cms.documents.DocumentService; import org.exoplatform.webui.ext.filter.UIExtensionAbstractFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilterType; /** * The filter checks if at least one NewDocumentTemplateProvider is registered. */ public class IsNewDocumentTemplatePresentFilter extends UIExtensionAbstractFilter { /** * Instantiates a new checks if is template plugin present filter. */ public IsNewDocumentTemplatePresentFilter() { this(null); } /** * Instantiates a new checks if is template plugin present filter. * * @param messageKey the message key */ public IsNewDocumentTemplatePresentFilter(String messageKey) { super(messageKey, UIExtensionFilterType.MANDATORY); } /** * Accept. * * @param context the context * @return true, if successful * @throws Exception the exception */ @Override public boolean accept(Map<String, Object> context) throws Exception { DocumentService documentService = ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(DocumentService.class); if (documentService != null) { return documentService.getNewDocumentTemplateProviders().size() > 0; } return false; } /** * On deny. * * @param context the context * @throws Exception the exception */ @Override public void onDeny(Map<String, Object> context) throws Exception { } }
2,353
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
NewDocumentManageComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/documents/NewDocumentManageComponent.java
/* * Copyright (C) 2003-2019 eXo Platform SAS. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.exoplatform.ecm.webui.component.explorer.documents; import java.util.Arrays; import java.util.List; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.control.filter.CanAddNodeFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotEditingDocumentFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotInTrashFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotNtFileFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotTrashHomeNodeFilter; import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; import org.exoplatform.webui.ext.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * The Class NewDocumentManageComponent creates and displays UINewDocumentForm. */ @ComponentConfig(events = { @EventConfig(listeners = NewDocumentManageComponent.NewDocumentActionListener.class) }) public class NewDocumentManageComponent extends UIAbstractManagerComponent { /** The Constant LOG. */ protected static final Log LOG = ExoLogger.getLogger(NewDocumentManageComponent.class); /** The Constant FILTERS. */ private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] { new IsNewDocumentTemplatePresentFilter(), new IsNotNtFileFilter(), new CanAddNodeFilter(), new IsNotLockedFilter(), new IsCheckedOutFilter(), new IsNotTrashHomeNodeFilter(), new IsNotInTrashFilter(), new IsNotEditingDocumentFilter() }); /** * The listener interface for receiving newDocumentAction events. The class * that is interested in processing a newDocumentAction event implements * this interface, and the object created with that class is registered with a * component using the component's method. When the * newDocumentAction event occurs, that object's appropriate method is * invoked. */ public static class NewDocumentActionListener extends UIActionBarActionListener<NewDocumentManageComponent> { /** * {@inheritDoc} */ public void processEvent(Event<NewDocumentManageComponent> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); addDocument(event, uiExplorer); } } /** * Gets the filters. * * @return the filters */ @UIExtensionFilters public List<UIExtensionFilter> getFilters() { return FILTERS; } /** * Adds the document. * * @param event the event * @param uiExplorer the ui explorer * @throws Exception the exception */ public static void addDocument(Event<? extends UIComponent> event, UIJCRExplorer uiExplorer) throws Exception { UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class); UINewDocumentForm documentForm = uiExplorer.createUIComponent(UINewDocumentForm.class, null, null); UIPopupContainer.activate(documentForm, 530, 220, false); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } /** * {@inheritDoc} */ @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return null; } }
5,648
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
DocumentEditorsFilter.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/documents/DocumentEditorsFilter.java
/* * Copyright (C) 2003-2020 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.documents; import java.io.IOException; import java.util.List; import org.exoplatform.container.ExoContainerContext; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.web.WebAppController; import org.exoplatform.web.application.ApplicationLifecycle; import org.exoplatform.web.filter.Filter; import org.exoplatform.webui.application.WebuiApplication; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; /** * The Class DocumentEditorsFilter. */ public class DocumentEditorsFilter implements Filter { /** The Constant LOG. */ protected static final Log LOG = ExoLogger.getLogger(DocumentEditorsFilter.class); /** The Constant ECMS_EXPLORER_APP_ID. */ protected static final String ECMS_EXPLORER_APP_ID = "ecmexplorer/FileExplorerPortlet"; /** * Instantiates a new document editors filter. */ public DocumentEditorsFilter() { } /** * {@inheritDoc} */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { WebAppController controller = ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(WebAppController.class); WebuiApplication app = controller.getApplication(ECMS_EXPLORER_APP_ID); // XXX It's known that since portal start this app will not present at very // first request to it (Documents Explorer app), thus the filter will not // add the lifecycle and it will not initialize the app in the first // request. if (app != null) { // Initialize ECMS Explorer app, this will happen once per app lifetime @SuppressWarnings("rawtypes") final List<ApplicationLifecycle> lifecycles = app.getApplicationLifecycle(); if (canAddLifecycle(lifecycles, DocumentEditorsLifecycle.class)) { synchronized (lifecycles) { if (canAddLifecycle(lifecycles, DocumentEditorsLifecycle.class)) { lifecycles.add(new DocumentEditorsLifecycle()); } } } } chain.doFilter(request, response); } /** * Consult if we can add a new lifecycle of given class to the list. This * method is not blocking and thread safe, but as result of working over a * {@link List} of lifecycles, weakly consistent regarding its answer. * * @param <C> the generic type * @param lifecycles the lifecycles list * @param lifecycleClass the lifecycle class to add * @return <code>true</code>, if can add, <code>false</code> otherwise */ @SuppressWarnings("rawtypes") protected <C extends ApplicationLifecycle> boolean canAddLifecycle(List<ApplicationLifecycle> lifecycles, Class<C> lifecycleClass) { return getLifecycle(lifecycles, lifecycleClass) == null; } /** * Returns a lifecycle instance of given class from the list. This method is * not blocking and thread safe, but as result of working over a {@link List} * of lifecycles, weakly consistent regarding its result. * * @param <C> the generic type * @param lifecycles the lifecycles list * @param lifecycleClass the lifecycle class * @return the lifecycle instance or <code>null</code> if nothing found in the * given list */ @SuppressWarnings("rawtypes") protected <C extends ApplicationLifecycle> C getLifecycle(List<ApplicationLifecycle> lifecycles, Class<C> lifecycleClass) { if (lifecycles.size() > 0) { // We want iterate from end of the list and don't be bothered by // ConcurrentModificationException for a case if someone else will modify // the list int index = lifecycles.size() - 1; do { try { ApplicationLifecycle lc = lifecycles.get(index); if (lc != null && lifecycleClass.isAssignableFrom(lc.getClass())) { return lifecycleClass.cast(lc); } else { index--; } } catch (IndexOutOfBoundsException e) { index--; } } while (index >= 0); } return null; } }
4,975
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UISavedSearches.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/UISavedSearches.java
/* * Copyright (C) 2003-2008 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar; import java.util.ArrayList; import java.util.List; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.query.Query; import org.exoplatform.ecm.utils.text.Text; import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace; import org.exoplatform.ecm.webui.component.explorer.UIDrivesArea; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.ecm.webui.component.explorer.search.UIContentNameSearch; import org.exoplatform.ecm.webui.component.explorer.search.UIECMSearch; import org.exoplatform.ecm.webui.component.explorer.search.UISavedQuery; import org.exoplatform.ecm.webui.component.explorer.search.UISearchResult; import org.exoplatform.ecm.webui.component.explorer.search.UISimpleSearch; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.cms.queries.QueryService; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.application.portlet.PortletRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Oct 23, 2009 * 4:01:53 AM */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/sidebar/UISavedSearches.gtmpl", events = { @EventConfig(listeners = UISavedSearches.ExecuteActionListener.class), @EventConfig(listeners = UISavedSearches.AdvanceSearchActionListener.class), @EventConfig(listeners = UISavedSearches.SavedQueriesActionListener.class) } ) public class UISavedSearches extends UIComponent { public final static String ACTION_TAXONOMY = "exo:taxonomyAction"; public final static String EXO_TARGETPATH = "exo:targetPath"; public final static String EXO_TARGETWORKSPACE = "exo:targetWorkspace"; private String queryPath; public UISavedSearches() throws Exception { } public List<Object> queryList() throws Exception { List<Object> objectList = new ArrayList<Object>(); List<Node> sharedQueries = getSharedQueries(); if(!sharedQueries.isEmpty()) { for(Node node : sharedQueries) { objectList.add(new NodeData(node)); } } List<Query> queries = getQueries(); if(!queries.isEmpty()) { for(Query query : queries) { objectList.add(new QueryData(query)); } } return objectList; } public String getCurrentUserId() { return Util.getPortalRequestContext().getRemoteUser();} public List<Query> getQueries() throws Exception { QueryService queryService = getApplicationComponent(QueryService.class); try { return queryService.getQueries(getCurrentUserId(), WCMCoreUtils.getUserSessionProvider()); } catch(AccessDeniedException ace) { return new ArrayList<Query>(); } } public List<Node> getSharedQueries() throws Exception { PortletRequestContext pcontext = (PortletRequestContext)WebuiRequestContext.getCurrentInstance(); QueryService queryService = getApplicationComponent(QueryService.class); String userId = pcontext.getRemoteUser(); return queryService.getSharedQueries(userId, WCMCoreUtils.getSystemSessionProvider()); } public void setQueryPath(String queryPath) throws Exception { this.queryPath = queryPath; } public String getQueryPath() throws Exception { return this.queryPath; } static public class ExecuteActionListener extends EventListener<UISavedSearches> { public void execute(Event<UISavedSearches> event) throws Exception { UISavedSearches uiSavedSearches = event.getSource(); UIJCRExplorer uiExplorer = uiSavedSearches.getAncestorOfType(UIJCRExplorer.class); String queryPath = event.getRequestContext().getRequestParameter(OBJECTID); uiSavedSearches.setQueryPath(queryPath); uiExplorer.setPathToAddressBar(Text.unescapeIllegalJcrChars( uiExplorer.filterPath(queryPath))); String wsName = uiSavedSearches.getAncestorOfType(UIJCRExplorer.class).getCurrentWorkspace(); UIApplication uiApp = uiSavedSearches.getAncestorOfType(UIApplication.class); QueryService queryService = uiSavedSearches.getApplicationComponent(QueryService.class); UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIComponent uiSearch = uiWorkingArea.getChild(UIDocumentWorkspace.class); UIDrivesArea uiDrivesArea = uiWorkingArea.getChild(UIDrivesArea.class); UISearchResult uiSearchResult = ((UIDocumentWorkspace)uiSearch).getChild(UISearchResult.class); Query query = null; try { query = queryService.getQuery(queryPath, wsName, WCMCoreUtils.getSystemSessionProvider(), uiSavedSearches.getCurrentUserId()); query.execute(); } catch(Exception e) { uiApp.addMessage(new ApplicationMessage("UISearchResult.msg.query-invalid", null, ApplicationMessage.WARNING)); } finally { uiSearchResult.setQuery(query.getStatement(), wsName, query.getLanguage(), false, null); uiSearchResult.updateGrid(); } if (uiDrivesArea != null) uiDrivesArea.setRendered(false); uiWorkingArea.getChild(UIDocumentWorkspace.class).setRendered(true); ((UIDocumentWorkspace)uiSearch).setRenderedChild(UISearchResult.class); } } static public class AdvanceSearchActionListener extends EventListener<UISavedSearches> { public void execute(Event<UISavedSearches> event) throws Exception { UIJCRExplorer uiJCRExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); UIPopupContainer UIPopupContainer = uiJCRExplorer.getChild(UIPopupContainer.class); UIECMSearch uiECMSearch = event.getSource().createUIComponent(UIECMSearch.class, null, null); UIContentNameSearch contentNameSearch = uiECMSearch.findFirstComponentOfType(UIContentNameSearch.class); String currentNodePath = uiJCRExplorer.getCurrentNode().getPath(); contentNameSearch.setLocation(currentNodePath); UISimpleSearch uiSimpleSearch = uiECMSearch.findFirstComponentOfType(UISimpleSearch.class); uiSimpleSearch.getUIFormInputInfo(UISimpleSearch.NODE_PATH).setValue(currentNodePath); UIPopupContainer.activate(uiECMSearch, 700, 500, false); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } } static public class SavedQueriesActionListener extends EventListener<UISavedSearches> { public void execute(Event<UISavedSearches> event) throws Exception { UIJCRExplorer uiJCRExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); UIPopupContainer UIPopupContainer = uiJCRExplorer.getChild(UIPopupContainer.class); UISavedQuery uiSavedQuery = event.getSource().createUIComponent(UISavedQuery.class, null, null); uiSavedQuery.setIsQuickSearch(true); uiSavedQuery.updateGrid(1); UIPopupContainer.activate(uiSavedQuery, 700, 400); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } } public class QueryData { private String storedQueryPath_; public QueryData(Query query) { try { storedQueryPath_ = query.getStoredQueryPath(); } catch (RepositoryException e) { storedQueryPath_ = ""; } } public String getStoredQueryPath() { return storedQueryPath_; } public void setStoredQueryPath(String storedQueryPath) { storedQueryPath_ = storedQueryPath; } } public class NodeData { private String path_; private String name_; public NodeData(Node node) throws RepositoryException { this.path_ = node.getPath(); this.name_ = node.getName(); } public String getPath() { return path_; } public void setPath(String path) { path_ = path; } public String getName() { return name_; } public void setName(String name) { name_ = name; } } }
9,677
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITreeExplorer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/UITreeExplorer.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar ; import java.util.HashSet; import java.util.List; import java.util.MissingResourceException; import java.util.ResourceBundle; import javax.jcr.AccessDeniedException; import javax.jcr.Item; import javax.jcr.ItemNotFoundException; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.nodetype.NodeType; import javax.jcr.query.Row; import javax.portlet.PortletPreferences; import org.apache.commons.lang3.StringUtils; import org.apache.ws.commons.util.Base64; import org.exoplatform.ecms.legacy.search.data.SearchResult; import org.exoplatform.commons.utils.CommonsUtils; import org.exoplatform.commons.utils.PageList; import org.exoplatform.container.xml.PortalContainerInfo; import org.exoplatform.ecm.jcr.model.Preference; import org.exoplatform.ecm.webui.component.explorer.DocumentProviderUtils; import org.exoplatform.ecm.webui.component.explorer.UIDocumentContainer; import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace; import org.exoplatform.ecm.webui.component.explorer.UIDrivesArea; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorerPortlet; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.ecm.webui.component.explorer.UIDocumentInfo; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.services.cms.BasePath; import org.exoplatform.services.cms.clipboard.ClipboardService; import org.exoplatform.services.cms.clouddrives.CloudDrive; import org.exoplatform.services.cms.clouddrives.CloudDriveService; import org.exoplatform.services.cms.documents.AutoVersionService; import org.exoplatform.services.cms.drives.DriveData; import org.exoplatform.services.cms.drives.impl.ManageDriveServiceImpl; import org.exoplatform.services.cms.impl.Utils; import org.exoplatform.services.cms.link.LinkManager; import org.exoplatform.services.cms.link.LinkUtils; import org.exoplatform.services.cms.link.NodeFinder; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.organization.OrganizationService; import org.exoplatform.services.organization.User; import org.exoplatform.services.security.ConversationState; import org.exoplatform.services.wcm.core.NodetypeConstant; import org.exoplatform.services.wcm.search.base.SearchDataCreator; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.web.application.RequestContext; import org.exoplatform.webui.application.portlet.PortletRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIRightClickPopupMenu; import org.exoplatform.webui.core.UIPageIterator; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.services.wcm.search.base.LazyPageList; /** * Created by The eXo Platform SARL * Author : Tran The Trong * trongtt@gmail.com * Aug 2, 2006 */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/sidebar/UITreeExplorer.gtmpl", events = { @EventConfig(listeners = UITreeExplorer.ExpandActionListener.class, csrfCheck = false), @EventConfig(listeners = UITreeExplorer.CollapseActionListener.class, csrfCheck = false), @EventConfig(listeners = UITreeExplorer.ExpandTreeActionListener.class, csrfCheck = false) } ) public class UITreeExplorer extends UIContainer { private class TreeNodeDataCreater implements SearchDataCreator<TreeNode>{ @Override public TreeNode createData(Node node, Row row, SearchResult searchResult){ try { return new TreeNode(node); } catch (RepositoryException e) { return null; } } } /** * Logger. */ private static final Log LOG = ExoLogger.getLogger(UITreeExplorer.class.getName()); private TreeNode treeRoot_; private String expandPath = null; private boolean isExpand = false; /** The cloud drive service. */ private CloudDriveService cloudDriveService; public UITreeExplorer() throws Exception { cloudDriveService = CommonsUtils.getService(CloudDriveService.class); } public UIRightClickPopupMenu getContextMenu() { return getAncestorOfType(UIWorkingArea.class).getChild(UIRightClickPopupMenu.class) ; } UIWorkingArea getWorkingArea() { return getAncestorOfType(UIWorkingArea.class); } private UISideBar getSideBar() { return getWorkingArea().findFirstComponentOfType(UISideBar.class); } UIComponent getCustomAction() throws Exception { return getAncestorOfType(UIWorkingArea.class).getCustomAction(); } public TreeNode getRootTreeNode() { return treeRoot_ ; } public String getRootActionList() throws Exception { ClipboardService clipboardService = WCMCoreUtils.getService(ClipboardService.class); String userId = ConversationState.getCurrent().getIdentity().getUserId(); UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); if (!clipboardService.getClipboardList(userId, false).isEmpty()) { return getContextMenu().getJSOnclickShowPopup(uiExplorer.getCurrentDriveWorkspace() + ":" + uiExplorer.getRootPath(), "Paste").toString(); } return "" ; } public boolean isDirectlyDrive() { PortletPreferences portletPref = getAncestorOfType(UIJCRExplorerPortlet.class).getPortletPreferences(); String usecase = portletPref.getValue("usecase", "").trim(); if ("selection".equals(usecase)) { return false; } return true; } public String getDriveName() { return getAncestorOfType(UIJCRExplorer.class).getDriveData().getName() ; } public String getLabel() { RequestContext context = RequestContext.getCurrentInstance(); ResourceBundle res = context.getApplicationResourceBundle(); DriveData driveData = getAncestorOfType(UIJCRExplorer.class).getDriveData(); String id = driveData.getName(); String path = driveData.getHomePath(); String driveLabelKey = "Drives.label." + id.replace(".", "").replace(" ", ""); try { if (ManageDriveServiceImpl.USER_DRIVE_NAME.equals(id)) { // User Documents drive driveLabelKey = "Drives.label.UserDocuments"; String userDisplayName = ""; String userIdPath = driveData.getParameters().get(ManageDriveServiceImpl.DRIVE_PARAMATER_USER_ID); String userId = userIdPath != null ? userIdPath.substring(userIdPath.lastIndexOf("/") + 1) : null; if (StringUtils.isNotEmpty(userId)) { userDisplayName = userId; User user = this.getApplicationComponent(OrganizationService.class).getUserHandler().findUserByName(userId); if (user != null) { userDisplayName = user.getDisplayName(); } } try { return res.getString(driveLabelKey).replace("{0}", userDisplayName); } catch (MissingResourceException mre) { LOG.error("Cannot get resource string for " + driveLabelKey); } } else { try { return res.getString(driveLabelKey); } catch (MissingResourceException ex) { try { CloudDrive cloudDrives = cloudDriveService.findDrive(driveData.getWorkspace(), driveData.getHomePath()); if (cloudDrives != null) { // Cloud drives return cloudDrives.getTitle(); } else { try { RepositoryService repoService = CommonsUtils.getService(RepositoryService.class); NodeHierarchyCreator nodeHierarchyCreator = CommonsUtils.getService(NodeHierarchyCreator.class); String groupPath = nodeHierarchyCreator.getJcrPath(BasePath.CMS_GROUPS_PATH); Node groupNode = (Node) WCMCoreUtils.getSystemSessionProvider().getSession( repoService.getCurrentRepository().getConfiguration().getDefaultWorkspaceName(), repoService.getCurrentRepository()).getItem( groupPath + driveData.getName().replace(".", "/")); return groupNode.getParent().getName() + " / " + groupNode.getProperty(NodetypeConstant.EXO_LABEL).getString(); } catch (Exception e) { return id.replace(".", " / "); } } } catch (RepositoryException e) { LOG.warn("Cannot find clouddrive " + driveData.getHomePath() + " in " + driveData.getWorkspace(), e); return id.replace(".", " / "); } } } } catch (Exception ex) { LOG.warn("Can not find resource string for " + driveLabelKey, ex); } return id.replace(".", " / "); } public boolean isAllowNodeTypesOnTree(Node node) throws RepositoryException { DriveData currentDrive = getAncestorOfType(UIJCRExplorer.class).getDriveData(); String allowNodeTypesOnTree = currentDrive.getAllowNodeTypesOnTree(); if ((allowNodeTypesOnTree == null) || (allowNodeTypesOnTree.equals("*"))) return true; String[] arrayAllowNodeTypesOnTree = allowNodeTypesOnTree.split(","); for (String itemAllowNodeTypes : arrayAllowNodeTypesOnTree) { if ((itemAllowNodeTypes.trim().length() > 0) && node.isNodeType(itemAllowNodeTypes.trim())) return true; } return false; } public String getActionsList(Node node) throws Exception { if(node == null) return "" ; UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); try { NodeFinder nodeFinder = getApplicationComponent(NodeFinder.class); nodeFinder.getItem(uiExplorer.getSession(), node.getPath()); //uiExplorer.getSession().getItem(node.getPath()); return getAncestorOfType(UIWorkingArea.class).getActionsExtensionList(node) ; } catch(PathNotFoundException pne) { uiExplorer.refreshExplorerWithoutClosingPopup(); return ""; } } public List<Node> getCustomActions(Node node) throws Exception { return getAncestorOfType(UIWorkingArea.class).getCustomActions(node) ; } public boolean isPreferenceNode(Node node) { return getAncestorOfType(UIWorkingArea.class).isPreferenceNode(node) ; } @SuppressWarnings("unchecked") public List<TreeNode> getRenderedChildren(TreeNode treeNode) throws Exception { if(isPaginated(treeNode)) { UITreeNodePageIterator pageIterator = findComponentById(treeNode.getPath()); return pageIterator.getCurrentPageData(); } if(isShowChildren(treeNode) && treeNode.getChildrenSize() > 0 && treeNode.getChildren().size() == 0) { UIJCRExplorer jcrExplorer = getAncestorOfType(UIJCRExplorer.class); treeNode.setChildren(jcrExplorer.getChildrenList(treeNode.getPath(), false)); return treeNode.getChildren(); } return treeNode.getChildren(); } public boolean isSystemWorkspace() throws Exception { return getAncestorOfType(UIJCRExplorer.class).isSystemWorkspace() ; } public UITreeNodePageIterator getUIPageIterator(String id) throws Exception { return findComponentById(id); } public boolean isSymLink(Node node) throws RepositoryException { LinkManager linkManager = getApplicationComponent(LinkManager.class); return linkManager.isLink(node); } public String getViewTemplate(String nodeTypeName, String templateName) throws Exception { TemplateService tempServ = getApplicationComponent(TemplateService.class) ; return tempServ.getTemplatePath(false, nodeTypeName, templateName) ; } public boolean isPaginated(TreeNode treeNode) { UIJCRExplorer jcrExplorer = getAncestorOfType(UIJCRExplorer.class) ; int nodePerPages = jcrExplorer.getPreference().getNodesPerPage(); return (treeNode.getChildrenSize()>nodePerPages) && (findComponentById(treeNode.getPath()) != null) ; } public String getPortalName() { PortalContainerInfo containerInfo = WCMCoreUtils.getService(PortalContainerInfo.class); return containerInfo.getContainerName(); } public String getServerPath() { PortletRequestContext portletRequestContext = PortletRequestContext.getCurrentInstance() ; String prefixWebDAV = portletRequestContext.getRequest().getScheme() + "://" + portletRequestContext.getRequest().getServerName() + ":" + String.format("%s",portletRequestContext.getRequest().getServerPort()) ; return prefixWebDAV ; } public boolean isShowChildren(TreeNode treeNode){ UIJCRExplorer jcrExplorer = getAncestorOfType(UIJCRExplorer.class); String currentPath = jcrExplorer.getCurrentPath(); return treeNode.isExpanded() || currentPath.startsWith(treeNode.getPath()); } public String getRepository() { return getAncestorOfType(UIJCRExplorer.class).getRepositoryName(); } public String getEncodeCurrentPath() { return encodeBase64(getAncestorOfType(UIJCRExplorer.class).getCurrentPath()); } public String getEncodeExpandPath() { if(expandPath != null) return encodeBase64(expandPath); else return null; } public boolean getIsExpand() { return isExpand; } public static String encodeBase64(String value) { value = value == null ? "" : value; return Base64.encode(value.getBytes()).replaceAll(Base64.LINE_SEPARATOR,""); } /** * * @param id ID of TreeNodePageIterator, should be path of node * @param pageList Paged list children of node * @param selectedPath Path relate with pageList * @param currentPath Path that user are working on * * */ private void addTreeNodePageIteratorAsChild(String id, PageList<TreeNode> pageList, String selectedPath, String currentPath) throws Exception { if (findComponentById(id) == null) { UITreeNodePageIterator nodePageIterator = addChild(UITreeNodePageIterator.class, null, id); nodePageIterator.setPageList(pageList); nodePageIterator.setSelectedPath(selectedPath); } else { UITreeNodePageIterator existedComponent = findComponentById(id); int currentPage = existedComponent.getCurrentPage(); existedComponent.setPageList(pageList); if (!selectedPath.equalsIgnoreCase(currentPath)) { if (currentPage <= existedComponent.getAvailablePage()) { existedComponent.setCurrentPage(currentPage); } } } } private Node getRootNode() throws Exception { UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ; return uiExplorer.getRootNode(); } private void buildTree(String path) throws Exception { if(getSideBar() == null || !getSideBar().isRenderComponent("Explorer")) { return; } UIJCRExplorer jcrExplorer = getAncestorOfType(UIJCRExplorer.class); int nodePerPages = jcrExplorer.getPreference().getNodesPerPage(); TreeNode treeRoot = new TreeNode(getRootNode()); if (path == null) path = jcrExplorer.getCurrentPath(); String[] arr = path.replaceFirst(treeRoot.getPath(), "").split("/"); TreeNode temp = treeRoot; StringBuffer subPath = null; String rootPath = treeRoot.getPath(); StringBuffer prefix = new StringBuffer(rootPath); if (!rootPath.equals("/")) { prefix.append("/"); } HashSet<String> emptySet = new HashSet<String>();//This control doesn't have any filter //Build root tree node if (temp.getChildrenSize() > nodePerPages) { LazyPageList<TreeNode> pageList = DocumentProviderUtils.getInstance().getPageList(jcrExplorer.getWorkspaceName(), rootPath, jcrExplorer.getPreference(), emptySet, emptySet, new TreeNodeDataCreater()); addTreeNodePageIteratorAsChild(treeRoot.getPath(), pageList, rootPath, path); } else temp.setChildren(jcrExplorer.getChildrenList(rootPath, false)); //Build children for (String nodeName : arr) { if (nodeName.length() == 0) continue; temp = temp.getChildByName(nodeName); if (temp == null) { treeRoot_ = treeRoot; return; } if (subPath == null) { subPath = new StringBuffer(); subPath.append(prefix).append(nodeName); } else { subPath.append("/").append(nodeName); } if (temp.getChildrenSize() > nodePerPages) { LazyPageList<TreeNode> pageList = DocumentProviderUtils.getInstance().getPageList(jcrExplorer.getWorkspaceName(), subPath.toString(), jcrExplorer.getPreference(), emptySet, emptySet, new TreeNodeDataCreater()); temp.setExpanded(isExpand); addTreeNodePageIteratorAsChild(temp.getPath(), pageList, subPath.toString(), path); } else temp.setChildren(jcrExplorer.getChildrenList(subPath.toString(), false)); } treeRoot_ = treeRoot; } public void buildTree() throws Exception { buildTree(null); } public boolean isDocumentNodeType(Node node) throws Exception { TemplateService templateService = getApplicationComponent(TemplateService.class); return templateService.isManagedNodeType(node.getPrimaryNodeType().getName()); } public String getSelectedPath() throws Exception { UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ; return encodeBase64(uiExplorer.getCurrentPath()); } static public class ExpandActionListener extends EventListener<UITreeExplorer> { public void execute(Event<UITreeExplorer> event) throws Exception { UITreeExplorer uiTreeExplorer = event.getSource(); String path = event.getRequestContext().getRequestParameter(OBJECTID) ; uiTreeExplorer.isExpand = false; UIJCRExplorer uiExplorer = uiTreeExplorer.getAncestorOfType(UIJCRExplorer.class) ; UIApplication uiApp = uiTreeExplorer.getAncestorOfType(UIApplication.class) ; String workspaceName = event.getRequestContext().getRequestParameter("workspaceName"); Item item = null; try { Session session = uiExplorer.getSessionByWorkspace(workspaceName); // Check if the path exists NodeFinder nodeFinder = uiTreeExplorer.getApplicationComponent(NodeFinder.class); item = nodeFinder.getItem(session, path); } catch(PathNotFoundException pa) { uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.path-not-found", null, ApplicationMessage.WARNING)) ; return ; } catch(ItemNotFoundException inf) { uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.path-not-found", null, ApplicationMessage.WARNING)) ; return ; } catch(AccessDeniedException ace) { uiApp.addMessage(new ApplicationMessage("UIDocumentInfo.msg.access-denied", null, ApplicationMessage.WARNING)) ; return ; } catch(RepositoryException e) { if (LOG.isErrorEnabled()) { LOG.error("Repository cannot be found"); } uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.repository-error", null, ApplicationMessage.WARNING)) ; return ; } catch (Exception e) { JCRExceptionManager.process(uiApp, e); return; } if (isInTrash(item)) return; UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class); AutoVersionService autoVersionService = WCMCoreUtils.getService(AutoVersionService.class); if(!uiDocumentWorkspace.isRendered()) { uiWorkingArea.getChild(UIDrivesArea.class).setRendered(false); uiDocumentWorkspace.setRendered(true); } else { uiDocumentWorkspace.setRenderedChild(UIDocumentContainer.class); } uiExplorer.setSelectNode(workspaceName, path); // UIDocumentContainer uiDocumentContainer = uiDocumentWorkspace.getChild(UIDocumentContainer.class); // UIDocumentInfo uiDocumentInfo = uiDocumentContainer.getChildById("UIDocumentInfo") ; UIPageIterator contentPageIterator = uiExplorer.findComponentById(UIDocumentInfo.CONTENT_PAGE_ITERATOR_ID); if(contentPageIterator != null) { contentPageIterator.setCurrentPage(1); } uiExplorer.updateAjax(event); event.getRequestContext().getJavascriptManager(). require("SHARED/multiUpload", "multiUpload"). addScripts("multiUpload.setLocation('" + uiExplorer.getWorkspaceName() + "','" + uiExplorer.getDriveData().getName() + "','" + uiTreeExplorer.getLabel() + "','" + uiExplorer.getCurrentPath() + "','" + Utils.getPersonalDrivePath(uiExplorer.getDriveData().getHomePath(), ConversationState.getCurrent().getIdentity().getUserId()) + "', '"+ autoVersionService.isVersionSupport(uiExplorer.getCurrentPath(), uiExplorer.getCurrentWorkspace())+"');"); } } private static boolean isInTrash(Item item) throws RepositoryException { return (item instanceof Node) && Utils.isInTrash((Node) item); } static public class ExpandTreeActionListener extends EventListener<UITreeExplorer> { public void execute(Event<UITreeExplorer> event) throws Exception { UITreeExplorer uiTreeExplorer = event.getSource(); String path = event.getRequestContext().getRequestParameter(OBJECTID); uiTreeExplorer.expandPath = path; uiTreeExplorer.isExpand = true; UIJCRExplorer uiExplorer = uiTreeExplorer.getAncestorOfType(UIJCRExplorer.class); UIApplication uiApp = uiTreeExplorer.getAncestorOfType(UIApplication.class); String workspaceName = event.getRequestContext().getRequestParameter("workspaceName"); Item item = null; try { Session session = uiExplorer.getSessionByWorkspace(workspaceName); // Check if the path exists NodeFinder nodeFinder = uiTreeExplorer.getApplicationComponent(NodeFinder.class); item = nodeFinder.getItem(session, path); } catch (PathNotFoundException pa) { uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.path-not-found", null, ApplicationMessage.WARNING)); return; } catch (ItemNotFoundException inf) { uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.path-not-found", null, ApplicationMessage.WARNING)); return; } catch (AccessDeniedException ace) { uiApp.addMessage(new ApplicationMessage("UIDocumentInfo.msg.access-denied", null, ApplicationMessage.WARNING)); return; } catch(RepositoryException e) { if (LOG.isErrorEnabled()) { LOG.error("Repository cannot be found"); } uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.repository-error", null, ApplicationMessage.WARNING)) ; return ; } catch (Exception e) { JCRExceptionManager.process(uiApp, e); return; } if (isInTrash(item)) return; if (uiExplorer.getPreference().isShowSideBar() && uiExplorer.getAncestorOfType(UIJCRExplorerPortlet.class).isShowSideBar()) { uiTreeExplorer.buildTree(path); } } } static public class CollapseActionListener extends EventListener<UITreeExplorer> { public void execute(Event<UITreeExplorer> event) throws Exception { UITreeExplorer treeExplorer = event.getSource(); UIApplication uiApp = treeExplorer.getAncestorOfType(UIApplication.class); try { String path = event.getRequestContext().getRequestParameter(OBJECTID) ; UIJCRExplorer uiExplorer = treeExplorer.getAncestorOfType(UIJCRExplorer.class) ; path = LinkUtils.getParentPath(path) ; uiExplorer.setSelectNode(path) ; uiExplorer.updateAjax(event) ; } catch(RepositoryException e) { if (LOG.isErrorEnabled()) { LOG.error("Repository cannot be found"); } uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.repository-error", null, ApplicationMessage.WARNING)) ; return ; } catch (Exception e) { JCRExceptionManager.process(uiApp, e); return; } } } /** * Check the node is passed have child node or not. * * @param node * @return * @throws Exception */ public boolean hasChildNode(Node node) throws Exception { if(!node.hasNodes()) return false; UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); Preference preferences = uiExplorer.getPreference(); if(!isFolderType(node) && !preferences.isJcrEnable() && !node.isNodeType(org.exoplatform.ecm.webui.utils.Utils.EXO_TAXONOMY)) return false; NodeIterator iterator = node.getNodes(); while(iterator.hasNext()) { Node tmpNode = iterator.nextNode(); // Not allow to show hidden and non-document nodes if (!preferences.isShowHiddenNode() && !preferences.isShowNonDocumentType()) { if(!tmpNode.isNodeType(org.exoplatform.ecm.webui.utils.Utils.EXO_HIDDENABLE) && isDocumentOrFolderType(tmpNode)) return true; } // Not allow to show non-document nodes else if (preferences.isShowHiddenNode() && !preferences.isShowNonDocumentType()) { if(isDocumentOrFolderType(tmpNode)) return true; } // Not allow to show hidden nodes else if (!preferences.isShowHiddenNode() && preferences.isShowNonDocumentType()) { if(!tmpNode.isNodeType(org.exoplatform.ecm.webui.utils.Utils.EXO_HIDDENABLE)) return true; } // Allow to show hidden and non-document nodes else return true; } return false; } /** * Check the node is passed is a document/folder or not. * * @param node * @return * @throws Exception */ private boolean isDocumentOrFolderType(Node node) throws Exception { if(node.isNodeType(org.exoplatform.ecm.webui.utils.Utils.NT_FOLDER) || node.isNodeType(org.exoplatform.ecm.webui.utils.Utils.NT_UNSTRUCTURED)) return true; TemplateService templateService = getApplicationComponent(TemplateService.class); NodeType nodeType = node.getPrimaryNodeType(); return templateService.getDocumentTemplates().contains(nodeType.getName()); } private boolean isFolderType(Node node) throws Exception { if(node.isNodeType(org.exoplatform.ecm.webui.utils.Utils.NT_FOLDER) || node.isNodeType(org.exoplatform.ecm.webui.utils.Utils.NT_UNSTRUCTURED)) return true; return false; } }
29,332
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITreeNodePageIterator.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/UITreeNodePageIterator.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar; import java.util.Set; import org.exoplatform.ecm.webui.component.explorer.UIDocumentContainer; import org.exoplatform.ecm.webui.component.explorer.UIDocumentInfo; import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.search.UISearchResult; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIPageIterator; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SAS * Author : Hoa Pham * hoa.pham@exoplatform.com * Sep 26, 2007 */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/sidebar/UITreeNodePageIterator.gtmpl", events = @EventConfig(listeners = UITreeNodePageIterator.ShowPageActionListener.class, csrfCheck = false ) ) public class UITreeNodePageIterator extends UIPageIterator { private String selectedPath_ ; public UITreeNodePageIterator() { } public String getSelectedPath() { return selectedPath_ ; } public void setSelectedPath(String path) { this.selectedPath_ = path ; } static public class ShowPageActionListener extends EventListener<UITreeNodePageIterator> { public void execute(Event<UITreeNodePageIterator> event) throws Exception { UITreeNodePageIterator uiPageIterator = event.getSource() ; int page = Integer.parseInt(event.getRequestContext().getRequestParameter(OBJECTID)) ; if(uiPageIterator.getAvailablePage() < page) page = uiPageIterator.getAvailablePage(); uiPageIterator.setCurrentPage(page) ; if(uiPageIterator.getParent() == null) return ; UIJCRExplorer uiExplorer = uiPageIterator.getAncestorOfType(UIJCRExplorer.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiExplorer); UIDocumentWorkspace uiDocumentWorkspace = uiExplorer.findFirstComponentOfType(UIDocumentWorkspace.class) ; UISearchResult uiSearchResult = uiDocumentWorkspace.getChild(UISearchResult.class) ; if(uiSearchResult.isRendered()) return ; UIDocumentContainer uiDocumentContainer = uiDocumentWorkspace.getChild(UIDocumentContainer.class); UIDocumentInfo uiDocumentInfo = null ; if(uiExplorer.isShowViewFile()) { uiDocumentInfo = uiDocumentContainer.getChildById("UIDocumentWithTree") ; } else { Set<String> allItemByTypeFilterMap = uiExplorer.getAllItemByTypeFilterMap(); if (allItemByTypeFilterMap.size() > 0) uiDocumentInfo = uiDocumentContainer.getChildById("UIDocumentWithTree"); else uiDocumentInfo = uiDocumentContainer.getChildById("UIDocumentInfo"); } if (uiDocumentInfo == null) return; String currentPath = uiExplorer.getCurrentNode().getPath(); if(!currentPath.equalsIgnoreCase(uiPageIterator.getSelectedPath())) return ; UIPageIterator iterator = uiDocumentInfo.getContentPageIterator(); if(iterator.getAvailablePage() >= page) iterator.setCurrentPage(page); if (uiDocumentWorkspace.isRendered() && uiDocumentContainer.isRendered() && uiDocumentInfo.isRendered()) { event.getRequestContext().addUIComponentToUpdateByAjax(uiDocumentInfo); } } } }
4,130
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIViewRelationList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/UIViewRelationList.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar; import java.util.ArrayList; import java.util.List; import javax.jcr.AccessDeniedException; import javax.jcr.ItemNotFoundException; import javax.jcr.Node; import javax.jcr.PropertyIterator; import javax.jcr.Session; import javax.jcr.UnsupportedRepositoryOperationException; import javax.jcr.Value; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.i18n.MultiLanguageService; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.core.ManageableRepository; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Pham Tuan * phamtuanchip@yahoo.de * September 19, 2006 */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/sidebar/UIViewRelationList.gtmpl", events = {@EventConfig(listeners = UIViewRelationList.ChangeNodeActionListener.class, csrfCheck = false)} ) public class UIViewRelationList extends UIContainer{ public UIViewRelationList() throws Exception { } public List<Node> getRelations() throws Exception { UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ; List<Node> relations = new ArrayList<Node>() ; Value[] vals = null ; try { vals = uiExplorer.getCurrentNode().getProperty("exo:relation").getValues() ; }catch (Exception e) { return relations ;} RepositoryService repositoryService = getApplicationComponent(RepositoryService.class) ; ManageableRepository repository = repositoryService.getCurrentRepository() ; String[] wsNames = repository.getWorkspaceNames() ; for(String wsName : wsNames) { Session session = WCMCoreUtils.getUserSessionProvider().getSession(wsName, repository) ; for(Value val : vals) { String uuid = val.getString(); try { Node node = session.getNodeByUUID(uuid) ; if (!Utils.isInTrash(node)) relations.add(node) ; } catch(Exception e) { continue ; } } } return relations ; } public List<Node> getReferences() throws Exception { List<Node> refNodes = new ArrayList<Node>() ; RepositoryService repositoryService = getApplicationComponent(RepositoryService.class) ; UIJCRExplorer uiJCRExplorer = getAncestorOfType(UIJCRExplorer.class) ; Node currentNode = uiJCRExplorer.getCurrentNode() ; try { String uuid = currentNode.getUUID() ; ManageableRepository repository = repositoryService.getCurrentRepository(); Session session = null ; for(String workspace : repository.getWorkspaceNames()) { session = WCMCoreUtils.getSystemSessionProvider().getSession(workspace, repository) ; try{ Node lookupNode = session.getNodeByUUID(uuid) ; PropertyIterator iter = lookupNode.getReferences() ; if(iter != null) { while(iter.hasNext()) { Node refNode = iter.nextProperty().getParent() ; if (!Utils.isInTrash(refNode) && !refNode.isNodeType("exo:auditHistory")) refNodes.add(refNode) ; } } } catch(Exception e) { continue; } } } catch (UnsupportedRepositoryOperationException e) { // currentNode is not referenceable } return refNodes ; } public List<Node> getLanguages() throws Exception { UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ; Node node = uiExplorer.getCurrentNode(); List<Node> relations = new ArrayList<Node>() ; MultiLanguageService langService = getApplicationComponent(MultiLanguageService.class) ; List<String> langs = langService.getSupportedLanguages(node); for(String lang: langs) { Node lnode = langService.getLanguage(node, lang); if (lnode!=null && lnode.hasProperty("exo:language")) { relations.add(lnode) ; } } return relations ; } public boolean isPreferenceNode(Node node) { return getAncestorOfType(UIJCRExplorer.class).isPreferenceNode(node) ; } static public class ChangeNodeActionListener extends EventListener<UIViewRelationList> { public void execute(Event<UIViewRelationList> event) throws Exception { UIViewRelationList uicomp = event.getSource() ; UIJCRExplorer uiExplorer = uicomp.getAncestorOfType(UIJCRExplorer.class) ; String uri = event.getRequestContext().getRequestParameter(OBJECTID) ; String workspaceName = event.getRequestContext().getRequestParameter("workspaceName") ; Session session = uiExplorer.getSessionByWorkspace(workspaceName); UIApplication uiApp = uicomp.getAncestorOfType(UIApplication.class) ; try { session.getItem(uri); } catch(ItemNotFoundException nu) { uiApp.addMessage(new ApplicationMessage("UIDocumentInfo.msg.null-exception", null, ApplicationMessage.WARNING)) ; return ; } catch(AccessDeniedException ace) { uiApp.addMessage(new ApplicationMessage("UIDocumentInfo.msg.null-exception", null, ApplicationMessage.WARNING)) ; return ; } catch(Exception e) { JCRExceptionManager.process(uiApp, e); return ; } uiExplorer.setSelectNode(workspaceName, uri); uiExplorer.updateAjax(event) ; } } }
6,618
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIDocumentFilterForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/UIDocumentFilterForm.java
/*************************************************************************** * Copyright (C) 2003-2009 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. * **************************************************************************/ package org.exoplatform.ecm.webui.component.explorer.sidebar; import java.util.ArrayList; import java.util.List; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorerPortlet; import org.exoplatform.services.cms.documents.DocumentTypeService; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.input.UICheckBoxInput; /** * Created by The eXo Platform SARL * Author : Phan Trong Lam * lamptdev@gmail.com * Oct 27, 2009 */ @ComponentConfig(lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIFormWithTitle.gtmpl", events = { @EventConfig(listeners = UIDocumentFilterForm.SaveActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIDocumentFilterForm.CancelActionListener.class, csrfCheck = false) } ) public class UIDocumentFilterForm extends UIForm implements UIPopupComponent { public UIDocumentFilterForm(){ } public void activate() { } public void deActivate() { } public void invoke(List<String> checkedTypes) { DocumentTypeService documentTypeService = getApplicationComponent(DocumentTypeService.class); List<String> supportedTypes = documentTypeService.getAllSupportedType(); for (String supportedName : supportedTypes) { addUIFormInput(new UICheckBoxInput(supportedName, supportedName, null)); for (String checkedTypeName : checkedTypes) { if (supportedName.equals(checkedTypeName)) { getUICheckBoxInput(supportedName).setChecked(true); continue; } } } } static public class SaveActionListener extends EventListener<UIDocumentFilterForm> { public void execute(Event<UIDocumentFilterForm> event) throws Exception { UIDocumentFilterForm uiForm = event.getSource(); UIJCRExplorerPortlet uiExplorerPorltet = uiForm.getAncestorOfType(UIJCRExplorerPortlet.class); UIJCRExplorer uiExplorer = uiExplorerPorltet.findFirstComponentOfType(UIJCRExplorer.class); DocumentTypeService documentTypeService = uiForm.getApplicationComponent(DocumentTypeService.class); List<String> supportedTypes = documentTypeService.getAllSupportedType(); List<String> checkedSupportTypes = new ArrayList<String>(); for (String checkedName : supportedTypes) { if (uiForm.getUICheckBoxInput(checkedName).isChecked()) checkedSupportTypes.add(checkedName); } uiExplorer.setCheckedSupportType(checkedSupportTypes); uiExplorer.setFilterSave(true); uiExplorer.refreshExplorer(); uiExplorerPorltet.setRenderedChild(UIJCRExplorer.class); } } static public class CancelActionListener extends EventListener<UIDocumentFilterForm> { public void execute(Event<UIDocumentFilterForm> event) throws Exception { UIDocumentFilterForm uiForm = event.getSource(); UIJCRExplorerPortlet explorerPorltet = uiForm.getAncestorOfType(UIJCRExplorerPortlet.class); UIJCRExplorer uiExplorer = explorerPorltet.findFirstComponentOfType(UIJCRExplorer.class); uiExplorer.getChild(UIPopupContainer.class).cancelPopupAction(); } } }
4,583
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIClipboard.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/UIClipboard.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.rightclick.manager.PasteManageComponent; import org.exoplatform.services.cms.clipboard.ClipboardService; import org.exoplatform.services.cms.clipboard.jcr.model.ClipboardCommand; import org.exoplatform.services.security.ConversationState; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import java.util.LinkedList; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * Oct 20, 2006 */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/sidebar/UIClipboard.gtmpl", events = { @EventConfig(listeners = UIClipboard.PasteActionListener.class), @EventConfig(listeners = UIClipboard.DeleteActionListener.class), @EventConfig(listeners = UIClipboard.ClearAllActionListener.class) } ) public class UIClipboard extends UIComponent { final static public String[] CLIPBOARD_BEAN_FIELD = {"path"} ; final static public String[] CLIPBOARD_ACTIONS = {"Paste", "Delete"} ; private LinkedList<ClipboardCommand> clipboard_ ; public UIClipboard() throws Exception { } public String[] getBeanFields() { return CLIPBOARD_BEAN_FIELD ; } public String[] getBeanActions() { return CLIPBOARD_ACTIONS ; } public LinkedList<ClipboardCommand> getClipboardData() throws Exception { String userId = ConversationState.getCurrent().getIdentity().getUserId(); ClipboardService clipboardService = WCMCoreUtils.getService(ClipboardService.class); clipboard_ = new LinkedList<ClipboardCommand>(clipboardService.getClipboardList(userId, false)); return clipboard_; } static public class PasteActionListener extends EventListener<UIClipboard> { public void execute(Event<UIClipboard> event) throws Exception { UIClipboard uiClipboard = event.getSource() ; UIJCRExplorer uiExplorer = uiClipboard.getAncestorOfType(UIJCRExplorer.class); String id = event.getRequestContext().getRequestParameter(OBJECTID) ; int index = Integer.parseInt(id) ; ClipboardCommand selectedClipboard = uiClipboard.clipboard_.get(index-1); Node node = uiExplorer.getCurrentNode() ; // String nodePath = node.getPath(); // String wsName = node.getSession().getWorkspace().getName(); UIApplication app = uiClipboard.getAncestorOfType(UIApplication.class); try { //PasteManageComponent.processPaste(selectedClipboard, wsName + ":" + nodePath, event); PasteManageComponent.processPaste(selectedClipboard, node, event, uiExplorer); //uiWorkingArea.processPaste(selectedClipboard, wsName + ":" + nodePath, event); if (PasteManageComponent.isIsRefresh()) { uiExplorer.updateAjax(event); } } catch(PathNotFoundException path) { app.addMessage(new ApplicationMessage("PathNotFoundException.msg", null, ApplicationMessage.WARNING)) ; return ; } catch (Exception e) { app.addMessage(new ApplicationMessage("UIClipboard.msg.unable-pasted", null, ApplicationMessage.WARNING)) ; return ; } } } static public class DeleteActionListener extends EventListener<UIClipboard> { public void execute(Event<UIClipboard> event) throws Exception{ UIClipboard uiClipboard = event.getSource() ; String itemIndex = event.getRequestContext().getRequestParameter(OBJECTID) ; ClipboardCommand command = uiClipboard.clipboard_.remove(Integer.parseInt(itemIndex)-1); String userId = ConversationState.getCurrent().getIdentity().getUserId(); ClipboardService clipboardService = WCMCoreUtils.getService(ClipboardService.class); clipboardService.removeClipboardCommand(userId, command); } } static public class ClearAllActionListener extends EventListener<UIClipboard> { public void execute(Event<UIClipboard> event) { UIClipboard uiClipboard = event.getSource() ; uiClipboard.clipboard_.clear() ; String userId = ConversationState.getCurrent().getIdentity().getUserId(); ClipboardService clipboardService = WCMCoreUtils.getService(ClipboardService.class); clipboardService.clearClipboardList(userId, false); } } }
5,624
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UISideBar.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/UISideBar.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar ; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.jcr.Node; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorerPortlet; import org.exoplatform.ecm.webui.component.explorer.UIJcrExplorerContainer; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.ecm.webui.component.explorer.control.UIAddressBar; import org.exoplatform.ecm.webui.component.explorer.sidebar.action.ExplorerActionComponent; import org.exoplatform.services.cms.views.ManageViewService; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.wcm.core.NodetypeConstant; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.ext.UIExtension; import org.exoplatform.webui.ext.UIExtensionManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SARL * Author : Hung Nguyen * nguyenkequanghung@yahoo.com * oct 5, 2006 */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/sidebar/UISideBar.gtmpl", events = { @EventConfig(listeners = UISideBar.CloseActionListener.class, csrfCheck = false) } ) public class UISideBar extends UIContainer { public static final String UI_TAG_EXPLORER = "TagExplorer"; private String currentComp; private static final Log LOG = ExoLogger.getLogger(UISideBar.class.getName()); public static final String EXTENSION_TYPE = "org.exoplatform.ecm.dms.UISideBar"; public static final int VISIBLE_COMPONENT_SIZE = 5; private List<UIAbstractManagerComponent> managers = Collections.synchronizedList(new ArrayList<UIAbstractManagerComponent>()); private String selectedComp; private List<UIAbstractManagerComponent> lstVisibleComp; private List<UIAbstractManagerComponent> lstHiddenComp; public UISideBar() throws Exception { addChild(UITreeExplorer.class, null, null).setRendered(false); addChild(UIViewRelationList.class, null, null).setRendered(false); addChild(UITagExplorer.class, null, null).setRendered(false); addChild(UIClipboard.class, null, null).setRendered(false); addChild(UISavedSearches.class, null, null).setRendered(false); addChild(UIAllItems.class, null, null); addChild(UIAllItemsByType.class, null, null); } public List<UIAbstractManagerComponent> getLstVisibleComp() { return lstVisibleComp; } public void setLstVisibleComp(List<UIAbstractManagerComponent> lstVisibleComp) { this.lstVisibleComp = lstVisibleComp; } public List<UIAbstractManagerComponent> getLstHiddenComp() { return lstHiddenComp; } public void setLstHiddenComp(List<UIAbstractManagerComponent> lstHiddenComp) { this.lstHiddenComp = lstHiddenComp; } public void setSelectedComp(String componentName) { selectedComp = componentName; } public void initComponents() throws Exception { lstVisibleComp = new ArrayList<UIAbstractManagerComponent>(VISIBLE_COMPONENT_SIZE); lstHiddenComp = new ArrayList<UIAbstractManagerComponent>(); List<UIAbstractManagerComponent> managers = getManagers(); for (int i = 0; i < managers.size(); i++) { UIAbstractManagerComponent component = managers.get(i); if (lstVisibleComp.size() < VISIBLE_COMPONENT_SIZE) { if (!isHideExplorerPanel() || !(component instanceof ExplorerActionComponent)) { lstVisibleComp.add(component); } } else { lstHiddenComp.add(component); } } } public String getCurrentComp() throws Exception { if(currentComp == null || currentComp.length() == 0) { currentComp = getChild(UITreeExplorer.class).getId(); } if (isHideExplorerPanel() && getChild(UITreeExplorer.class).getId().equals(currentComp)) { currentComp = getChild(UITagExplorer.class).getId(); this.getAncestorOfType(UIJCRExplorer.class).setCurrentState(); this.getChild(UITagExplorer.class).updateTagList(); } return currentComp; } public String getSelectedComp() throws Exception { if(selectedComp == null || selectedComp.length() == 0) { selectedComp = "Explorer"; } if (isHideExplorerPanel() && "Explorer".equals(selectedComp)) { selectedComp = UI_TAG_EXPLORER; } return selectedComp; } public void updateSideBarView() throws Exception { boolean showFilterBar = getAncestorOfType(UIJCRExplorerPortlet.class).isShowFilterBar(); getChild(UIAllItems.class).setRendered(showFilterBar); getChild(UIAllItemsByType.class).setRendered(showFilterBar); } public void setCurrentComp(String currentComp) { this.currentComp = currentComp; } public void renderSideBarChild(String[] arrId) throws Exception { for(String id : arrId) { setRenderedChild(id); // Need to remove this because we've already called updateSideBarView() but need Checking renderChild(id); } } public String getRepository() { return getAncestorOfType(UIJCRExplorer.class).getRepositoryName(); } static public class CloseActionListener extends EventListener<UISideBar> { public void execute(Event<UISideBar> event) throws Exception { UIWorkingArea uiWorkingArea = event.getSource().getParent(); uiWorkingArea.setShowSideBar(false); UIJCRExplorerPortlet explorerPorltet = uiWorkingArea.getAncestorOfType(UIJCRExplorerPortlet.class); UIJCRExplorer uiExplorer = explorerPorltet.findFirstComponentOfType(UIJCRExplorer.class); UIJcrExplorerContainer uiJcrExplorerContainer= explorerPorltet.getChild(UIJcrExplorerContainer.class); uiExplorer.refreshExplorer(); uiJcrExplorerContainer.setRenderedChild(UIJCRExplorer.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiExplorer); } } private List<UIExtension> getUIExtensionList() { UIExtensionManager manager = getApplicationComponent(UIExtensionManager.class); return manager.getUIExtensions(EXTENSION_TYPE); } public synchronized void initialize() throws Exception { List<UIExtension> extensions = getUIExtensionList(); if (extensions == null) { return; } managers.clear(); Map<String, Object> context = new HashMap<String, Object>(); UIJCRExplorer uiExplorer = this.getAncestorOfType(UIJCRExplorer.class); context.put(UIJCRExplorer.class.getName(), uiExplorer); for (UIExtension extension : extensions) { UIComponent component = addUIExtension(extension, context); if (component != null && !managers.contains(component)) { managers.add((UIAbstractManagerComponent) component); } } initComponents(); } private synchronized UIComponent addUIExtension(UIExtension extension, Map<String, Object> context) throws Exception { UIExtensionManager manager = getApplicationComponent(UIExtensionManager.class); UIComponent component = manager.addUIExtension(extension, context, this); if (component instanceof UIAbstractManagerComponent) { // You can access to the given extension and the extension is valid UIAbstractManagerComponent uiAbstractManagerComponent = (UIAbstractManagerComponent) component; uiAbstractManagerComponent.setUIExtensionName(extension.getName()); uiAbstractManagerComponent.setUIExtensionCategory(extension.getCategory()); return component; } else if (component != null) { // You can access to the given extension but the extension is not valid if (LOG.isWarnEnabled()) { LOG.warn("All the extension '" + extension.getName() + "' of type '" + EXTENSION_TYPE + "' must be associated to a component of type " + UIAbstractManagerComponent.class); } removeChild(component.getClass()); } return null; } public List<UIAbstractManagerComponent> getManagers() { List<UIAbstractManagerComponent> managers = new ArrayList<UIAbstractManagerComponent>(); managers.addAll(this.managers); return managers; } public void unregister(UIAbstractManagerComponent component) { managers.remove(component); } public boolean isRenderComponent(String actionName) throws Exception { if ("Explorer".equals(actionName)) { return !isHideExplorerPanel(); } return true; } private boolean isHideExplorerPanel() throws Exception { UIAddressBar uiAddress = this.getAncestorOfType(UIJCRExplorer.class). findFirstComponentOfType(UIAddressBar.class); String viewName = uiAddress.getSelectedViewName(); Node viewNode = WCMCoreUtils.getService(ManageViewService.class).getViewByName( viewName, WCMCoreUtils.getSystemSessionProvider()); return viewNode.getProperty(NodetypeConstant.EXO_HIDE_EXPLORER_PANEL).getBoolean(); } }
10,325
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIAllItemsByType.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/UIAllItemsByType.java
/* * Copyright (C) 2003-2008 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar; import java.util.List; import java.util.Set; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.services.cms.documents.DocumentTypeService; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Oct 29, 2009 * 7:08:57 AM */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/sidebar/UIAllItemsByType.gtmpl", events = { @EventConfig(listeners = UIAllItemsByType.ShowDocumentTypeActionListener.class), @EventConfig(listeners = UIAllItemsByType.DocumentFilterActionListener.class) } ) public class UIAllItemsByType extends UIComponent { public UIAllItemsByType() { } public List<String> getAllSupportedType() { DocumentTypeService documentTypeService = getApplicationComponent(DocumentTypeService.class); UIJCRExplorer uiJCRExplorer = getAncestorOfType(UIJCRExplorer.class); if (uiJCRExplorer.isFilterSave()) return uiJCRExplorer.getCheckedSupportType(); return documentTypeService.getAllSupportedType(); } static public class ShowDocumentTypeActionListener extends EventListener<UIAllItemsByType> { public void execute(Event<UIAllItemsByType> event) throws Exception { UIAllItemsByType uiViewDocumentTypes = event.getSource(); String supportedType = event.getRequestContext().getRequestParameter(OBJECTID); UIJCRExplorer uiExplorer = uiViewDocumentTypes.getAncestorOfType(UIJCRExplorer.class); Set<String> allItemByTypeFilterMap = uiExplorer.getAllItemByTypeFilterMap(); if (allItemByTypeFilterMap.contains(supportedType)) { allItemByTypeFilterMap.remove(supportedType); } else { allItemByTypeFilterMap.add(supportedType); } uiExplorer.setIsViewTag(false); uiExplorer.updateAjax(event); } } static public class DocumentFilterActionListener extends EventListener<UIAllItemsByType> { public void execute(Event<UIAllItemsByType> event) throws Exception { UIAllItemsByType uiSideBar = event.getSource(); UIJCRExplorer uiJCRExplorer = uiSideBar.getAncestorOfType(UIJCRExplorer.class); UIPopupContainer popupAction = uiJCRExplorer.getChild(UIPopupContainer.class); UIDocumentFilterForm uiDocumentFilter = popupAction.activate(UIDocumentFilterForm.class, 350); uiDocumentFilter.invoke(uiSideBar.getAllSupportedType()); event.getRequestContext().addUIComponentToUpdateByAjax(popupAction) ; } } }
3,649
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIAllItems.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/UIAllItems.java
/* * Copyright (C) 2003-2008 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar; import java.util.Set; import org.exoplatform.ecm.jcr.model.Preference; import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace; import org.exoplatform.ecm.webui.component.explorer.UIDrivesArea; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.ecm.webui.component.explorer.control.UIAllItemsPreferenceForm; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.wcm.core.NodetypeConstant; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletResponse; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Oct 29, 2009 * 7:07:27 AM */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/sidebar/UIAllItems.gtmpl", events = { @EventConfig(listeners = UIAllItems.ClickFilterActionListener.class), @EventConfig(listeners = UIAllItems.PreferencesActionListener.class) } ) public class UIAllItems extends UIComponent { public UIAllItems() throws Exception { } public static String getFAVORITE() { return NodetypeConstant.FAVORITE; } public static String getOWNED_BY_ME() { return NodetypeConstant.OWNED_BY_ME; } public static String getHIDDEN() { return NodetypeConstant.HIDDEN; } public static String getTRASH() { return NodetypeConstant.TRASH; } public Preference getPreference() { return getAncestorOfType(UIJCRExplorer.class).getPreference(); } static public class ClickFilterActionListener extends EventListener<UIAllItems> { public void execute(Event<UIAllItems> event) throws Exception { UIAllItems UIAllItems = event.getSource(); UIJCRExplorer uiExplorer = UIAllItems.getAncestorOfType(UIJCRExplorer.class); Set<String> allItemFilterMap = uiExplorer.getAllItemFilterMap(); HttpServletResponse response = Util.getPortalRequestContext().getResponse(); String userId = Util.getPortalRequestContext().getRemoteUser(); String cookieName = Preference.PREFERENCE_SHOW_HIDDEN_NODE + userId; String filterType = event.getRequestContext().getRequestParameter(OBJECTID); if (allItemFilterMap.contains(filterType)) { allItemFilterMap.remove(filterType); if (filterType.equals(NodetypeConstant.HIDDEN)) { uiExplorer.getPreference().setShowHiddenNode(false); response.addCookie(new Cookie(cookieName, "false")); } } else { allItemFilterMap.add(filterType); if (filterType.equals(NodetypeConstant.HIDDEN)) { uiExplorer.getPreference().setShowHiddenNode(true); response.addCookie(new Cookie(cookieName, "true")); } } // new code UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class); if(!uiDocumentWorkspace.isRendered()) { uiWorkingArea.getChild(UIDrivesArea.class).setRendered(false); uiWorkingArea.getChild(UIDocumentWorkspace.class).setRendered(true); } uiExplorer.updateAjax(event); } } static public class PreferencesActionListener extends EventListener<UIAllItems> { public void execute(Event<UIAllItems> event) throws Exception { UIAllItems uiAllItems = event.getSource(); UIJCRExplorer uiJCRExplorer = uiAllItems.getAncestorOfType(UIJCRExplorer.class); UIPopupContainer popupAction = uiJCRExplorer.getChild(UIPopupContainer.class); UIAllItemsPreferenceForm uiPrefForm = popupAction.activate(UIAllItemsPreferenceForm.class,350) ; uiPrefForm.update(uiJCRExplorer.getPreference()) ; event.getRequestContext().addUIComponentToUpdateByAjax(popupAction) ; } } }
5,061
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
TreeNode.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/TreeNode.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar; import org.exoplatform.services.cms.link.NodeLinkAware; import org.exoplatform.services.jcr.impl.core.NodeImpl; import org.exoplatform.services.jcr.util.Text; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.wcm.core.NodeLocation; import javax.jcr.Node; import javax.jcr.RepositoryException; import java.util.ArrayList; import java.util.List; /** * Created by The eXo Platform SARL * Author : Tran The Trong * trongtt@gmail.com * Sep 29, 2006 * 5:37:31 PM */ public class TreeNode { private static final Log LOG = ExoLogger.getLogger(TreeNode.class.getName()); //TODO Need use this class for BC TreeNode private boolean isExpanded_ ; private String path_; private String prefix; private NodeLocation node_ ; private NodeLinkAware node; private String name_; private List<TreeNode> children_ = new ArrayList<TreeNode>() ; private long childrenSize; public TreeNode(Node node) throws RepositoryException { this(node, node.getPath()); } private TreeNode(Node node, String path) { if (node instanceof NodeLinkAware) { this.node = (NodeLinkAware)node; try { this.childrenSize = this.node.getNodesLazily().getSize(); } catch (RepositoryException e) { this.childrenSize = 0; } } else { node_ = NodeLocation.getNodeLocationByNode(node); try { this.childrenSize = ((NodeImpl) node).getNodesLazily().getSize(); } catch (RepositoryException e) { this.childrenSize = 0; } } name_ = getName(node); isExpanded_ = false ; path_ = path; prefix = path_.equals("/") ? "" : path_; } public boolean isExpanded() { return isExpanded_; } public void setExpanded(boolean isExpanded) { isExpanded_ = isExpanded; } public String getName() throws RepositoryException { return name_; } private String getName(Node node) { StringBuilder buffer = new StringBuilder(128); try { buffer.append(node.getName()); int index = node.getIndex(); if (index > 1) { buffer.append('['); buffer.append(index); buffer.append(']'); } } catch (RepositoryException e) { if (LOG.isWarnEnabled()) { LOG.warn(e.getMessage()); } } return buffer.toString(); } public String getPath() { return path_; } public String getNodePath() throws RepositoryException { return node != null ? node.getPath() : node_.getPath(); } public Node getNode() { return node != null ? node : NodeLocation.getNodeByLocation(node_); } public void setNode(Node node) { if (node instanceof NodeLinkAware) { this.node = (NodeLinkAware)node; } else { node_ = NodeLocation.getNodeLocationByNode(node); } } public String getNodePath4ID() { String tmp = Text.escape(path_); return tmp.replace('%', '_'); } public List<TreeNode> getChildren() { return children_ ; } public int getChildrenSize() { return (int) childrenSize; } public TreeNode getChildByName(String name) throws RepositoryException { for(TreeNode child : children_) { if(child.getName().equals(name)) return child ; } Node tempNode = null; if(this.getNode().hasNode(name)) { tempNode = this.getNode().getNode(name); } if (tempNode == null) { return null; } TreeNode tempTreeNode = new TreeNode(tempNode, prefix + "/" + getName(tempNode)); return tempTreeNode; } public void setChildren(List<Node> children) throws Exception { setExpanded(true) ; for(Node child : children) { children_.add(new TreeNode(child, prefix + "/" + getName(child))) ; } } }
4,652
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITagExplorer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/UITagExplorer.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar; import org.apache.commons.lang3.StringUtils; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.component.explorer.UIDocumentContainer; import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.ecm.webui.component.explorer.control.UIAddressBar; import org.exoplatform.ecm.webui.component.explorer.popup.actions.UIEditingTagsForm; import org.exoplatform.ecm.webui.component.explorer.search.UISearchResult; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.folksonomy.NewFolksonomyService; import org.exoplatform.services.cms.impl.DMSConfiguration; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.core.ManageableRepository; import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator; import org.exoplatform.services.wcm.core.NodeLocation; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.ComponentConfigs; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPageIterator; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import java.util.Map.Entry; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Oct 26, 2007 4:59:40 PM */ @ComponentConfigs( { @ComponentConfig(template = "app:/groovy/webui/component/explorer/sidebar/UITagExplorer.gtmpl", events = { @EventConfig(listeners = UITagExplorer.ViewTagActionListener.class, csrfCheck = false), @EventConfig(listeners = UITagExplorer.EditTagsActionListener.class) }), @ComponentConfig(type = UIPageIterator.class, id = "PublicTagPageIterator", template = "app:/groovy/webui/component/explorer/sidebar/UITagPageIterator.gtmpl", events = {@EventConfig(listeners = UIPageIterator.ShowPageActionListener.class)}) }) public class UITagExplorer extends UIContainer { public static final String PUBLIC_TAG_NODE_PATH = "exoPublicTagNode"; private static final String PRIVATE_TAG_PAGE_ITERATOR_ID = "PrivateTagPageIterator"; private static final String PUBLIC_TAG_PAGE_ITERATOR_ID = "PublicTagPageIterator"; private static final int TAG_PAGE_SIZE = 50; private int tagScope; private UIPageIterator privateTagPageIterator_; private UIPageIterator publicTagPageIterator_; private NewFolksonomyService folksonomyService; public UITagExplorer() throws Exception { privateTagPageIterator_ = addChild(UIPageIterator.class, null, PRIVATE_TAG_PAGE_ITERATOR_ID); publicTagPageIterator_ = addChild(UIPageIterator.class, null, PUBLIC_TAG_PAGE_ITERATOR_ID); folksonomyService = getApplicationComponent(NewFolksonomyService.class); } public int getTagScope() { return tagScope; } public void setTagScope(int scope) { tagScope = scope; } public List<Node> getPrivateTagLink() throws Exception { return NodeLocation.getNodeListByLocationList(privateTagPageIterator_.getCurrentPageData()); } public List<Node> getPublicTagLink() throws Exception { return NodeLocation.getNodeListByLocationList(publicTagPageIterator_.getCurrentPageData()); } public Map<String ,String> getTagStyle() throws Exception { NewFolksonomyService folksonomyService = getApplicationComponent(NewFolksonomyService.class) ; String workspace = getApplicationComponent(DMSConfiguration.class).getConfig().getSystemWorkspace(); Map<String , String> tagStyle = new HashMap<String ,String>() ; for(Node tag : folksonomyService.getAllTagStyle(workspace)) { tagStyle.put(tag.getProperty("exo:styleRange").getValue().getString(), tag.getProperty("exo:htmlStyle").getValue().getString()); } return tagStyle ; } public String inverseBGColorByFontColor(String tagStyle) { StringBuilder result = new StringBuilder(); StringTokenizer stringTokenizer = new StringTokenizer(tagStyle, ":|;", true); while (stringTokenizer.hasMoreTokens()) { String token = stringTokenizer.nextToken().trim(); if (token.equals("color")) { token = "background-color"; } else if (token.equals("background-color")) { token = "color"; } result.append(token); } return result.toString(); } public String getTagHtmlStyle(Node tag) throws Exception { int tagCount = (int)tag.getProperty("exo:total").getValue().getLong(); for (Entry<String, String> entry : getTagStyle().entrySet()) { if (checkTagRate(tagCount, entry.getKey())) { String tagStyle = entry.getValue(); if(isTagSelected(tag.getPath())) { tagStyle = inverseBGColorByFontColor(tagStyle); } return tagStyle; } } return ""; } /** * updates the private tag list and public tag list * @throws Exception */ public void updateTagList() throws Exception { //update private tag list ListAccess<NodeLocation> privateTagList = new ListAccessImpl<NodeLocation>(NodeLocation.class, NodeLocation.getLocationsByNodeList(folksonomyService.getAllPrivateTags(getUserName()))); LazyPageList<NodeLocation> privatePageList = new LazyPageList<NodeLocation>(privateTagList, TAG_PAGE_SIZE); privateTagPageIterator_.setPageList(privatePageList); //update public tag list NodeHierarchyCreator nodeHierarchyCreator = getApplicationComponent(NodeHierarchyCreator.class); String publicTagNodePath = nodeHierarchyCreator.getJcrPath(PUBLIC_TAG_NODE_PATH); RepositoryService repositoryService = getApplicationComponent(RepositoryService.class); ManageableRepository manageableRepo = repositoryService.getCurrentRepository(); String workspace = manageableRepo.getConfiguration().getDefaultWorkspaceName(); ListAccess<NodeLocation> publicTagList = new ListAccessImpl<NodeLocation>(NodeLocation.class, NodeLocation.getLocationsByNodeList(folksonomyService.getAllPublicTags(publicTagNodePath, workspace))); LazyPageList<NodeLocation> publicPageList = new LazyPageList<NodeLocation>(publicTagList, TAG_PAGE_SIZE); publicTagPageIterator_.setPageList(publicPageList); } public boolean isTagSelected(String tagPath) { UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ; return uiExplorer.getTagPaths().contains(tagPath); } /** * gets public tag page iterator */ public UIPageIterator getPublicPageIterator() { return publicTagPageIterator_; } /** * gets private tag page iterator */ public UIPageIterator getPrivatePageIterator() { return privateTagPageIterator_; } private boolean checkTagRate(int numOfDocument, String range) throws Exception { String[] vals = StringUtils.split(range ,"..") ; int minValue = Integer.parseInt(vals[0]) ; int maxValue ; if(vals[1].equals("*")) { maxValue = Integer.MAX_VALUE ; }else { maxValue = Integer.parseInt(vals[1]) ; } if(minValue <=numOfDocument && numOfDocument <maxValue ) return true ; return false ; } public String getRepository() { return getAncestorOfType(UIJCRExplorer.class).getRepositoryName();} public String getWorkspace() { return getAncestorOfType(UIJCRExplorer.class).getCurrentWorkspace();} public String getUserName() { try { return WCMCoreUtils.getRemoteUser(); } catch (Exception ex) { return ""; } } static public class ViewTagActionListener extends EventListener<UITagExplorer> { public void execute(Event<UITagExplorer> event) throws Exception { UITagExplorer uiTagExplorer = event.getSource() ; UIApplication uiApp = uiTagExplorer.getAncestorOfType(UIApplication.class); String tagPath = event.getRequestContext().getRequestParameter(OBJECTID) ; UIJCRExplorer uiExplorer = uiTagExplorer.getAncestorOfType(UIJCRExplorer.class); uiExplorer.setTagPath(tagPath); UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDocumentContainer uiDocumentContainer = uiExplorer.findFirstComponentOfType(UIDocumentContainer.class); if(uiDocumentContainer.isDocumentNode()) { Node currentNode = uiExplorer.getCurrentNode(); uiExplorer.setSelectNode(currentNode.getParent().getPath()); } UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class); UISearchResult uiSearchResult = uiDocumentWorkspace.getChildById(UIDocumentWorkspace.SIMPLE_SEARCH_RESULT); if(uiSearchResult != null && uiSearchResult.isRendered()) { uiSearchResult.updateGrid(); } else { uiExplorer.setIsViewTag(uiExplorer.getTagPaths() != null && !uiExplorer.getTagPaths().isEmpty()); try { uiExplorer.updateAjax(event); } catch(PathNotFoundException pne) { uiApp.addMessage(new ApplicationMessage("UITaggingForm.msg.path-not-found", null, ApplicationMessage.WARNING)) ; return; } } } } static public class EditTagsActionListener extends EventListener<UITagExplorer> { public void execute(Event<UITagExplorer> event) throws Exception { UITagExplorer uiTagExplorer = event.getSource(); NewFolksonomyService newFolksonomyService = uiTagExplorer.getApplicationComponent(NewFolksonomyService.class); String scope = event.getRequestContext().getRequestParameter(OBJECTID); int intScope = Utils.PUBLIC.equals(scope) ? NewFolksonomyService.PUBLIC : NewFolksonomyService.PRIVATE; uiTagExplorer.getAncestorOfType(UIJCRExplorer.class).setTagScope(intScope); List<String> memberships = Utils.getMemberships(); if (newFolksonomyService.canEditTag(intScope, memberships)) { UIJCRExplorer uiExplorer = uiTagExplorer.getAncestorOfType(UIJCRExplorer.class); UIPopupContainer uiPopupContainer = uiExplorer.getChild(UIPopupContainer.class); uiPopupContainer.activate(UIEditingTagsForm.class, 600); event.getRequestContext().addUIComponentToUpdateByAjax(uiPopupContainer); } else { UIApplication uiApp = uiTagExplorer.getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.editTagAccessDenied", null, ApplicationMessage.WARNING)); uiTagExplorer.getAncestorOfType(UIJCRExplorer.class).updateAjax(event); } } } }
12,060
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UISideBarActionListener.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/action/UISideBarActionListener.java
/* * Copyright (C) 2003-2010 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar.action; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import javax.jcr.Session; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.ecm.webui.component.explorer.sidebar.UISideBar; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.exception.MessageException; import org.exoplatform.webui.ext.UIExtensionEventListener; /** * Created by The eXo Platform SAS * Author : eXoPlatform * ha.dangviet@exoplatform.com * Nov 22, 2010 */ public abstract class UISideBarActionListener<T extends UIComponent> extends UIExtensionEventListener<T> { private static final Log LOG = ExoLogger.getLogger(UISideBarActionListener.class.getName()); /** * */ @Override protected Map<String, Object> createContext(Event<T> event) throws Exception { Map<String, Object> context = new HashMap<String, Object>(); UISideBar uiSideBar = event.getSource().getAncestorOfType(UISideBar.class); UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); String nodePath = event.getRequestContext().getRequestParameter(UIComponent.OBJECTID); try { Node currentNode; if (nodePath != null && nodePath.length() != 0 && !nodePath.contains(";")) { Matcher matcher = UIWorkingArea.FILE_EXPLORER_URL_SYNTAX.matcher(nodePath); String wsName = null; if (matcher.find()) { wsName = matcher.group(1); nodePath = matcher.group(2); } else { throw new IllegalArgumentException("The ObjectId is invalid '" + nodePath + "'"); } Session session = uiExplorer.getSessionByWorkspace(wsName); // Use the method getNodeByPath because it is link aware currentNode = uiExplorer.getNodeByPath(nodePath, session); } else { currentNode = uiExplorer.getCurrentNode(); } WebuiRequestContext requestContext = event.getRequestContext(); UIApplication uiApp = requestContext.getUIApplication(); context.put(UISideBar.class.getName(), uiSideBar); context.put(UIJCRExplorer.class.getName(), uiExplorer); context.put(UIApplication.class.getName(), uiApp); context.put(Node.class.getName(), currentNode); context.put(WebuiRequestContext.class.getName(), requestContext); } catch (PathNotFoundException pne) { throw new MessageException(new ApplicationMessage("UIPopupMenu.msg.path-not-found", null, ApplicationMessage.WARNING)); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected problem occurs", e); } } return context; } @Override protected String getExtensionType() { return UISideBar.EXTENSION_TYPE; } }
4,141
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
TagExplorerActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/action/TagExplorerActionComponent.java
/* * Copyright (C) 2003-2010 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar.action; import java.util.Arrays; import java.util.List; import javax.jcr.PathNotFoundException; import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.ecm.webui.component.explorer.search.UISearchResult; import org.exoplatform.ecm.webui.component.explorer.sidebar.UISideBar; import org.exoplatform.ecm.webui.component.explorer.sidebar.UITagExplorer; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; import org.exoplatform.webui.ext.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * ha.dangviet@exoplatform.com * Nov 22, 2010 */ @ComponentConfig(events = { @EventConfig( listeners = TagExplorerActionComponent.TagExplorerActionListener.class) }) public class TagExplorerActionComponent extends UIAbstractManagerComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] {}); @UIExtensionFilters public static List<UIExtensionFilter> getFilters() { return FILTERS; } public static class TagExplorerActionListener extends UISideBarActionListener<TagExplorerActionComponent> { @Override protected void processEvent(Event<TagExplorerActionComponent> event) throws Exception { UISideBar uiSideBar = event.getSource().getAncestorOfType(UISideBar.class); UIJCRExplorer uiExplorer = uiSideBar.getAncestorOfType(UIJCRExplorer.class); uiExplorer.setCurrentState(); UITagExplorer uiTagExplorer = uiSideBar.getChild(UITagExplorer.class); if (uiTagExplorer != null) { uiSideBar.setCurrentComp(uiTagExplorer.getId()); uiSideBar.setSelectedComp(event.getSource().getUIExtensionName()); } UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class); UISearchResult uiSearchResult = uiDocumentWorkspace.getChildById(UIDocumentWorkspace.SIMPLE_SEARCH_RESULT); if(uiSearchResult != null && uiSearchResult.isRendered()) { uiSearchResult.updateGrid(); } else if(uiTagExplorer != null) { uiTagExplorer.updateTagList(); uiExplorer.setIsViewTag(uiExplorer.getTagPaths() != null && !uiExplorer.getTagPaths().isEmpty()); event.getRequestContext().addUIComponentToUpdateByAjax(uiSideBar.getParent()); try { uiExplorer.updateAjax(event); } catch(PathNotFoundException pne) { return; } } } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return null; } }
3,905
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
ExplorerActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/action/ExplorerActionComponent.java
/* * Copyright (C) 2003-2010 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar.action; import java.util.Arrays; import java.util.List; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.sidebar.UISideBar; import org.exoplatform.ecm.webui.component.explorer.sidebar.UITreeExplorer; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; import org.exoplatform.webui.ext.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * ha.dangviet@exoplatform.com * Nov 22, 2010 */ @ComponentConfig(events = { @EventConfig( listeners = ExplorerActionComponent.ExplorerActionListener.class) }) public class ExplorerActionComponent extends UIAbstractManagerComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] {}); @UIExtensionFilters public static List<UIExtensionFilter> getFilters() { return FILTERS; } public static class ExplorerActionListener extends UISideBarActionListener<ExplorerActionComponent> { @Override protected void processEvent(Event<ExplorerActionComponent> event) throws Exception { UISideBar uiSideBar = event.getSource().getAncestorOfType(UISideBar.class); UIJCRExplorer uiExplorer = uiSideBar.getAncestorOfType(UIJCRExplorer.class); uiExplorer.setSelectNode(uiExplorer.getCurrentPath()); uiExplorer.setIsViewTag(false); uiSideBar.setCurrentComp(uiSideBar.getChild(UITreeExplorer.class).getId()); uiSideBar.setSelectedComp(event.getSource().getUIExtensionName()); uiExplorer.updateAjax(event); } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return null; } }
2,772
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
SavedSearchesActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/action/SavedSearchesActionComponent.java
/* * Copyright (C) 2003-2010 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar.action; import java.util.Arrays; import java.util.List; import org.exoplatform.ecm.webui.component.explorer.sidebar.UISavedSearches; import org.exoplatform.ecm.webui.component.explorer.sidebar.UISideBar; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; import org.exoplatform.webui.ext.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * ha.dangviet@exoplatform.com * Nov 22, 2010 */ @ComponentConfig(events = { @EventConfig( listeners = SavedSearchesActionComponent.SavedSearchesActionListener.class) }) public class SavedSearchesActionComponent extends UIAbstractManagerComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] {}); @UIExtensionFilters public static List<UIExtensionFilter> getFilters() { return FILTERS; } public static class SavedSearchesActionListener extends UISideBarActionListener<SavedSearchesActionComponent> { @Override protected void processEvent(Event<SavedSearchesActionComponent> event) throws Exception { UISideBar uiSideBar = event.getSource().getAncestorOfType(UISideBar.class); uiSideBar.setCurrentComp(uiSideBar.getChild(UISavedSearches.class).getId()); uiSideBar.setSelectedComp(event.getSource().getUIExtensionName()); event.getRequestContext().addUIComponentToUpdateByAjax(uiSideBar.getParent()); } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return null; } }
2,604
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
RelationActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/action/RelationActionComponent.java
/* * Copyright (C) 2003-2010 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar.action; import java.util.Arrays; import java.util.List; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotSystemWorkspaceFilter; import org.exoplatform.ecm.webui.component.explorer.sidebar.UISideBar; import org.exoplatform.ecm.webui.component.explorer.sidebar.UIViewRelationList; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; import org.exoplatform.webui.ext.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * ha.dangviet@exoplatform.com * Nov 22, 2010 */ @ComponentConfig(events = { @EventConfig(listeners = RelationActionComponent.RelationActionListener.class) }) public class RelationActionComponent extends UIAbstractManagerComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] {new IsNotSystemWorkspaceFilter()}); @UIExtensionFilters public static List<UIExtensionFilter> getFilters() { return FILTERS; } public static class RelationActionListener extends UISideBarActionListener<RelationActionComponent> { protected void processEvent(Event<RelationActionComponent> event) throws Exception { UISideBar uiSideBar = event.getSource().getAncestorOfType(UISideBar.class); uiSideBar.setCurrentComp(uiSideBar.getChild(UIViewRelationList.class).getId()); uiSideBar.setSelectedComp(event.getSource().getUIExtensionName()); event.getRequestContext().addUIComponentToUpdateByAjax(uiSideBar.getParent()); } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return null; } }
2,674
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
ClipboardActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/sidebar/action/ClipboardActionComponent.java
/* * Copyright (C) 2003-2010 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.sidebar.action; import java.util.Arrays; import java.util.List; import org.exoplatform.ecm.webui.component.explorer.sidebar.UIClipboard; import org.exoplatform.ecm.webui.component.explorer.sidebar.UISideBar; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; import org.exoplatform.webui.ext.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * ha.dangviet@exoplatform.com * Nov 22, 2010 */ @ComponentConfig( events = { @EventConfig( listeners = ClipboardActionComponent.ClipboardActionListener.class) }) public class ClipboardActionComponent extends UIAbstractManagerComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] {}); @UIExtensionFilters public static List<UIExtensionFilter> getFilters() { return FILTERS; } public static class ClipboardActionListener extends UISideBarActionListener<ClipboardActionComponent> { @Override protected void processEvent(Event<ClipboardActionComponent> event) throws Exception { UISideBar uiSideBar = event.getSource().getAncestorOfType(UISideBar.class); uiSideBar.setCurrentComp(uiSideBar.getChild(UIClipboard.class).getId()); uiSideBar.setSelectedComp(event.getSource().getUIExtensionName()); event.getRequestContext().addUIComponentToUpdateByAjax(uiSideBar.getParent()); } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return null; } }
2,625
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIViewSearchResult.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UIViewSearchResult.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.search; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.Value; import javax.jcr.ValueFormatException; import javax.portlet.PortletRequest; import org.exoplatform.container.ExoContainer; import org.exoplatform.container.ExoContainerContext; import org.exoplatform.container.xml.PortalContainerInfo; import org.exoplatform.download.DownloadService; import org.exoplatform.download.InputStreamDownloadResource; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.presentation.AbstractActionComponent; import org.exoplatform.ecm.webui.presentation.UIBaseNodePresentation; import org.exoplatform.ecm.webui.presentation.removeattach.RemoveAttachmentComponent; import org.exoplatform.ecm.webui.presentation.removecomment.RemoveCommentComponent; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.resolver.ResourceResolver; import org.exoplatform.services.cms.comments.CommentsService; import org.exoplatform.services.cms.i18n.MultiLanguageService; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.cms.views.ManageViewService; import org.exoplatform.services.jcr.core.ManageableRepository; import org.exoplatform.services.jcr.ext.common.SessionProvider; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.wcm.core.NodeLocation; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.Parameter; import org.exoplatform.web.application.RequireJS; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.application.portlet.PortletRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.ext.UIExtensionManager; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Apr 6, 2007 4:21:18 PM */ @ComponentConfig( events = { @EventConfig(listeners = UIViewSearchResult.ChangeLanguageActionListener.class), @EventConfig(listeners = UIViewSearchResult.DownloadActionListener.class), @EventConfig(listeners = UIViewSearchResult.ChangeNodeActionListener.class) } ) public class UIViewSearchResult extends UIBaseNodePresentation { private NodeLocation node_ ; private String language_ ; final private static String COMMENT_COMPONENT = "Comment"; /** * Logger. */ private static final Log LOG = ExoLogger.getLogger(UIViewSearchResult.class.getName()); public UIViewSearchResult() throws Exception { } public String getTemplate() { TemplateService templateService = getApplicationComponent(TemplateService.class) ; String userName = Util.getPortalRequestContext().getRemoteUser() ; try { String nodeType = getOriginalNode().getPrimaryNodeType().getName() ; return templateService.getTemplatePathByUser(false, nodeType, userName) ; } catch(Exception e) { if (LOG.isErrorEnabled()) { LOG.error(e); } } return null; } public List<Node> getAttachments() throws Exception { List<Node> attachments = new ArrayList<Node>() ; Node originalNode = getOriginalNode(); NodeIterator childrenIterator = originalNode.getNodes();; TemplateService templateService = getApplicationComponent(TemplateService.class) ; int attachData = 0 ; while(childrenIterator.hasNext()) { Node childNode = childrenIterator.nextNode(); String nodeType = childNode.getPrimaryNodeType().getName(); List<String> listCanCreateNodeType = Utils.getListAllowedFileType(originalNode, templateService) ; if(listCanCreateNodeType.contains(nodeType)) { // Case of childNode has jcr:data property if (childNode.hasProperty(Utils.JCR_DATA)) { attachData = childNode.getProperty(Utils.JCR_DATA).getStream().available(); // Case of jcr:data has content. if (attachData > 0) attachments.add(childNode); } else { attachments.add(childNode); } } } return attachments; } public String getViewableLink(Node attNode, Parameter[] params) throws Exception { return this.event("ChangeNode", Utils.formatNodeName(attNode.getPath()), params); } public UIComponent getRemoveAttach() throws Exception { removeChild(RemoveAttachmentComponent.class); UIComponent uicomponent = addChild(RemoveAttachmentComponent.class, null, "UIViewSearchResultRemoveAttach"); ((AbstractActionComponent)uicomponent).setLstComponentupdate(Arrays.asList(new Class[] {UIPopupWindow.class})); return uicomponent; } public UIComponent getRemoveComment() throws Exception { removeChild(RemoveCommentComponent.class); UIComponent uicomponent = addChild(RemoveCommentComponent.class, null, "UIViewSearchResultRemoveComment"); ((AbstractActionComponent)uicomponent).setLstComponentupdate(Arrays.asList(new Class[] {UIPopupWindow.class})); return uicomponent; } public Node getNode() throws ValueFormatException, PathNotFoundException, RepositoryException { Node originalNode = getOriginalNode(); if(originalNode.hasProperty(Utils.EXO_LANGUAGE)) { String defaultLang = originalNode.getProperty(Utils.EXO_LANGUAGE).getString() ; if(language_ == null) language_ = defaultLang ; if(originalNode.hasNode(Utils.LANGUAGES)) { if(!language_.equals(defaultLang)) { Node curNode = originalNode.getNode(Utils.LANGUAGES + Utils.SLASH + language_) ; return curNode ; } } return originalNode ; } return originalNode ; } public Node getOriginalNode(){ return NodeLocation.getNodeByLocation(node_); } public String getIcons(Node node, String size) throws Exception { return Utils.getNodeTypeIcon(node, size) ; } public String getNodeType() throws Exception { return null; } public List<Node> getRelations() throws Exception { List<Node> relations = new ArrayList<Node>() ; Node originalNode = getOriginalNode(); if (originalNode.hasProperty(Utils.EXO_RELATION)) { Value[] vals = originalNode.getProperty(Utils.EXO_RELATION).getValues(); for (int i = 0; i < vals.length; i++) { String uuid = vals[i].getString(); Node node = getNodeByUUID(uuid); relations.add(node); } } return relations; } public boolean isRssLink() { return false ; } public String getRssLink() { return null ; } public List<String> getSupportedLocalise() throws Exception { MultiLanguageService multiLanguageService = getApplicationComponent(MultiLanguageService.class) ; return multiLanguageService.getSupportedLanguages(getOriginalNode()) ; } public String getTemplatePath() throws Exception { return null; } public boolean isNodeTypeSupported() { return false; } public boolean isNodeTypeSupported(String nodeTypeName) { try { TemplateService templateService = getApplicationComponent(TemplateService.class); return templateService.isManagedNodeType(nodeTypeName); } catch (Exception e) { return false; } } public UIComponent getCommentComponent() { UIComponent uicomponent = null; try { UIExtensionManager manager = getApplicationComponent(UIExtensionManager.class); Map<String, Object> context = new HashMap<String, Object>(); UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); context.put(UIJCRExplorer.class.getName(), uiExplorer); context.put(Node.class.getName(), node_); uicomponent = manager.addUIExtension(ManageViewService.EXTENSION_TYPE, COMMENT_COMPONENT, context, this); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("An error occurs while checking the action", e); } } return (uicomponent != null ? uicomponent : this); } public boolean hasPropertyContent(Node node, String property) { try { String value = node.getProperty(property).getString() ; if(value.length() > 0) return true ; } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error(e); } } return false ; } public void setNode(Node node) { node_ = NodeLocation.getNodeLocationByNode(node); } public Node getNodeByUUID(String uuid) { ManageableRepository manageRepo = WCMCoreUtils.getRepository(); String[] workspaces = manageRepo.getWorkspaceNames() ; SessionProvider sessionProvider = WCMCoreUtils.getUserSessionProvider(); for(String ws : workspaces) { try{ return sessionProvider.getSession(ws,manageRepo).getNodeByUUID(uuid); }catch(Exception e) { // Do nothing } } return null; } public ResourceResolver getTemplateResourceResolver(WebuiRequestContext context, String template) { return getAncestorOfType(UIJCRExplorer.class).getJCRTemplateResourceResolver() ; } public List<Node> getComments() throws Exception { return getApplicationComponent(CommentsService.class).getComments(getOriginalNode(), language_) ; } public String getViewTemplate(String nodeTypeName, String templateName) throws Exception { TemplateService tempServ = getApplicationComponent(TemplateService.class) ; return tempServ.getTemplatePath(false, nodeTypeName, templateName) ; } public String getLanguage() { return language_; } public void setLanguage(String language) { language_ = language ; } @SuppressWarnings("unchecked") public Object getComponentInstanceOfType(String className) { Object service = null; try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class clazz = loader.loadClass(className); service = getApplicationComponent(clazz); } catch (ClassNotFoundException ex) { if (LOG.isErrorEnabled()) { LOG.error(ex); } } return service; } public String getImage(Node node) throws Exception { DownloadService downloadService = getApplicationComponent(DownloadService.class) ; InputStreamDownloadResource inputResource ; Node imageNode = node.getNode(Utils.EXO_IMAGE) ; InputStream input = imageNode.getProperty(Utils.JCR_DATA).getStream() ; inputResource = new InputStreamDownloadResource(input, "image") ; inputResource.setDownloadName(node.getName()) ; return downloadService.getDownloadLink(downloadService.addDownloadResource(inputResource)) ; } public String getImage(Node node, String nodeTypeName) throws Exception { DownloadService dservice = getApplicationComponent(DownloadService.class) ; InputStreamDownloadResource dresource ; Node imageNode = node.getNode(nodeTypeName) ; InputStream input = imageNode.getProperty(Utils.JCR_DATA).getStream() ; dresource = new InputStreamDownloadResource(input, "image") ; dresource.setDownloadName(node.getName()) ; return dservice.getDownloadLink(dservice.addDownloadResource(dresource)) ; } public String getPortalName() { ExoContainer container = ExoContainerContext.getCurrentContainer(); PortalContainerInfo containerInfo = (PortalContainerInfo)container.getComponentInstanceOfType(PortalContainerInfo.class); return containerInfo.getContainerName(); } public String getRepository() throws Exception { return ((ManageableRepository)getOriginalNode().getSession().getRepository()).getConfiguration().getName() ; } public String getWebDAVServerPrefix() throws Exception { PortletRequestContext pRequestContext = PortletRequestContext.getCurrentInstance() ; PortletRequest pRequest = pRequestContext.getRequest() ; String prefixWebDAV = pRequest.getScheme() + "://" + pRequest.getServerName() + ":" + String.format("%s",pRequest.getServerPort()) ; return prefixWebDAV ; } public String getWorkspaceName() throws Exception { return getOriginalNode().getSession().getWorkspace().getName() ; } static public class ChangeLanguageActionListener extends EventListener<UIViewSearchResult> { public void execute(Event<UIViewSearchResult> event) throws Exception { UIViewSearchResult uiViewSearchResult = event.getSource() ; String selectedLanguage = event.getRequestContext().getRequestParameter(OBJECTID) ; uiViewSearchResult.setLanguage(selectedLanguage) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiViewSearchResult.getParent()) ; } } public String getDownloadLink(Node node) throws Exception { return org.exoplatform.wcm.webui.Utils.getDownloadLink(node); } public String encodeHTML(String text) throws Exception { return Utils.encodeHTML(text) ; } public String getTemplateSkin(String nodeTypeName, String skinName) throws Exception { TemplateService tempServ = getApplicationComponent(TemplateService.class) ; return tempServ.getSkinPath(nodeTypeName, skinName, getLanguage()) ; } public UIComponent getUIComponent(String mimeType) throws Exception { return Utils.getUIComponent(mimeType, this); } static public class DownloadActionListener extends EventListener<UIViewSearchResult> { public void execute(Event<UIViewSearchResult> event) throws Exception { UIViewSearchResult uiComp = event.getSource() ; String downloadLink = uiComp.getDownloadLink(org.exoplatform.wcm.webui.Utils.getFileLangNode(uiComp.getNode())); RequireJS requireJS = event.getRequestContext().getJavascriptManager().getRequireJS(); requireJS.require("SHARED/ecm-utils", "ecmutil").addScripts("ecmutil.ECMUtils.ajaxRedirect('" + downloadLink + "');"); event.getRequestContext().addUIComponentToUpdateByAjax(uiComp.getParent()) ; } } static public class ChangeNodeActionListener extends EventListener<UIViewSearchResult> { public void execute(Event<UIViewSearchResult> event) throws Exception { UIViewSearchResult uicomp = event.getSource() ; UIJCRExplorer uiExplorer = uicomp.getAncestorOfType(UIJCRExplorer.class) ; String uri = event.getRequestContext().getRequestParameter(OBJECTID) ; String workspaceName = event.getRequestContext().getRequestParameter("workspaceName") ; Session session = uiExplorer.getSessionByWorkspace(workspaceName) ; Node selectedNode = (Node) session.getItem(uri) ; uicomp.setNode(selectedNode) ; event.getRequestContext().addUIComponentToUpdateByAjax(uicomp.getParent()) ; } } public boolean isEnableComment() { return false; } public boolean isEnableVote() { return false; } public void setEnableComment(boolean value) { } public void setEnableVote(boolean value) { } public String getInlineEditingField(Node orgNode, String propertyName, String defaultValue, String inputType, String idGenerator, String cssClass, boolean isGenericProperty, String... arguments) throws Exception { if (orgNode.hasProperty(propertyName)) { return orgNode.getProperty(propertyName).getString(); } return defaultValue; } public String getInlineEditingField(Node orgNode, String propertyName) throws Exception { if (orgNode.hasProperty(propertyName)) { return orgNode.getProperty(propertyName).getString(); } return ""; } }
17,057
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UISelectPropertyForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UISelectPropertyForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.search; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.Session; import javax.jcr.nodetype.NodeType; import javax.jcr.nodetype.NodeTypeManager; import javax.jcr.nodetype.PropertyDefinition; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.services.cms.BasePath; import org.exoplatform.services.cms.impl.DMSConfiguration; import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormRadioBoxInput; import org.exoplatform.webui.form.UIFormSelectBox; /** * Created by The eXo Platform SARL * Author : Tran The Trong * trong.tran@exoplatform.com * May 6, 2007 * 10:18:56 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(phase=Phase.DECODE, listeners = UISelectPropertyForm.CancelActionListener.class), @EventConfig(listeners = UISelectPropertyForm.AddActionListener.class), @EventConfig(listeners = UISelectPropertyForm.ChangeMetadataTypeActionListener.class) } ) public class UISelectPropertyForm extends UIForm implements UIPopupComponent { private static final Log LOG = ExoLogger.getLogger(UISelectPropertyForm.class.getName()); final static public String METADATA_TYPE= "metadataType" ; final static public String PROPERTY = "property" ; private String fieldName_ = null ; private List<SelectItemOption<String>> properties_ = new ArrayList<SelectItemOption<String>>() ; public UISelectPropertyForm() throws Exception { setActions(new String[] {"Add", "Cancel"}) ; } public String getLabel(ResourceBundle res, String id) { try { return super.getLabel(res, id) ; } catch (Exception ex) { return id ; } } public void activate() { try { List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>() ; NodeHierarchyCreator nodeHierarchyCreator = getApplicationComponent(NodeHierarchyCreator.class) ; UIFormSelectBox uiSelect = new UIFormSelectBox(METADATA_TYPE, METADATA_TYPE, options) ; uiSelect.setOnChange("ChangeMetadataType") ; addUIFormInput(uiSelect) ; String metadataPath = nodeHierarchyCreator.getJcrPath(BasePath.METADATA_PATH) ; UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ; DMSConfiguration dmsConfiguration = getApplicationComponent(DMSConfiguration.class); String workspaceName = dmsConfiguration.getConfig().getSystemWorkspace(); Session session = uiExplorer.getSystemProvider().getSession(workspaceName, uiExplorer.getRepository()); Node homeNode = (Node) session.getItem(metadataPath) ; NodeIterator nodeIter = homeNode.getNodes() ; Node meta = nodeIter.nextNode() ; renderProperties(meta.getName()) ; options.add(new SelectItemOption<String>(meta.getName(), meta.getName())) ; while(nodeIter.hasNext()) { meta = nodeIter.nextNode() ; options.add(new SelectItemOption<String>(meta.getName(), meta.getName())) ; } addUIFormInput(new UIFormRadioBoxInput(PROPERTY, null, properties_). setAlign(UIFormRadioBoxInput.VERTICAL_ALIGN)) ; } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } public void deActivate() {} public void setFieldName(String fieldName) { fieldName_ = fieldName ; } public void renderProperties(String metadata) throws Exception { properties_.clear() ; UIJCRExplorer uiExpolrer = getAncestorOfType(UIJCRExplorer.class) ; NodeTypeManager ntManager = uiExpolrer.getSession().getWorkspace().getNodeTypeManager() ; NodeType nt = ntManager.getNodeType(metadata) ; PropertyDefinition[] properties = nt.getPropertyDefinitions() ; for(PropertyDefinition property : properties) { String name = property.getName() ; if(!name.equals("exo:internalUse")) properties_.add(new SelectItemOption<String>(name, name)) ; } } static public class CancelActionListener extends EventListener<UISelectPropertyForm> { public void execute(Event<UISelectPropertyForm> event) throws Exception { UISearchContainer uiSearchContainer = event.getSource().getAncestorOfType(UISearchContainer.class) ; UIPopupContainer uiPopup = uiSearchContainer.getChild(UIPopupContainer.class) ; uiPopup.deActivate() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiPopup) ; } } static public class AddActionListener extends EventListener<UISelectPropertyForm> { public void execute(Event<UISelectPropertyForm> event) throws Exception { UISelectPropertyForm uiForm = event.getSource() ; String property = uiForm.<UIFormRadioBoxInput>getUIInput(PROPERTY).getValue(); UIPopupContainer UIPopupContainer = uiForm.getAncestorOfType(UIPopupContainer.class); UISearchContainer uiSearchContainer = UIPopupContainer.getParent() ; UIConstraintsForm uiConstraintsForm = uiSearchContainer.findFirstComponentOfType(UIConstraintsForm.class) ; /* Set value for textbox */ uiConstraintsForm.getUIStringInput(uiForm.fieldName_).setValue(property) ; /* Set value of checkbox is checked when choose value of property */ if (uiForm.fieldName_.equals(UIConstraintsForm.PROPERTY1)) { uiConstraintsForm.getUICheckBoxInput(UIConstraintsForm.EXACTLY_PROPERTY).setChecked(true); } else if (uiForm.fieldName_.equals(UIConstraintsForm.PROPERTY2)) { uiConstraintsForm.getUICheckBoxInput(UIConstraintsForm.CONTAIN_PROPERTY).setChecked(true); } else if (uiForm.fieldName_.equals(UIConstraintsForm.PROPERTY3)) { uiConstraintsForm.getUICheckBoxInput(UIConstraintsForm.NOT_CONTAIN_PROPERTY).setChecked(true); } UIPopupContainer.deActivate() ; event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiConstraintsForm) ; } } static public class ChangeMetadataTypeActionListener extends EventListener<UISelectPropertyForm> { public void execute(Event<UISelectPropertyForm> event) throws Exception { UISelectPropertyForm uiForm = event.getSource() ; uiForm.renderProperties(uiForm.getUIFormSelectBox(METADATA_TYPE).getValue()) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm) ; } } }
8,045
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIContentNameSearch.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UIContentNameSearch.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.search; import javax.jcr.RepositoryException; import javax.jcr.query.Query; import org.apache.commons.lang3.StringUtils; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.services.security.IdentityConstants; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormInputInfo; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.validator.MandatoryValidator; /** * Created by The eXo Platform SAS * Author : Hoa Pham * hoa.pham@exoplatform.com * Oct 2, 2007 */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UIContentNameSearch.SearchActionListener.class), @EventConfig(listeners = UIContentNameSearch.CancelActionListener.class, phase=Phase.DECODE) } ) public class UIContentNameSearch extends UIForm { private static String KEYWORD = "keyword"; private static String SEARCH_LOCATION = "location"; private static final String ROOT_PATH_SQL_QUERY = "select * from nt:base where " + "contains(exo:name, '$1') or contains(exo:title, '$1') or " + "lower(exo:name) like '%$2%' order by exo:title ASC"; private static final String PATH_SQL_QUERY = "select * from nt:base where jcr:path like '$0/%' AND " + "( contains(exo:name, '$1') or contains(exo:title, '$1') or " + "lower(exo:name) like '%$2%') order by exo:title ASC"; public UIContentNameSearch() throws Exception { addChild(new UIFormInputInfo(SEARCH_LOCATION,null,null)); addChild(new UIFormStringInput(KEYWORD,null).addValidator(MandatoryValidator.class)); } public void setLocation(String location) { getUIFormInputInfo(SEARCH_LOCATION).setValue(location); } static public class SearchActionListener extends EventListener<UIContentNameSearch> { public void execute(Event<UIContentNameSearch> event) throws Exception { UIContentNameSearch contentNameSearch = event.getSource(); UIECMSearch uiECMSearch = contentNameSearch.getAncestorOfType(UIECMSearch.class); UISearchResult uiSearchResult = uiECMSearch.getChild(UISearchResult.class); UIApplication application = contentNameSearch.getAncestorOfType(UIApplication.class); try { String keyword = contentNameSearch.getUIStringInput(KEYWORD).getValue(); keyword = keyword.trim(); String escapedText = org.exoplatform.services.cms.impl.Utils.escapeIllegalCharacterInQuery(keyword); UIJCRExplorer explorer = contentNameSearch.getAncestorOfType(UIJCRExplorer.class); String currentNodePath = explorer.getCurrentNode().getPath(); String statement = null; if("/".equalsIgnoreCase(currentNodePath)) { statement = StringUtils.replace(ROOT_PATH_SQL_QUERY,"$1",escapedText); statement = StringUtils.replace(statement,"$2",escapedText.toLowerCase()); }else { statement = StringUtils.replace(PATH_SQL_QUERY,"$0",currentNodePath); statement = StringUtils.replace(statement,"$1",escapedText); statement = StringUtils.replace(statement,"$2",escapedText.toLowerCase()); } long startTime = System.currentTimeMillis(); uiSearchResult.setQuery(statement, explorer.getTargetSession().getWorkspace().getName(), Query.SQL, IdentityConstants.SYSTEM.equals(explorer.getTargetSession()), null); uiSearchResult.updateGrid(); long time = System.currentTimeMillis() - startTime; uiSearchResult.setSearchTime(time); contentNameSearch.getUIFormInputInfo(SEARCH_LOCATION).setValue(currentNodePath); uiECMSearch.setSelectedTab(uiSearchResult.getId()); } catch (RepositoryException reEx) { application.addMessage(new ApplicationMessage("UIContentNameSearch.msg.keyword-not-allowed", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(contentNameSearch); return; } catch (Exception e) { uiSearchResult.setQuery(null, null, null, false, null); uiSearchResult.updateGrid(); } } } static public class CancelActionListener extends EventListener<UIContentNameSearch> { public void execute(Event<UIContentNameSearch> event) throws Exception { event.getSource().getAncestorOfType(UIJCRExplorer.class).cancelAction(); } } }
6,097
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINodeTypeSelectForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UINodeTypeSelectForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.search; import java.util.ArrayList; import java.util.List; import java.util.MissingResourceException; import java.util.ResourceBundle; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.input.UICheckBoxInput; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * May 11, 2007 4:21:57 PM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UINodeTypeSelectForm.SaveActionListener.class), @EventConfig(listeners = UINodeTypeSelectForm.CancelActionListener.class, phase=Phase.DECODE) } ) public class UINodeTypeSelectForm extends UIForm implements UIPopupComponent { public UINodeTypeSelectForm() throws Exception { } public String getLabel(ResourceBundle res, String id) { try { return res.getString("UINodeTypeSelectForm.label." + id) ; } catch (MissingResourceException ex) { return id + " "; // Need for changed in gatein !fieldName.equals(field.getName()) } } public void setRenderNodeTypes() throws Exception { getChildren().clear() ; UICheckBoxInput uiCheckBox ; TemplateService templateService = getApplicationComponent(TemplateService.class) ; List<String> templates = templateService.getDocumentTemplates() ; for(String template : templates) { uiCheckBox = new UICheckBoxInput(template, template, null); if(propertiesSelected(template)) uiCheckBox.setChecked(true) ; else uiCheckBox.setChecked(false) ; addUIFormInput(uiCheckBox) ; } } private boolean propertiesSelected(String name) { UISearchContainer uiSearchContainer = getAncestorOfType(UISearchContainer.class) ; UIConstraintsForm uiConstraintsForm = uiSearchContainer.findFirstComponentOfType(UIConstraintsForm.class) ; String typeValues = uiConstraintsForm.getUIStringInput(UIConstraintsForm.DOC_TYPE).getValue() ; if(typeValues == null) return false ; if(typeValues.indexOf(",") > -1) { String[] values = typeValues.split(",") ; for(String value : values) { if(value.equals(name)) return true ; } } else if(typeValues.equals(name)) { return true ; } return false ; } public void setNodeTypes(List<String> selectedNodeTypes) { StringBuffer strNodeTypes = null; UISearchContainer uiContainer = getAncestorOfType(UISearchContainer.class); UIConstraintsForm uiConstraintsForm = uiContainer.findFirstComponentOfType(UIConstraintsForm.class); for (int i = 0; i < selectedNodeTypes.size(); i++) { if (strNodeTypes == null) { strNodeTypes = new StringBuffer(selectedNodeTypes.get(i)); } else { strNodeTypes.append(",").append(selectedNodeTypes.get(i)); } } uiConstraintsForm.getUIStringInput(UIConstraintsForm.DOC_TYPE) .setValue(strNodeTypes.toString()); } public void activate() {} public void deActivate() {} static public class SaveActionListener extends EventListener<UINodeTypeSelectForm> { public void execute(Event<UINodeTypeSelectForm> event) throws Exception { UINodeTypeSelectForm uiForm = event.getSource() ; UISearchContainer uiSearchContainer = uiForm.getAncestorOfType(UISearchContainer.class) ; UIConstraintsForm uiConstraintsForm = uiSearchContainer.findFirstComponentOfType(UIConstraintsForm.class) ; List<String> selectedNodeTypes = new ArrayList<String>() ; List<UICheckBoxInput> listCheckbox = new ArrayList<UICheckBoxInput>(); uiForm.findComponentOfType(listCheckbox, UICheckBoxInput.class); String nodeTypesValue = uiConstraintsForm.getUIStringInput(UIConstraintsForm.DOC_TYPE).getValue() ; if(nodeTypesValue != null && nodeTypesValue.length() > 0) { String[] array = nodeTypesValue.split(",") ; for(int i = 0; i < array.length; i ++) { selectedNodeTypes.add(array[i].trim()) ; } } for(int i = 0; i < listCheckbox.size(); i ++) { if(listCheckbox.get(i).isChecked()) { if(!selectedNodeTypes.contains(listCheckbox.get(i).getName())) { selectedNodeTypes.add(listCheckbox.get(i).getName()) ; } } else if(selectedNodeTypes.contains(listCheckbox.get(i))) { selectedNodeTypes.remove(listCheckbox.get(i).getName()) ; } else { selectedNodeTypes.remove(listCheckbox.get(i).getName()) ; } } /* Set value for textbox */ uiForm.setNodeTypes(selectedNodeTypes) ; /* Set value of checkbox is checked */ uiConstraintsForm.getUICheckBoxInput(UIConstraintsForm.NODETYPE_PROPERTY).setChecked(true); UIPopupContainer uiPopup = uiSearchContainer.getChild(UIPopupContainer.class) ; uiPopup.deActivate() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiSearchContainer) ; } } static public class CancelActionListener extends EventListener<UINodeTypeSelectForm> { public void execute(Event<UINodeTypeSelectForm> event) throws Exception { UISearchContainer uiSearchContainer = event.getSource().getAncestorOfType(UISearchContainer.class) ; UIPopupContainer uiPopup = uiSearchContainer.getChild(UIPopupContainer.class) ; uiPopup.deActivate() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiSearchContainer) ; } } }
6,850
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UISaveQueryForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UISaveQueryForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.search; import javax.jcr.AccessDeniedException; import org.exoplatform.ecm.webui.form.validator.ECMNameValidator; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.cms.queries.QueryService; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.validator.MandatoryValidator; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jun 28, 2007 9:43:21 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UISaveQueryForm.SaveActionListener.class), @EventConfig(listeners = UISaveQueryForm.CancelActionListener.class, phase=Phase.DECODE) } ) public class UISaveQueryForm extends UIForm implements UIPopupComponent { final static public String QUERY_NAME = "queryName" ; private String statement_ ; private boolean isSimpleSearch_ = false ; private String queryType_ ; public UISaveQueryForm() throws Exception { addUIFormInput(new UIFormStringInput(QUERY_NAME, QUERY_NAME, null). addValidator(ECMNameValidator.class). addValidator(MandatoryValidator.class)) ; } public void activate() {} public void deActivate() {} public void setSimpleSearch(boolean isSimpleSearch) { isSimpleSearch_ = isSimpleSearch ; } public void setStatement(String statement) { statement_ = statement ; } public void setQueryType(String queryType) { queryType_ = queryType ; } static public class SaveActionListener extends EventListener<UISaveQueryForm> { public void execute(Event<UISaveQueryForm> event) throws Exception { UISaveQueryForm uiSaveQueryForm = event.getSource() ; UIECMSearch uiECMSearch = uiSaveQueryForm.getAncestorOfType(UIECMSearch.class) ; UIApplication uiApp = uiSaveQueryForm.getAncestorOfType(UIApplication.class) ; String userName = Util.getPortalRequestContext().getRemoteUser() ; QueryService queryService = uiSaveQueryForm.getApplicationComponent(QueryService.class) ; String queryName = uiSaveQueryForm.getUIStringInput(QUERY_NAME).getValue() ; if(queryName == null || queryName.trim().length() == 0) { uiApp.addMessage(new ApplicationMessage("UISaveQueryForm.msg.query-name-null", null)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiECMSearch); return ; } try { queryService.addQuery(queryName, uiSaveQueryForm.statement_, uiSaveQueryForm.queryType_, userName) ; } catch(AccessDeniedException ace) { uiApp.addMessage(new ApplicationMessage("UISaveQueryForm.msg.access-denied", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiECMSearch); return ; } catch (Exception e){ uiApp.addMessage(new ApplicationMessage("UISaveQueryForm.msg.save-failed", null, ApplicationMessage.WARNING)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiECMSearch); return ; } uiECMSearch.getChild(UISavedQuery.class).updateGrid(1); if(uiSaveQueryForm.isSimpleSearch_) { UISearchContainer uiSearchContainer = uiSaveQueryForm.getAncestorOfType(UISearchContainer.class) ; UIPopupContainer uiPopup = uiSearchContainer.getChild(UIPopupContainer.class) ; uiPopup.deActivate() ; } uiECMSearch.setSelectedTab(uiECMSearch.getChild(UISavedQuery.class).getId()) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiECMSearch) ; } } static public class CancelActionListener extends EventListener<UISaveQueryForm> { public void execute(Event<UISaveQueryForm> event) throws Exception { UISearchContainer uiSearchContainer = event.getSource().getAncestorOfType(UISearchContainer.class) ; UIPopupContainer uiPopup = uiSearchContainer.getChild(UIPopupContainer.class) ; uiPopup.deActivate() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiPopup) ; } } }
5,624
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIConstraintsForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UIConstraintsForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.search; import java.util.ArrayList; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.List; import java.util.ResourceBundle; import org.exoplatform.commons.utils.ISO8601; import org.exoplatform.ecm.jcr.model.Preference; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.web.application.RequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.form.UIFormDateTimeInput; import org.exoplatform.webui.form.UIFormSelectBox; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.input.UICheckBoxInput; import org.exoplatform.webui.form.validator.DateTimeValidator; @ComponentConfig( template = "app:/groovy/webui/component/explorer/search/UIConstraintsForm.gtmpl" ) public class UIConstraintsForm extends UIFormInputSetWithAction implements UISelectable{ final static public String OPERATOR = "operator" ; final static public String TIME_OPTION = "timeOpt" ; final static public String PROPERTY1 = "property1" ; final static public String PROPERTY2 = "property2" ; final static public String PROPERTY3 = "property3" ; final static public String CONTAIN_EXACTLY = "containExactly" ; final static public String CONTAIN = "contain" ; final static public String NOT_CONTAIN = "notContain" ; final static public String START_TIME = "startTime" ; final static public String END_TIME = "endTime" ; final static public String DOC_TYPE = "docType" ; final static public String CATEGORY_TYPE = "categoryType" ; final static public String AND_OPERATION = "and" ; final static public String OR_OPERATION = "or" ; final static public String CREATED_DATE = "CREATED" ; final static public String MODIFIED_DATE = "MODIFIED" ; final static public String EXACTLY_PROPERTY = "exactlyPro" ; final static public String CONTAIN_PROPERTY = "containPro" ; final static public String NOT_CONTAIN_PROPERTY = "notContainPro" ; final static public String DATE_PROPERTY = "datePro" ; final static public String NODETYPE_PROPERTY = "nodetypePro" ; final static public String CATEGORY_PROPERTY = "categoryPro" ; final static public String SPLIT_REGEX = "/|\\s+|:" ; final static public String DATETIME_REGEX = "^(\\d{1,2}\\/\\d{1,2}\\/\\d{1,4})\\s*(\\s+\\d{1,2}:\\d{1,2}:\\d{1,2})?$" ; private String virtualDateQuery_; private String _CREATED_DATE; private String _MODIFIED_DATE; private String _AND_OPERATION; private String _OR_OPERATION; public UIConstraintsForm(String name) throws Exception { super(name); RequestContext context = RequestContext.getCurrentInstance(); ResourceBundle res = context.getApplicationResourceBundle(); _AND_OPERATION = res.getString("UIConstraintForm.label.and"); _OR_OPERATION = res.getString("UIConstraintForm.label.or"); _CREATED_DATE = res.getString("UIConstraintForm.label.created"); _MODIFIED_DATE = res.getString("UIConstraintForm.label.modified"); setActions(new String[] {"Add", "Cancel"}, null) ; List<SelectItemOption<String>> typeOperation = new ArrayList<SelectItemOption<String>>() ; typeOperation.add(new SelectItemOption<String>(_AND_OPERATION, AND_OPERATION)); typeOperation.add(new SelectItemOption<String>(_OR_OPERATION, OR_OPERATION)); addUIFormInput(new UIFormSelectBox(OPERATOR, OPERATOR, typeOperation)) ; addUIFormInput(new UICheckBoxInput(EXACTLY_PROPERTY, EXACTLY_PROPERTY, null)) ; addUIFormInput(new UIFormStringInput(PROPERTY1, PROPERTY1, null)) ; addUIFormInput(new UIFormStringInput(CONTAIN_EXACTLY, CONTAIN_EXACTLY, null)) ; addUIFormInput(new UICheckBoxInput(CONTAIN_PROPERTY, CONTAIN_PROPERTY, null)) ; addUIFormInput(new UIFormStringInput(PROPERTY2, PROPERTY2, null)) ; addUIFormInput(new UIFormStringInput(CONTAIN, CONTAIN, null)) ; addUIFormInput(new UICheckBoxInput(NOT_CONTAIN_PROPERTY, NOT_CONTAIN_PROPERTY, null)) ; addUIFormInput(new UIFormStringInput(PROPERTY3, PROPERTY3, null)) ; addUIFormInput(new UIFormStringInput(NOT_CONTAIN, NOT_CONTAIN, null)) ; addUIFormInput(new UICheckBoxInput(DATE_PROPERTY, DATE_PROPERTY, null)) ; List<SelectItemOption<String>> dateOperation = new ArrayList<SelectItemOption<String>>() ; dateOperation.add(new SelectItemOption<String>(_CREATED_DATE, CREATED_DATE)); dateOperation.add(new SelectItemOption<String>(_MODIFIED_DATE, MODIFIED_DATE)); addUIFormInput(new UIFormSelectBox(TIME_OPTION, TIME_OPTION, dateOperation)) ; UIFormDateTimeInput uiFromDate = new UIFormDateTimeInput(START_TIME, START_TIME, null) ; uiFromDate.addValidator(DateTimeValidator.class); uiFromDate.setDisplayTime(true) ; addUIFormInput(uiFromDate) ; UIFormDateTimeInput uiToDate = new UIFormDateTimeInput(END_TIME, END_TIME, null) ; uiToDate.addValidator(DateTimeValidator.class); uiToDate.setDisplayTime(true) ; addUIFormInput(uiToDate) ; addUIFormInput(new UICheckBoxInput(NODETYPE_PROPERTY, NODETYPE_PROPERTY, null)) ; addUIFormInput(new UIFormStringInput(DOC_TYPE, DOC_TYPE, null)) ; addUIFormInput(new UICheckBoxInput(CATEGORY_PROPERTY, CATEGORY_PROPERTY, null)) ; addUIFormInput(new UIFormStringInput(CATEGORY_TYPE, CATEGORY_TYPE, null)) ; } private String getContainQueryString(String property, String type, boolean isContain) { String value = getUIStringInput(type).getValue() ; if(value == null) return "" ; if(value.trim().length() > 0) { if(isContain) return " jcr:contains(@" + property.trim() + ", '"+ value.trim() + "')" ; return " fn:not(jcr:contains(@" + property.trim() + ", '"+ value.trim() + "'))" ; } return "" ; } private String getContainSQLQueryString(String property, String type, boolean isContain) { String value = getUIStringInput(type).getValue(); if(value == null) return ""; if(value.trim().length() > 0) { if(isContain) return " CONTAINS(" + property.trim() + ", '"+ value.trim() + "')"; return " NOT CONTAINS(" + property.trim() + ", '"+ value.trim() + "')"; } return ""; } private String getDateTimeQueryString(String beforeDate, String afterDate, String type) { Calendar bfDate = getUIFormDateTimeInput(START_TIME).getCalendar() ; if(bfDate==null) return ""; if (afterDate != null && afterDate.trim().length() > 0) { Calendar afDate = getUIFormDateTimeInput(END_TIME).getCalendar(); if (type.equals(CREATED_DATE)) { virtualDateQuery_ = "(documents created from '" + beforeDate + "') and (documents created to '" + afterDate + "')"; return "@exo:dateCreated >= xs:dateTime('" + ISO8601.format(bfDate) + "') and @exo:dateCreated <= xs:dateTime('" + ISO8601.format(afDate) + "')"; } else if (type.equals(MODIFIED_DATE)) { virtualDateQuery_ = "(documents modified from '" + beforeDate + "') and (documents modified to '" + afterDate + "')"; return "@exo:dateModified >= xs:dateTime('" + ISO8601.format(bfDate) + "') and @exo:dateModified <= xs:dateTime('" + ISO8601.format(afDate) + "')"; } } else { if(type.equals(CREATED_DATE)) { virtualDateQuery_ = "(documents created from '"+beforeDate+"')" ; return "@exo:dateCreated >= xs:dateTime('"+ISO8601.format(bfDate)+"')" ; } else if(type.equals(MODIFIED_DATE)) { virtualDateQuery_ = "(documents modified from '"+beforeDate+"')" ; return "@exo:dateModified >= xs:dateTime('"+ISO8601.format(bfDate)+"')" ; } } return "" ; } private String getDateTimeSQLQueryString(String beforeDate, String afterDate, String type) { Calendar bfDate = getUIFormDateTimeInput(START_TIME).getCalendar(); if(bfDate==null) return ""; if (afterDate != null && afterDate.trim().length() > 0) { Calendar afDate = getUIFormDateTimeInput(END_TIME).getCalendar(); if (type.equals(CREATED_DATE)) { virtualDateQuery_ = "(documents created from '" + beforeDate + "') and (documents created to '" + afterDate + "')"; return "exo:dateCreated >= TIMESTAMP '" + ISO8601.format(bfDate) + "' and exo:dateCreated <= TIMESTAMP '" + ISO8601.format(afDate) + "'"; } else if (type.equals(MODIFIED_DATE)) { virtualDateQuery_ = "(documents modified from '" + beforeDate + "') and (documents modified to '" + afterDate + "')"; return "exo:dateModified >= TIMESTAMP '" + ISO8601.format(bfDate) + "' and exo:dateModified <= TIMESTAMP '" + ISO8601.format(afDate) + "'"; } } else { if(type.equals(CREATED_DATE)) { virtualDateQuery_ = "(documents created from '"+beforeDate+"')"; return "exo:dateCreated >= TIMESTAMP '"+ISO8601.format(bfDate)+"'"; } else if(type.equals(MODIFIED_DATE)) { virtualDateQuery_ = "(documents modified from '"+beforeDate+"')"; return "exo:dateModified >= TIMESTAMP '"+ISO8601.format(bfDate)+"'"; } } return "" ; } private String getNodeTypeQueryString(String nodeTypes) { StringBuffer advanceQuery = new StringBuffer(); String[] arrNodeTypes = {}; if (nodeTypes.indexOf(",") > -1) arrNodeTypes = nodeTypes.split(","); if (arrNodeTypes.length > 0) { for (String nodeType : arrNodeTypes) { if (advanceQuery.length() == 0) advanceQuery.append("@jcr:primaryType = '").append(nodeType).append("'"); else advanceQuery.append(" ") .append(OR_OPERATION) .append(" ") .append("@jcr:primaryType = '") .append(nodeType) .append("'"); } } else { advanceQuery.append("@jcr:primaryType = '").append(nodeTypes).append("'"); } return advanceQuery.toString(); } private String getNodeTypeSQLQueryString(String nodeTypes) { StringBuffer advanceQuery = new StringBuffer(); String[] arrNodeTypes = {}; if (nodeTypes.indexOf(",") > -1) arrNodeTypes = nodeTypes.split(","); if (arrNodeTypes.length > 0) { for (String nodeType : arrNodeTypes) { if (advanceQuery.length() == 0) advanceQuery.append("jcr:primaryType = '").append(nodeType).append("'"); else advanceQuery.append(" ") .append(OR_OPERATION) .append(" ") .append("jcr:primaryType = '") .append(nodeType) .append("'"); } } else { advanceQuery.append("jcr:primaryType = '").append(nodeTypes).append("'"); } return advanceQuery.toString(); } /** * Create query string for category * @param categoryPath * @return */ private String getCategoryQueryString(String categoryPath) { if (categoryPath == null || categoryPath.length() == 0) return ""; return ("@exo:category = '" + categoryPath + "'"); } private String getCategorySQLQueryString(String categoryPath) { if (categoryPath == null || categoryPath.length() == 0) return ""; return ("exo:category = '" + categoryPath + "'"); } void addConstraint(int opt) throws Exception { String advanceQuery = "" ; String property ; virtualDateQuery_ = null ; UISimpleSearch uiSimpleSearch = this.getParent(); UIJCRExplorer uiExplorer = uiSimpleSearch.getAncestorOfType(UIJCRExplorer.class); Preference pref = uiExplorer.getPreference(); String queryType = pref.getQueryType(); switch (opt) { case 0: property = getUIStringInput(PROPERTY1).getValue() ; String value = getUIStringInput(CONTAIN_EXACTLY).getValue() ; if (queryType.equals(Preference.XPATH_QUERY)) advanceQuery = "@" + property + " = '" + value.trim() + "'" ; else advanceQuery = " CONTAINS(" + property + ", '" + value.trim() + "')" ; break; case 1: property = getUIStringInput(PROPERTY2).getValue() ; if (queryType.equals(Preference.XPATH_QUERY)) advanceQuery = getContainQueryString(property, CONTAIN, true); else advanceQuery = getContainSQLQueryString(property, CONTAIN, true); break; case 2: property = getUIStringInput(PROPERTY3).getValue(); if (queryType.equals(Preference.XPATH_QUERY)) advanceQuery = getContainQueryString(property, NOT_CONTAIN, false); else advanceQuery = getContainSQLQueryString(property, NOT_CONTAIN, false); break; case 3: String fromDate = getUIFormDateTimeInput(START_TIME).getValue() ; String toDate = getUIFormDateTimeInput(END_TIME).getValue() ; String type = getUIFormSelectBox(TIME_OPTION).getValue() ; if (queryType.equals(Preference.XPATH_QUERY)) advanceQuery = getDateTimeQueryString(fromDate, toDate, type); else advanceQuery = getDateTimeSQLQueryString(fromDate, toDate, type); break ; case 4: property = getUIStringInput(DOC_TYPE).getValue(); if (queryType.equals(Preference.XPATH_QUERY)) advanceQuery = getNodeTypeQueryString(property); else advanceQuery = getNodeTypeSQLQueryString(property); break; case 5: property = getUIStringInput(CATEGORY_TYPE).getValue(); if (queryType.equals(Preference.XPATH_QUERY)) advanceQuery = getCategoryQueryString(property); else advanceQuery = getCategorySQLQueryString(property); String firstOperator = uiSimpleSearch.getUIStringInput(UISimpleSearch.FIRST_OPERATOR).getValue(); if (!uiSimpleSearch.getCategoryPathList().contains(property) && firstOperator.equals("and")) uiSimpleSearch.getCategoryPathList().add(property); break; default: break; } uiSimpleSearch.updateAdvanceConstraint(advanceQuery, getUIFormSelectBox(OPERATOR).getValue(), virtualDateQuery_); } void resetConstraintForm() { reset(); getUICheckBoxInput(EXACTLY_PROPERTY).setChecked(false); getUICheckBoxInput(CONTAIN_PROPERTY).setChecked(false); getUICheckBoxInput(NOT_CONTAIN_PROPERTY).setChecked(false); getUICheckBoxInput(DATE_PROPERTY).setChecked(false); getUICheckBoxInput(NODETYPE_PROPERTY).setChecked(false); getUICheckBoxInput(CATEGORY_PROPERTY).setChecked(false); } boolean isValidDateTime(String dateTime) { String[] arr = dateTime.split(SPLIT_REGEX, 7) ; int valid = Integer.parseInt(arr[0]) ; if(valid < 1 || valid > 12) return false; Calendar date = new GregorianCalendar(Integer.parseInt(arr[2]), valid - 1, 1) ; if(Integer.parseInt(arr[1]) > date.getActualMaximum(Calendar.DAY_OF_MONTH)) return false; if (arr.length > 3 && (Integer.parseInt(arr[3]) > 23 || Integer.parseInt(arr[4]) > 59 || Integer.parseInt(arr[5]) > 59)) return false; return true; } /** * Set category to text box and closeof choose category popup window * @param selectField: name of text field input * @param value: value of chosen category * @throws Exception */ public void doSelect(String selectField, Object value) throws Exception { /* Set value to textbox */ if (value==null) { getUIStringInput(selectField).setValue(""); getUICheckBoxInput(UIConstraintsForm.CATEGORY_PROPERTY).setChecked(false); }else { getUIStringInput(selectField).setValue(value.toString()); /* Set value for checkBox is checked */ getUICheckBoxInput(UIConstraintsForm.CATEGORY_PROPERTY).setChecked(true); } UISearchContainer uiSearchContainer = getAncestorOfType(UISearchContainer.class); /* * Close popup window when finish choose category */ UIPopupWindow uiPopup = uiSearchContainer.findComponentById(UISearchContainer.CATEGORY_POPUP); uiPopup.setRendered(false); uiPopup.setShow(false); } public UIFormDateTimeInput getUIFormDateTimeInput(String name) { return findComponentById(name); } }
17,207
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UISavedQuery.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UISavedQuery.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.search; import java.util.ArrayList; import java.util.List; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.query.Query; import javax.jcr.query.QueryResult; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.cms.queries.QueryService; import org.exoplatform.services.wcm.core.NodeLocation; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.application.portlet.PortletRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPageIterator; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jan 4, 2006 * 16:37:15 */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/search/UISavedQuery.gtmpl", events = { @EventConfig(listeners = UISavedQuery.ExecuteActionListener.class), @EventConfig(listeners = UISavedQuery.DeleteActionListener.class, confirm = "UISavedQuery.msg.confirm-delete-query"), @EventConfig(listeners = UISavedQuery.EditActionListener.class) } ) public class UISavedQuery extends UIContainer implements UIPopupComponent { final static public String EDIT_FORM = "EditSavedQueryForm"; private UIPageIterator uiPageIterator_; private boolean isQuickSearch_ = false; public UISavedQuery() throws Exception { uiPageIterator_ = addChild(UIPageIterator.class, null, "SavedQueryIterator"); } public void updateGrid(int currentPage) throws Exception { ListAccess<Object> queryList = new ListAccessImpl<Object>(Object.class, NodeLocation.getLocationsByNodeList(queryList())); LazyPageList<Object> pageList = new LazyPageList<Object>(queryList, 10); uiPageIterator_.setPageList(pageList); if (currentPage > uiPageIterator_.getAvailablePage()) uiPageIterator_.setCurrentPage(uiPageIterator_.getAvailablePage()); else uiPageIterator_.setCurrentPage(currentPage); } public List<Object> queryList() throws Exception { List<Object> objectList = new ArrayList<Object>(); List<Node> sharedQueries = getSharedQueries(); if(!sharedQueries.isEmpty()) { for(Node node : sharedQueries) { objectList.add(node); } } List<Query> queries = getQueries(); if(!queries.isEmpty()) { for(Query query : queries) { objectList.add(new QueryData(query)); } } return objectList; } public UIPageIterator getUIPageIterator() { return uiPageIterator_; } public List getQueryList() throws Exception { return NodeLocation.getNodeListByLocationList(uiPageIterator_.getCurrentPageData()); } public void initPopupEditForm(Query query) throws Exception { removeChildById(EDIT_FORM); UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, EDIT_FORM); uiPopup.setWindowSize(500,0); UIJCRAdvancedSearch uiJAdvancedSearch = createUIComponent(UIJCRAdvancedSearch.class, null, "EditQueryForm"); uiJAdvancedSearch.setActions(new String[] {"Save", "Cancel"}); uiPopup.setUIComponent(uiJAdvancedSearch); uiPopup.setRendered(true); uiJAdvancedSearch.setIsEdit(true); uiJAdvancedSearch.setQuery(query); uiJAdvancedSearch.update(query); uiPopup.setShow(true); uiPopup.setResizable(true); } public List<Query> getQueries() throws Exception { QueryService queryService = getApplicationComponent(QueryService.class); try { return queryService.getQueries(getCurrentUserId(), WCMCoreUtils.getUserSessionProvider()); } catch(AccessDeniedException ace) { return new ArrayList<Query>(); } } public String getCurrentUserId() { return Util.getPortalRequestContext().getRemoteUser();} public List<Node> getSharedQueries() throws Exception { PortletRequestContext pcontext = (PortletRequestContext)WebuiRequestContext.getCurrentInstance(); QueryService queryService = getApplicationComponent(QueryService.class); String userId = pcontext.getRemoteUser(); return queryService.getSharedQueries(userId, WCMCoreUtils.getSystemSessionProvider()); } //public List<Node> getSharedQueries() { return sharedQueries_; } public void activate() { } public void deActivate() { } public void setIsQuickSearch(boolean isQuickSearch) { isQuickSearch_ = isQuickSearch; } static public class ExecuteActionListener extends EventListener<UISavedQuery> { public void execute(Event<UISavedQuery> event) throws Exception { UISavedQuery uiQuery = event.getSource(); UIJCRExplorer uiExplorer = uiQuery.getAncestorOfType(UIJCRExplorer.class); String wsName = uiQuery.getAncestorOfType(UIJCRExplorer.class).getCurrentWorkspace(); UIApplication uiApp = uiQuery.getAncestorOfType(UIApplication.class); QueryService queryService = uiQuery.getApplicationComponent(QueryService.class); String queryPath = event.getRequestContext().getRequestParameter(OBJECTID); UIComponent uiSearch = null; UISearchResult uiSearchResult = null; if(uiQuery.isQuickSearch_) { uiSearch = uiExplorer.getChild(UIWorkingArea.class).getChild(UIDocumentWorkspace.class); uiSearchResult = ((UIDocumentWorkspace)uiSearch).getChild(UISearchResult.class); } else { uiSearch = uiQuery.getParent(); uiSearchResult = ((UIECMSearch)uiSearch).getChild(UISearchResult.class); ((UIECMSearch)uiSearch).setSelectedTab(uiSearchResult.getId()); } Query query = null; QueryResult queryResult = null; try { query = queryService.getQuery(queryPath, wsName, WCMCoreUtils.getSystemSessionProvider(), uiQuery.getCurrentUserId()); queryResult = query.execute(); } catch(Exception e) { uiApp.addMessage(new ApplicationMessage("UISearchResult.msg.query-invalid", null, ApplicationMessage.WARNING)); if(!uiQuery.isQuickSearch_) ((UIECMSearch)uiSearch).setSelectedTab(uiQuery.getId()); return; } finally { if(queryResult == null || queryResult.getNodes().getSize() ==0) { uiApp.addMessage(new ApplicationMessage("UISavedQuery.msg.not-result-found", null)); if(!uiQuery.isQuickSearch_) ((UIECMSearch)uiSearch).setSelectedTab(uiQuery.getId()); return; } uiSearchResult.setQuery(query.getStatement(), wsName, query.getLanguage(), true, null); uiSearchResult.updateGrid(); } if(uiQuery.isQuickSearch_) { ((UIDocumentWorkspace)uiSearch).setRenderedChild(UISearchResult.class); UIPopupContainer uiPopup = uiExplorer.getChild(UIPopupContainer.class); uiPopup.deActivate(); } } } static public class EditActionListener extends EventListener<UISavedQuery> { public void execute(Event<UISavedQuery> event) throws Exception { UISavedQuery uiQuery = event.getSource(); String userName = Util.getPortalRequestContext().getRemoteUser(); QueryService queryService = uiQuery.getApplicationComponent(QueryService.class); String queryPath = event.getRequestContext().getRequestParameter(OBJECTID); Query query = queryService.getQueryByPath(queryPath, userName, WCMCoreUtils.getSystemSessionProvider()); uiQuery.initPopupEditForm(query); if(!uiQuery.isQuickSearch_) { UIECMSearch uiECSearch = uiQuery.getParent(); uiECSearch.setSelectedTab(uiQuery.getId()); event.getRequestContext().addUIComponentToUpdateByAjax(uiECSearch); } else { event.getRequestContext().addUIComponentToUpdateByAjax(uiQuery.getParent()); } } } static public class DeleteActionListener extends EventListener<UISavedQuery> { public void execute(Event<UISavedQuery> event) throws Exception { UISavedQuery uiQuery = event.getSource(); String userName = Util.getPortalRequestContext().getRemoteUser(); QueryService queryService = uiQuery.getApplicationComponent(QueryService.class); String path = event.getRequestContext().getRequestParameter(OBJECTID); queryService.removeQuery(path, userName); uiQuery.updateGrid(uiQuery.getUIPageIterator().getCurrentPage()); event.getRequestContext().addUIComponentToUpdateByAjax(uiQuery); } } public class QueryData { private String language_; private String statement_; private String storedQueryPath_; public QueryData(Query query) { language_ = query.getLanguage(); statement_ = query.getStatement(); try { storedQueryPath_ = query.getStoredQueryPath(); } catch (RepositoryException e) { storedQueryPath_ = ""; } } public String getLanguage() { return language_; } public void setLanguage(String language) { language_ = language; } public String getStatement() { return statement_; } public void setStatement(String statement) { statement_ = statement; } public String getStoredQueryPath() { return storedQueryPath_; } public void setStoredQueryPath(String storedQueryPath) { storedQueryPath_ = storedQueryPath; } } }
11,467
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UISimpleSearch.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UISimpleSearch.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.search; import java.util.*; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.query.*; import org.apache.commons.lang3.StringUtils; import org.exoplatform.ecm.jcr.model.Preference; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.services.cms.impl.Utils; import org.exoplatform.services.jcr.impl.util.XPathUtils; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.security.IdentityConstants; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.web.application.RequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.*; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.*; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Dec 26, 2006 * 4:29:08 PM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/explorer/search/UISimpleSearch.gtmpl", events = { @EventConfig(listeners = UISimpleSearch.CancelActionListener.class, phase=Phase.DECODE), @EventConfig(listeners = UISimpleSearch.SearchActionListener.class), @EventConfig(listeners = UISimpleSearch.SaveActionListener.class), @EventConfig(listeners = UISimpleSearch.MoreConstraintsActionListener.class, phase=Phase.DECODE), @EventConfig(listeners = UISimpleSearch.RemoveConstraintActionListener.class, phase=Phase.DECODE), @EventConfig(listeners = UISimpleSearch.AddActionListener.class), @EventConfig(listeners = UISimpleSearch.CompareExactlyActionListener.class), @EventConfig(listeners = UISimpleSearch.AddMetadataTypeActionListener.class), @EventConfig(listeners = UISimpleSearch.AddNodeTypeActionListener.class), @EventConfig(listeners = UISimpleSearch.AddCategoryActionListener.class) } ) public class UISimpleSearch extends UIForm { public static final String CONSTRAINTS_FORM = "ConstraintsForm"; public static final String INPUT_SEARCH = "input"; public static final String CONSTRAINTS = "constraints"; public static final String NODE_PATH = "nodePath"; public static final String FIRST_OPERATOR = "firstOperator"; public static final String OR = "or"; public static final String AND = "and"; private static final Log LOG = ExoLogger.getLogger(UISimpleSearch.class.getName()); private List<String> constraints_ = new ArrayList<String>(); private List<String> virtualConstraints_ = new ArrayList<String>(); private List<String> categoryPathList = new ArrayList<String>(); public List<String> getCategoryPathList() { return categoryPathList; } public void setCategoryPathList(List<String> categoryPathListItem) { categoryPathList = categoryPathListItem; } private static final String ROOT_XPATH_QUERY = "//*"; private static final String XPATH_QUERY = "/jcr:root$0//*"; private static final String ROOT_SQL_QUERY = "SELECT * FROM nt:base WHERE jcr:path LIKE '/%' "; private static final String NT_RESOURCE_EXCLUDE = "AND ( not jcr:primaryType like 'nt:resource') "; private static final String LINK_REQUIREMENT = "AND ( (jcr:primaryType like 'exo:symlink' or " + "jcr:primaryType like 'exo:taxonomyLink') "; private static final String SQL_QUERY = "SELECT * FROM nt:base WHERE jcr:path LIKE '$0/%' "; private String _OR = "Or"; private String _AND = "And"; public UISimpleSearch() throws Exception { addUIFormInput(new UIFormInputInfo(NODE_PATH, NODE_PATH, null)); addUIFormInput(new UIFormStringInput(INPUT_SEARCH, INPUT_SEARCH, null)); List<SelectItemOption<String>> operators = new ArrayList<SelectItemOption<String>>(); RequestContext context = RequestContext.getCurrentInstance(); try { ResourceBundle res = context.getApplicationResourceBundle(); _AND = res.getString("UIConstraintForm.label.and"); _OR = res.getString("UIConstraintForm.label.or"); }catch (MissingResourceException e) { // There is no resource found, just use the default resource-bundle in English as first value of _OR & _AND if (LOG.isWarnEnabled()) { LOG.warn("Can not get resource bundle for UISimpleSearch label: " + e.getMessage()); } } operators.add(new SelectItemOption<String>(_AND, AND)); operators.add(new SelectItemOption<String>(_OR, OR)); addUIFormInput(new UIFormSelectBox(FIRST_OPERATOR, FIRST_OPERATOR, operators)); UIFormInputSetWithAction uiInputAct = new UIFormInputSetWithAction("moreConstraints"); uiInputAct.addUIFormInput(new UIFormInputInfo(CONSTRAINTS, CONSTRAINTS, null)); addUIComponentInput(uiInputAct); UIConstraintsForm uiConstraintsForm = new UIConstraintsForm(CONSTRAINTS_FORM); uiConstraintsForm.setRendered(false); addChild(uiConstraintsForm); setActions(new String[] {"MoreConstraints", "Search", "Save", "Cancel"}); } public List<String> getConstraints() { return constraints_; } public void updateAdvanceConstraint(String constraint, String operator, String virtualDateQuery) { if (constraint.length() > 0) { if (constraints_.size() == 0) { constraints_.add("(" + constraint + " )"); if (virtualDateQuery != null) virtualConstraints_.add("(" + virtualDateQuery + " )"); else virtualConstraints_.add("(" + constraint + " )"); } else { constraints_.add(" " + operator.toLowerCase() + " (" + constraint + " ) "); if (virtualDateQuery != null) virtualConstraints_.add(" " + operator.toLowerCase() + " (" + virtualDateQuery + " ) "); else virtualConstraints_.add(" " + operator.toLowerCase() + " (" + constraint + " ) "); } } UIFormInputSetWithAction inputInfor = getChildById("moreConstraints"); inputInfor.setIsDeleteOnly(true); inputInfor.setListInfoField(CONSTRAINTS, virtualConstraints_); String[] actionInfor = {"RemoveConstraint"}; inputInfor.setActionInfo(CONSTRAINTS, actionInfor); } private String getQueryStatement() throws Exception { Node currentNode = getAncestorOfType(UIJCRExplorer.class).getCurrentNode(); StringBuilder statement = new StringBuilder(1024); String text = getUIStringInput(INPUT_SEARCH).getValue(); String escapedText = text == null ? null : Utils.escapeIllegalCharacterInQuery(text); if(text != null && constraints_.size() == 0) { if ("/".equals(currentNode.getPath())) { statement.append(ROOT_XPATH_QUERY); } else { statement.append(StringUtils.replace(XPATH_QUERY, "$0", currentNode.getPath())); } statement.append("[(jcr:contains(.,'").append(escapedText).append("'))]"); } else if(constraints_.size() > 0) { if(text == null) { if ("/".equals(currentNode.getPath())) { statement.append(ROOT_XPATH_QUERY).append("[("); } else { statement.append(StringUtils.replace(XPATH_QUERY, "$0", currentNode.getPath())).append("[("); } } else { String operator = getUIFormSelectBox(FIRST_OPERATOR).getValue(); if ("/".equals(currentNode.getPath())) { statement.append(ROOT_XPATH_QUERY); } else { statement.append(StringUtils.replace(XPATH_QUERY, "$0", currentNode.getPath())); } statement.append("[(jcr:contains(.,'") .append(escapedText.replaceAll("'", "''")) .append("')) ") .append(operator) .append(" ("); } for(String constraint : constraints_) { if (!constraint.contains("exo:category")) statement.append(constraint); } statement.append(")]"); } return statement.toString(); } private String getSQLStatement() throws Exception { Node currentNode = getAncestorOfType(UIJCRExplorer.class).getCurrentNode(); StringBuilder statement = new StringBuilder(1024); String text = getUIStringInput(INPUT_SEARCH).getValue(); String escapedText = text == null ? null : Utils.escapeIllegalCharacterInQuery(text); if(text != null && constraints_.size() == 0) {//no constraint if ("/".equals(currentNode.getPath())) { statement.append(ROOT_SQL_QUERY); } else { statement.append(StringUtils.replace(SQL_QUERY, "$0", currentNode.getPath())); } statement.append(NT_RESOURCE_EXCLUDE); statement.append(LINK_REQUIREMENT).append(" OR ( CONTAINS(*,'"). append(escapedText).append("') ) )"); } else if(constraints_.size() > 0) {//constraint != null //get constraint statement StringBuilder tmpStatement = new StringBuilder(); String operator = getUIFormSelectBox(FIRST_OPERATOR).getValue(); for(String constraint : constraints_) { if (!constraint.contains("exo:category")) { tmpStatement.append(constraint); } } String str = tmpStatement.toString().trim(); if (str.toLowerCase().startsWith("or")) str = str.substring("or".length()); if (str.toLowerCase().startsWith("and")) str = str.substring("and".length()); String constraintsStatement = str.length() == 0 ? str : operator + " ( " + str + " ) "; //get statement if(text == null) { if ("/".equals(currentNode.getPath())) { statement.append(ROOT_SQL_QUERY); } else { statement.append(StringUtils.replace(SQL_QUERY, "$0", currentNode.getPath())); } statement.append(NT_RESOURCE_EXCLUDE); if (constraintsStatement.length() > 0) statement.append(constraintsStatement); } else { if ("/".equals(currentNode.getPath())) { statement.append(ROOT_SQL_QUERY); } else { statement.append(StringUtils.replace(SQL_QUERY, "$0", currentNode.getPath())); } statement.append(NT_RESOURCE_EXCLUDE); statement.append(LINK_REQUIREMENT).append("OR ( CONTAINS(*,'"). append(escapedText.replaceAll("'", "''")).append("') "); if (constraintsStatement.length() > 0) statement.append(constraintsStatement); statement.append(" ) )"); } } return statement.toString(); } static public class SaveActionListener extends EventListener<UISimpleSearch> { public void execute(Event<UISimpleSearch> event) throws Exception { UISimpleSearch uiSimpleSearch = event.getSource(); UIApplication uiApp = uiSimpleSearch.getAncestorOfType(UIApplication.class); String text = uiSimpleSearch.getUIStringInput(INPUT_SEARCH).getValue(); if((text == null) && uiSimpleSearch.constraints_.size() == 0) { uiApp.addMessage(new ApplicationMessage("UISimpleSearch.msg.value-save-null", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiSimpleSearch); return; } UISearchContainer uiSearchContainer = uiSimpleSearch.getParent(); uiSearchContainer.initSaveQueryPopup(uiSimpleSearch.getQueryStatement(), true, Query.XPATH); event.getRequestContext().addUIComponentToUpdateByAjax(uiSearchContainer); } } static public class CancelActionListener extends EventListener<UISimpleSearch> { public void execute(Event<UISimpleSearch> event) throws Exception { event.getSource().getAncestorOfType(UIJCRExplorer.class).cancelAction(); } } static public class RemoveConstraintActionListener extends EventListener<UISimpleSearch> { public void execute(Event<UISimpleSearch> event) throws Exception { UISimpleSearch uiSimpleSearch = event.getSource(); int intIndex = Integer.parseInt(event.getRequestContext().getRequestParameter(OBJECTID)); uiSimpleSearch.constraints_.remove(intIndex); uiSimpleSearch.virtualConstraints_.remove(intIndex); if (uiSimpleSearch.categoryPathList.size() > intIndex) uiSimpleSearch.categoryPathList.remove(intIndex); if(uiSimpleSearch.constraints_.size() > 0 && intIndex == 0) { String newFirstConstraint = null; String newFirstVirtualConstraint = null; if(uiSimpleSearch.constraints_.get(0).trim().startsWith(OR)) { newFirstConstraint = uiSimpleSearch.constraints_.get(0).substring(3, uiSimpleSearch.constraints_.get(0).length()); newFirstVirtualConstraint = uiSimpleSearch.virtualConstraints_.get(0) .substring(3, uiSimpleSearch.virtualConstraints_.get(0) .length()); uiSimpleSearch.constraints_.set(0, newFirstConstraint); uiSimpleSearch.virtualConstraints_.set(0, newFirstVirtualConstraint); } else if(uiSimpleSearch.constraints_.get(0).trim().startsWith(AND)) { newFirstConstraint = uiSimpleSearch.constraints_.get(0).substring(4, uiSimpleSearch.constraints_.get(0).length()); newFirstVirtualConstraint = uiSimpleSearch.virtualConstraints_.get(0) .substring(4, uiSimpleSearch.virtualConstraints_.get(0) .length()); uiSimpleSearch.constraints_.set(0, newFirstConstraint); uiSimpleSearch.virtualConstraints_.set(0, newFirstVirtualConstraint); } } event.getRequestContext().addUIComponentToUpdateByAjax(uiSimpleSearch.getParent()); } } static public class SearchActionListener extends EventListener<UISimpleSearch> { public void execute(Event<UISimpleSearch> event) throws Exception { UISimpleSearch uiSimpleSearch = event.getSource(); String text = uiSimpleSearch.getUIStringInput(INPUT_SEARCH).getValue(); UIJCRExplorer uiExplorer = uiSimpleSearch.getAncestorOfType(UIJCRExplorer.class); Node currentNode = uiExplorer.getCurrentNode(); UIECMSearch uiECMSearch = uiSimpleSearch.getAncestorOfType(UIECMSearch.class); UISearchResult uiSearchResult = uiECMSearch.getChild(UISearchResult.class); UIApplication uiApp = uiSimpleSearch.getAncestorOfType(UIApplication.class); if(text == null && uiSimpleSearch.constraints_.size() == 0) { uiApp.addMessage(new ApplicationMessage("UISimpleSearch.msg.value-null", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiSimpleSearch); return; } uiSearchResult.setCategoryPathList(uiSimpleSearch.getCategoryPathList()); Preference pref = uiExplorer.getPreference(); String queryType = pref.getQueryType(); String statement; //List<String> searchCategoryPathList = uiSimpleSearch.getCategoryPathList(); if (queryType.equals(Preference.XPATH_QUERY)) { statement = uiSimpleSearch.getQueryStatement() + " order by @exo:dateCreated descending"; } else { statement = uiSimpleSearch.getSQLStatement() + " order by exo:dateCreated DESC"; } long startTime = System.currentTimeMillis(); try { uiSearchResult.setQuery(statement, currentNode.getSession().getWorkspace().getName(), queryType.equals(Preference.XPATH_QUERY) ? Query.XPATH : Query.SQL, IdentityConstants.SYSTEM.equals(currentNode.getSession().getUserID()), text); uiSearchResult.updateGrid(); } catch (RepositoryException reEx) { uiApp.addMessage(new ApplicationMessage("UISimpleSearch.msg.inputSearch-invalid", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiSimpleSearch); return; } catch(Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } uiApp.addMessage(new ApplicationMessage("UISimpleSearch.msg.query-invalid", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiSimpleSearch); return; } long time = System.currentTimeMillis() - startTime; uiSearchResult.setSearchTime(time); uiECMSearch.setSelectedTab(uiSearchResult.getId()); uiSimpleSearch.getUIFormInputInfo(UISimpleSearch.NODE_PATH).setValue(currentNode.getPath()); event.getRequestContext().addUIComponentToUpdateByAjax(uiECMSearch); } } static public class MoreConstraintsActionListener extends EventListener<UISimpleSearch> { public void execute(Event<UISimpleSearch> event) throws Exception { UISimpleSearch uiSimpleSearch = event.getSource(); UIConstraintsForm uiConstraintsForm = uiSimpleSearch.getChild(UIConstraintsForm.class); if(uiConstraintsForm.isRendered()) uiConstraintsForm.setRendered(false); else uiConstraintsForm.setRendered(true); event.getRequestContext().addUIComponentToUpdateByAjax(uiSimpleSearch); } } static public class AddActionListener extends EventListener<UISimpleSearch> { public void execute(Event<UISimpleSearch> event) throws Exception { UIConstraintsForm uiForm = event.getSource().getChild(UIConstraintsForm.class); boolean isExactly = uiForm.getUICheckBoxInput(UIConstraintsForm.EXACTLY_PROPERTY).isChecked() ; boolean isContain = uiForm.getUICheckBoxInput(UIConstraintsForm.CONTAIN_PROPERTY).isChecked() ; boolean isNotContain = uiForm.getUICheckBoxInput(UIConstraintsForm.NOT_CONTAIN_PROPERTY).isChecked() ; boolean isDateTime = uiForm.getUICheckBoxInput(UIConstraintsForm.DATE_PROPERTY).isChecked() ; boolean isNodeType = uiForm.getUICheckBoxInput(UIConstraintsForm.NODETYPE_PROPERTY).isChecked() ; boolean isCategory = uiForm.getUICheckBoxInput(UIConstraintsForm.CATEGORY_PROPERTY).isChecked() ; UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class) ; if (!isExactly && !isContain && !isNotContain && !isDateTime && !isNodeType && !isCategory) { uiApp.addMessage(new ApplicationMessage("UIConstraintsForm.msg.must-choose-one", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return; } if (isExactly) { String property = uiForm.getUIStringInput(UIConstraintsForm.PROPERTY1).getValue(); if (property == null || property.length() < 1) { uiApp.addMessage(new ApplicationMessage("UIConstraintsForm.msg.properties-required", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return; } String value = uiForm.getUIStringInput(UIConstraintsForm.CONTAIN_EXACTLY).getValue() ; if (value == null || value.trim().length() < 0) { uiApp.addMessage(new ApplicationMessage("UIConstraintsForm.msg.exactly-require", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return; } uiForm.addConstraint(0) ; } if(isContain) { String property = uiForm.getUIStringInput(UIConstraintsForm.PROPERTY2).getValue() ; if(property == null || property.length() < 1) { uiApp.addMessage(new ApplicationMessage("UIConstraintsForm.msg.properties-required", null, ApplicationMessage.WARNING)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return ; } String value = uiForm.getUIStringInput(UIConstraintsForm.CONTAIN).getValue() ; if(value == null || value.trim().length() < 0) { uiApp.addMessage(new ApplicationMessage("UIConstraintsForm.msg.value-required", null, ApplicationMessage.WARNING)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return ; } uiForm.addConstraint(1) ; } if(isNotContain) { String property = uiForm.getUIStringInput(UIConstraintsForm.PROPERTY3).getValue() ; if(property == null || property.length() < 1) { uiApp.addMessage(new ApplicationMessage("UIConstraintsForm.msg.properties-required", null, ApplicationMessage.WARNING)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return ; } String value = uiForm.getUIStringInput(UIConstraintsForm.NOT_CONTAIN).getValue() ; if(value == null || value.trim().length() < 0) { uiApp.addMessage(new ApplicationMessage("UIConstraintsForm.msg.value-required", null, ApplicationMessage.WARNING)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return ; } uiForm.addConstraint(2) ; } if(isDateTime) { String fromDate = uiForm.getUIFormDateTimeInput(UIConstraintsForm.START_TIME).getValue() ; String toDate = uiForm.getUIFormDateTimeInput(UIConstraintsForm.END_TIME).getValue() ; if(fromDate == null || fromDate.trim().length() == 0) { uiApp.addMessage(new ApplicationMessage("UIConstraintsForm.msg.fromDate-required", null, ApplicationMessage.WARNING)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return ; } Calendar bfDate = uiForm.getUIFormDateTimeInput(UIConstraintsForm.START_TIME).getCalendar() ; if(toDate != null && toDate.trim().length() >0) { Calendar afDate = uiForm.getUIFormDateTimeInput(UIConstraintsForm.END_TIME).getCalendar(); if(bfDate.compareTo(afDate) == 1) { uiApp.addMessage(new ApplicationMessage("UIConstraintsForm.msg.date-invalid", null, ApplicationMessage.WARNING)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return ; } } uiForm.addConstraint(3); } if(isNodeType) { String property = uiForm.getUIStringInput(UIConstraintsForm.DOC_TYPE).getValue() ; if(property == null || property.length() < 1) { uiApp.addMessage(new ApplicationMessage("UIConstraintsForm.msg.properties-required", null, ApplicationMessage.WARNING)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return ; } uiForm.addConstraint(4) ; } if (isCategory) { String category = uiForm.getUIStringInput(UIConstraintsForm.CATEGORY_TYPE).getValue(); if (category == null || category.length() < 1) { uiApp.addMessage(new ApplicationMessage("UIConstraintsForm.msg.properties-required", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return; } uiForm.addConstraint(5); } uiForm.resetConstraintForm() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()) ; } } static public class AddMetadataTypeActionListener extends EventListener<UISimpleSearch> { public void execute(Event<UISimpleSearch> event) throws Exception { UISearchContainer uiContainer = event.getSource().getAncestorOfType(UISearchContainer.class); String type = event.getRequestContext().getRequestParameter(OBJECTID) ; String popupId = UIConstraintsForm.PROPERTY1; if(type.equals("1")) popupId = UIConstraintsForm.PROPERTY2 ; else if(type.equals("2")) popupId = UIConstraintsForm.PROPERTY3 ; uiContainer.initMetadataPopup(popupId) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiContainer) ; } } static public class AddNodeTypeActionListener extends EventListener<UISimpleSearch> { public void execute(Event<UISimpleSearch> event) throws Exception { UISearchContainer uiContainer = event.getSource().getAncestorOfType(UISearchContainer.class); uiContainer.initNodeTypePopup() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiContainer) ; } } static public class CompareExactlyActionListener extends EventListener<UISimpleSearch> { public void execute(Event<UISimpleSearch> event) throws Exception { UIConstraintsForm uiConstraintForm = event.getSource().getChild(UIConstraintsForm.class); String property = uiConstraintForm.getUIStringInput(UIConstraintsForm.PROPERTY1).getValue() ; UIJCRExplorer uiExplorer = uiConstraintForm.getAncestorOfType(UIJCRExplorer.class); UIApplication uiApp = uiConstraintForm.getAncestorOfType(UIApplication.class) ; if(property == null || property.trim().length() == 0) { uiApp.addMessage(new ApplicationMessage("UIConstraintsForm.msg.properties-null", null, ApplicationMessage.WARNING)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiConstraintForm); return ; } String currentPath = uiExplorer.getCurrentNode().getPath() ; StringBuffer statement = new StringBuffer("select * from nt:base where "); if (!currentPath.equals("/")) { statement.append("jcr:path like '").append(currentPath).append("/%' AND "); } property = XPathUtils.escapeIllegalXPathName(property); statement.append(property).append(" is not null"); QueryManager queryManager = uiExplorer.getTargetSession().getWorkspace().getQueryManager() ; Query query = queryManager.createQuery(statement.toString(), Query.SQL) ; QueryResult result = query.execute() ; if(result == null || result.getNodes().getSize() == 0) { uiApp.addMessage(new ApplicationMessage("UICompareExactlyForm.msg.not-result-found", null)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiConstraintForm); return ; } UISearchContainer uiContainer = uiConstraintForm.getAncestorOfType(UISearchContainer.class); UICompareExactlyForm uiCompareExactlyForm = uiContainer.createUIComponent(UICompareExactlyForm.class, null, null) ; UIPopupContainer uiPopup = uiContainer.getChild(UIPopupContainer.class); uiPopup.getChild(UIPopupWindow.class).setId("ExactlyFormPopup") ; uiPopup.getChild(UIPopupWindow.class).setShowMask(true); uiCompareExactlyForm.init(property, result) ; uiPopup.activate(uiCompareExactlyForm, 600, 500) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiPopup) ; } } static public class AddCategoryActionListener extends EventListener<UISimpleSearch> { public void execute(Event<UISimpleSearch> event) throws Exception { UISearchContainer uiSearchContainer = event.getSource().getAncestorOfType(UISearchContainer.class); uiSearchContainer.initCategoryPopup(); event.getRequestContext().addUIComponentToUpdateByAjax(uiSearchContainer) ; } } }
29,393
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIECMSearch.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UIECMSearch.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.search; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPageIterator; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UITabPane; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : le bien thuy * lebienthuyt@gmail.com * Oct 2, 2006 * 10:08:51 AM * Editor: pham tuan Oct 27, 2006 */ @ComponentConfig(template = "system:/groovy/webui/core/UITabPane_New.gtmpl", events = { @EventConfig(listeners = UIECMSearch.SelectTabActionListener.class) }) public class UIECMSearch extends UITabPane implements UIPopupComponent { private static final Log LOG = ExoLogger.getLogger(UIECMSearch.class.getName()); static public String ADVANCED_RESULT = "AdvancedSearchResult" ; public UIECMSearch() throws Exception { addChild(UIContentNameSearch.class,null,null); setSelectedTab("UIContentNameSearch"); addChild(UISearchContainer.class, null, null) ; addChild(UIJCRAdvancedSearch.class, null, null); addChild(UISavedQuery.class, null, null); UISearchResult uiSearchResult = addChild(UISearchResult.class, null, ADVANCED_RESULT); UIPageIterator uiPageIterator = uiSearchResult.getChild(UIPageIterator.class) ; uiPageIterator.setId("AdvanceSearchIterator") ; } public void activate() { try { UIJCRAdvancedSearch advanceSearch = getChild(UIJCRAdvancedSearch.class); advanceSearch.update(null); UISavedQuery uiQuery = getChild(UISavedQuery.class); uiQuery.updateGrid(1); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } public void deActivate() { } static public class SelectTabActionListener extends EventListener<UIECMSearch> { public void execute(Event<UIECMSearch> event) throws Exception { WebuiRequestContext context = event.getRequestContext(); String renderTab = context.getRequestParameter(UIComponent.OBJECTID); if (renderTab == null) return; event.getSource().setSelectedTab(renderTab); context.setResponseComplete(true); context.addUIComponentToUpdateByAjax(event.getSource().getParent()); } } }
3,456
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIJCRAdvancedSearch.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UIJCRAdvancedSearch.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.search; import org.apache.commons.lang3.StringUtils; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.form.validator.ECMNameValidator; import org.exoplatform.webui.form.validator.MandatoryValidator; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.cms.queries.QueryService; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.core.ManageableRepository; import org.exoplatform.services.security.IdentityConstants; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormSelectBox; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.UIFormTextAreaInput; import javax.jcr.Node; import javax.jcr.Session; import javax.jcr.query.Query; import javax.jcr.query.QueryManager; import java.util.ArrayList; import java.util.List; /** * Created by The eXo Platform SARL * Author : Tran The Trong * trongtt@gmail.com * Oct 2, 2006 * 1:55:22 PM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UIJCRAdvancedSearch.SaveActionListener.class), @EventConfig(listeners = UIJCRAdvancedSearch.SearchActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIJCRAdvancedSearch.CancelActionListener.class, phase = Phase.DECODE), @EventConfig(phase=Phase.DECODE, listeners = UIJCRAdvancedSearch.ChangeOptionActionListener.class) } ) public class UIJCRAdvancedSearch extends UIForm implements UIPopupComponent { public static final String FIELD_NAME = "name" ; public static final String FIELD_QUERY = "query" ; public static final String FIELD_SELECT_BOX = "selectBox" ; private static final String ROOT_SQL_QUERY = "select * from nt:base order by exo:dateCreated DESC" ; private static final String SQL_QUERY = "select * from nt:base where jcr:path like '$0/%' order by exo:dateCreated DESC" ; private static final String ROOT_XPATH_QUERY = "//* order by @exo:dateCreated descending" ; private static final String XPATH_QUERY = "/jcr:root$0//* order by @exo:dateCreated descending" ; private static final String CHANGE_OPTION = "ChangeOption" ; private boolean isEdit_ = false ; private String queryPath_ ; private String queryStatement_; private String queryLanguage_; public UIJCRAdvancedSearch() throws Exception { addUIFormInput(new UIFormStringInput(FIELD_NAME, FIELD_NAME, null).addValidator(ECMNameValidator.class) .addValidator(MandatoryValidator.class)); List<SelectItemOption<String>> ls = new ArrayList<SelectItemOption<String>>() ; ls.add(new SelectItemOption<String>("SQL", "sql")) ; ls.add(new SelectItemOption<String>("xPath", "xpath")) ; UIFormSelectBox uiSelectBox = new UIFormSelectBox(FIELD_SELECT_BOX, FIELD_SELECT_BOX, ls) ; uiSelectBox.setOnChange("Change") ; addUIFormInput(uiSelectBox) ; addUIFormInput(new UIFormTextAreaInput(FIELD_QUERY, FIELD_QUERY, null)) ; setActions(new String[]{"Search", "Save", "Cancel"}) ; } public void update(Query query) throws Exception { if(query == null) { UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ; Node selectedNode = uiExplorer.getCurrentNode() ; String path = selectedNode.getPath() ; String queryText = StringUtils.replace(SQL_QUERY, "$0", path) ; if ("/".equals(path)) queryText = ROOT_SQL_QUERY ; getUIStringInput(FIELD_NAME).setValue(null) ; getUIStringInput(FIELD_NAME).setReadOnly(false) ; getUIFormSelectBox(FIELD_SELECT_BOX).setOnChange(CHANGE_OPTION) ; getUIFormSelectBox(FIELD_SELECT_BOX).setValue("sql") ; getUIFormTextAreaInput(FIELD_QUERY).setValue(queryText) ; } else { String storedPath = query.getStoredQueryPath() ; queryPath_ = storedPath ; storedPath = storedPath.substring(storedPath.lastIndexOf("/") + 1, storedPath.length()) ; getUIStringInput(FIELD_NAME).setValue(storedPath) ; getUIStringInput(FIELD_NAME).setReadOnly(true); getUIFormSelectBox(FIELD_SELECT_BOX).setOnChange(CHANGE_OPTION) ; getUIFormSelectBox(FIELD_SELECT_BOX).setValue(query.getLanguage()) ; getUIFormTextAreaInput(FIELD_QUERY).setValue(query.getStatement()) ; } } public void setQuery(Query query) { if (query != null) { queryLanguage_ = query.getLanguage(); queryStatement_ = query.getStatement(); } else { queryLanguage_ = null; queryStatement_ = null; } } public void setIsEdit(boolean isEdit) { isEdit_ = isEdit ; } public boolean isEdit() { return isEdit_ ; } public void activate() {} public void deActivate() {} static public class CancelActionListener extends EventListener<UIJCRAdvancedSearch> { public void execute(Event<UIJCRAdvancedSearch> event) throws Exception { UIJCRAdvancedSearch uiJAdvancedSearch = event.getSource() ; if(uiJAdvancedSearch.isEdit_) { UIPopupWindow uiPopup = uiJAdvancedSearch.getParent() ; uiPopup.setShow(false) ; uiPopup.setRendered(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiJAdvancedSearch.getParent()) ; } else { uiJAdvancedSearch.getAncestorOfType(UIPopupContainer.class).deActivate() ; } } } static public class SearchActionListener extends EventListener<UIJCRAdvancedSearch> { public void execute(Event<UIJCRAdvancedSearch> event) throws Exception { UIJCRAdvancedSearch uiForm = event.getSource() ; UIJCRExplorer uiExplorer = uiForm.getAncestorOfType(UIJCRExplorer.class) ; StringBuffer queryS = new StringBuffer(); queryS.append(uiForm.getUIFormTextAreaInput(FIELD_QUERY).getValue()); String searchType = uiForm.getUIFormSelectBox(FIELD_SELECT_BOX).getValue() ; UIECMSearch uiSearch = uiForm.getParent() ; long startTime = System.currentTimeMillis(); try { if(queryS.toString().toLowerCase().indexOf("order by") < 0) { if(searchType.equals("sql")) { queryS.append(" order by exo:dateCreated DESC"); } else if(searchType.equals("xpath")) { queryS.append(" order by @exo:dateCreated descending"); } } UISearchResult uiSearchResult = uiSearch.getChild(UISearchResult.class) ; uiSearchResult.setQuery(queryS.toString(), uiExplorer.getTargetSession().getWorkspace().getName(), searchType, IdentityConstants.SYSTEM.equals(WCMCoreUtils.getRemoteUser()), null); uiSearchResult.updateGrid() ; long time = System.currentTimeMillis() - startTime; uiSearchResult.setSearchTime(time); uiSearch.setSelectedTab(UIECMSearch.ADVANCED_RESULT) ; } catch (Exception e){ UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class) ; uiApp.addMessage(new ApplicationMessage("UIJCRAdvancedSearch.msg.invalid-queryStatement", null, ApplicationMessage.WARNING)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return ; } } } static public class ChangeOptionActionListener extends EventListener<UIJCRAdvancedSearch> { public void execute(Event<UIJCRAdvancedSearch> event) throws Exception { UIJCRAdvancedSearch uiForm = event.getSource() ; UIJCRExplorer uiExplorer = uiForm.getAncestorOfType(UIJCRExplorer.class) ; String currentPath = uiExplorer.getCurrentNode().getPath() ; String queryText = "" ; String searchType = uiForm.getUIFormSelectBox(FIELD_SELECT_BOX).getValue() ; if(searchType.equals(Query.SQL)){ if ("/".equals(currentPath)) queryText = ROOT_SQL_QUERY ; else queryText = StringUtils.replace(SQL_QUERY, "$0", currentPath) ; uiForm.getUIFormTextAreaInput(FIELD_QUERY).setValue(queryText) ; } else { if ("/".equals(currentPath)) queryText = ROOT_XPATH_QUERY ; else queryText = StringUtils.replace(XPATH_QUERY, "$0", currentPath) ; uiForm.getUIFormTextAreaInput(FIELD_QUERY).setValue(queryText) ; } if(uiForm.isEdit_ && uiForm.queryLanguage_ != null) { if(searchType.equals(uiForm.queryLanguage_)) { uiForm.getUIFormTextAreaInput(FIELD_QUERY).setValue(uiForm.queryStatement_) ; } } event.getRequestContext().addUIComponentToUpdateByAjax(uiForm) ; } } static public class SaveActionListener extends EventListener<UIJCRAdvancedSearch> { public void execute(Event<UIJCRAdvancedSearch> event) throws Exception { UIJCRAdvancedSearch uiForm = event.getSource() ; String statement = uiForm.getUIFormTextAreaInput(FIELD_QUERY).getValue() ; String queryLang = uiForm.getUIFormSelectBox(FIELD_SELECT_BOX).getValue() ; UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class) ; if(statement == null || statement.trim().length() ==0) { uiApp.addMessage(new ApplicationMessage("UIJCRAdvancedSearch.msg.value-save-null", null, ApplicationMessage.WARNING)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return ; } if(!uiForm.isEdit_) { QueryService queryService = uiForm.getApplicationComponent(QueryService.class) ; String name = uiForm.getUIStringInput(FIELD_NAME).getValue() ; String userName = Util.getPortalRequestContext().getRemoteUser() ; try { queryService.addQuery(name, statement, queryLang, userName) ; } catch(Exception e){ uiApp.addMessage(new ApplicationMessage("UIJCRAdvancedSearch.msg.save_unSuccessful", null, ApplicationMessage.WARNING)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return ; } UIECMSearch uiSearch = uiForm.getParent() ; uiSearch.getChild(UISavedQuery.class).updateGrid(1); uiForm.update(null) ; uiSearch.setSelectedTab(uiSearch.getChild(UISavedQuery.class).getId()) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiSearch) ; } else { UIJCRExplorer uiExplorer = uiForm.getAncestorOfType(UIJCRExplorer.class) ; QueryManager queryManager = uiExplorer.getTargetSession().getWorkspace().getQueryManager() ; try { queryManager.createQuery(statement, queryLang) ; } catch(Exception e) { uiApp.addMessage(new ApplicationMessage("UIJCRAdvancedSearch.msg.save_unSuccessful", null, ApplicationMessage.WARNING)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); return ; } ManageableRepository repository = uiForm.getApplicationComponent(RepositoryService.class).getRepository(uiExplorer.getRepositoryName()) ; Session session = repository.getSystemSession(repository.getConfiguration().getDefaultWorkspaceName()) ; Node queryNode = (Node) session.getItem(uiForm.queryPath_) ; queryNode.setProperty("jcr:language", queryLang) ; queryNode.setProperty("jcr:statement", statement) ; queryNode.save() ; session.save() ; session.logout() ; UISavedQuery uiSavedQuery = uiForm.getAncestorOfType(UISavedQuery.class) ; uiSavedQuery.updateGrid(1); uiSavedQuery.removeChildById(UISavedQuery.EDIT_FORM) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiSavedQuery.getParent()) ; } } } }
13,454
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UICategoryManagerSearch.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UICategoryManagerSearch.java
/*************************************************************************** * Copyright 2001-2008 The eXo Platform SARL All rights reserved. * * Please look at license.txt in info directory for more license detail. * **************************************************************************/ package org.exoplatform.ecm.webui.component.explorer.search; import org.exoplatform.ecm.webui.tree.selectone.UIOneTaxonomySelector; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Hoang Van Hung * hunghvit@gmail.com * Nov 18, 2008 */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/UITabPaneWithAction.gtmpl", events = @EventConfig(listeners = UICategoryManagerSearch.CloseActionListener.class) ) /** * Choose category when execute search function */ public class UICategoryManagerSearch extends UIContainer implements UIPopupComponent { final static public String[] ACTIONS = { "Close" }; public UICategoryManagerSearch() throws Exception { addChild(UIOneTaxonomySelector.class, null, null); } public String[] getActions() { return ACTIONS; } static public class CloseActionListener extends EventListener<UICategoryManagerSearch> { public void execute(Event<UICategoryManagerSearch> event) throws Exception { UISearchContainer uiSearchContainer = event.getSource().getAncestorOfType(UISearchContainer.class); UIPopupContainer uiPopupContainer = uiSearchContainer.getChild(UIPopupContainer.class); uiPopupContainer.deActivate() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiSearchContainer) ; } } public void activate() { } public void deActivate() { } }
2,113
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UISearchContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UISearchContainer.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.search; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.Session; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.tree.selectone.UIOneTaxonomySelector; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.BasePath; import org.exoplatform.services.cms.impl.DMSConfiguration; import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Dec 27, 2006 * 2:04:24 PM */ @ComponentConfig(lifecycle = UIContainerLifecycle.class) public class UISearchContainer extends UIContainer { final static public String METADATA_POPUP = "MetadataPopup" ; final static public String NODETYPE_POPUP = "NodeTypePopup" ; final static public String SAVEQUERY_POPUP = "SaveQueryPopup" ; final static public String CATEGORY_POPUP = "CategoryPopup" ; public UISearchContainer() throws Exception { addChild(UISimpleSearch.class, null, null); UIPopupContainer popup = addChild(UIPopupContainer.class, null, METADATA_POPUP); popup.getChild(UIPopupWindow.class).setId(METADATA_POPUP + "_Popup"); } public void initMetadataPopup(String fieldName) throws Exception { UIPopupContainer uiPopup = getChild(UIPopupContainer.class) ; uiPopup.getChild(UIPopupWindow.class).setId(fieldName + METADATA_POPUP) ; UISelectPropertyForm uiSelectForm = createUIComponent(UISelectPropertyForm.class, null, null) ; uiSelectForm.setFieldName(fieldName) ; uiPopup.getChild(UIPopupWindow.class).setShowMask(true); uiPopup.activate(uiSelectForm, 500, 450) ; } public void initNodeTypePopup() throws Exception { UIPopupContainer uiPopup = getChild(UIPopupContainer.class) ; uiPopup.getChild(UIPopupWindow.class).setId(NODETYPE_POPUP) ; UINodeTypeSelectForm uiSelectForm = createUIComponent(UINodeTypeSelectForm.class, null, null) ; uiPopup.getChild(UIPopupWindow.class).setShowMask(true); uiPopup.activate(uiSelectForm, 400, 400) ; uiSelectForm.setRenderNodeTypes() ; } public void initCategoryPopup() throws Exception { /* Get UIJCRExplorer object*/ UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); /* Get repository name */ String repository = uiExplorer.getRepositoryName(); DMSConfiguration dmsConfiguration = getApplicationComponent(DMSConfiguration.class); String workspaceName = dmsConfiguration.getConfig().getSystemWorkspace(); NodeHierarchyCreator nodeHierarchyCreator = uiExplorer.getApplicationComponent(NodeHierarchyCreator.class); uiExplorer.setIsHidePopup(true); /* Create Category panel in Search function */ UICategoryManagerSearch uiCategoryManagerSearch = uiExplorer.createUIComponent(UICategoryManagerSearch.class, null, null); UIOneTaxonomySelector uiOneTaxonomySelector = uiCategoryManagerSearch.getChild(UIOneTaxonomySelector.class); uiOneTaxonomySelector.setIsDisable(workspaceName, true); String rootTreePath = nodeHierarchyCreator.getJcrPath(BasePath.TAXONOMIES_TREE_STORAGE_PATH); Session session = uiExplorer.getSessionByWorkspace(workspaceName); Node rootTree = (Node) session.getItem(rootTreePath); NodeIterator childrenIterator = rootTree.getNodes(); while (childrenIterator.hasNext()) { Node childNode = childrenIterator.nextNode(); rootTreePath = childNode.getPath(); break; } uiOneTaxonomySelector.setRootNodeLocation(repository, workspaceName, rootTreePath); uiOneTaxonomySelector.setExceptedNodeTypesInPathPanel(new String[] {Utils.EXO_SYMLINK}); uiOneTaxonomySelector.init(uiExplorer.getSystemProvider()); UIConstraintsForm uiConstraintsForm = findFirstComponentOfType(UIConstraintsForm.class); uiOneTaxonomySelector.setSourceComponent(uiConstraintsForm, new String[] {UIConstraintsForm.CATEGORY_TYPE}); UIPopupContainer UIPopupContainer = getChild(UIPopupContainer.class); UIPopupContainer.getChild(UIPopupWindow.class).setId(CATEGORY_POPUP) ; UIPopupContainer.activate(uiCategoryManagerSearch, 650, 500); } public void initSaveQueryPopup(String statement, boolean isSimpleSearch, String queryType) throws Exception { UIPopupContainer uiPopup = getChild(UIPopupContainer.class) ; uiPopup.getChild(UIPopupWindow.class).setId(SAVEQUERY_POPUP) ; UISaveQueryForm uiSaveQueryForm = createUIComponent(UISaveQueryForm.class, null, null) ; uiSaveQueryForm.setStatement(statement) ; uiSaveQueryForm.setSimpleSearch(isSimpleSearch) ; uiSaveQueryForm.setQueryType(queryType) ; uiPopup.getChild(UIPopupWindow.class).setShowMask(true); uiPopup.activate(uiSaveQueryForm, 420, 200) ; } }
5,835
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UICompareExactlyForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UICompareExactlyForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.search; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.Property; import javax.jcr.Value; import javax.jcr.query.QueryResult; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormSelectBox; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.validator.MandatoryValidator; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * May 6, 2007 * 10:18:56 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/explorer/search/UICompareExactlyForm.gtmpl", events = { @EventConfig(listeners = UICompareExactlyForm.SelectActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UICompareExactlyForm.CancelActionListener.class) } ) public class UICompareExactlyForm extends UIForm implements UIPopupComponent { private static final String FILTER = "filter" ; private static final String RESULT = "result"; private static final String TEMP_RESULT = "tempSel"; private List<String> listValue_ ; public UICompareExactlyForm() throws Exception {} public void activate() {} public void deActivate() {} public void init(String properties, QueryResult result) throws Exception { listValue_ = new ArrayList<String>() ; List<SelectItemOption<String>> opts = new ArrayList<SelectItemOption<String>>(); addUIFormInput(new UIFormStringInput(FILTER, FILTER, null)) ; addUIFormInput(new UIFormSelectBox(RESULT, RESULT, opts).setSize(15).addValidator(MandatoryValidator.class)) ; addUIFormInput(new UIFormSelectBox(TEMP_RESULT, TEMP_RESULT, opts)) ; NodeIterator iter = result.getNodes() ; String[] props = {} ; if(properties.indexOf(",") > -1) props = properties.split(",") ; while(iter.hasNext()) { Node node = iter.nextNode() ; if(props.length > 0) { for(String pro : props) { if(node.hasProperty(pro)) { Property property = node.getProperty(pro) ; setPropertyResult(property) ; } } } else { if(node.hasProperty(properties)) { Property property = node.getProperty(properties) ; setPropertyResult(property) ; } } } Collections.sort(listValue_) ; for(String value : listValue_) { opts.add(new SelectItemOption<String>(value, value)) ; } } public void setPropertyResult(Property property) throws Exception { if(property.getDefinition().isMultiple()) { Value[] values = property.getValues() ; for(Value value : values) { if(!listValue_.contains(value.getString())) listValue_.add(value.getString()) ; } } else { Value value = property.getValue() ; if(!listValue_.contains(value.getString())) listValue_.add(value.getString()) ; } } static public class CancelActionListener extends EventListener<UICompareExactlyForm> { public void execute(Event<UICompareExactlyForm> event) throws Exception { UISearchContainer uiSearchContainer = event.getSource().getAncestorOfType(UISearchContainer.class) ; UIPopupContainer uiPopup = uiSearchContainer.getChild(UIPopupContainer.class) ; uiPopup.deActivate() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiPopup) ; } } static public class SelectActionListener extends EventListener<UICompareExactlyForm> { public void execute(Event<UICompareExactlyForm> event) throws Exception { UICompareExactlyForm uiForm = event.getSource() ; String value = uiForm.getUIFormSelectBox(RESULT).getValue(); UIPopupContainer uiPopupAction = uiForm.getAncestorOfType(UIPopupContainer.class); UISearchContainer uiSearchContainer = uiPopupAction.getParent() ; UIConstraintsForm uiConstraintsForm = uiSearchContainer.findFirstComponentOfType(UIConstraintsForm.class) ; uiConstraintsForm.getUIStringInput(UIConstraintsForm.CONTAIN_EXACTLY).setValue(value) ; uiPopupAction.deActivate() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiPopupAction) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiConstraintsForm) ; } } }
5,685
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UISearchResult.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UISearchResult.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.search; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Comparator; import java.util.Date; import java.util.GregorianCalendar; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Set; import javax.jcr.*; import javax.jcr.query.Query; import javax.jcr.query.QueryManager; import javax.jcr.query.QueryResult; import javax.jcr.query.Row; import org.apache.commons.lang3.StringUtils; import org.exoplatform.ecm.jcr.model.Preference; import org.exoplatform.ecm.webui.component.explorer.UIDocumentContainer; import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace; import org.exoplatform.ecm.webui.component.explorer.UIDrivesArea; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.ecm.webui.component.explorer.sidebar.UISideBar; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.ecms.legacy.search.data.SearchResult; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.portal.webui.workspace.UIPortalApplication; import org.exoplatform.services.cms.BasePath; import org.exoplatform.services.cms.folksonomy.NewFolksonomyService; import org.exoplatform.services.cms.link.LinkManager; import org.exoplatform.services.cms.link.LinkUtils; import org.exoplatform.services.cms.link.NodeFinder; import org.exoplatform.services.cms.taxonomy.TaxonomyService; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.core.ManageableRepository; import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator; import org.exoplatform.services.jcr.impl.core.JCRPath; import org.exoplatform.services.jcr.impl.core.SessionImpl; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.wcm.core.NodetypeConstant; import org.exoplatform.services.wcm.search.QueryCriteria; import org.exoplatform.services.wcm.search.base.AbstractPageList; import org.exoplatform.services.wcm.search.base.NodeSearchFilter; import org.exoplatform.services.wcm.search.base.PageListFactory; import org.exoplatform.services.wcm.search.base.QueryData; import org.exoplatform.services.wcm.search.base.SearchDataCreator; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.wcm.webui.paginator.UILazyPageIterator; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPageIterator; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Tran The Trong * trongtt@gmail.com * Oct 2, 2006 * 16:37:15 * * Edited by : Dang Van Minh * minh.dang@exoplatform.com * Jan 5, 2007 */ @ComponentConfig( template = "app:/groovy/webui/component/explorer/search/UISearchResult.gtmpl", events = { @EventConfig(listeners = UISearchResult.ViewActionListener.class), @EventConfig(listeners = UISearchResult.OpenFolderActionListener.class), @EventConfig(listeners = UISearchResult.SortASCActionListener.class), @EventConfig(listeners = UISearchResult.SortDESCActionListener.class) } ) public class UISearchResult extends UIContainer { /** * Logger. */ private static final Log LOG = ExoLogger.getLogger(UISearchResult.class.getName()); private QueryData queryData_; private long searchTime_ = 0; private UIPageIterator uiPageIterator_; private String iconType = ""; private String iconScore = ""; static private int PAGE_SIZE = 10; private List<String> categoryPathList = new ArrayList<String>(); private String constraintsCondition; private String workspaceName = null; private String currentPath = null; private String keyword =""; private AbstractPageList<RowData> pageList; public List<String> getCategoryPathList() { return categoryPathList; } public void setCategoryPathList(List<String> categoryPathListItem) { categoryPathList = categoryPathListItem; } public String getConstraintsCondition() { return constraintsCondition; } public void setConstraintsCondition(String constraintsConditionItem) { constraintsCondition = constraintsConditionItem; } public UISearchResult() throws Exception { uiPageIterator_ = addChild(UILazyPageIterator.class, null, "UISearchResultPageIterator"); } public void setQuery(String queryStatement, String workspaceName, String language, boolean isSystemSession, String keyword) { queryData_ = new QueryData(queryStatement, workspaceName, language, isSystemSession); this.keyword = keyword; } public long getSearchTime() { return searchTime_; } public void setSearchTime(long time) { this.searchTime_ = time; } public String getIconType() { return iconType; } public String getIconScore() { return iconScore; } public void setIconScore(String iconScore) { this.iconScore = iconScore; } public void setIconType(String iconType) { this.iconType = iconType; } public List getCurrentList() throws Exception { return uiPageIterator_.getCurrentPageData(); } public DateFormat getSimpleDateFormat() { Locale locale = Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale(); return SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT, locale); } public Session getSession() throws Exception { return getAncestorOfType(UIJCRExplorer.class).getTargetSession(); } public Date getDateCreated(Node node) throws Exception{ if (node.hasProperty("exo:dateCreated")) { return node.getProperty("exo:dateCreated").getDate().getTime(); } return new GregorianCalendar().getTime(); } public Node getNodeByPath(String path) throws Exception { try { JCRPath nodePath = ((SessionImpl)getSession()).getLocationFactory().parseJCRPath(path); return (Node)getSession().getItem(nodePath.getAsString(false)); } catch (Exception e) { return null; } } public UIPageIterator getUIPageIterator() { return uiPageIterator_; } public void updateGrid() throws Exception { TemplateService templateService = WCMCoreUtils.getService(TemplateService.class); List<String> documentList = templateService.getDocumentTemplates(); UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); UISideBar uiSideBar = uiExplorer.findFirstComponentOfType(UISideBar.class); Set<String> tagPathsUsedInSearch = null; if (uiSideBar != null && uiSideBar.isRendered() && StringUtils.equals(uiSideBar.getSelectedComp(), UISideBar.UI_TAG_EXPLORER)) { tagPathsUsedInSearch = uiExplorer.getTagPaths(); } QueryCriteria queryCriteria = new QueryCriteria(); queryCriteria.setKeyword(keyword); queryCriteria.setSearchPath(uiExplorer.getCurrentPath()); queryCriteria.setSearchWebpage(false); queryCriteria.setSearchWebContent(true); WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance(); pageList = PageListFactory.createPageList(queryData_.getQueryStatement(), requestContext.getLocale(), queryData_.getWorkSpace(), queryData_.getLanguage_(), queryData_.isSystemSession(), new NodeFilter(categoryPathList, tagPathsUsedInSearch, keyword, documentList), new RowDataCreator(), PAGE_SIZE, 0, queryCriteria); uiPageIterator_.setPageList(pageList); } private static class SearchComparator implements Comparator<RowData> { public static final String SORT_TYPE = "NODE_TYPE"; public static final String SORT_SCORE = "JCR_SCORE"; public static final String ASC = "ASC"; public static final String DESC = "DECS"; private String sortType; private String orderType; public void setSortType(String value) { sortType = value; } public void setOrderType(String value) { orderType = value; } public int compare(RowData row1, RowData row2) { try { if (SORT_TYPE.equals(sortType.trim())) { String s1 = row1.getJcrPrimaryType(); String s2 = row2.getJcrPrimaryType(); if (DESC.equals(orderType.trim())) { return s2.compareTo(s1); } return s1.compareTo(s2); } else if (SORT_SCORE.equals(sortType.trim())) { Long l1 = row1.getJcrScore(); Long l2 = row2.getJcrScore(); if (DESC.equals(orderType.trim())) { return l2.compareTo(l1); } return l1.compareTo(l2); } } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Cannot compare rows", e); } } return 0; } } public String StriptHTML(String s) { String[] targets = {"<div>", "</div>", "<span>", "</span>"}; for (String target : targets) { s = s.replace(target, ""); } return s; } static public class ViewActionListener extends EventListener<UISearchResult> { public void execute(Event<UISearchResult> event) throws Exception { UISearchResult uiSearchResult = event.getSource(); UIJCRExplorer uiExplorer = uiSearchResult.getAncestorOfType(UIJCRExplorer.class); String path = event.getRequestContext().getRequestParameter(OBJECTID); UIApplication uiApp = uiSearchResult.getAncestorOfType(UIApplication.class); String workspaceName = event.getRequestContext().getRequestParameter("workspaceName"); Item item = null; try { Session session = uiExplorer.getSessionByWorkspace(workspaceName); // Check if the path exists NodeFinder nodeFinder = uiSearchResult.getApplicationComponent(NodeFinder.class); item = nodeFinder.getItem(session, path); } catch(PathNotFoundException pa) { uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.path-not-found", null, ApplicationMessage.WARNING)) ; return ; } catch(ItemNotFoundException inf) { uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.path-not-found", null, ApplicationMessage.WARNING)) ; return ; } catch(AccessDeniedException ace) { uiApp.addMessage(new ApplicationMessage("UIDocumentInfo.msg.access-denied", null, ApplicationMessage.WARNING)) ; return ; } catch(RepositoryException e) { if (LOG.isErrorEnabled()) { LOG.error("Repository cannot be found"); } uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.repository-error", null, ApplicationMessage.WARNING)) ; return ; } catch (Exception e) { JCRExceptionManager.process(uiApp, e); return; } if (isInTrash(item)) return; UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class); if(!uiDocumentWorkspace.isRendered()) { uiWorkingArea.getChild(UIDrivesArea.class).setRendered(false); uiWorkingArea.getChild(UIDocumentWorkspace.class).setRendered(true); } uiExplorer.setSelectNode(workspaceName, path) ; uiDocumentWorkspace.getChild(UIDocumentContainer.class).setRendered(true); uiSearchResult.setRendered(false); uiExplorer.refreshExplorer((Node)item, true); } private boolean isInTrash(Item item) throws RepositoryException { return (item instanceof Node) && Utils.isInTrash((Node) item); } } static public class OpenFolderActionListener extends EventListener<UISearchResult> { public void execute(Event<UISearchResult> event) throws Exception { UISearchResult uiSearchResult = event.getSource(); UIJCRExplorer uiExplorer = uiSearchResult.getAncestorOfType(UIJCRExplorer.class); String path = event.getRequestContext().getRequestParameter(OBJECTID); String folderPath = LinkUtils.getParentPath(path); Node node = null; try { node = uiExplorer.getNodeByPath(folderPath, uiExplorer.getTargetSession()); } catch(AccessDeniedException ace) { UIApplication uiApp = uiSearchResult.getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UISearchResult.msg.access-denied", null, ApplicationMessage.WARNING)); return; } catch(PathNotFoundException ace) { UIApplication uiApp = uiSearchResult.getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UISearchResult.msg.access-denied", null, ApplicationMessage.WARNING)); return; } catch(Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Cannot access the node at " + folderPath, e); } } uiExplorer.setSelectNode(node.getSession().getWorkspace().getName(), folderPath); uiExplorer.refreshExplorer(node, true); } } static public class SortASCActionListener extends EventListener<UISearchResult> { public void execute(Event<UISearchResult> event) throws Exception { UISearchResult uiSearchResult = event.getSource(); String objectId = event.getRequestContext().getRequestParameter(OBJECTID); SearchComparator comparator = new SearchComparator(); if (objectId.equals("type")) { uiSearchResult.pageList.setSortByField(Utils.JCR_PRIMARYTYPE); comparator.setSortType(SearchComparator.SORT_TYPE); uiSearchResult.setIconType(Preference.BLUE_DOWN_ARROW); uiSearchResult.setIconScore(""); } else if (objectId.equals("score")) { uiSearchResult.pageList.setSortByField(Utils.JCR_SCORE); comparator.setSortType(SearchComparator.SORT_SCORE); uiSearchResult.setIconScore(Preference.BLUE_DOWN_ARROW); uiSearchResult.setIconType(""); } comparator.setOrderType(SearchComparator.ASC); uiSearchResult.pageList.setComparator(comparator); uiSearchResult.pageList.setOrder("ASC"); uiSearchResult.pageList.sortData(); event.getRequestContext().addUIComponentToUpdateByAjax(uiSearchResult.getParent()); } } static public class SortDESCActionListener extends EventListener<UISearchResult> { public void execute(Event<UISearchResult> event) throws Exception { UISearchResult uiSearchResult = event.getSource() ; String objectId = event.getRequestContext().getRequestParameter(OBJECTID); SearchComparator comparator = new SearchComparator(); if (objectId.equals("type")) { uiSearchResult.pageList.setSortByField(Utils.JCR_PRIMARYTYPE); comparator.setSortType(SearchComparator.SORT_TYPE); uiSearchResult.setIconType(Preference.BLUE_UP_ARROW); uiSearchResult.setIconScore(""); } else if (objectId.equals("score")) { uiSearchResult.pageList.setSortByField(Utils.JCR_SCORE); comparator.setSortType(SearchComparator.SORT_SCORE); uiSearchResult.setIconScore(Preference.BLUE_UP_ARROW); uiSearchResult.setIconType(""); } comparator.setOrderType(SearchComparator.DESC); uiSearchResult.pageList.setComparator(comparator); uiSearchResult.pageList.setOrder("DESC"); uiSearchResult.pageList.sortData(); event.getRequestContext().addUIComponentToUpdateByAjax(uiSearchResult.getParent()); } } public static class NodeFilter implements NodeSearchFilter { private List<String> categoryPathList; private Set<String> tagPaths; private TaxonomyService taxonomyService; private NodeHierarchyCreator nodeHierarchyCreator; private RepositoryService repositoryService; private NewFolksonomyService folksonomyService; private String rootTreePath; private LinkManager linkManager = null; private String keyword =""; private List<String> documentTypes; final static private String CHECK_LINK_MATCH_QUERY1 = "select * from nt:base " + "where jcr:path = '$0' and ( contains(*, '$1') " + "or lower(exo:name) like '%$2%' " + "or lower(exo:title) like '%$2%')"; final static private String CHECK_LINK_MATCH_QUERY2 = "select * from nt:base where jcr:path like '$0/%' " + "and ( contains(*, '$1') or lower(exo:name) like '%$2%' " + "or lower(exo:title) like '%$2%')"; public NodeFilter(List<String> categories, Set<String> tagPaths, String keyword, List<String> documentTypes) { taxonomyService = WCMCoreUtils.getService(TaxonomyService.class); nodeHierarchyCreator = WCMCoreUtils.getService(NodeHierarchyCreator.class); linkManager = WCMCoreUtils.getService(LinkManager.class); repositoryService = WCMCoreUtils.getService(RepositoryService.class); folksonomyService = WCMCoreUtils.getService(NewFolksonomyService.class); rootTreePath = nodeHierarchyCreator.getJcrPath(BasePath.TAXONOMIES_TREE_STORAGE_PATH); categoryPathList = categories; this.tagPaths = tagPaths; this.keyword = keyword; this.documentTypes = documentTypes; } public NodeFilter(List<String> categories, String keyword, List<String> documentTypes) { taxonomyService = WCMCoreUtils.getService(TaxonomyService.class); nodeHierarchyCreator = WCMCoreUtils.getService(NodeHierarchyCreator.class); linkManager = WCMCoreUtils.getService(LinkManager.class); rootTreePath = nodeHierarchyCreator.getJcrPath(BasePath.TAXONOMIES_TREE_STORAGE_PATH); categoryPathList = categories; this.keyword = keyword; this.documentTypes = documentTypes; } public Node filterNodeToDisplay(Node node) { try { if (node == null || node.getPath().contains("/jcr:system/")) return null; if (node != null) { if ((tagPaths != null) && (tagPaths.size() > 0)) { ManageableRepository repository = repositoryService.getCurrentRepository(); String workspaceName = repository.getConfiguration().getDefaultWorkspaceName(); if (node.isNodeType(Utils.EXO_SYMLINK) || ((Node) node.getAncestor(1)).isNodeType(NodetypeConstant.EXO_TRASH_FOLDER)) { return null; } else { for (String tagPath : tagPaths) { List<Node> taggedDocuments = folksonomyService.getAllDocumentsByTag(tagPath, workspaceName, WCMCoreUtils.getUserSessionProvider()); boolean nodeExistsInTag = false; Iterator<Node> nodesIterator = taggedDocuments.iterator(); while (nodesIterator.hasNext() && !nodeExistsInTag) { Node taggedNode = nodesIterator.next(); nodeExistsInTag = taggedNode.isSame(node); } if (!nodeExistsInTag) { return null; } } } } if ((categoryPathList != null) && (categoryPathList.size() > 0)){ for (String categoryPath : categoryPathList) { int index = categoryPath.indexOf("/"); String taxonomyName = categoryPath; String postFixTaxonomy = ""; if (index > 0) { taxonomyName = categoryPath.substring(0, index); postFixTaxonomy = categoryPath.substring(index + 1); } List<String> pathCategoriesList = new ArrayList<String>(); String searchCategory = taxonomyService.getTaxonomyTree(taxonomyName).getPath() + ("".equals(postFixTaxonomy) ? "" : "/" + postFixTaxonomy); Node targetNode = node.isNodeType(Utils.EXO_SYMLINK) ? linkManager.getTarget(node) : node; List<Node> listCategories = taxonomyService.getCategories(targetNode, taxonomyName); for (Node category : listCategories) { pathCategoriesList.add(category.getPath()); } if (pathCategoriesList.contains(searchCategory)) { if (node.isNodeType(Utils.EXO_SYMLINK)) { if (checkTargetMatch(node, keyword)) return node; }else { return node; } } } return null; } else { if (node.isNodeType(Utils.EXO_SYMLINK)) { if (checkTargetMatch(node, keyword)) return node; } else if (node.isNodeType(Utils.NT_RESOURCE)) { return node.getParent(); } else if (node.isNodeType(Utils.EXO_COMMENTS)) { return node.getParent().getParent(); } else { return node; } } } } catch (Exception e) { LOG.warn(e.getMessage()); } return null; } /** * Check a symlink/taxonomylink if its target matches with keyword for searching ...link * @param symlinkNode * @param keyword * @return */ protected boolean checkTargetMatch(Node symlinkNode, String keyword) { String queryStatement = CHECK_LINK_MATCH_QUERY1; Session targetSession; Node target=null; if (keyword ==null || keyword.length()==0 ) return true; if (linkManager==null) { linkManager = WCMCoreUtils.getService(LinkManager.class); } try { if (!linkManager.isLink(symlinkNode)) return true; target = linkManager.getTarget(symlinkNode); if (target == null) return false; targetSession = target.getSession(); queryStatement = StringUtils.replace(queryStatement,"$0", target.getPath()); queryStatement = StringUtils.replace(queryStatement,"$1", keyword.replaceAll("'", "''")); queryStatement = StringUtils.replace(queryStatement,"$2", keyword.replaceAll("'", "''").toLowerCase()); QueryManager queryManager = targetSession.getWorkspace().getQueryManager(); Query query = queryManager.createQuery(queryStatement, Query.SQL); QueryResult queryResult = query.execute(); if ( queryResult.getNodes().getSize()>0 ) return true; if (isFodlderDocument(target)||target.hasNode("jcr:content") ) { queryStatement = CHECK_LINK_MATCH_QUERY2; queryStatement = StringUtils.replace(queryStatement,"$0", target.getPath()); queryStatement = StringUtils.replace(queryStatement,"$1", keyword.replaceAll("'", "''")); queryStatement = StringUtils.replace(queryStatement,"$2", keyword.replaceAll("'", "''").toLowerCase()); query = queryManager.createQuery(queryStatement, Query.SQL); queryResult = query.execute(); return queryResult.getNodes().getSize()>0; }else { return false; } } catch (RepositoryException e) { return false; } } private boolean isFodlderDocument(Node node) throws RepositoryException{ if (!node.isNodeType(NodetypeConstant.NT_UNSTRUCTURED)) return false; for (String documentType : documentTypes) { if (node.getPrimaryNodeType().isNodeType(documentType)) return true; } return false; } } public static class RowDataCreator implements SearchDataCreator<RowData> { public RowData createData(Node node, Row row, SearchResult searchResult) { return new RowData(row, node, searchResult); } } public static class RowData { private String jcrPath = ""; private String repExcerpt = ""; private long jcrScore = 0; private String jcrPrimaryType = ""; public RowData(Row row) { this(row, null, null); } public RowData(Row row, Node node, SearchResult result) { try { jcrPath = node != null ? node.getPath() : row.getValue("jcr:path").getString(); } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn(e.getMessage()); } } try { if(row != null) { Value rowExcerptValue = row.getValue("rep:excerpt(.)"); repExcerpt = rowExcerptValue != null ? rowExcerptValue.getString() : ""; } if(StringUtils.isEmpty(repExcerpt) && result != null) { repExcerpt = result.getExcerpt(); } } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn("Cannot get excerpt of node " + jcrPath, e); } } try { if(row != null) { Value rowScoreValue = row.getValue("jcr:score"); jcrScore = rowScoreValue != null ? rowScoreValue.getLong() : 0; } if(jcrScore == 0 && result != null) { jcrScore = result.getRelevancy(); } } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn("Cannot get excerpt of node " + jcrPath, e); } } try { if(row != null) { Value rowPrimaryTypeValue = row.getValue("jcr:primaryType"); jcrPrimaryType = rowPrimaryTypeValue != null ? rowPrimaryTypeValue.getString() : ""; } if(StringUtils.isEmpty(jcrPrimaryType) && result != null) { jcrPrimaryType = node.getPrimaryNodeType().getName(); } } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn("Cannot get excerpt of node " + jcrPath, e); } } } public String getJcrPath() { return jcrPath; } public void setJcrPath(String jcrPath) { this.jcrPath = jcrPath; } public String getRepExcerpt() { return repExcerpt; } public void setRepExcerpt(String repExcerpt) { this.repExcerpt = repExcerpt; } public long getJcrScore() { return jcrScore; } public void setJcrScore(long jcrScore) { this.jcrScore = jcrScore; } public String getJcrPrimaryType() { return jcrPrimaryType; } public void setJcrPrimaryType(String value) { jcrPrimaryType = value; } public int hashCode() { return (jcrPath == null ? 0 : jcrPath.hashCode()); } public boolean equals(Object o) { if (o == null) return false; if (! (o instanceof RowData)) return false; RowData data = (RowData) o; return (jcrPath == null && data.jcrPath == null || jcrPath.equals(data.jcrPath)); } } }
28,976
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIAllItemsPreferenceForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/UIAllItemsPreferenceForm.java
/* * Copyright (C) 2003-2008 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control; import org.exoplatform.ecm.jcr.model.Preference; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorerPortlet; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.input.UICheckBoxInput; /** * Created by The eXo Platform SARL * Author : Nguyen Anh Vu * anhvurz90@gmail.com * Oct 27, 2009 * 10:22:38 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIFormWithTitle.gtmpl", events = { @EventConfig(listeners = UIAllItemsPreferenceForm.SaveActionListener.class), @EventConfig(listeners = UIAllItemsPreferenceForm.CancelActionListener.class, phase = Phase.DECODE) } ) public class UIAllItemsPreferenceForm extends UIForm implements UIPopupComponent { final static public String FIELD_SHOW_OWNED_BY_USER_DOC = "showOwnedByUser"; final static public String FIELD_SHOW_FAVOURITES = "showFavourites"; final static public String FIELD_SHOW_HIDDENS = "showHiddens"; public UIAllItemsPreferenceForm() throws Exception { addUIFormInput(new UICheckBoxInput(FIELD_SHOW_OWNED_BY_USER_DOC, FIELD_SHOW_OWNED_BY_USER_DOC, null)); addUIFormInput(new UICheckBoxInput(FIELD_SHOW_FAVOURITES, FIELD_SHOW_FAVOURITES, null)); addUIFormInput(new UICheckBoxInput(FIELD_SHOW_HIDDENS, FIELD_SHOW_HIDDENS, null)); } public void activate() { } public void deActivate() { } public void update(Preference pref) { getUICheckBoxInput(FIELD_SHOW_OWNED_BY_USER_DOC).setChecked(pref.isShowOwnedByUserDoc()); getUICheckBoxInput(FIELD_SHOW_FAVOURITES).setChecked(pref.isShowFavouriteDoc()); getUICheckBoxInput(FIELD_SHOW_HIDDENS).setChecked(pref.isShowHiddenDoc()); } static public class SaveActionListener extends EventListener<UIAllItemsPreferenceForm> { public void execute(Event<UIAllItemsPreferenceForm> event) throws Exception { UIAllItemsPreferenceForm uiForm = event.getSource(); UIJCRExplorerPortlet uiExplorerPortlet = uiForm.getAncestorOfType(UIJCRExplorerPortlet.class); UIJCRExplorer uiExplorer = uiExplorerPortlet.findFirstComponentOfType(UIJCRExplorer.class); Preference pref = uiExplorer.getPreference(); pref.setShowOwnedByUserDoc( uiForm.getUICheckBoxInput(FIELD_SHOW_OWNED_BY_USER_DOC).isChecked()); pref.setShowFavouriteDoc( uiForm.getUICheckBoxInput(FIELD_SHOW_FAVOURITES).isChecked()); pref.setShowHiddenDoc( uiForm.getUICheckBoxInput(FIELD_SHOW_HIDDENS).isChecked()); uiExplorer.refreshExplorer(); uiExplorerPortlet.setRenderedChild(UIJCRExplorer.class); } } static public class CancelActionListener extends EventListener<UIAllItemsPreferenceForm> { public void execute(Event<UIAllItemsPreferenceForm> event) throws Exception { UIAllItemsPreferenceForm uiForm = event.getSource(); UIJCRExplorerPortlet uiExplorerPortlet = uiForm.getAncestorOfType(UIJCRExplorerPortlet.class); UIJCRExplorer uiExplorer = uiExplorerPortlet.findFirstComponentOfType(UIJCRExplorer.class); uiExplorer.getChild(UIPopupContainer.class).cancelPopupAction(); } } }
4,400
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIAddressBar.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/UIAddressBar.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control ; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.query.InvalidQueryException; import javax.jcr.query.Query; import org.apache.commons.lang3.StringUtils; import org.exoplatform.ecm.jcr.SimpleSearchValidator; import org.exoplatform.ecm.utils.text.Text; import org.exoplatform.ecm.webui.component.explorer.UIDocumentContainer; import org.exoplatform.ecm.webui.component.explorer.UIDocumentInfo; import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace; import org.exoplatform.ecm.webui.component.explorer.UIDrivesArea; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer.HistoryEntry; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.ecm.webui.component.explorer.search.UISearchResult; import org.exoplatform.ecm.webui.component.explorer.sidebar.UISideBar; import org.exoplatform.services.cms.link.LinkUtils; import org.exoplatform.services.jcr.core.ManageableRepository; import org.exoplatform.services.jcr.ext.common.SessionProvider; import org.exoplatform.services.security.ConversationState; import org.exoplatform.services.security.IdentityConstants; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormHiddenInput; import org.exoplatform.webui.form.UIFormStringInput; /** * Created by The eXo Platform SARL * Author : Tran The Trong * trongtt@exoplatform.com * Aug 2, 2006 */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/explorer/control/UIAddressBar.gtmpl", events = { @EventConfig(listeners = UIAddressBar.ChangeNodeActionListener.class, phase = Phase.DECODE, csrfCheck = false), @EventConfig(listeners = UIAddressBar.BackActionListener.class, phase = Phase.DECODE, csrfCheck = false), @EventConfig(listeners = UIAddressBar.HistoryActionListener.class, phase = Phase.DECODE, csrfCheck = false), @EventConfig(listeners = UIAddressBar.ChangeViewActionListener.class, phase = Phase.DECODE, csrfCheck = false), @EventConfig(listeners = UIAddressBar.SimpleSearchActionListener.class, csrfCheck = false), @EventConfig(listeners = UIAddressBar.RefreshSessionActionListener.class, phase = Phase.DECODE, csrfCheck = false) } ) public class UIAddressBar extends UIForm { public static final Pattern FILE_EXPLORER_URL_SYNTAX = Pattern.compile("([^:/]+):(.*)"); public final static String WS_NAME = "workspaceName"; public final static String FIELD_ADDRESS = "address"; public final static String FIELD_ADDRESS_HIDDEN = "address_hidden"; public final static String ACTION_TAXONOMY = "exo:taxonomyAction"; public final static String EXO_TARGETPATH = "exo:targetPath"; public final static String EXO_TARGETWORKSPACE = "exo:targetWorkspace"; private String selectedViewName_; private String[] arrView_ = {}; /** The Constant MESSAGE_NOT_SUPPORT_KEYWORD. */ private final static String MESSAGE_NOT_SUPPORT_KEYWORD = "UIAddressBar.msg.keyword-not-support"; final static private String FIELD_SIMPLE_SEARCH = "simpleSearch"; final static private String ROOT_SQL_QUERY = "select * from nt:base where (not jcr:primaryType like 'nt:resource') AND" + "((jcr:primaryType like 'exo:symlink' or jcr:primaryType like 'exo:taxonomyLink')" + " OR ( contains(*, '$1') or lower(exo:name) like '%$2%' or lower(exo:summary) like '%$3%' or lower(exo:commentContent) like '%$4%')) order by exo:title ASC"; final static private String SQL_QUERY = "select * from nt:base where (not jcr:primaryType like 'nt:resource') AND jcr:path like '$0/%' AND " + "( (jcr:primaryType like 'exo:symlink' or jcr:primaryType like 'exo:taxonomyLink')" + " OR ( contains(*, '$1') or lower(exo:name) like '%$2%' or lower(exo:summary) like '%$3%' or lower(exo:commentContent) like '%$4%')) order by exo:title ASC"; public UIAddressBar() throws Exception { addUIFormInput(new UIFormStringInput(FIELD_ADDRESS, FIELD_ADDRESS, null)); addUIFormInput(new UIFormStringInput(FIELD_SIMPLE_SEARCH, FIELD_SIMPLE_SEARCH, null).addValidator(SimpleSearchValidator.class)); addUIFormInput(new UIFormHiddenInput(FIELD_ADDRESS_HIDDEN, FIELD_ADDRESS_HIDDEN, null)); } public void setViewList(List<String> viewList) { Collections.sort(viewList); arrView_ = viewList.toArray(new String[viewList.size()]); } public String[] getViewList() { return arrView_; } public void setSelectedViewName(String viewName) { selectedViewName_ = viewName; } public boolean isSelectedView(String viewName) { if(selectedViewName_ != null && selectedViewName_.equals(viewName)) return true; return false; } public String getSelectedViewName() { return selectedViewName_; } public Collection<HistoryEntry> getFullHistory() { UIJCRExplorer uiJCRExplorer = getAncestorOfType(UIJCRExplorer.class) ; return uiJCRExplorer.getHistory() ; } static public class BackActionListener extends EventListener<UIAddressBar> { public void execute(Event<UIAddressBar> event) throws Exception { UIAddressBar uiAddressBar = event.getSource() ; UIJCRExplorer uiExplorer = uiAddressBar.getAncestorOfType(UIJCRExplorer.class) ; UIApplication uiApp = uiExplorer.getAncestorOfType(UIApplication.class) ; try { UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class); if(!uiDocumentWorkspace.isRendered()) { uiWorkingArea.getChild(UIDrivesArea.class).setRendered(false); uiWorkingArea.getChild(UIDocumentWorkspace.class).setRendered(true); uiDocumentWorkspace.setRenderedChild(UIDocumentContainer.class) ; } if(uiExplorer.isViewTag() && !uiExplorer.getCurrentNode().equals(uiExplorer.getRootNode())) { uiExplorer.setSelectRootNode() ; uiExplorer.setIsViewTag(true) ; } else if(uiExplorer.isViewTag() && uiExplorer.getCurrentStateNode() != null) { uiExplorer.setIsViewTag(false) ; uiExplorer.setSelectNode(uiExplorer.getCurrentStatePath()) ; } else { // Retrieve previous node path by refactoring current path and adding the RootPath String CurrentPath = Text.escapeIllegalJcrChars(uiAddressBar.getUIStringInput(FIELD_ADDRESS).getValue()); String RootPath = uiExplorer.getRootPath(); String previousNodePath = RootPath + CurrentPath.substring(0,CurrentPath.lastIndexOf('/')) ; String previousWs = uiExplorer.previousWsName(); uiExplorer.setBackNodePath(previousWs, previousNodePath); if (uiExplorer.hasPaginator(previousNodePath, previousWs)) { event.getRequestContext().addUIComponentToUpdateByAjax(uiExplorer); return; } } uiExplorer.updateAjax(event) ; } catch (AccessDeniedException ade) { uiApp.addMessage(new ApplicationMessage("UIAddressBar.msg.access-denied", null, ApplicationMessage.WARNING)) ; return ; } catch (Exception e) { uiApp.addMessage(new ApplicationMessage("UIJCRExplorer.msg.no-node-history", null, ApplicationMessage.WARNING)) ; return ; } } } static public class ChangeNodeActionListener extends EventListener<UIAddressBar> { public void execute(Event<UIAddressBar> event) throws Exception { UIAddressBar uiAddress = event.getSource() ; String path = Text.escapeIllegalJcrChars(uiAddress.getUIStringInput(FIELD_ADDRESS).getValue()); ((UIFormHiddenInput)uiAddress.getChildById(FIELD_ADDRESS_HIDDEN)).setValue(path); if (path == null || path.trim().length() == 0) path = "/"; UIJCRExplorer uiExplorer = uiAddress.getAncestorOfType(UIJCRExplorer.class) ; uiExplorer.setIsViewTag(false) ; try { String prefix = uiExplorer.getRootPath(); String nodePath = LinkUtils.evaluatePath(LinkUtils.createPath(prefix, path)); if (!nodePath.startsWith(prefix)) { nodePath = prefix; } uiExplorer.setSelectNode(nodePath) ; uiExplorer.setCurrentStatePath(nodePath) ; UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class); if(!uiDocumentWorkspace.isRendered()) { uiDocumentWorkspace.setRendered(true); } else { uiDocumentWorkspace.setRenderedChild(UIDocumentContainer.class); } } catch(Exception e) { UIApplication uiApp = uiAddress.getAncestorOfType(UIApplication.class) ; uiApp.addMessage(new ApplicationMessage("UIAddressBar.msg.path-not-found", null, ApplicationMessage.WARNING)) ; return ; } uiExplorer.updateAjax(event) ; } } static public class HistoryActionListener extends EventListener<UIAddressBar> { public void execute(Event<UIAddressBar> event) throws Exception { UIAddressBar uiAddressBar = event.getSource() ; String fullPath = event.getRequestContext().getRequestParameter(OBJECTID) ; UIJCRExplorer uiExplorer = uiAddressBar.getAncestorOfType(UIJCRExplorer.class) ; String workspace = null; String path = null; try{ Matcher matcher = FILE_EXPLORER_URL_SYNTAX.matcher(fullPath); if (matcher.find()) { workspace = matcher.group(1); path = matcher.group(2); } uiExplorer.setSelectNode(workspace, path) ; uiExplorer.refreshExplorer() ; } catch (AccessDeniedException ade) { UIApplication uiApp = uiAddressBar.getAncestorOfType(UIApplication.class) ; uiApp.addMessage(new ApplicationMessage("UIAddressBar.msg.access-denied", null, ApplicationMessage.WARNING)) ; return ; } } } static public class ChangeViewActionListener extends EventListener<UIAddressBar> { public void execute(Event<UIAddressBar> event) throws Exception { UIAddressBar uiAddressBar = event.getSource() ; UIJCRExplorer uiExplorer = uiAddressBar.getAncestorOfType(UIJCRExplorer.class); UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class); if(!uiDocumentWorkspace.isRendered()) { uiWorkingArea.getChild(UIDrivesArea.class).setRendered(false); uiWorkingArea.getChild(UIDocumentWorkspace.class).setRendered(true); } String viewName = event.getRequestContext().getRequestParameter(OBJECTID); uiAddressBar.setSelectedViewName(viewName); UIActionBar uiActionBar = uiWorkingArea.getChild(UIActionBar.class); uiActionBar.setTabOptions(viewName) ; uiWorkingArea.getChild(UISideBar.class).initComponents(); uiExplorer.findFirstComponentOfType(UIDocumentInfo.class).getExpandedFolders().clear(); uiExplorer.updateAjax(event); } } static public class SimpleSearchActionListener extends EventListener<UIAddressBar> { public void execute(Event<UIAddressBar> event) throws Exception { UIAddressBar uiAddressBar = event.getSource(); UIApplication uiApp = uiAddressBar.getAncestorOfType(UIApplication.class); UIJCRExplorer uiExplorer = uiAddressBar.getAncestorOfType(UIJCRExplorer.class); String text = uiAddressBar.getUIStringInput(FIELD_SIMPLE_SEARCH).getValue(); Node currentNode = uiExplorer.getCurrentNode(); String queryStatement = null; if("/".equals(currentNode.getPath())) { queryStatement = ROOT_SQL_QUERY; }else { queryStatement = StringUtils.replace(SQL_QUERY,"$0",currentNode.getPath()); } String escapedText = org.exoplatform.services.cms.impl.Utils.escapeIllegalCharacterInQuery(text); queryStatement = StringUtils.replace(queryStatement,"$1", escapedText); queryStatement = StringUtils.replace(queryStatement,"$2", escapedText.toLowerCase()); queryStatement = StringUtils.replace(queryStatement,"$3", escapedText.toLowerCase()); queryStatement = StringUtils.replace(queryStatement,"$4", escapedText.toLowerCase()); uiExplorer.removeChildById("ViewSearch"); UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class); if(!uiDocumentWorkspace.isRendered()) { uiWorkingArea.getChild(UIDrivesArea.class).setRendered(false); uiWorkingArea.getChild(UIDocumentWorkspace.class).setRendered(true); } SessionProvider sessionProvider = new SessionProvider(ConversationState.getCurrent()); Session session = sessionProvider.getSession(currentNode.getSession().getWorkspace().getName(), (ManageableRepository)currentNode.getSession().getRepository()); UISearchResult uiSearchResult = uiDocumentWorkspace.getChildById(UIDocumentWorkspace.SIMPLE_SEARCH_RESULT); long startTime = System.currentTimeMillis(); uiSearchResult.setQuery(queryStatement, session.getWorkspace().getName(), Query.SQL, IdentityConstants.SYSTEM.equals(session.getUserID()), text); try { uiSearchResult.updateGrid(); } catch (InvalidQueryException invalidEx) { uiApp.addMessage(new ApplicationMessage(MESSAGE_NOT_SUPPORT_KEYWORD, null, ApplicationMessage.WARNING)); return; } catch (RepositoryException reEx) { uiApp.addMessage(new ApplicationMessage(MESSAGE_NOT_SUPPORT_KEYWORD, null, ApplicationMessage.WARNING)); return; } long time = System.currentTimeMillis() - startTime; uiSearchResult.setSearchTime(time); uiDocumentWorkspace.setRenderedChild(UISearchResult.class); if(!uiDocumentWorkspace.isRendered()) { event.getRequestContext().addUIComponentToUpdateByAjax(uiDocumentWorkspace); } } } static public class RefreshSessionActionListener extends EventListener<UIAddressBar> { public void execute(Event<UIAddressBar> event) throws Exception { UIJCRExplorer uiJCRExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class) ; uiJCRExplorer.getSession().refresh(false) ; uiJCRExplorer.refreshExplorer() ; UIWorkingArea uiWorkingArea = uiJCRExplorer.getChild(UIWorkingArea.class); UIActionBar uiActionBar = uiWorkingArea.getChild(UIActionBar.class); uiActionBar.setTabOptions(event.getSource().getSelectedViewName()) ; UIApplication uiApp = uiJCRExplorer.getAncestorOfType(UIApplication.class) ; String mess = "UIJCRExplorer.msg.refresh-session-success" ; uiApp.addMessage(new ApplicationMessage(mess, null, ApplicationMessage.INFO)) ; } } public static String UppercaseFirstLetters(String str) { boolean prevWasWhiteSp = true; char[] chars = str.toCharArray(); for (int i = 0; i < chars.length; i++) { if (Character.isLetter(chars[i])) { if (prevWasWhiteSp) { chars[i] = Character.toUpperCase(chars[i]); } prevWasWhiteSp = false; } else { prevWasWhiteSp = Character.isWhitespace(chars[i]); } } return new String(chars); } }
17,581
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIActionBar.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/UIActionBar.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control; import org.apache.commons.lang3.StringUtils; import org.exoplatform.commons.utils.CommonsUtils; import org.exoplatform.ecm.jcr.SearchValidator; import org.exoplatform.ecm.webui.component.explorer.*; import org.exoplatform.ecm.webui.component.explorer.popup.actions.UIDocumentForm; import org.exoplatform.ecm.webui.component.explorer.popup.actions.UIDocumentFormController; import org.exoplatform.ecm.webui.component.explorer.search.*; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.cms.BasePath; import org.exoplatform.services.cms.clouddrives.CloudDrive; import org.exoplatform.services.cms.clouddrives.CloudDriveService; import org.exoplatform.services.cms.drives.DriveData; import org.exoplatform.services.cms.drives.impl.ManageDriveServiceImpl; import org.exoplatform.services.cms.queries.QueryService; import org.exoplatform.services.cms.views.ManageViewService; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.organization.OrganizationService; import org.exoplatform.services.organization.User; import org.exoplatform.services.security.IdentityConstants; import org.exoplatform.services.wcm.core.NodeLocation; import org.exoplatform.services.wcm.core.NodetypeConstant; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.RequestContext; import org.exoplatform.web.application.RequireJS; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.ext.UIExtension; import org.exoplatform.webui.ext.UIExtensionManager; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormSelectBox; import org.exoplatform.webui.form.UIFormStringInput; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.query.Query; import javax.portlet.PortletPreferences; import java.util.*; /** * Created by The eXo Platform SARL * Author : Tran The Trong * trongtt@gmail.com * Aug 2, 2006 */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/explorer/control/UIActionBar.gtmpl", events = { @EventConfig(listeners = UIActionBar.SearchActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIActionBar.SimpleSearchActionListener.class), @EventConfig(listeners = UIActionBar.AdvanceSearchActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIActionBar.SavedQueriesActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIActionBar.ChangeTabActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIActionBar.PreferencesActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIActionBar.BackToActionListener.class, phase=Phase.DECODE), @EventConfig(listeners = UIActionBar.ShowDrivesActionListener.class, phase=Phase.DECODE) } ) public class UIActionBar extends UIForm { /** * Logger. */ private static final Log LOG = ExoLogger.getLogger(UIActionBar.class.getName()); private OrganizationService organizationService; private NodeLocation view_ ; private String templateName_ ; //private List<SelectItemOption<String>> tabOptions = new ArrayList<SelectItemOption<String>>() ; private List<String> tabList_ = new ArrayList<String>(); private List<String[]> tabs_ = new ArrayList<String[]>(); private Map<String, String[]> actionInTabs_ = new HashMap<String, String[]>(); private String selectedTabName_; final static private String FIELD_SIMPLE_SEARCH = "simpleSearch"; final static private String FIELD_ADVANCE_SEARCH = "advanceSearch"; final static private String FIELD_SEARCH_TYPE = "searchType"; final static private String FIELD_SQL = "SQL"; final static private String FIELD_XPATH = "xPath"; final static private String ROOT_SQL_QUERY = "select * from nt:base where contains(*, '$1') " + "order by exo:dateCreated DESC, jcr:primaryType DESC"; final static private String SQL_QUERY = "select * from nt:base where jcr:path like '$0/%' and contains(*, '$1') " + "order by jcr:path DESC, jcr:primaryType DESC"; private String backLink; /** The cloud drive service. */ private CloudDriveService cloudDriveService; public UIActionBar() throws Exception { organizationService = CommonsUtils.getService(OrganizationService.class); addChild(new UIFormStringInput(FIELD_SIMPLE_SEARCH, FIELD_SIMPLE_SEARCH, null).addValidator(SearchValidator.class)); List<SelectItemOption<String>> typeOptions = new ArrayList<SelectItemOption<String>>(); typeOptions.add(new SelectItemOption<String>(FIELD_SQL, Query.SQL)); typeOptions.add(new SelectItemOption<String>(FIELD_XPATH, Query.XPATH)); addChild(new UIFormSelectBox(FIELD_SEARCH_TYPE, FIELD_SEARCH_TYPE, typeOptions)); addChild(new UIFormStringInput(FIELD_ADVANCE_SEARCH, FIELD_ADVANCE_SEARCH, null)); cloudDriveService = CommonsUtils.getService(CloudDriveService.class); } public void setTabOptions(String viewName) throws Exception { tabList_ = new ArrayList<String>(); Node viewNode = getApplicationComponent(ManageViewService.class).getViewByName(viewName, WCMCoreUtils.getSystemSessionProvider()); view_ = NodeLocation.getNodeLocationByNode(viewNode); NodeIterator tabs = viewNode.getNodes(); while (tabs.hasNext()) { Node tab = tabs.nextNode(); if(!tabList_.contains(tab.getName())) tabList_.add(tab.getName()); setListButton(tab.getName()); } setSelectedTab(tabList_.get(0)); String template = viewNode.getProperty("exo:template").getString(); templateName_ = template.substring(template.lastIndexOf("/") + 1); UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); uiExplorer.setRenderTemplate(template); } public boolean hasBackButton() { String newLink = getAncestorOfType(UIJCRExplorerPortlet.class).getBacktoValue(); if (newLink != null && newLink.length()>0) backLink = newLink; return backLink != null; } public String getBackLink() { return getAncestorOfType(UIJCRExplorerPortlet.class).getBacktoValue(); } public String getTemplateName() { return templateName_; } private void setListButton(String tabName) throws PathNotFoundException, RepositoryException { Node tabNode = NodeLocation.getNodeByLocation(view_).getNode(tabName); if(tabNode.hasProperty("exo:buttons")) { String buttons = tabNode.getProperty("exo:buttons").getString(); String[] buttonsInTab = StringUtils.split(buttons, ";"); Set<String> bt = new HashSet<String>(); //get all buttons in tab for (String b : buttonsInTab) { b = b.trim(); b = b.substring(0, 1).toUpperCase() + b.substring(1); bt.add(b); } //sort the buttons by UIExtension sorting order List<String> sortedButtons = new ArrayList<String>(); UIExtensionManager manager = getApplicationComponent(UIExtensionManager.class); List<UIExtension> extensions = manager.getUIExtensions(ManageViewService.EXTENSION_TYPE); for(UIExtension e : extensions) { if (bt.contains(e.getName())) { sortedButtons.add(e.getName().trim()); } } buttonsInTab = sortedButtons.toArray(new String[]{}); actionInTabs_.put(tabName, buttonsInTab); tabs_.add(buttonsInTab); } } public String[] getActionInTab(String tabName) { return actionInTabs_.get(tabName); } public void setSelectedTab(String tabName) { selectedTabName_ = tabName; } public boolean isDirectlyDrive() { PortletPreferences portletPref = getAncestorOfType(UIJCRExplorerPortlet.class).getPortletPreferences(); String usecase = portletPref.getValue("usecase", "").trim(); if ("selection".equals(usecase)) { return false; } return true; } public String getSelectedTab() throws Exception { if(selectedTabName_ == null || selectedTabName_.length() == 0) { setTabOptions(tabList_.get(0)); return tabList_.get(0); } return selectedTabName_; } public List<String> getTabList() { return tabList_; } public List<Query> getSavedQueries() throws Exception { String userName = Util.getPortalRequestContext().getRemoteUser(); return getApplicationComponent(QueryService.class).getQueries(userName, WCMCoreUtils.getSystemSessionProvider()); } public synchronized UIComponent getUIAction(String action) { try { UIExtensionManager manager = getApplicationComponent(UIExtensionManager.class); Map<String, Object> context = new HashMap<String, Object>(); UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class); Node currentNode = uiExplorer.getCurrentNode(); context.put(UIJCRExplorer.class.getName(), uiExplorer); context.put(Node.class.getName(), currentNode); return manager.addUIExtension(ManageViewService.EXTENSION_TYPE, action, context, this); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("An error occurs while checking the action", e); } } return null; } public boolean isActionAvailable(String tabName) { List<UIComponent> listActions = new ArrayList<UIComponent>(); for(String action : getActionInTab(tabName)) { UIComponent uicomp = getUIAction(action); if(uicomp != null) listActions.add(uicomp); } if(listActions.size() > 0) return true; return false; } static public class SearchActionListener extends EventListener<UIActionBar> { public void execute(Event<UIActionBar> event) throws Exception { UIJCRExplorer uiJCRExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); UIPopupContainer UIPopupContainer = uiJCRExplorer.getChild(UIPopupContainer.class); UIPopupContainer.activate(UIECMSearch.class, 700); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } } static public class SimpleSearchActionListener extends EventListener<UIActionBar> { public void execute(Event<UIActionBar> event) throws Exception { UIActionBar uiForm = event.getSource(); UIJCRExplorer uiExplorer = uiForm.getAncestorOfType(UIJCRExplorer.class); String text = uiForm.getUIStringInput(FIELD_SIMPLE_SEARCH).getValue(); Node currentNode = uiExplorer.getCurrentNode(); String queryStatement = null; if("/".equals(currentNode.getPath())) { queryStatement = ROOT_SQL_QUERY; }else { queryStatement = StringUtils.replace(SQL_QUERY,"$0",currentNode.getPath()); } queryStatement = StringUtils.replace(queryStatement,"$1", text.replaceAll("'", "''")); uiExplorer.removeChildById("ViewSearch"); UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class); if(!uiDocumentWorkspace.isRendered()) { uiWorkingArea.getChild(UIDrivesArea.class).setRendered(false); uiWorkingArea.getChild(UIDocumentWorkspace.class).setRendered(true); uiDocumentWorkspace.setRenderedChild(UIDocumentContainer.class) ; } UISearchResult uiSearchResult = uiDocumentWorkspace.getChildById(UIDocumentWorkspace.SIMPLE_SEARCH_RESULT); long startTime = System.currentTimeMillis(); uiSearchResult.setQuery(queryStatement, currentNode.getSession().getWorkspace().getName(), Query.SQL, IdentityConstants.SYSTEM.equals(WCMCoreUtils.getRemoteUser()), null); uiSearchResult.updateGrid(); long time = System.currentTimeMillis() - startTime; uiSearchResult.setSearchTime(time); uiDocumentWorkspace.setRenderedChild(UISearchResult.class); } } static public class AdvanceSearchActionListener extends EventListener<UIActionBar> { public void execute(Event<UIActionBar> event) throws Exception { UIJCRExplorer uiJCRExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); UIPopupContainer UIPopupContainer = uiJCRExplorer.getChild(UIPopupContainer.class); UIECMSearch uiECMSearch = event.getSource().createUIComponent(UIECMSearch.class, null, null); UIContentNameSearch contentNameSearch = uiECMSearch.findFirstComponentOfType(UIContentNameSearch.class); String currentNodePath = uiJCRExplorer.getCurrentNode().getPath(); contentNameSearch.setLocation(currentNodePath); UISimpleSearch uiSimpleSearch = uiECMSearch.findFirstComponentOfType(UISimpleSearch.class); uiSimpleSearch.getUIFormInputInfo(UISimpleSearch.NODE_PATH).setValue(currentNodePath); UIPopupContainer.activate(uiECMSearch, 700, 500); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } } static public class BackToActionListener extends EventListener<UIActionBar> { public void execute(Event<UIActionBar> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class); UIDocumentFormController uiDocumentFormController = uiDocumentWorkspace.getChild(UIDocumentFormController.class); String backLink = event.getSource().getBackLink(); if (uiDocumentFormController != null) { UIDocumentForm uiDocument = uiDocumentFormController.getChild(UIDocumentForm.class); if (uiDocument!=null) { uiDocument.releaseLock(); } uiDocumentWorkspace.removeChild(UIDocumentFormController.class); } else uiExplorer.cancelAction(); RequireJS requireJS = event.getRequestContext().getJavascriptManager().getRequireJS(); requireJS.require("SHARED/ecm-utils", "ecmutil").addScripts("ecmutil.ECMUtils.ajaxRedirect('" + backLink + "');"); } } static public class SavedQueriesActionListener extends EventListener<UIActionBar> { public void execute(Event<UIActionBar> event) throws Exception { UIJCRExplorer uiJCRExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); UIPopupContainer UIPopupContainer = uiJCRExplorer.getChild(UIPopupContainer.class); UISavedQuery uiSavedQuery = event.getSource().createUIComponent(UISavedQuery.class, null, null); uiSavedQuery.setIsQuickSearch(true); uiSavedQuery.updateGrid(1); UIPopupContainer.activate(uiSavedQuery, 700, 400); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } } static public class ChangeTabActionListener extends EventListener<UIActionBar> { public void execute(Event<UIActionBar> event) throws Exception { UIActionBar uiActionBar = event.getSource(); String selectedTabName = event.getRequestContext().getRequestParameter(OBJECTID); uiActionBar.setSelectedTab(selectedTabName); event.getRequestContext().addUIComponentToUpdateByAjax(uiActionBar.getAncestorOfType(UIJCRExplorer.class)); } } static public class PreferencesActionListener extends EventListener<UIActionBar> { public void execute(Event<UIActionBar> event) throws Exception { UIActionBar uiActionBar = event.getSource(); UIJCRExplorer uiJCRExplorer = uiActionBar.getAncestorOfType(UIJCRExplorer.class); UIPopupContainer popupAction = uiJCRExplorer.getChild(UIPopupContainer.class); UIPreferencesForm uiPrefForm = popupAction.activate(UIPreferencesForm.class,600) ; uiPrefForm.update(uiJCRExplorer.getPreference()) ; event.getRequestContext().addUIComponentToUpdateByAjax(popupAction) ; } } static public class ShowDrivesActionListener extends EventListener<UIActionBar> { public void execute(Event<UIActionBar> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDrivesArea uiDriveArea = uiWorkingArea.getChild(UIDrivesArea.class); if (uiDriveArea.isRendered()) { uiDriveArea.setRendered(false); uiWorkingArea.getChild(UIDocumentWorkspace.class).setRendered(true); } else { uiDriveArea.setRendered(true); uiWorkingArea.getChild(UIDocumentWorkspace.class).setRendered(false); } event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingArea) ; } } public String getDriveLabel() { RequestContext context = RequestContext.getCurrentInstance(); ResourceBundle res = context.getApplicationResourceBundle(); DriveData drive = getAncestorOfType(UIJCRExplorer.class).getDriveData(); String driveName = drive.getName(); String driveLabel = ""; try { if(ManageDriveServiceImpl.GROUPS_DRIVE_NAME.equals(driveName) || driveName.startsWith(".")) { // Groups drive RepositoryService repoService = WCMCoreUtils.getService(RepositoryService.class); NodeHierarchyCreator nodeHierarchyCreator = WCMCoreUtils.getService(NodeHierarchyCreator.class); String groupPath = nodeHierarchyCreator.getJcrPath(BasePath.CMS_GROUPS_PATH); Node groupNode = (Node)WCMCoreUtils.getSystemSessionProvider().getSession( repoService.getCurrentRepository().getConfiguration().getDefaultWorkspaceName(), repoService.getCurrentRepository()).getItem( groupPath + drive.getName().replace(".", "/")); driveLabel = groupNode.getProperty(NodetypeConstant.EXO_LABEL).getString(); } else if(ManageDriveServiceImpl.USER_DRIVE_NAME.equals(driveName)) { // User Documents drive String userDisplayName = ""; String driveLabelKey = "Drives.label.UserDocuments"; String userIdPath = drive.getParameters().get(ManageDriveServiceImpl.DRIVE_PARAMATER_USER_ID); String userId = userIdPath != null ? userIdPath.substring(userIdPath.lastIndexOf("/") + 1) : null; if(StringUtils.isNotEmpty(userId)) { userDisplayName = userId; User user = organizationService.getUserHandler().findUserByName(userId); if(user != null) { userDisplayName = user.getDisplayName(); } } try { driveLabel = res.getString(driveLabelKey).replace("{0}", userDisplayName); } catch(MissingResourceException mre) { LOG.error("Cannot get resource string " + driveLabel + " : " + mre.getMessage(), mre); driveLabel = userDisplayName; } } else { // Others drives try { CloudDrive cloudDrives = cloudDriveService.findDrive(drive.getWorkspace(), drive.getHomePath()); if (cloudDrives != null) { // Cloud drives driveLabel = cloudDrives.getTitle(); } else { String driveLabelKey = "Drives.label." + driveName.replace(".", "").replace(" ", ""); try { driveLabel = res.getString(driveLabelKey); } catch (MissingResourceException ex) { // driveLabel = driveName.replace(".", "/"); } } } catch (RepositoryException e) { LOG.warn("Cannot find clouddrive " + drive.getHomePath() + " in " + drive.getWorkspace(), e); driveLabel = driveName.replace(".", " / "); } } } catch(Exception e) { driveLabel = driveName.replace(".", " / "); } return driveLabel; } }
21,635
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIControl.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/UIControl.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control ; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; /** * Created by The eXo Platform SARL * Author : Hung Nguyen * nguyenkequanghung@yahoo.com * oct 5, 2006 */ @ComponentConfig( lifecycle = UIContainerLifecycle.class ) public class UIControl extends UIContainer { public UIControl() throws Exception { addChild(UIAddressBar.class, null, null) ; /*addChild(UIActionBar.class, null, null) ;*/ } }
1,323
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIPreferencesForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/UIPreferencesForm.java
/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control; import java.io.Writer; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; import org.exoplatform.ecm.jcr.model.Preference; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorerPortlet; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.wcm.core.NodetypeConstant; import org.exoplatform.web.application.RequestContext; import org.exoplatform.web.security.csrf.CSRFTokenUtil; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.core.lifecycle.UIFormLifecycle; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.UIFormSelectBox; import org.exoplatform.webui.form.input.UICheckBoxInput; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletResponse; /** * Created by The eXo Platform SARL * Author : Chien Nguyen * chien.nguyen@exoplatform.org * July 28, 2010 * 14:07:15 PM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/explorer/UIPreferencesForm.gtmpl", events = { @EventConfig(listeners = UIPreferencesForm.SaveActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPreferencesForm.AdvanceActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPreferencesForm.BackActionListener.class) }) public class UIPreferencesForm extends UIForm implements UIPopupComponent { final static public String FIELD_ENABLESTRUCTURE = "enableStructure"; final static public String FIELD_SHOWSIDEBAR = "showSideBar"; final static public String FIELD_SHOWNONDOCUMENT = "showNonDocument"; final static public String FIELD_SHOWREFDOCUMENTS = "showRefDocuments"; final static public String FIELD_SHOW_HIDDEN_NODE = "showHiddenNode"; final static public String FIELD_SHOW_ITEMS_BY_USER = "showItemsByUserInTimeline"; final static public String FIELD_ENABLE_DRAG_AND_DROP = "enableDragAndDrop"; final static public String FIELD_SHORTBY = "sortBy"; final static public String FIELD_ORDERBY = "order"; final static public String FIELD_PROPERTY = "property"; final static public String NODES_PER_PAGE = "nodesPerPage"; final static public String FIELD_QUERY_TYPE = "queryType"; private boolean advancePreferences = false; public UIPreferencesForm() throws Exception { RequestContext context = RequestContext.getCurrentInstance(); ResourceBundle res = context.getApplicationResourceBundle(); String sortByNodeName; String sortByNodeType; String sortByCreatedDate; String sortByModifiedDate; String ascendingOrder; String descendingOrder; String SQLQuery; String XPathQuery; try { sortByNodeName = res.getString("UIPreferencesForm.label." + NodetypeConstant.SORT_BY_NODENAME); sortByNodeType = res.getString("UIPreferencesForm.label." + NodetypeConstant.SORT_BY_NODETYPE); sortByCreatedDate = res.getString("UIPreferencesForm.label." + NodetypeConstant.SORT_BY_CREATED_DATE); sortByModifiedDate = res.getString("UIPreferencesForm.label." + NodetypeConstant.SORT_BY_MODIFIED_DATE); ascendingOrder = res.getString("UIPreferencesForm.label." + Preference.ASCENDING_ORDER); descendingOrder = res.getString("UIPreferencesForm.label." + Preference.DESCENDING_ORDER); SQLQuery = res.getString("UIPreferencesForm.label." + Preference.SQL_QUERY); XPathQuery = res.getString("UIPreferencesForm.label." + Preference.XPATH_QUERY); } catch (Exception e) { sortByNodeName = NodetypeConstant.SORT_BY_NODENAME; sortByNodeType = NodetypeConstant.SORT_BY_NODETYPE; sortByCreatedDate = NodetypeConstant.SORT_BY_CREATED_DATE; sortByModifiedDate = NodetypeConstant.SORT_BY_MODIFIED_DATE; ascendingOrder = Preference.ASCENDING_ORDER; descendingOrder = Preference.DESCENDING_ORDER; SQLQuery = Preference.SQL_QUERY; XPathQuery = Preference.XPATH_QUERY; } List<SelectItemOption<String>> sortOptions = new ArrayList<SelectItemOption<String>>(); sortOptions.add(new SelectItemOption<String>(sortByNodeName, NodetypeConstant.SORT_BY_NODENAME)); sortOptions.add(new SelectItemOption<String>(sortByNodeType, NodetypeConstant.SORT_BY_NODETYPE)); sortOptions.add(new SelectItemOption<String>(sortByCreatedDate, NodetypeConstant.SORT_BY_CREATED_DATE)); sortOptions.add(new SelectItemOption<String>(sortByModifiedDate, NodetypeConstant.SORT_BY_MODIFIED_DATE)); List<SelectItemOption<String>> orderOption = new ArrayList<SelectItemOption<String>>(); orderOption.add(new SelectItemOption<String>(ascendingOrder, Preference.ASCENDING_ORDER)); orderOption.add(new SelectItemOption<String>(descendingOrder, Preference.DESCENDING_ORDER)); List<SelectItemOption<String>> nodesPerPagesOptions = new ArrayList<SelectItemOption<String>>(); nodesPerPagesOptions.add(new SelectItemOption<String>("5", "5")); nodesPerPagesOptions.add(new SelectItemOption<String>("10", "10")); nodesPerPagesOptions.add(new SelectItemOption<String>("15", "15")); nodesPerPagesOptions.add(new SelectItemOption<String>("20", "20")); nodesPerPagesOptions.add(new SelectItemOption<String>("30", "30")); nodesPerPagesOptions.add(new SelectItemOption<String>("40", "40")); nodesPerPagesOptions.add(new SelectItemOption<String>("50", "50")); List<SelectItemOption<String>> queryOption = new ArrayList<SelectItemOption<String>>(); queryOption.add(new SelectItemOption<String>(SQLQuery, Preference.SQL_QUERY)); queryOption.add(new SelectItemOption<String>(XPathQuery, Preference.XPATH_QUERY)); addUIFormInput(new UICheckBoxInput(FIELD_ENABLESTRUCTURE, FIELD_ENABLESTRUCTURE, null)); addUIFormInput(new UICheckBoxInput(FIELD_SHOWSIDEBAR, FIELD_SHOWSIDEBAR, null)); addUIFormInput(new UICheckBoxInput(FIELD_SHOWNONDOCUMENT, FIELD_SHOWNONDOCUMENT, null)); addUIFormInput(new UICheckBoxInput(FIELD_SHOWREFDOCUMENTS, FIELD_SHOWREFDOCUMENTS, null)); addUIFormInput(new UICheckBoxInput(FIELD_SHOW_HIDDEN_NODE, FIELD_SHOW_HIDDEN_NODE, null)); addUIFormInput(new UICheckBoxInput(FIELD_SHOW_ITEMS_BY_USER, FIELD_SHOW_ITEMS_BY_USER, null)); addUIFormInput(new UICheckBoxInput(FIELD_ENABLE_DRAG_AND_DROP, FIELD_ENABLE_DRAG_AND_DROP, null)); addUIFormInput(new UIFormSelectBox(FIELD_QUERY_TYPE, FIELD_QUERY_TYPE, queryOption)); addUIFormInput(new UIFormSelectBox(FIELD_SHORTBY, FIELD_SHORTBY, sortOptions)); addUIFormInput(new UIFormSelectBox(FIELD_ORDERBY, FIELD_ORDERBY, orderOption)); addUIFormInput(new UIFormSelectBox(NODES_PER_PAGE, NODES_PER_PAGE, nodesPerPagesOptions)); } public boolean isAdvancePreferences() { return advancePreferences; } public void setAdvancePreferences(boolean adPreferences) { advancePreferences = adPreferences; } public void begin() throws Exception { WebuiRequestContext context = WebuiRequestContext.getCurrentInstance(); String b = context.getURLBuilder().createURL(this, null, null); Writer writer = context.getWriter(); writer.append("<form class=\"") .append(getId()) .append("\" id=\"") .append(getId()) .append("\" action=\"") .append(b) .append('\"'); if (getSubmitAction() != null) writer.append(" onsubmit=\"").append(getSubmitAction()).append("\""); if (isMultipart()) writer.append(" enctype=\"multipart/form-data\""); writer.append(" method=\"post\">"); writer.append("<div><input type=\"hidden\" name=\"") .append(ACTION) .append("\" value=\"\"/>"); writer.append("<input type=\"hidden\" name=\"").append(CSRFTokenUtil.CSRF_TOKEN).append("\" value=\""); writer.append(CSRFTokenUtil.getToken(org.exoplatform.webui.Util.getRequest())); writer.append("\"/></div>"); } public void activate() { } public void deActivate() { } public void update(Preference pref) { getUICheckBoxInput(FIELD_ENABLESTRUCTURE).setChecked(pref.isJcrEnable()); UICheckBoxInput showSideBar = getUICheckBoxInput(FIELD_SHOWSIDEBAR); showSideBar.setChecked(pref.isShowSideBar()); showSideBar.setDisabled(!this.getAncestorOfType(UIJCRExplorerPortlet.class).isShowSideBar()); getUICheckBoxInput(FIELD_SHOWNONDOCUMENT).setChecked(pref.isShowNonDocumentType()); getUICheckBoxInput(FIELD_SHOWREFDOCUMENTS).setChecked(pref.isShowPreferenceDocuments()); getUICheckBoxInput(FIELD_SHOW_HIDDEN_NODE).setChecked(pref.isShowHiddenNode()); getUICheckBoxInput(FIELD_SHOW_ITEMS_BY_USER).setChecked(pref.isShowItemsByUser()); getUICheckBoxInput(FIELD_ENABLE_DRAG_AND_DROP).setChecked(pref.isEnableDragAndDrop()); getUIFormSelectBox(FIELD_SHORTBY).setValue(pref.getSortType()); getUIFormSelectBox(FIELD_ORDERBY).setValue(pref.getOrder()); getUIFormSelectBox(NODES_PER_PAGE).setValue(Integer.toString(pref.getNodesPerPage())); getUIFormSelectBox(FIELD_QUERY_TYPE).setValue(pref.getQueryType()); } private Cookie createNewCookie(String cookieName, String cookieValue) { String userId = Util.getPortalRequestContext().getRemoteUser(); cookieName += userId; return new Cookie(cookieName, cookieValue); } private void savePreferenceInCookies() { HttpServletResponse response = Util.getPortalRequestContext().getResponse(); if (getUICheckBoxInput(FIELD_ENABLESTRUCTURE).isChecked()) response.addCookie(createNewCookie(Preference.PREFERENCE_ENABLESTRUCTURE, "true")); else response.addCookie(createNewCookie(Preference.PREFERENCE_ENABLESTRUCTURE, "false")); if (getUICheckBoxInput(FIELD_SHOWSIDEBAR).isChecked()) response.addCookie(createNewCookie(Preference.PREFERENCE_SHOWSIDEBAR, "true")); else response.addCookie(createNewCookie(Preference.PREFERENCE_SHOWSIDEBAR, "false")); if (getUICheckBoxInput(FIELD_SHOWNONDOCUMENT).isChecked()) response.addCookie(createNewCookie(Preference.SHOW_NON_DOCUMENTTYPE, "true")); else response.addCookie(createNewCookie(Preference.SHOW_NON_DOCUMENTTYPE, "false")); if (getUICheckBoxInput(FIELD_SHOWREFDOCUMENTS).isChecked()) response.addCookie(createNewCookie(Preference.PREFERENCE_SHOWREFDOCUMENTS, "true")); else response.addCookie(createNewCookie(Preference.PREFERENCE_SHOWREFDOCUMENTS, "false")); if (getUICheckBoxInput(FIELD_SHOW_HIDDEN_NODE).isChecked()) response.addCookie(createNewCookie(Preference.PREFERENCE_SHOW_HIDDEN_NODE, "true")); else response.addCookie(createNewCookie(Preference.PREFERENCE_SHOW_HIDDEN_NODE, "false")); if (getUICheckBoxInput(FIELD_ENABLE_DRAG_AND_DROP).isChecked()) response.addCookie(createNewCookie(Preference.ENABLE_DRAG_AND_DROP, "true")); else response.addCookie(createNewCookie(Preference.ENABLE_DRAG_AND_DROP, "false")); response.addCookie(createNewCookie(Preference.PREFERENCE_QUERY_TYPE, getUIFormSelectBox(FIELD_QUERY_TYPE).getValue())); response.addCookie(createNewCookie(Preference.PREFERENCE_SORT_BY, getUIFormSelectBox(FIELD_SHORTBY).getValue())); response.addCookie(createNewCookie(Preference.PREFERENCE_ORDER_BY, getUIFormSelectBox(FIELD_ORDERBY).getValue())); response.addCookie(createNewCookie(Preference.NODES_PER_PAGE, getUIFormSelectBox(NODES_PER_PAGE).getValue())); } static public class SaveActionListener extends EventListener<UIPreferencesForm> { public void execute(Event<UIPreferencesForm> event) throws Exception { UIPreferencesForm uiForm = event.getSource(); UIJCRExplorerPortlet explorerPorltet = uiForm.getAncestorOfType(UIJCRExplorerPortlet.class); UIJCRExplorer uiExplorer = explorerPorltet.findFirstComponentOfType(UIJCRExplorer.class); Preference pref = uiExplorer.getPreference(); pref.setJcrEnable(uiForm.getUICheckBoxInput(FIELD_ENABLESTRUCTURE).isChecked()); pref.setShowSideBar(uiForm.getUICheckBoxInput(FIELD_SHOWSIDEBAR).isChecked()); pref.setShowNonDocumentType(uiForm.getUICheckBoxInput(FIELD_SHOWNONDOCUMENT).isChecked()); pref.setShowPreferenceDocuments(uiForm.getUICheckBoxInput(FIELD_SHOWREFDOCUMENTS).isChecked()); pref.setShowHiddenNode(uiForm.getUICheckBoxInput(FIELD_SHOW_HIDDEN_NODE).isChecked()); if (pref.isShowHiddenNode()) { uiExplorer.getAllItemFilterMap().add(NodetypeConstant.HIDDEN); } else { uiExplorer.getAllItemFilterMap().remove(NodetypeConstant.HIDDEN); } pref.setEnableDragAndDrop(uiForm.getUICheckBoxInput(FIELD_ENABLE_DRAG_AND_DROP).isChecked()); pref.setSortType(uiForm.getUIFormSelectBox(FIELD_SHORTBY).getValue()); pref.setQueryType(uiForm.getUIFormSelectBox(FIELD_QUERY_TYPE).getValue()); pref.setOrder(uiForm.getUIFormSelectBox(FIELD_ORDERBY).getValue()); pref.setNodesPerPage(Integer.parseInt(uiForm.getUIFormSelectBox(NODES_PER_PAGE).getValue())); uiForm.savePreferenceInCookies(); uiExplorer.setPreferencesSaved(true); uiExplorer.refreshExplorer(); explorerPorltet.setRenderedChild(UIJCRExplorer.class); uiExplorer.updateAjax(event); } } static public class BackActionListener extends EventListener<UIPreferencesForm> { public void execute(Event<UIPreferencesForm> event) throws Exception { UIPreferencesForm uiForm = event.getSource(); UIJCRExplorerPortlet explorerPorltet = uiForm.getAncestorOfType(UIJCRExplorerPortlet.class); UIJCRExplorer uiExplorer = explorerPorltet.findFirstComponentOfType(UIJCRExplorer.class); uiExplorer.getChild(UIPopupContainer.class).cancelPopupAction(); } } static public class AdvanceActionListener extends EventListener<UIPreferencesForm> { public void execute(Event<UIPreferencesForm> event) throws Exception { UIPreferencesForm uiPreferencesForm = event.getSource(); if (uiPreferencesForm.isAdvancePreferences()) { uiPreferencesForm.setAdvancePreferences(false); } else { uiPreferencesForm.setAdvancePreferences(true); } event.getRequestContext().addUIComponentToUpdateByAjax(uiPreferencesForm.getParent()); } } }
15,447
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UploadActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/action/UploadActionComponent.java
/* * Copyright (C) 2003-2009 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control.action; import java.util.Arrays; import java.util.List; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.control.filter.CanAddNodeFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotInTrashFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotNtFileFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotTrashHomeNodeFilter; import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener; import org.exoplatform.ecm.webui.component.explorer.upload.UIUploadManager; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; import org.exoplatform.webui.ext.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 6 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = UploadActionComponent.UploadActionListener.class) } ) public class UploadActionComponent extends UIAbstractManagerComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[]{new IsNotNtFileFilter(), new CanAddNodeFilter(), new IsNotLockedFilter(), new IsCheckedOutFilter(), new IsNotTrashHomeNodeFilter(), new IsNotInTrashFilter()}); @UIExtensionFilters public List<UIExtensionFilter> getFilters() { return FILTERS; } public static void upload(Event<? extends UIComponent> event, UIJCRExplorer uiExplorer) throws Exception { UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class); UIUploadManager uiUploadManager = event.getSource().createUIComponent(UIUploadManager.class, null, null); UIPopupContainer.activate(uiUploadManager, 600, 250); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } public static class UploadActionListener extends UIActionBarActionListener<UploadActionComponent> { public void processEvent(Event<UploadActionComponent> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); upload(event, uiExplorer); } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return null; } }
3,997
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
ManagePublicationsActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/action/ManagePublicationsActionComponent.java
/* * Copyright (C) 2003-2009 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control.action; import java.util.Arrays; import java.util.List; import javax.jcr.Node; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.control.UIActionBar; import org.exoplatform.ecm.webui.component.explorer.control.filter.CanRemoveNodeFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.CanSetPropertyFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.HasPublicationLifecycleFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsDocumentFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotEditingDocumentFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotRootNodeFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotIgnoreVersionNodeFilter; import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener; import org.exoplatform.ecm.webui.component.explorer.popup.admin.UIActivePublication; import org.exoplatform.ecm.webui.component.explorer.popup.admin.UIPublicationManager; import org.exoplatform.services.ecm.publication.PublicationPresentationService; import org.exoplatform.services.ecm.publication.PublicationService; import org.exoplatform.services.ecm.publication.plugins.webui.UIPublicationLogList; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; import org.exoplatform.webui.form.UIForm; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 6 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = ManagePublicationsActionComponent.ManagePublicationsActionListener.class) } ) public class ManagePublicationsActionComponent extends UIComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] { new HasPublicationLifecycleFilter(), new IsDocumentFilter("UIActionBar.msg.manage-publication.not-supported-nodetype"), new IsNotRootNodeFilter("UIActionBar.msg.cannot-enable-publication-rootnode"), new CanSetPropertyFilter("UIActionBar.msg.access-denied"), new IsNotLockedFilter(), new IsNotIgnoreVersionNodeFilter(), new IsNotEditingDocumentFilter(), new IsCheckedOutFilter()}); @UIExtensionFilters public List<UIExtensionFilter> getFilters() { return FILTERS; } public static class ManagePublicationsActionListener extends UIActionBarActionListener<ManagePublicationsActionComponent> { public void processEvent(Event<ManagePublicationsActionComponent> event) throws Exception { UIActionBar uiActionBar = event.getSource().getAncestorOfType(UIActionBar.class); UIJCRExplorer uiExplorer = uiActionBar.getAncestorOfType(UIJCRExplorer.class); UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class); Node currentNode = uiExplorer.getCurrentNode(); uiExplorer.setIsHidePopup(false); PublicationService publicationService = uiActionBar.getApplicationComponent(PublicationService.class); PublicationPresentationService publicationPresentationService = uiActionBar. getApplicationComponent(PublicationPresentationService.class); if (!publicationService.isNodeEnrolledInLifecycle(currentNode)) { UIActivePublication activePublication = uiActionBar.createUIComponent(UIActivePublication.class,null,null); if(publicationService.getPublicationPlugins().size() == 1) { activePublication.setRendered(false); uiExplorer.addChild(activePublication); String lifecycleName = publicationService.getPublicationPlugins().keySet().iterator().next(); activePublication.enrolNodeInLifecycle(currentNode,lifecycleName,event.getRequestContext()); return; } activePublication.setRendered(true); activePublication.refresh(activePublication.getUIPageIterator().getCurrentPage()); UIPopupContainer.activate(activePublication, 600, 300); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); return; } UIContainer cont = uiActionBar.createUIComponent(UIContainer.class, null, null); UIForm uiForm = publicationPresentationService.getStateUI(currentNode, cont); if (uiForm instanceof UIPopupComponent) { //This is special case for wcm want to more than 2 tabs in PublicationManager //The uiForm in this case should be a UITabPane or UIFormTabPane and need be a UIPopupComponent UIPopupContainer.activate(uiForm, 700, 500); } else { UIPublicationManager uiPublicationManager = uiExplorer.createUIComponent(UIPublicationManager.class, null, null); uiPublicationManager.addChild(uiForm); uiPublicationManager.addChild(UIPublicationLogList.class, null, null).setRendered(false); UIPublicationLogList uiPublicationLogList = uiPublicationManager.getChild(UIPublicationLogList.class); UIPopupContainer.activate(uiPublicationManager, 700, 500); uiPublicationLogList.setNode(currentNode); uiPublicationLogList.updateGrid(); } event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } } }
6,791
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
CommentActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/action/CommentActionComponent.java
/* * Copyright (C) 2003-2009 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control.action; import java.util.Arrays; import java.util.List; import org.exoplatform.ecm.utils.text.Text; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.control.filter.CanAddNodeFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsMixCommentable; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter; import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener; import org.exoplatform.ecm.webui.component.explorer.popup.actions.UICommentForm; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 7 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = CommentActionComponent.CommentActionListener.class) } ) public class CommentActionComponent extends UIComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] { new CanAddNodeFilter(), new IsMixCommentable(), new IsCheckedOutFilter("UICommentForm.msg.not-checkedout"), new IsNotLockedFilter() }); @UIExtensionFilters public List<UIExtensionFilter> getFilters() { return FILTERS; } public static class CommentActionListener extends UIActionBarActionListener<CommentActionComponent> { public void processEvent(Event<CommentActionComponent> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); UIPopupContainer uiPopupContainer = uiExplorer.getChild(UIPopupContainer.class); UICommentForm uiCommentForm = uiPopupContainer.createUIComponent(UICommentForm.class, null, null); String commentNodePath = event.getRequestContext().getRequestParameter("nodePath"); if (commentNodePath != null && commentNodePath.length() > 0) { uiCommentForm.setNodeCommentPath(Text.escapeIllegalJcrChars(commentNodePath)); uiCommentForm.setEdit(true); } uiPopupContainer.activate(uiCommentForm, 750, 0); event.getRequestContext().addUIComponentToUpdateByAjax(uiPopupContainer); } } }
3,479
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
ManageActionsActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/action/ManageActionsActionComponent.java
/* * Copyright (C) 2003-2009 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control.action; import java.util.Arrays; import java.util.List; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.control.filter.CanAddNodeFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.CanSetPropertyFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotEditingDocumentFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotRootNodeFilter; import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener; import org.exoplatform.ecm.webui.component.explorer.popup.admin.UIActionManager; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 6 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = ManageActionsActionComponent.ManageActionsActionListener.class) } ) public class ManageActionsActionComponent extends UIComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] { new IsNotRootNodeFilter(), new CanSetPropertyFilter(), new CanAddNodeFilter(), new IsNotLockedFilter(), new IsCheckedOutFilter(), new IsNotEditingDocumentFilter() }); @UIExtensionFilters public List<UIExtensionFilter> getFilters() { return FILTERS; } public static class ManageActionsActionListener extends UIActionBarActionListener<ManageActionsActionComponent> { public void processEvent(Event<ManageActionsActionComponent> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class); UIPopupContainer.activate(UIActionManager.class, null, 610, 550); uiExplorer.setIsHidePopup(true); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } } }
3,344
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
AddSymLinkActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/action/AddSymLinkActionComponent.java
/* * Copyright (C) 2003-2009 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control.action; import java.security.AccessControlException; import java.util.Arrays; import java.util.List; import java.util.regex.Matcher; import javax.jcr.AccessDeniedException; import javax.jcr.ItemExistsException; import javax.jcr.Node; import javax.jcr.Session; import javax.jcr.nodetype.ConstraintViolationException; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.ecm.webui.component.explorer.control.filter.CanAddNodeFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.CanAddSymlinkFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsLockForSymlink; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotEditingDocumentFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotInTrashFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotSymlinkFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotTrashHomeNodeFilter; import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener; import org.exoplatform.ecm.webui.component.explorer.symlink.UISymLinkManager; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.link.LinkManager; import org.exoplatform.services.jcr.util.Text; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; import org.exoplatform.webui.ext.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 6 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = AddSymLinkActionComponent.AddSymLinkActionListener.class) } ) public class AddSymLinkActionComponent extends UIAbstractManagerComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[]{new CanAddNodeFilter(), new CanAddSymlinkFilter(), new IsLockForSymlink(), new IsCheckedOutFilter(), new IsNotSymlinkFilter(), new IsNotTrashHomeNodeFilter(), new IsNotInTrashFilter(), new IsNotEditingDocumentFilter()}); private static final Log LOG = ExoLogger.getLogger(AddSymLinkActionComponent.class.getName()); @UIExtensionFilters public List<UIExtensionFilter> getFilters() { return FILTERS; } public static class AddSymLinkActionListener extends UIActionBarActionListener<AddSymLinkActionComponent> { public void processEvent(Event<AddSymLinkActionComponent> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); String srcPath = event.getRequestContext().getRequestParameter(OBJECTID); Node currentNode = uiExplorer.getCurrentNode(); UIApplication uiApp = event.getSource().getAncestorOfType(UIApplication.class); LinkManager linkManager = uiWorkingArea.getApplicationComponent(LinkManager.class); String symLinkName; try { if ((srcPath != null) && (srcPath.indexOf(";") > -1)) { String[] nodePaths = srcPath.split(";"); for (int i = 0; i < nodePaths.length; i++) { Matcher matcher = UIWorkingArea.FILE_EXPLORER_URL_SYNTAX.matcher(nodePaths[i]); String wsName = null; if (matcher.find()) { wsName = matcher.group(1); nodePaths[i] = matcher.group(2); } else { throw new IllegalArgumentException("The ObjectId is invalid '" + nodePaths[i] + "'"); } Session userSession = uiExplorer.getSessionByWorkspace(wsName); // Use the method getNodeByPath because it is link aware Node selectedNode = uiExplorer.getNodeByPath(nodePaths[i], userSession, false); // Reset the path to manage the links that potentially create // virtual path nodePaths[i] = selectedNode.getPath(); if (linkManager.isLink(selectedNode)) { Object[] args = { selectedNode.getPath() }; uiApp.addMessage(new ApplicationMessage("UIWorkingArea.msg.selected-is-link", args, ApplicationMessage.WARNING)); continue; } try { if (selectedNode.getName().indexOf(".lnk") > -1) symLinkName = selectedNode.getName(); else symLinkName = selectedNode.getName() + ".lnk"; linkManager.createLink(currentNode, Utils.EXO_SYMLINK, selectedNode, symLinkName); } catch (Exception e) { Object[] arg = { Text.unescapeIllegalJcrChars(selectedNode.getPath()), Text.unescapeIllegalJcrChars(currentNode.getPath()) }; uiApp.addMessage(new ApplicationMessage("UIWorkingArea.msg.create-link-problem", arg, ApplicationMessage.WARNING)); return; } } uiExplorer.updateAjax(event); } else { if (srcPath != null) { Matcher matcher = UIWorkingArea.FILE_EXPLORER_URL_SYNTAX.matcher(srcPath); String wsName = null; if (matcher.find()) { wsName = matcher.group(1); srcPath = matcher.group(2); } else { throw new IllegalArgumentException("The ObjectId is invalid '" + srcPath + "'"); } Session userSession = uiExplorer.getSessionByWorkspace(wsName); // Use the method getNodeByPath because it is link aware Node selectedNode = uiExplorer.getNodeByPath(srcPath, userSession, false); // Reset the path to manage the links that potentially create // virtual path srcPath = selectedNode.getPath(); // Reset the session to manage the links that potentially change of // workspace userSession = selectedNode.getSession(); if (linkManager.isLink(selectedNode)) { Object[] args = { selectedNode.getPath() }; uiApp.addMessage(new ApplicationMessage("UIWorkingArea.msg.selected-is-link", args, ApplicationMessage.WARNING)); return; } if (selectedNode.getName().indexOf(".lnk") > -1) symLinkName = selectedNode.getName(); else symLinkName = selectedNode.getName() + ".lnk"; try { linkManager.createLink(currentNode, Utils.EXO_SYMLINK, selectedNode, symLinkName); } catch (Exception e) { Object[] arg = { Text.unescapeIllegalJcrChars(selectedNode.getPath()), Text.unescapeIllegalJcrChars(currentNode.getPath()) }; uiApp.addMessage(new ApplicationMessage("UIWorkingArea.msg.create-link-problem", arg, ApplicationMessage.WARNING)); return; } uiExplorer.updateAjax(event); } else { UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class); UISymLinkManager uiSymLinkManager = event.getSource().createUIComponent(UISymLinkManager.class, null, null); uiSymLinkManager.useDriveSelector(); UIPopupContainer.activate(uiSymLinkManager, 600, 190); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } } } catch (AccessControlException ace) { uiApp.addMessage(new ApplicationMessage("UISymLinkForm.msg.repository-exception", null, ApplicationMessage.WARNING)); return; } catch (AccessDeniedException ade) { uiApp.addMessage(new ApplicationMessage("UISymLinkForm.msg.repository-exception", null, ApplicationMessage.WARNING)); return; } catch (NumberFormatException nume) { uiApp.addMessage(new ApplicationMessage("UISymLinkForm.msg.numberformat-exception", null, ApplicationMessage.WARNING)); return; } catch (ConstraintViolationException cve) { uiApp.addMessage(new ApplicationMessage("UISymLinkForm.msg.cannot-save", null, ApplicationMessage.WARNING)); return; } catch (ItemExistsException iee) { uiApp.addMessage(new ApplicationMessage("UISymLinkForm.msg.item-exists-exception", null, ApplicationMessage.WARNING)); return; } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("an unexpected error occurs while adding a symlink to the node", e); } uiApp.addMessage(new ApplicationMessage("UISymLinkForm.msg.cannot-save", null, ApplicationMessage.WARNING)); return; } } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return null; } }
11,091
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
EditDocumentActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/action/EditDocumentActionComponent.java
/* * Copyright (C) 2003-2009 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control.action; import java.util.Arrays; import java.util.List; import java.util.regex.Matcher; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.ValueFormatException; import javax.jcr.lock.Lock; import org.exoplatform.ecm.webui.component.explorer.UIDocumentContainer; import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace; import org.exoplatform.ecm.webui.component.explorer.UIDrivesArea; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.ecm.webui.component.explorer.control.UIControl; import org.exoplatform.ecm.webui.component.explorer.control.filter.CanSetPropertyFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsDocumentFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsEditableFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotContainBinaryFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotEditingDocumentFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotInTrashFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter; import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener; import org.exoplatform.ecm.webui.component.explorer.popup.actions.UIDocumentForm; import org.exoplatform.ecm.webui.component.explorer.popup.actions.UIDocumentFormController; import org.exoplatform.ecm.webui.component.explorer.popup.admin.UIActionContainer; import org.exoplatform.ecm.webui.component.explorer.popup.admin.UIActionForm; import org.exoplatform.ecm.webui.component.explorer.popup.admin.UIActionTypeForm; import org.exoplatform.ecm.webui.component.explorer.search.UISearchResult; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.ecm.utils.lock.LockUtil; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.lock.LockService; import org.exoplatform.services.cms.mimetype.DMSMimeTypeResolver; import org.exoplatform.services.organization.MembershipType; import org.exoplatform.services.organization.OrganizationService; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; import org.exoplatform.webui.ext.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 6 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = EditDocumentActionComponent.EditDocumentActionListener.class) } ) public class EditDocumentActionComponent extends UIAbstractManagerComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] { new IsDocumentFilter(), new IsEditableFilter(), new CanSetPropertyFilter(), new IsNotLockedFilter(), new IsCheckedOutFilter(), new IsNotInTrashFilter(), new IsNotEditingDocumentFilter(), new IsNotContainBinaryFilter()}); @UIExtensionFilters public static List<UIExtensionFilter> getFilters() { return FILTERS; } private static void refresh(Node node) throws Exception { node.refresh(true); } @SuppressWarnings("unchecked") public static void editDocument(Event <? extends UIComponent> event, WebuiRequestContext context, UIComponent comp, UIJCRExplorer uiExplorer, Node selectedNode, UIApplication uiApp) throws RepositoryException, Exception, ValueFormatException, PathNotFoundException { if (event != null) context = event.getRequestContext(); if (selectedNode.isNodeType(Utils.EXO_ACTION)) { UIActionContainer uiContainer = uiExplorer.createUIComponent(UIActionContainer.class, null, null); uiExplorer.setIsHidePopup(true); UIActionForm uiActionForm = uiContainer.getChild(UIActionForm.class); uiContainer.getChild(UIActionTypeForm.class).setRendered(false); uiActionForm.createNewAction(selectedNode, selectedNode.getPrimaryNodeType().getName(), false); uiActionForm.setIsUpdateSelect(false); uiActionForm.setNodePath(selectedNode.getPath()); uiActionForm.setWorkspace(selectedNode.getSession().getWorkspace().getName()); uiActionForm.setStoredPath(selectedNode.getPath()); UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class); UIPopupContainer.activate(uiContainer, 700, 550); context.addUIComponentToUpdateByAjax(UIPopupContainer); } else { String nodeType = null; if(selectedNode.hasProperty("exo:presentationType")) { nodeType = selectedNode.getProperty("exo:presentationType").getString(); }else { nodeType = selectedNode.getPrimaryNodeType().getName(); } UIDocumentFormController uiController = event != null ? event.getSource().createUIComponent(UIDocumentFormController.class, null, "EditFormController") : comp.createUIComponent(UIDocumentFormController.class, null, "EditFormController"); UIDocumentForm uiDocumentForm = uiController.getChild(UIDocumentForm.class); uiDocumentForm.setRepositoryName(uiExplorer.getRepositoryName()); uiDocumentForm.setContentType(nodeType); uiDocumentForm.clearRemovedNode(); uiDocumentForm.clearDataRemovedList(); if(uiDocumentForm.getTemplate() == null) { uiApp.addMessage(new ApplicationMessage("UIActionBar.msg.template-null", null)); return; } refresh(selectedNode); // Check document is lock for editing uiDocumentForm.setIsKeepinglock(false); if (!selectedNode.isLocked()) { OrganizationService service = WCMCoreUtils.getService(OrganizationService.class); List<MembershipType> memberships = (List<MembershipType>) service.getMembershipTypeHandler().findMembershipTypes(); synchronized (EditDocumentActionComponent.class) { refresh(selectedNode); if (!selectedNode.isLocked()) { if(selectedNode.canAddMixin(Utils.MIX_LOCKABLE)){ selectedNode.addMixin(Utils.MIX_LOCKABLE); selectedNode.save(); } Lock lock = selectedNode.lock(false, false); LockUtil.keepLock(lock); LockService lockService = uiExplorer.getApplicationComponent(LockService.class); List<String> settingLockList = lockService.getAllGroupsOrUsersForLock(); for (String settingLock : settingLockList) { LockUtil.keepLock(lock, settingLock); if (!settingLock.startsWith("*")) continue; String lockTokenString = settingLock; for (MembershipType membership : memberships) { lockTokenString = settingLock.replace("*", membership.getName()); LockUtil.keepLock(lock, lockTokenString); } } selectedNode.save(); uiDocumentForm.setIsKeepinglock(true); } } } // Add mixin type exo:documentSize if the current node is flash file String mimeType = DMSMimeTypeResolver.getInstance().getMimeType(selectedNode.getName()); if(mimeType.indexOf(Utils.FLASH_MIMETYPE) >= 0 && selectedNode.canAddMixin(Utils.EXO_RISIZEABLE)) { selectedNode.addMixin(Utils.EXO_RISIZEABLE); selectedNode.save(); } // Update data avoid concurrent modification by other session refresh(selectedNode); // Check again after node is locking by current user or another if (LockUtil.getLockTokenOfUser(selectedNode) == null) { Object[] arg = { selectedNode.getPath() }; uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.node-locked-editing", arg, ApplicationMessage.WARNING)); return; } uiDocumentForm.setNodePath(selectedNode.getPath()); uiDocumentForm.addNew(false); uiDocumentForm.setWorkspace(selectedNode.getSession().getWorkspace().getName()); uiDocumentForm.setStoredPath(selectedNode.getPath()); uiController.setRenderedChild(UIDocumentForm.class); UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class); UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class); if(!uiDocumentWorkspace.isRendered()) { uiWorkingArea.getChild(UIDrivesArea.class).setRendered(false); uiWorkingArea.getChild(UIDocumentWorkspace.class).setRendered(true); } uiDocumentWorkspace.getChild(UIDocumentContainer.class).setRendered(false); uiDocumentWorkspace.getChild(UISearchResult.class).setRendered(false); UIDocumentFormController controller = uiDocumentWorkspace.removeChild(UIDocumentFormController.class); if (controller != null) { controller.getChild(UIDocumentForm.class).releaseLock(); } uiDocumentWorkspace.addChild(uiController); uiController.initOptionBlockPanel(); uiController.setRendered(true); context.addUIComponentToUpdateByAjax(uiWorkingArea); if (event != null) { uiExplorer.updateAjax(event); } context.addUIComponentToUpdateByAjax(uiExplorer.getChild(UIControl.class)); } } public static class EditDocumentActionListener extends UIActionBarActionListener<EditDocumentActionComponent> { public void processEvent(Event<EditDocumentActionComponent> event) throws Exception { EditDocumentActionComponent uicomp = event.getSource(); String nodePath = event.getRequestContext().getRequestParameter(OBJECTID); UIJCRExplorer uiExplorer = uicomp.getAncestorOfType(UIJCRExplorer.class); Node selectedNode = null; if (nodePath != null && nodePath.length() != 0) { Matcher matcher = UIWorkingArea.FILE_EXPLORER_URL_SYNTAX.matcher(nodePath); String wsName = null; if (matcher.find()) { wsName = matcher.group(1); nodePath = matcher.group(2); } else { throw new IllegalArgumentException("The ObjectId is invalid '" + nodePath + "'"); } Session session = uiExplorer.getSessionByWorkspace(wsName); UIApplication uiApp = uicomp.getAncestorOfType(UIApplication.class); try { // Use the method getNodeByPath because it is link aware selectedNode = uiExplorer.getNodeByPath(nodePath, session); } catch (PathNotFoundException path) { uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.path-not-found-exception", null, ApplicationMessage.WARNING)); return; } catch (AccessDeniedException ace) { uiApp.addMessage(new ApplicationMessage("UIDocumentInfo.msg.null-exception", null, ApplicationMessage.WARNING)); return; } catch (Exception e) { JCRExceptionManager.process(uiApp, e); return; } } if (selectedNode == null) selectedNode = uiExplorer.getCurrentNode(); uiExplorer.setSelectNode(selectedNode.getPath()); UIApplication uiApp = uicomp.getAncestorOfType(UIApplication.class); editDocument(event, null, uicomp, uiExplorer, selectedNode, uiApp); } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return null; } }
14,005
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
ViewNodeTypeActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/action/ViewNodeTypeActionComponent.java
/* * Copyright (C) 2003-2009 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control.action; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener; import org.exoplatform.ecm.webui.component.explorer.popup.info.UINodeTypeInfo; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 6 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = ViewNodeTypeActionComponent.ViewNodeTypeActionListener.class) } ) public class ViewNodeTypeActionComponent extends UIComponent { public static class ViewNodeTypeActionListener extends UIActionBarActionListener<ViewNodeTypeActionComponent> { public void processEvent(Event<ViewNodeTypeActionComponent> event) throws Exception { UIJCRExplorer uiJCRExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); UIPopupContainer UIPopupContainer = uiJCRExplorer.getChild(UIPopupContainer.class); UINodeTypeInfo uiNodeTypeInfo = uiJCRExplorer.createUIComponent(UINodeTypeInfo.class, null, null); UIPopupContainer.activate(uiNodeTypeInfo, 700, 0, false); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } } }
2,310
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
ViewMetadatasActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/action/ViewMetadatasActionComponent.java
/* * Copyright (C) 2003-2009 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control.action; import java.util.Arrays; import java.util.Enumeration; import java.util.Hashtable; import java.util.List; import javax.jcr.Node; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.control.UIActionBar; import org.exoplatform.ecm.webui.component.explorer.control.filter.HasMetadataTemplatesFilter; import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener; import org.exoplatform.ecm.webui.component.explorer.popup.info.UIViewMetadataContainer; import org.exoplatform.ecm.webui.component.explorer.popup.info.UIViewMetadataManager; import org.exoplatform.ecm.webui.component.explorer.popup.info.UIViewMetadataTemplate; import org.exoplatform.services.cms.impl.Utils; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 6 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = ViewMetadatasActionComponent.ViewMetadatasActionListener.class) } ) public class ViewMetadatasActionComponent extends UIComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[]{new HasMetadataTemplatesFilter()}); @UIExtensionFilters public List<UIExtensionFilter> getFilters() { return FILTERS; } public static class ViewMetadatasActionListener extends UIActionBarActionListener<ViewMetadatasActionComponent> { public void processEvent(Event<ViewMetadatasActionComponent> event) throws Exception { UIActionBar uiActionBar = event.getSource().getAncestorOfType(UIActionBar.class); UIJCRExplorer uiJCRExplorer = uiActionBar.getAncestorOfType(UIJCRExplorer.class); Node currentNode = uiJCRExplorer.getCurrentNode() ; Hashtable<String, String> metaDataTemp = WCMCoreUtils.getMetadataTemplates(currentNode); UIPopupContainer UIPopupContainer = uiJCRExplorer.getChild(UIPopupContainer.class); UIPopupContainer.activate(UIViewMetadataManager.class, 700); UIViewMetadataManager uiMetadataManager = UIPopupContainer.findFirstComponentOfType(UIViewMetadataManager.class); UIViewMetadataContainer uiMetadataContainer = uiMetadataManager.getChild(UIViewMetadataContainer.class); int i = 0; Enumeration<String> enu = metaDataTemp.keys(); while (enu.hasMoreElements()) { String key = (String) enu.nextElement(); String template = metaDataTemp.get(key); if(template != null && template.length() > 0) { UIViewMetadataTemplate uiMetaView = uiMetadataContainer.createUIComponent(UIViewMetadataTemplate.class, null, Utils.cleanString(key)) ; uiMetaView.setTemplateType(key) ; uiMetadataContainer.addChild(uiMetaView) ; uiMetaView.setRendered(true); i++ ; } } uiMetadataContainer.setSelectedTab(1); uiMetadataContainer.setHasMoreOneMetaData(i > 1); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } } }
4,370
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
ViewPropertiesActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/action/ViewPropertiesActionComponent.java
/* * Copyright (C) 2003-2009 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control.action; import javax.jcr.Node; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener; import org.exoplatform.ecm.webui.component.explorer.popup.admin.UIPropertiesManager; import org.exoplatform.ecm.webui.component.explorer.popup.admin.UIPropertyForm; import org.exoplatform.ecm.webui.utils.PermissionUtil; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 6 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = ViewPropertiesActionComponent.ViewPropertiesActionListener.class) } ) public class ViewPropertiesActionComponent extends UIComponent { private static final Log LOG = ExoLogger.getLogger(ViewPropertiesActionComponent.class.getName()); public static class ViewPropertiesActionListener extends UIActionBarActionListener<ViewPropertiesActionComponent> { public void processEvent(Event<ViewPropertiesActionComponent> event) throws Exception { UIJCRExplorer uiJCRExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); Node node = uiJCRExplorer.getCurrentNode(); UIPropertiesManager uiPropertiesManager = uiJCRExplorer.createUIComponent(UIPropertiesManager.class, null, null); try { if (node.isNodeType(Utils.NT_UNSTRUCTURED)) { UIPropertyForm uiForm = uiPropertiesManager.getChild(UIPropertyForm.class); uiForm.init(node); uiForm.getUIFormSelectBox(UIPropertyForm.FIELD_NAMESPACE) .setOptions(uiForm.getNamespaces()); } else { if (org.exoplatform.services.cms.impl.Utils.getProperties(node) != null && org.exoplatform.services.cms.impl.Utils.getProperties(node).size() > 0) { UIPropertyForm uiForm = uiPropertiesManager.getChild(UIPropertyForm.class); uiForm.init(node); uiForm.getUIFormSelectBox(UIPropertyForm.PROPERTY_SELECT) .setOptions(uiForm.renderProperties(node)); } } if (uiJCRExplorer.nodeIsLocked(node)) { uiPropertiesManager.setLockForm(true); } else { uiPropertiesManager.setLockForm(!PermissionUtil.canSetProperty(node)); } } catch (NullPointerException npe) { if (LOG.isWarnEnabled()) { LOG.warn(npe.getMessage()); } } UIPopupContainer UIPopupContainer = uiJCRExplorer.getChild(UIPopupContainer.class); UIPopupContainer.activate(uiPropertiesManager, 700, 0); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } } }
3,970
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
VoteActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/action/VoteActionComponent.java
/* * Copyright (C) 2003-2009 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control.action; import java.util.Arrays; import java.util.List; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.control.filter.CanSetPropertyFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsMixVotable; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter; import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener; import org.exoplatform.ecm.webui.component.explorer.popup.actions.UIVoteForm; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 7 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = VoteActionComponent.VoteActionListener.class) } ) public class VoteActionComponent extends UIComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] { new CanSetPropertyFilter(), new IsMixVotable(), new IsCheckedOutFilter("UIVoteForm.msg.not-checkedout"), new IsNotLockedFilter() }); @UIExtensionFilters public List<UIExtensionFilter> getFilters() { return FILTERS; } public static class VoteActionListener extends UIActionBarActionListener<VoteActionComponent> { public void processEvent(Event<VoteActionComponent> event) throws Exception { UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class); UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class); UIPopupContainer.activate(UIVoteForm.class, 300); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } } }
3,008
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
ManageRelationsActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/action/ManageRelationsActionComponent.java
/* * Copyright (C) 2003-2009 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control.action; import java.util.Arrays; import java.util.List; import javax.jcr.Node; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.control.UIActionBar; import org.exoplatform.ecm.webui.component.explorer.control.filter.CanSetPropertyFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotRootNodeFilter; import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener; import org.exoplatform.ecm.webui.component.explorer.popup.admin.UIRelationManager; import org.exoplatform.ecm.webui.component.explorer.popup.admin.UIRelationsAddedList; import org.exoplatform.ecm.webui.tree.selectone.UIOneNodePathSelector; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.relations.RelationsService; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 6 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = ManageRelationsActionComponent.ManageRelationsActionListener.class) } ) public class ManageRelationsActionComponent extends UIComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] { new IsNotRootNodeFilter(), new IsCheckedOutFilter(), new CanSetPropertyFilter(), new IsNotLockedFilter() }); @UIExtensionFilters public List<UIExtensionFilter> getFilters() { return FILTERS; } public static class ManageRelationsActionListener extends UIActionBarActionListener<ManageRelationsActionComponent> { public void processEvent(Event<ManageRelationsActionComponent> event) throws Exception { UIActionBar uiActionBar = event.getSource().getAncestorOfType(UIActionBar.class); UIJCRExplorer uiExplorer = uiActionBar.getAncestorOfType(UIJCRExplorer.class); uiExplorer.setIsHidePopup(true); RepositoryService repoService = uiActionBar.getApplicationComponent(RepositoryService.class); UIRelationManager uiRelationManager = uiExplorer.createUIComponent(UIRelationManager.class, null, null); RelationsService relateService = uiActionBar.getApplicationComponent(RelationsService.class); UIRelationsAddedList uiRelateAddedList = uiRelationManager.getChild(UIRelationsAddedList.class); List<Node> relations = relateService.getRelations(uiExplorer.getCurrentNode(), WCMCoreUtils.getUserSessionProvider()); uiRelateAddedList.updateGrid(relations, 1); String repository = uiActionBar.getAncestorOfType(UIJCRExplorer.class).getRepositoryName(); String defaultWsName = repoService.getCurrentRepository().getConfiguration().getDefaultWorkspaceName(); UIOneNodePathSelector uiNodePathSelector = uiRelationManager.getChild(UIOneNodePathSelector.class); uiNodePathSelector.setIsDisable(defaultWsName, false); uiNodePathSelector.setRootNodeLocation(repository, defaultWsName, "/"); TemplateService tservice = uiActionBar.getApplicationComponent(TemplateService.class); List<String> documentNodeType = tservice.getDocumentTemplates(); String [] arrAcceptedNodeTypes = new String[documentNodeType.size()]; documentNodeType.toArray(arrAcceptedNodeTypes) ; uiNodePathSelector.setAcceptedNodeTypesInPathPanel(arrAcceptedNodeTypes); uiNodePathSelector.setIsShowSystem(false); uiNodePathSelector.setAcceptedNodeTypesInTree(new String[] {Utils.NT_UNSTRUCTURED, Utils.NT_FOLDER}); uiNodePathSelector.init(uiExplorer.getSessionProvider()); uiNodePathSelector.setSourceComponent(uiRelateAddedList, null); UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class); UIPopupContainer.activate(uiRelationManager, 710, 500); event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer); } } }
5,518
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
EditPropertyActionComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/control/action/EditPropertyActionComponent.java
/* * Copyright (C) 2003-2009 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.explorer.control.action; import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer; import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea; import org.exoplatform.ecm.webui.component.explorer.control.filter.CanSetPropertyFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsDocumentFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsContainBinaryFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsEditableFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotEditingDocumentFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotInTrashFilter; import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter; import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.ext.filter.UIExtensionFilter; import org.exoplatform.webui.ext.filter.UIExtensionFilters; import org.exoplatform.webui.ext.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.ValueFormatException; import java.util.Arrays; import java.util.List; import java.util.regex.Matcher; /** * Created by The eXo Platform SEA * Author : eXoPlatform * toannh@exoplatform.com * On 8/7/15 * Edit property for nt:file */ @ComponentConfig( events = { @EventConfig(listeners = EditPropertyActionComponent.EditPropertyActionListener.class) } ) public class EditPropertyActionComponent extends UIAbstractManagerComponent { private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] { new IsDocumentFilter(), new IsEditableFilter(), new CanSetPropertyFilter(), new IsNotLockedFilter(), new IsCheckedOutFilter(), new IsNotInTrashFilter(), new IsNotEditingDocumentFilter(), new IsContainBinaryFilter() }); @UIExtensionFilters public static List<UIExtensionFilter> getFilters() { return FILTERS; } public static class EditPropertyActionListener extends UIActionBarActionListener<EditPropertyActionComponent> { public void processEvent(Event<EditPropertyActionComponent> event) throws Exception { EditPropertyActionComponent uicomp = event.getSource(); String nodePath = event.getRequestContext().getRequestParameter(OBJECTID); UIJCRExplorer uiExplorer = uicomp.getAncestorOfType(UIJCRExplorer.class); Node selectedNode = null; if (nodePath != null && nodePath.length() != 0) { Matcher matcher = UIWorkingArea.FILE_EXPLORER_URL_SYNTAX.matcher(nodePath); String wsName = null; if (matcher.find()) { wsName = matcher.group(1); nodePath = matcher.group(2); } else { throw new IllegalArgumentException("The ObjectId is invalid '" + nodePath + "'"); } Session session = uiExplorer.getSessionByWorkspace(wsName); UIApplication uiApp = uicomp.getAncestorOfType(UIApplication.class); try { // Use the method getNodeByPath because it is link aware selectedNode = uiExplorer.getNodeByPath(nodePath, session); } catch (PathNotFoundException path) { uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.path-not-found-exception", null, ApplicationMessage.WARNING)); return; } catch (AccessDeniedException ace) { uiApp.addMessage(new ApplicationMessage("UIDocumentInfo.msg.null-exception", null, ApplicationMessage.WARNING)); return; } catch (Exception e) { JCRExceptionManager.process(uiApp, e); return; } } if (selectedNode == null) selectedNode = uiExplorer.getCurrentNode(); uiExplorer.setSelectNode(selectedNode.getPath()); UIApplication uiApp = uicomp.getAncestorOfType(UIApplication.class); editDocument(event, null, uicomp, uiExplorer, selectedNode, uiApp); } } @SuppressWarnings("unchecked") public static void editDocument(Event <? extends UIComponent> event, WebuiRequestContext context, UIComponent comp, UIJCRExplorer uiExplorer, Node selectedNode, UIApplication uiApp) throws Exception{ EditDocumentActionComponent.editDocument(event, context, comp, uiExplorer, selectedNode, uiApp); } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return null; } }
6,120
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z