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
UITabContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/views/UITabContainer.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.admin.views; import org.exoplatform.portal.webui.container.UIContainer; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIComponent; 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 * Mar 13, 2013 * 6:53:17 PM */ @ComponentConfig(lifecycle = UIContainerLifecycle.class) public class UITabContainer extends UIContainer { public UITabContainer() throws Exception { addChild(UITabList.class, null, null); } public void initPopup(String popupId, UIComponent uiComponent, int width, int height) throws Exception { removeChildById(popupId); UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, popupId) ; uiPopup.setShowMask(true); uiPopup.setShowMask(true); uiPopup.setWindowSize(width, height) ; uiPopup.setUIComponent(uiComponent); uiPopup.setShow(true) ; uiPopup.setResizable(true); } }
1,981
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITemplateForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/views/UITemplateForm.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.admin.views; import java.util.ArrayList; import java.util.List; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.version.VersionHistory; import org.exoplatform.ecm.jcr.model.VersionNode; import org.exoplatform.ecm.resolver.JCRResourceResolver; import org.exoplatform.ecm.webui.form.validator.ECMNameValidator; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.groovyscript.text.TemplateService; import org.exoplatform.services.cms.BasePath; import org.exoplatform.services.cms.views.ManageViewService; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.ext.common.SessionProvider; 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.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 org.exoplatform.webui.form.input.UICheckBoxInput; import org.exoplatform.webui.form.validator.MandatoryValidator; /** * Created by The eXo Platform SARL Author : Tran The Trong trongtt@gmail.com * July 3, 2006 10:07:15 AM */ @ComponentConfig(lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UITemplateForm.SaveActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UITemplateForm.CancelActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UITemplateForm.ResetActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UITemplateForm.ChangeActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UITemplateForm.RestoreActionListener.class) }) public class UITemplateForm extends UIForm { final static private String FIELD_VERSION = "version"; final static private String FIELD_CONTENT = "content"; final static private String FIELD_NAME = "name"; final static private String FIELD_HOMETEMPLATE = "homeTemplate"; final static private String FIELD_ENABLEVERSION = "enableVersion"; private NodeLocation template_ = null; private List<String> listVersion = new ArrayList<String>(); private String baseVersionName_; private VersionNode selectedVersion_; public boolean isAddNew_ = false; private String templatePath_; private VersionNode rootVersionNode; private org.exoplatform.services.cms.templates.TemplateService templateService; public UITemplateForm() throws Exception { templateService = WCMCoreUtils.getService(org.exoplatform.services.cms.templates.TemplateService.class); List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>(); UIFormSelectBox versions = new UIFormSelectBox(FIELD_VERSION, FIELD_VERSION, options); versions.setOnChange("Change"); versions.setRendered(false); addUIFormInput(versions); addUIFormInput(new UIFormTextAreaInput(FIELD_CONTENT, FIELD_CONTENT, null) .addValidator(MandatoryValidator.class)); addUIFormInput(new UIFormStringInput(FIELD_NAME, FIELD_NAME, null).addValidator( MandatoryValidator.class).addValidator(ECMNameValidator.class)); List<SelectItemOption<String>> typeList = new ArrayList<SelectItemOption<String>>(); addUIFormInput(new UIFormSelectBox(FIELD_HOMETEMPLATE, FIELD_HOMETEMPLATE, typeList)); UICheckBoxInput enableVersion = new UICheckBoxInput(FIELD_ENABLEVERSION, FIELD_ENABLEVERSION, null); enableVersion.setRendered(false); addUIFormInput(enableVersion); } public String getRepository() { try { return getApplicationComponent(RepositoryService.class).getCurrentRepository() .getConfiguration() .getName(); } catch (RepositoryException e) { return null; } } public void updateOptionList() throws Exception { getUIFormSelectBox(FIELD_HOMETEMPLATE).setOptions(getOptionList()); } public List<SelectItemOption<String>> getOptionList() throws Exception { List<SelectItemOption<String>> typeList = new ArrayList<SelectItemOption<String>>(); SessionProvider provider = WCMCoreUtils.getSystemSessionProvider(); if (getId().equalsIgnoreCase("ecmTempForm")) { Node ecmTemplateHome = getApplicationComponent(ManageViewService.class).getTemplateHome( BasePath.ECM_EXPLORER_TEMPLATES, provider); if (ecmTemplateHome != null) { typeList.add(new SelectItemOption<String>(ecmTemplateHome.getName(), ecmTemplateHome .getPath())); } } return typeList; } public boolean canEnableVersionning(Node node) throws Exception { return node.canAddMixin(Utils.MIX_VERSIONABLE); } private boolean isVersioned(Node node) throws RepositoryException { return node.isNodeType(Utils.MIX_VERSIONABLE); } private VersionNode getRootVersion(Node node) throws Exception { VersionHistory vH = node.getVersionHistory(); return (vH != null) ? new VersionNode(vH.getRootVersion(), node.getSession()) : null; } private List<String> getNodeVersions(List<VersionNode> children) throws Exception { List<VersionNode> child = new ArrayList<VersionNode>(); for (VersionNode vNode : children) { listVersion.add(vNode.getName()); child = vNode.getChildren(); if (!child.isEmpty()) getNodeVersions(child); } return listVersion; } private List<SelectItemOption<String>> getVersionValues(Node node) throws Exception { List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>(); List<VersionNode> children = getRootVersion(node).getChildren(); listVersion.clear(); List<String> versionList = getNodeVersions(children); for (int i = 0; i < versionList.size(); i++) { for (int j = i + 1; j < versionList.size(); j++) { if (Integer.parseInt(versionList.get(j)) < Integer.parseInt(versionList.get(i))) { String temp = versionList.get(i); versionList.set(i, versionList.get(j)); versionList.set(j, temp); } } options.add(new SelectItemOption<String>(versionList.get(i), versionList.get(i))); } return options; } public void refresh() throws Exception { UIFormSelectBox versionField = getUIFormSelectBox(FIELD_VERSION); if (isAddNew_) { versionField.setRendered(false); getUIFormTextAreaInput(FIELD_CONTENT).setValue(null); getUIStringInput(FIELD_NAME).setDisabled(false).setValue(null); getUIFormSelectBox(FIELD_HOMETEMPLATE).setValue(null); getUIFormSelectBox(FIELD_HOMETEMPLATE).setDisabled(false); getUICheckBoxInput(FIELD_ENABLEVERSION).setRendered(false); template_ = null; selectedVersion_ = null; baseVersionName_ = null; return; } update(template_.getPath(), null); } public void update(String templatePath, VersionNode selectedVersion) throws Exception { if (templatePath != null) { templatePath_ = templatePath; Node templateNode = getApplicationComponent(ManageViewService.class). getTemplate(templatePath, WCMCoreUtils.getSystemSessionProvider()); template_ = NodeLocation.getNodeLocationByNode(templateNode); getUIStringInput(FIELD_NAME).setValue(templateNode.getName()); getUIStringInput(FIELD_NAME).setDisabled(true); String value = templatePath.substring(0, templatePath.lastIndexOf("/")); getUIFormSelectBox(FIELD_HOMETEMPLATE).setValue(value); getUIFormSelectBox(FIELD_HOMETEMPLATE).setDisabled(false); getUICheckBoxInput(FIELD_ENABLEVERSION).setRendered(true); if (isVersioned(templateNode)) { rootVersionNode = getRootVersion(templateNode); baseVersionName_ = templateNode.getBaseVersion().getName(); List<SelectItemOption<String>> options = getVersionValues(templateNode); getUIFormSelectBox(FIELD_VERSION).setOptions(options).setRendered(true); getUIFormSelectBox(FIELD_VERSION).setValue(baseVersionName_); getUICheckBoxInput(FIELD_ENABLEVERSION).setChecked(true).setDisabled(true); if (options.size() > 1) setActions(new String[] { "Save", "Reset", "Restore", "Cancel" }); else setActions(new String[] { "Save", "Reset", "Cancel" }); } else if (canEnableVersionning(templateNode)) { getUIFormSelectBox(FIELD_VERSION).setRendered(false); getUICheckBoxInput(FIELD_ENABLEVERSION).setChecked(false).setDisabled(false); } } if (selectedVersion != null) { NodeLocation.getNodeByLocation(template_).restore(selectedVersion.getName(), false); selectedVersion_ = selectedVersion; Object[] args = { getUIStringInput(FIELD_VERSION).getValue() }; UIApplication app = getAncestorOfType(UIApplication.class); app.addMessage(new ApplicationMessage("UITemplateForm.msg.version-restored", args)); } String content = templateService.getTemplate(NodeLocation.getNodeByLocation(template_)); getUIFormTextAreaInput(FIELD_CONTENT).setValue(content); } static public class SaveActionListener extends EventListener<UITemplateForm> { public void execute(Event<UITemplateForm> event) throws Exception { UITemplateForm uiForm = event.getSource(); String templateName = uiForm.getUIStringInput(FIELD_NAME).getValue().trim(); String content = uiForm.getUIFormTextAreaInput(FIELD_CONTENT).getValue(); String homeTemplate = uiForm.getUIFormSelectBox(FIELD_HOMETEMPLATE).getValue(); ManageViewService manageViewService = uiForm.getApplicationComponent(ManageViewService.class); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); if (homeTemplate == null) { String tempPath = uiForm.template_.getPath(); homeTemplate = tempPath.substring(0, tempPath.lastIndexOf("/")); } boolean isEnableVersioning = uiForm.getUICheckBoxInput(FIELD_ENABLEVERSION).isChecked(); String path = null; if (uiForm.getId().equalsIgnoreCase(UIECMTemplateList.ST_ecmTempForm)) { List<Node> ecmTemps = manageViewService.getAllTemplates(BasePath.ECM_EXPLORER_TEMPLATES, WCMCoreUtils.getSystemSessionProvider()); for (Node temp : ecmTemps) { if (temp.getName().equals(templateName) && uiForm.isAddNew_) { Object[] args = { templateName }; uiApp.addMessage(new ApplicationMessage("UITemplateForm.msg.template-name-exist", args, ApplicationMessage.WARNING)); return; } } } if (uiForm.isAddNew_) { try { if (uiForm.templatePath_ != null) { String oldHomeTemplate = uiForm.templatePath_.substring(0, uiForm.templatePath_.lastIndexOf("/")); if (!oldHomeTemplate.equals(homeTemplate)) { Node oldNode = manageViewService.getTemplate(uiForm.templatePath_, WCMCoreUtils.getSystemSessionProvider()); oldNode.remove(); manageViewService.getTemplate(oldHomeTemplate, WCMCoreUtils.getSystemSessionProvider()).save(); } } path = manageViewService.addTemplate(templateName, content, homeTemplate, WCMCoreUtils.getSystemSessionProvider()); uiForm.template_ = NodeLocation.getNodeLocationByNode(manageViewService.getTemplate(path, WCMCoreUtils.getSystemSessionProvider())); } catch (AccessDeniedException ex) { uiApp.addMessage(new ApplicationMessage("UITemplateForm.msg.add-permission-denied", null, ApplicationMessage.WARNING)); return; } } else { try { Node templateNode = NodeLocation.getNodeByLocation(uiForm.template_); if (isEnableVersioning) { if (!templateNode.isNodeType(Utils.MIX_VERSIONABLE)) { templateNode.addMixin(Utils.MIX_VERSIONABLE); templateNode.save(); } else { templateNode.checkout(); } } path = manageViewService.updateTemplate(templateName, content, homeTemplate, WCMCoreUtils.getSystemSessionProvider()); templateNode.save(); if (isEnableVersioning) { templateNode.checkin(); } } catch (AccessDeniedException ex) { Object[] args = { "UIViewFormTabPane.label.option." + templateName }; uiApp.addMessage(new ApplicationMessage("UITemplateForm.msg.edit-permission-denied", args, ApplicationMessage.WARNING)); return; } } String workspaceName = NodeLocation.getNodeByLocation(uiForm.template_).getSession().getWorkspace().getName(); JCRResourceResolver resourceResolver = new JCRResourceResolver(workspaceName); TemplateService templateService = uiForm.getApplicationComponent(TemplateService.class); if (path != null) templateService.invalidateTemplate(path, resourceResolver); UITemplateContainer uiTempContainer = uiForm.getAncestorOfType(UIPopupWindow.class).getParent(); UIECMTemplateList uiECMTempList = uiTempContainer.getChild(UIECMTemplateList.class); uiECMTempList.refresh(uiECMTempList.getUIPageIterator().getCurrentPage()); if (uiForm.isAddNew_) { uiTempContainer.removeChildById(UIECMTemplateList.ST_ecmTempForm + "Add"); } else { uiTempContainer.removeChildById(UIECMTemplateList.ST_ecmTempForm + "Edit"); } event.getRequestContext().addUIComponentToUpdateByAjax(uiTempContainer); } } static public class CancelActionListener extends EventListener<UITemplateForm> { public void execute(Event<UITemplateForm> event) throws Exception { UITemplateForm uiForm = event.getSource(); uiForm.refresh(); UITemplateContainer uiTempContainer = uiForm.getAncestorOfType(UIPopupWindow.class).getParent(); if (uiForm.isAddNew_) { uiTempContainer.removeChildById(UIECMTemplateList.ST_ecmTempForm + "Add"); } else { uiTempContainer.removeChildById(UIECMTemplateList.ST_ecmTempForm + "Edit"); } event.getRequestContext().addUIComponentToUpdateByAjax(uiTempContainer); } } static public class ResetActionListener extends EventListener<UITemplateForm> { public void execute(Event<UITemplateForm> event) throws Exception { UITemplateForm uiForm = event.getSource(); UITemplateContainer uiTempContainer = uiForm.getAncestorOfType(UIPopupWindow.class).getParent(); if (uiForm.selectedVersion_ != null) { if (!uiForm.selectedVersion_.getName().equals(uiForm.baseVersionName_)) { Node templateNode = NodeLocation.getNodeByLocation(uiForm.template_); templateNode.restore(uiForm.baseVersionName_, true); templateNode.checkout(); } } uiForm.refresh(); UIECMTemplateList uiECMTempList = uiTempContainer.getChild(UIECMTemplateList.class); uiECMTempList.refresh(uiECMTempList.getUIPageIterator().getCurrentPage()); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); } } static public class ChangeActionListener extends EventListener<UITemplateForm> { public void execute(Event<UITemplateForm> event) throws Exception { UITemplateForm uiForm = event.getSource(); String version = uiForm.getUIFormSelectBox(FIELD_VERSION).getValue(); String path = NodeLocation.getNodeByLocation(uiForm.template_).getVersionHistory().getVersion(version).getPath(); VersionNode versionNode = uiForm.rootVersionNode.findVersionNode(path); Node frozenNode = versionNode.getNode(Utils.JCR_FROZEN); String content = uiForm.templateService.getTemplate(frozenNode); uiForm.getUIFormTextAreaInput(FIELD_CONTENT).setValue(content); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); } } static public class RestoreActionListener extends EventListener<UITemplateForm> { public void execute(Event<UITemplateForm> event) throws Exception { UITemplateForm uiForm = event.getSource(); String version = uiForm.getUIFormSelectBox(FIELD_VERSION).getValue(); String path = NodeLocation.getNodeByLocation(uiForm.template_).getVersionHistory().getVersion(version).getPath(); VersionNode selectedVesion = uiForm.rootVersionNode.findVersionNode(path); if (uiForm.baseVersionName_.equals(selectedVesion.getName())) return; uiForm.update(null, selectedVesion); UITemplateContainer uiTempContainer = uiForm.getAncestorOfType(UIPopupWindow.class).getParent(); UIECMTemplateList uiECMTempList = uiTempContainer.getChild(UIECMTemplateList.class); uiECMTempList.refresh(uiECMTempList.getUIPageIterator().getCurrentPage()); UITemplateContainer uiTemplateContainer = uiForm.getAncestorOfType(UITemplateContainer.class); if (uiForm.isAddNew_) { uiTemplateContainer.removeChildById(UIECMTemplateList.ST_ecmTempForm + "Add"); } else { uiTemplateContainer.removeChildById(UIECMTemplateList.ST_ecmTempForm + "Edit"); } event.getRequestContext().addUIComponentToUpdateByAjax(uiTempContainer); } } }
19,850
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITemplateContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/views/UITemplateContainer.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.admin.views; 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 * Nov 23, 2006 * 3:47:44 PM */ @ComponentConfig(lifecycle = UIContainerLifecycle.class) public class UITemplateContainer extends UIContainer { public UITemplateContainer() throws Exception { } public void initPopup(String compId, String type) throws Exception { String popupId = compId + type ; removeChildById(popupId) ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, popupId) ; uiPopup.setShowMask(true); uiPopup.setWindowSize(600,280) ; UITemplateForm uiTempForm = createUIComponent(UITemplateForm.class, null, compId) ; if(type.equals("Add")) { uiTempForm.isAddNew_ = true ; uiTempForm.setActions(new String[]{"Save", "Reset", "Cancel"}) ; } else if(type.equals("Edit")) { uiTempForm.isAddNew_ = false ; uiTempForm.setActions(new String[]{"Save", "Cancel"}) ; } uiTempForm.updateOptionList() ; uiPopup.setUIComponent(uiTempForm) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } }
2,128
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIECMTemplateList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/views/UIECMTemplateList.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.admin.views; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import javax.jcr.AccessDeniedException; 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.core.UIPagingGrid; import org.exoplatform.services.cms.BasePath; import org.exoplatform.services.cms.drives.ManageDriveService; import org.exoplatform.services.cms.impl.Utils; import org.exoplatform.services.cms.views.ManageViewService; import org.exoplatform.services.cms.views.impl.ManageViewPlugin; import org.exoplatform.services.jcr.ext.common.SessionProvider; 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.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Tran The Trong * trongtt@exoplatform.com * Sep 19, 2006 * 11:45:11 AM */ @ComponentConfig( template = "system:/groovy/ecm/webui/UIGridWithButton.gtmpl", events = { @EventConfig(listeners = UIECMTemplateList.DeleteActionListener.class, confirm = "UIECMTemplateList.msg.confirm-delete"), @EventConfig(listeners = UIECMTemplateList.EditInfoActionListener.class), @EventConfig(listeners = UIECMTemplateList.AddActionListener.class) } ) public class UIECMTemplateList extends UIPagingGrid { private static String[] VIEW_BEAN_FIELD = {"name"} ; private static String[] VIEW_ACTION = {"EditInfo","Delete"} ; public static String ST_ecmTempForm = "ecmTempForm" ; public static String ST_ECMTemp = "ECMTemplate" ; public UIECMTemplateList() throws Exception { getUIPageIterator().setId("UIECMTemplateGrid") ; configure("path", VIEW_BEAN_FIELD, VIEW_ACTION) ; } public String[] getActions() { return new String[] {"Add"} ; } public void refresh(int currentPage) throws Exception { List<Node> nodes = getApplicationComponent(ManageViewService.class) .getAllTemplates( BasePath.ECM_EXPLORER_TEMPLATES, WCMCoreUtils.getSystemSessionProvider()); List<TemplateBean> tempBeans = new ArrayList<TemplateBean>(); for (Node node : nodes) { tempBeans.add(new TemplateBean(node.getName(), node.getPath())); } Collections.sort(tempBeans, new ECMViewComparator()); ListAccess<TemplateBean> tmplBeanList = new ListAccessImpl<TemplateBean>(TemplateBean.class, tempBeans); getUIPageIterator().setPageList(new LazyPageList<TemplateBean>(tmplBeanList, getUIPageIterator().getItemsPerPage())); getUIPageIterator().setTotalItems(tempBeans.size()); if (currentPage > getUIPageIterator().getAvailablePage()) getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage()); else getUIPageIterator().setCurrentPage(currentPage); } static public class ECMViewComparator implements Comparator<TemplateBean> { public int compare(TemplateBean o1, TemplateBean o2) throws ClassCastException { String name1 = o1.getName(); String name2 = o2.getName(); return name1.compareToIgnoreCase(name2); } } static public class AddActionListener extends EventListener<UIECMTemplateList> { public void execute(Event<UIECMTemplateList> event) throws Exception { UIECMTemplateList uiECMTempList = event.getSource() ; SessionProvider provider = WCMCoreUtils.getSystemSessionProvider(); Node ecmTemplateHome = uiECMTempList.getApplicationComponent(ManageViewService.class) .getTemplateHome(BasePath.ECM_EXPLORER_TEMPLATES, provider); if (ecmTemplateHome == null) { UIApplication uiApp = event.getSource().getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UIECMTemplateList.msg.access-denied", null, ApplicationMessage.WARNING)); return; } UIViewManager uiViewManager = uiECMTempList.getAncestorOfType(UIViewManager.class) ; UITemplateContainer uiECMTempContainer = uiViewManager.getChildById(UIECMTemplateList.ST_ECMTemp) ; uiECMTempContainer.removeChildById(UIECMTemplateList.ST_ecmTempForm + "Edit") ; uiECMTempContainer.initPopup(UIECMTemplateList.ST_ecmTempForm, "Add") ; event.getRequestContext().addUIComponentToUpdateByAjax(uiECMTempContainer) ; } } static public class DeleteActionListener extends EventListener<UIECMTemplateList> { public void execute(Event<UIECMTemplateList> event) throws Exception { UIECMTemplateList uiECMTemp = event.getSource() ; ManageViewService vservice = uiECMTemp.getApplicationComponent(ManageViewService.class) ; uiECMTemp.setRenderSibling(UIECMTemplateList.class); String templatePath = event.getRequestContext().getRequestParameter(OBJECTID) ; String templateName = templatePath.substring(templatePath.lastIndexOf("/") + 1) ; if (uiECMTemp.getApplicationComponent(ManageDriveService.class).isUsedView(templateName)) { UIApplication app = uiECMTemp.getAncestorOfType(UIApplication.class); Object[] args = { templateName }; app.addMessage(new ApplicationMessage("UIECMTemplateList.msg.template-in-use", args)); return; } try { vservice.removeTemplate(templatePath, WCMCoreUtils.getSystemSessionProvider()); Utils.addEditedConfiguredData(templateName, ManageViewPlugin.class.getSimpleName(), ManageViewPlugin.EDITED_CONFIGURED_VIEWS_TEMPLATES, true); } catch (AccessDeniedException ex) { UIApplication app = uiECMTemp.getAncestorOfType(UIApplication.class); Object[] args = { "UIViewFormTabPane.label.option." + templateName }; app.addMessage(new ApplicationMessage("UIECMTemplateList.msg.delete-permission-denied", args, ApplicationMessage.WARNING)); return; } uiECMTemp.refresh(uiECMTemp.getUIPageIterator().getCurrentPage()) ; UITemplateContainer uiTempContainer = uiECMTemp.getParent() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiTempContainer) ; } } static public class EditInfoActionListener extends EventListener<UIECMTemplateList> { public void execute(Event<UIECMTemplateList> event) throws Exception { UIECMTemplateList uiECMTemp = event.getSource() ; String tempPath = event.getRequestContext().getRequestParameter(OBJECTID) ; UITemplateContainer uiTempContainer = uiECMTemp.getParent() ; uiTempContainer.removeChildById(UIECMTemplateList.ST_ecmTempForm + "Add") ; uiTempContainer.initPopup(UIECMTemplateList.ST_ecmTempForm, "Edit") ; UITemplateForm uiTempForm = uiTempContainer.findComponentById(UIECMTemplateList.ST_ecmTempForm) ; uiTempForm.update(tempPath, null) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiTempContainer) ; } } }
8,439
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIViewPermissionForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/views/UIViewPermissionForm.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.admin.views; import javax.jcr.Node; import org.exoplatform.ecm.permission.info.UIPermissionInputSet; import org.exoplatform.ecm.webui.core.UIPermissionFormBase; import org.exoplatform.ecm.webui.core.UIPermissionManagerBase; import org.exoplatform.ecm.webui.selector.UIGroupMemberSelector; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.ecm.webui.utils.Utils; 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.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; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Feb 18, 2013 * 1:39:45 PM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/admin/view/UIViewPermissionForm.gtmpl", events = { @EventConfig(listeners = UIViewPermissionForm.AddActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIViewPermissionForm.SelectUserActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIViewPermissionForm.SelectMemberActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIViewPermissionForm.AddAnyActionListener.class) } ) public class UIViewPermissionForm extends UIPermissionFormBase implements UISelectable{ public static final String TAB_PERMISSION = "permission"; public UIViewPermissionForm() throws Exception { removeChildById(UIPermissionFormBase.PERMISSION); addChild(new UIPermissionInputSet(TAB_PERMISSION)); UIPermissionInputSet uiPerInputset = getChildById(TAB_PERMISSION); uiPerInputset.setButtonActions(new String[] {"Add"}); uiPerInputset.setPrimaryButtonAction("Add"); uiPerInputset.setActionInfo(UIPermissionInputSet.FIELD_USERORGROUP, new String[] {"SelectUser", "SelectMember"}); } static public class SelectUserActionListener extends EventListener<UIViewPermissionForm> { public void execute(Event<UIViewPermissionForm> event) throws Exception { UIViewPermissionForm uiForm = event.getSource(); ((UIPermissionManagerBase)uiForm.getParent()).initUserSelector(); UIPopupContainer popupContainer = uiForm.getAncestorOfType(UIPopupContainer.class); if (popupContainer != null) { event.getRequestContext().addUIComponentToUpdateByAjax(popupContainer); } else { event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } } static public class AddAnyActionListener extends EventListener<UIViewPermissionForm> { public void execute(Event<UIViewPermissionForm> event) throws Exception { UIViewPermissionForm uiForm = event.getSource(); UIPermissionInputSet uiInputSet = uiForm.getChildById(TAB_PERMISSION); uiInputSet.getUIStringInput(UIPermissionInputSet.FIELD_USERORGROUP).setValue(IdentityConstants.ANY); UIPopupContainer popupContainer = uiForm.getAncestorOfType(UIPopupContainer.class); if (popupContainer != null) { event.getRequestContext().addUIComponentToUpdateByAjax(popupContainer); } else { event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } } static public class SelectMemberActionListener extends EventListener<UIViewPermissionForm> { public void execute(Event<UIViewPermissionForm> event) throws Exception { UIViewPermissionForm uiForm = event.getSource(); UIGroupMemberSelector uiGroupMemberSelector = uiForm.createUIComponent(UIGroupMemberSelector.class, null, null); uiGroupMemberSelector.setShowAnyPermission(false); uiGroupMemberSelector.setSourceComponent(uiForm, new String[] { UIPermissionInputSet.FIELD_USERORGROUP }); uiForm.getAncestorOfType(UIPermissionManagerBase.class).initPopupPermission(uiGroupMemberSelector); UIPopupContainer popupContainer = uiForm.getAncestorOfType(UIPopupContainer.class); if (popupContainer != null) { event.getRequestContext().addUIComponentToUpdateByAjax(popupContainer); } else { event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } } static public class AddActionListener extends EventListener<UIViewPermissionForm> { public void execute(Event<UIViewPermissionForm> event) throws Exception { UIViewPermissionForm uiForm = event.getSource(); UIViewPermissionContainer uiContainer = uiForm.getParent(); UIViewFormTabPane uiTabPane = uiContainer.getParent(); UIViewForm uiViewForm = uiTabPane.getChild(UIViewForm.class); UIViewPermissionList uiList = uiContainer.getChild(UIViewPermissionList.class); String permission = uiForm.getUIStringInput(UIPermissionInputSet.FIELD_USERORGROUP).getValue(); String strPermission = uiViewForm.getPermission(); if (Utils.isNameEmpty(permission)) { UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UIPermissionForm.msg.userOrGroup-required", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiContainer); uiTabPane.setSelectedTab(uiContainer.getId()); return; } if(strPermission.contains(permission)) { UIApplication app = uiForm.getAncestorOfType(UIApplication.class); Object[] args = { permission }; app.addMessage(new ApplicationMessage("UIViewPermissionForm.msg.permission-exist", args, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiContainer); uiTabPane.setSelectedTab(uiContainer.getId()); return; } StringBuilder strBuilder = new StringBuilder(strPermission); if(strPermission.length() > 0) { strBuilder = strBuilder.append(","); } strBuilder.append(permission); uiViewForm.setPermission(strBuilder.toString()); uiList.refresh(uiList.getUIPageIterator().getCurrentPage()); uiForm.getUIStringInput(UIPermissionInputSet.FIELD_USERORGROUP).setValue(null); event.getRequestContext().addUIComponentToUpdateByAjax(uiContainer); } } @Override public void doSelect(String selectField, Object value) { getUIStringInput(selectField).setValue(value.toString()); } @Override public Node getCurrentNode() throws Exception { return null; } }
7,830
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINamespaceList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/namespace/UINamespaceList.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.admin.namespace; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import javax.jcr.NamespaceRegistry; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.core.UIPagingGrid; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; 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 20, 2006 * 16:37:15 */ @ComponentConfig( template = "system:/groovy/ecm/webui/UIGridWithButton.gtmpl", events = {@EventConfig(listeners = UINamespaceList.AddNamespaceActionListener.class)} ) public class UINamespaceList extends UIPagingGrid { private static String[] NAMESPACE_BEAN_FIELD = {"prefix", "uri"} ; public UINamespaceList() throws Exception { getUIPageIterator().setId("NamespaceListIterator") ; configure("prefix", NAMESPACE_BEAN_FIELD, null) ; } public String[] getActions() { return new String[] {"AddNamespace"} ;} @SuppressWarnings("unchecked") public void refresh(int currentPage) throws Exception { NamespaceRegistry namespaceRegistry = getApplicationComponent(RepositoryService.class).getCurrentRepository() .getNamespaceRegistry(); List<NamespaceBean> nspBeans = new ArrayList<NamespaceBean>(); String[] prefixs = namespaceRegistry.getPrefixes(); for (int i = 0; i < prefixs.length; i++) { String prefix = prefixs[i]; if (prefix == null || prefix.trim().length() == 0) { continue; } NamespaceBean bean = new NamespaceBean(prefix, namespaceRegistry.getURI(prefix)); nspBeans.add(bean); } Collections.sort(nspBeans, new NameSpaceComparator()); ListAccess<NamespaceBean> namespaceList = new ListAccessImpl<NamespaceBean>(NamespaceBean.class, nspBeans); LazyPageList<NamespaceBean> dataPageList = new LazyPageList<NamespaceBean>(namespaceList, getUIPageIterator().getItemsPerPage()); getUIPageIterator().setTotalItems(nspBeans.size()); getUIPageIterator().setPageList(dataPageList); if (currentPage > getUIPageIterator().getAvailablePage()) getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage()); else getUIPageIterator().setCurrentPage(currentPage); } static public class NameSpaceComparator implements Comparator<NamespaceBean> { public int compare(NamespaceBean o1, NamespaceBean o2) throws ClassCastException { String name1 = o1.getPrefix(); String name2 = o2.getPrefix(); return name1.compareToIgnoreCase(name2); } } static public class AddNamespaceActionListener extends EventListener<UINamespaceList> { public void execute(Event<UINamespaceList> event) throws Exception { UINamespaceManager uiManager = event.getSource().getParent() ; uiManager.initPopup() ; UINamespaceForm uiForm = uiManager.findFirstComponentOfType(UINamespaceForm.class) ; uiForm.reset() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } public static class NamespaceBean { private String prefix ; private String uri ; public NamespaceBean(String prefix, String uri){ this.prefix = prefix ; this.uri = uri ; } public String getPrefix () { return prefix ;} public String getUri () { return uri ;} } }
4,641
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINamespaceForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/namespace/UINamespaceForm.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.admin.namespace; import javax.jcr.NamespaceRegistry; import org.exoplatform.ecm.webui.form.validator.ECMNameValidator; import org.exoplatform.services.jcr.RepositoryService; 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.EventListener; import org.exoplatform.webui.event.Event.Phase; 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 : phamtuan * phamtuanchip@yahoo.de September 20, 2006 16:37:15 */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "classpath:groovy/ecm/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UINamespaceForm.SaveActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UINamespaceForm.CancelActionListener.class) } ) public class UINamespaceForm extends UIForm { final static public String FIELD_PREFIX = "namespace" ; final static public String FIELD_URI = "uri" ; public UINamespaceForm() throws Exception { addUIFormInput(new UIFormStringInput(FIELD_PREFIX, FIELD_PREFIX, null). addValidator(MandatoryValidator.class). addValidator(ECMNameValidator.class)) ; addUIFormInput(new UIFormStringInput(FIELD_URI, FIELD_URI, null). addValidator(MandatoryValidator.class)) ; } static public class SaveActionListener extends EventListener<UINamespaceForm> { public void execute(Event<UINamespaceForm> event) throws Exception { UINamespaceForm uiForm = event.getSource() ; String uri = uiForm.getUIStringInput(FIELD_URI).getValue() ; UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class) ; NamespaceRegistry namespaceRegistry = uiForm.getApplicationComponent(RepositoryService.class) .getCurrentRepository().getNamespaceRegistry() ; String prefix = uiForm.getUIStringInput(FIELD_PREFIX).getValue() ; if(prefix == null || prefix.trim().length() == 0) { uiApp.addMessage(new ApplicationMessage("UINamespaceForm.msg.prefix-null", null, ApplicationMessage.WARNING)) ; return ; } if(uri == null || uri.trim().length() == 0) { uiApp.addMessage(new ApplicationMessage("UINamespaceForm.msg.uri-null", null, ApplicationMessage.WARNING)) ; return ; } UINamespaceManager uiManager = uiForm.getAncestorOfType(UINamespaceManager.class) ; if (contains(namespaceRegistry.getPrefixes(), prefix) || contains(namespaceRegistry.getURIs(), uri)) { uiApp.addMessage(new ApplicationMessage("UINamespaceForm.msg.register-unsuccessfull", null, ApplicationMessage.WARNING)) ; return ; } try { namespaceRegistry.registerNamespace(prefix, uri) ; uiManager.refresh() ; uiManager.removeChild(UIPopupWindow.class) ; } catch (Exception e) { uiApp.addMessage(new ApplicationMessage("UINamespaceForm.msg.register-unsuccessfull", null, ApplicationMessage.WARNING)) ; return ; } event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } private boolean contains(String[] arr, String st) { if (st == null) return false; for (String value : arr) if (st.equals(value)) return true; return false; } } static public class CancelActionListener extends EventListener<UINamespaceForm> { public void execute(Event<UINamespaceForm> event) throws Exception { UINamespaceForm uiForm = event.getSource() ; UINamespaceManager uiManager = uiForm.getAncestorOfType(UINamespaceManager.class) ; uiManager.removeChild(UIPopupWindow.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } }
5,064
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINamespaceManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/namespace/UINamespaceManager.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.admin.namespace; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; import org.exoplatform.webui.ext.manager.UIAbstractManager; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * September 20, 2006 * 16:37:15 AM */ @ComponentConfig(lifecycle = UIContainerLifecycle.class) public class UINamespaceManager extends UIAbstractManager { public UINamespaceManager() throws Exception {addChild(UINamespaceList.class, null, null) ;} public void refresh ()throws Exception { UINamespaceList list = getChild(UINamespaceList.class) ; list.refresh(1); } public void initPopup() throws Exception { UIPopupWindow uiPopup = getChild(UIPopupWindow.class) ; if(uiPopup == null) { uiPopup = addChild(UIPopupWindow.class, null, "NamespacePopup") ; uiPopup.setWindowSize(600,0) ; UINamespaceForm uiNamespaceForm = createUIComponent(UINamespaceForm.class, null, "UINamespaceForm") ; uiPopup.setUIComponent(uiNamespaceForm) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; uiPopup.setShowMask(true); return ; } uiPopup.setRendered(true) ; uiPopup.setShow(true) ; } }
2,077
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITaxonomyTreeContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/UITaxonomyTreeContainer.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.admin.taxonomy; import java.security.AccessControlException; import java.util.ArrayList; import java.util.List; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.Workspace; import org.exoplatform.ecm.webui.component.admin.taxonomy.action.UIActionForm; import org.exoplatform.ecm.webui.component.admin.taxonomy.action.UIActionTaxonomyManager; import org.exoplatform.ecm.webui.component.admin.taxonomy.action.UIActionTypeForm; import org.exoplatform.ecm.webui.component.admin.taxonomy.tree.info.UIPermissionTreeForm; import org.exoplatform.ecm.webui.component.admin.taxonomy.tree.info.UIPermissionTreeInfo; import org.exoplatform.ecm.webui.component.admin.taxonomy.tree.info.UIPermissionTreeManager; import org.exoplatform.ecm.webui.core.bean.PermissionBean; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.ecm.webui.utils.PermissionUtil; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.cms.actions.ActionServiceContainer; import org.exoplatform.services.cms.taxonomy.TaxonomyService; import org.exoplatform.services.cms.taxonomy.TaxonomyTreeData; import org.exoplatform.services.cms.taxonomy.impl.TaxonomyAlreadyExistsException; import org.exoplatform.services.cms.taxonomy.impl.TaxonomyNodeAlreadyExistsException; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.access.AccessControlEntry; import org.exoplatform.services.jcr.access.AccessControlList; import org.exoplatform.services.jcr.access.PermissionType; import org.exoplatform.services.jcr.core.ExtendedNode; import org.exoplatform.services.security.IdentityConstants; 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.core.UIPopupWindow; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIFormStringInput; /** * Created by The eXo Platform SARL * Author : Hoang Van Hung * hunghvit@gmail.com * Apr 3, 2009 */ @ComponentConfig( template = "app:/groovy/webui/component/admin/taxonomy/UITaxonomyTreeWizard.gtmpl", events = { @EventConfig(listeners = UITaxonomyTreeContainer.RefreshActionListener.class), @EventConfig(listeners = UITaxonomyTreeContainer.CancelActionListener.class) } ) public class UITaxonomyTreeContainer extends UIContainer implements UISelectable { private int selectedStep_ = 1; private int currentStep_ = 0; private TaxonomyTreeData taxonomyTreeData; public static final String POPUP_PERMISSION = "PopupTaxonomyTreePermission"; public static final String POPUP_TAXONOMYHOMEPATH = "PopupTaxonomyJCRBrowser"; private String[] actions_ = { "Cancel" }; public UITaxonomyTreeContainer() throws Exception { addChild(UITaxonomyTreeMainForm.class, null, "TaxonomyTreeMainForm"); addChild(UIPermissionTreeManager.class, null, "TaxonomyPermissionTree").setRendered(false); addChild(UIActionTaxonomyManager.class, null, null).setRendered(false); } public String[] getActions() {return actions_;} public void setCurrentSep(int step) { currentStep_ = step; } public int getCurrentStep() { return currentStep_; } public void setSelectedStep(int step) { selectedStep_ = step; } public int getSelectedStep() { return selectedStep_; } public TaxonomyTreeData getTaxonomyTreeData() { return taxonomyTreeData; } public void setTaxonomyTreeData(TaxonomyTreeData taxonomyTreeData) { this.taxonomyTreeData = taxonomyTreeData; } public void viewStep(int step) { selectedStep_ = step; currentStep_ = step - 1; List<UIComponent> children = getChildren(); for(int i=0; i<children.size(); i++){ if(i == getCurrentStep()) { children.get(i).setRendered(true); } else { children.get(i).setRendered(false); } } } public void refresh() throws Exception { if (taxonomyTreeData == null) { taxonomyTreeData = new TaxonomyTreeData(); } taxonomyTreeData.setRepository(getApplicationComponent(RepositoryService.class).getCurrentRepository() .getConfiguration() .getName()); String taxoTreeName = taxonomyTreeData.getTaxoTreeName(); UIActionTaxonomyManager uiActionTaxonomyManager = getChild(UIActionTaxonomyManager.class); UIActionTypeForm uiActionTypeForm = uiActionTaxonomyManager.getChild(UIActionTypeForm.class); if (taxonomyTreeData.isEdit()) { removeChild(UITaxonomyTreeCreateChild.class); UITaxonomyTreeCreateChild uiTaxonomyCreateChild = addChild(UITaxonomyTreeCreateChild.class, null, null); TaxonomyService taxonomyService = getApplicationComponent(TaxonomyService.class); ActionServiceContainer actionService = getApplicationComponent(ActionServiceContainer.class); Node taxoTreeNode = taxonomyService.getTaxonomyTree(taxoTreeName, true); if (taxoTreeNode != null) { loadData(taxoTreeNode); Node actionNode = actionService.getAction(taxoTreeNode, taxonomyTreeData .getTaxoTreeActionName()); uiActionTaxonomyManager.removeChild(UIActionForm.class); UIActionForm uiActionForm = uiActionTaxonomyManager.addChild(UIActionForm.class, null, null); uiActionTypeForm.setDefaultActionType(taxonomyTreeData.getTaxoTreeActionTypeName()); uiActionForm.createNewAction(taxoTreeNode, taxonomyTreeData.getTaxoTreeActionTypeName(), true); uiActionForm.setWorkspace(taxonomyTreeData.getTaxoTreeWorkspace()); uiActionForm.setNodePath(actionNode.getPath()); if (uiTaxonomyCreateChild == null) uiTaxonomyCreateChild = addChild(UITaxonomyTreeCreateChild.class, null, null); uiTaxonomyCreateChild.setWorkspace(getTaxonomyTreeData().getTaxoTreeWorkspace()); uiTaxonomyCreateChild.setTaxonomyTreeNode(taxoTreeNode); UIPermissionTreeInfo uiPermInfo = findFirstComponentOfType(UIPermissionTreeInfo.class); UIPermissionTreeForm uiPermForm = findFirstComponentOfType(UIPermissionTreeForm.class); uiPermInfo.setCurrentNode(taxoTreeNode); uiPermForm.setCurrentNode(taxoTreeNode); uiPermInfo.updateGrid(); } } uiActionTypeForm.setDefaultActionType(null); findFirstComponentOfType(UITaxonomyTreeMainForm.class).update(taxonomyTreeData); } private void loadData(Node taxoTreeTargetNode) throws RepositoryException, Exception{ String taxoTreeName = taxonomyTreeData.getTaxoTreeName(); if (taxoTreeName == null || taxoTreeName.length() == 0) return; if (taxoTreeTargetNode != null) { Session session = taxoTreeTargetNode.getSession(); taxonomyTreeData.setTaxoTreeWorkspace(session.getWorkspace().getName()); taxonomyTreeData.setTaxoTreeHomePath(taxoTreeTargetNode.getParent().getPath()); taxonomyTreeData.setTaxoTreePermissions(""); ActionServiceContainer actionService = getApplicationComponent(ActionServiceContainer.class); List<Node> lstActionNodes = actionService.getActions(taxoTreeTargetNode); if (lstActionNodes != null && lstActionNodes.size() > 0) { Node node = lstActionNodes.get(0); if (node != null) { taxonomyTreeData.setTaxoTreeActionName(node.getName()); taxonomyTreeData.setTaxoTreeActionTypeName(node.getPrimaryNodeType().getName()); } } } } private UIFormStringInput getFormInputById(String id) { return (UIFormStringInput)findComponentById(id); } public Session getSession(String workspace) throws RepositoryException { return WCMCoreUtils.getSystemSessionProvider().getSession(workspace, WCMCoreUtils.getRepository()); } public void doSelect(String selectField, Object value) throws Exception { getFormInputById(selectField).setValue(value.toString()); UITaxonomyManagerTrees uiContainer = getAncestorOfType(UITaxonomyManagerTrees.class); for (UIComponent uiChild : uiContainer.getChildren()) { if (uiChild.getId().equals(UITaxonomyTreeContainer.POPUP_PERMISSION) || uiChild.getId().equals(UITaxonomyTreeContainer.POPUP_TAXONOMYHOMEPATH)) { UIPopupWindow uiPopup = uiContainer.getChildById(uiChild.getId()); uiPopup.setRendered(false); uiPopup.setShow(false); } } } /** * Add taxonomy tree with given name, workspace, home path. Add permission for tree node * @param name * @param workspace * @param homePath * @param permBeans * @throws TaxonomyAlreadyExistsException * @throws TaxonomyNodeAlreadyExistsException * @throws AccessControlException * @throws Exception */ public void addTaxonomyTree(String name, String workspace, String homePath, List<PermissionBean> permBeans) throws TaxonomyAlreadyExistsException, TaxonomyNodeAlreadyExistsException, AccessControlException, Exception { TaxonomyService taxonomyService = getApplicationComponent(TaxonomyService.class); taxonomyService.addTaxonomyNode(workspace, homePath, name, Util.getPortalRequestContext().getRemoteUser()); Session session = getSession(workspace); Node homeNode = (Node)session.getItem(homePath); Node taxonomyTreeNode = homeNode.getNode(name); ExtendedNode node = (ExtendedNode) taxonomyTreeNode; if (permBeans != null && permBeans.size() > 0) { if (PermissionUtil.canChangePermission(node)) { if (node.canAddMixin("exo:privilegeable")){ node.addMixin("exo:privilegeable"); } if (node.isNodeType("exo:privilegeable")) { AccessControlList acl = node.getACL(); List<AccessControlEntry> permissionEntries = acl.getPermissionEntries(); String nodeOwner = Utils.getNodeOwner(node); for (AccessControlEntry accessControlEntry : permissionEntries) { String identity = accessControlEntry.getIdentity(); if (IdentityConstants.SYSTEM.equals(identity) || identity.equals(nodeOwner)) { continue; } node.removePermission(identity); } if(nodeOwner != null) { node.setPermission(nodeOwner, PermissionType.ALL); } if(PermissionUtil.canChangePermission(node)) { for(PermissionBean permBean : permBeans) { List<String> permsList = new ArrayList<String>(); if (permBean.isRead()) permsList.add(PermissionType.READ); if (permBean.isAddNode()) permsList.add(PermissionType.ADD_NODE); if (permBean.isRemove()) permsList.add(PermissionType.REMOVE); if (permsList.size() > 0) { node.setPermission(permBean.getUsersOrGroups(), permsList.toArray(new String[permsList.size()])); } } } node.save(); } } } homeNode.save(); session.save(); taxonomyService.addTaxonomyTree(taxonomyTreeNode); } /** * Update taxonomy tree: If home path or workspace is changed, move taxonomy tree to new target * @param name * @param workspace * @param homePath * @return true: if taxonomy tree already has moved successfully * false: if taxonomy has not changed * @throws RepositoryException * @throws AccessControlException * @throws Exception */ public boolean updateTaxonomyTree(String name, String workspace, String homePath, String actionName) throws RepositoryException, AccessControlException, Exception { String repository = getApplicationComponent(RepositoryService.class).getCurrentRepository() .getConfiguration() .getName(); TaxonomyService taxonomyService = getApplicationComponent(TaxonomyService.class); Node taxonomyTreeNode = taxonomyService.getTaxonomyTree(name, true); Node homeNode = taxonomyTreeNode.getParent(); String srcWorkspace = taxonomyTreeNode.getSession().getWorkspace().getName(); Session session = getSession(workspace); Workspace objWorkspace = session.getWorkspace(); //No change if (homeNode.getPath().equals(homePath) && srcWorkspace.equals(workspace)) return false; ActionServiceContainer actionService = getApplicationComponent(ActionServiceContainer.class); if (actionService.hasActions(taxonomyTreeNode)) { actionService.removeAction(taxonomyTreeNode, actionName, repository); } String destPath = homePath + "/" + name; destPath = destPath.replaceAll("/+", "/"); if (srcWorkspace.equals(workspace)) { objWorkspace.move(taxonomyTreeNode.getPath(), destPath); } else { objWorkspace.copy(srcWorkspace, taxonomyTreeNode.getPath(), destPath); taxonomyTreeNode.remove(); homeNode.save(); } session.save(); //Update taxonomy tree taxonomyTreeNode = (Node)session.getItem(destPath); taxonomyService.updateTaxonomyTree(name, taxonomyTreeNode); return true; } public static class RefreshActionListener extends EventListener<UITaxonomyTreeContainer> { public void execute(Event<UITaxonomyTreeContainer> event) throws Exception { event.getSource().refresh(); event.getRequestContext().addUIComponentToUpdateByAjax(event.getSource()); } } public static class CancelActionListener extends EventListener<UITaxonomyTreeContainer> { public void execute(Event<UITaxonomyTreeContainer> event) throws Exception { UITaxonomyTreeContainer uiTaxonomyTreeContainer = event.getSource(); UIPopupWindow uiPopup = uiTaxonomyTreeContainer.getParent(); UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiTaxonomyTreeContainer.getAncestorOfType(UITaxonomyManagerTrees.class); uiTaxonomyManagerTrees.removeChildById(UITaxonomyTreeList.ST_ADD); uiTaxonomyManagerTrees.removeChildById(UITaxonomyTreeList.ST_EDIT); uiTaxonomyManagerTrees.update(); uiPopup.setRendered(false); uiPopup.setShow(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } } }
15,928
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITaxonomyTreeCreateChildForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/UITaxonomyTreeCreateChildForm.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.admin.taxonomy; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; import org.exoplatform.ecm.webui.form.validator.ECMNameValidator; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.cms.taxonomy.TaxonomyService; import org.exoplatform.services.cms.taxonomy.TaxonomyTreeData; import org.exoplatform.services.cms.taxonomy.impl.TaxonomyNodeAlreadyExistsException; import org.exoplatform.services.jcr.ext.common.SessionProvider; import org.exoplatform.services.jcr.util.Text; import org.exoplatform.services.wcm.utils.WCMCoreUtils; 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.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.UIFormInputInfo; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.validator.MandatoryValidator; /** * Created by The eXo Platform SARL * Author : Hoang Van Hung * hunghvit@gmail.com * Apr 15, 2009 */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UITaxonomyTreeCreateChildForm.SaveActionListener.class), @EventConfig(listeners = UITaxonomyTreeCreateChildForm.CancelActionListener.class, phase = Phase.DECODE) } ) public class UITaxonomyTreeCreateChildForm extends UIForm { final static private String FIELD_PARENT = "parentPath"; final static private String FIELD_NAME = "taxonomyName"; public UITaxonomyTreeCreateChildForm() throws Exception { addUIFormInput(new UIFormInputInfo(FIELD_PARENT, FIELD_PARENT, null)); addUIFormInput(new UIFormStringInput(FIELD_NAME, FIELD_NAME, null).addValidator(MandatoryValidator.class).addValidator(ECMNameValidator.class)); } public void setParent(String path) { getUIFormInputInfo(FIELD_PARENT).setValue(path); getUIStringInput(FIELD_NAME).setValue(null); } public static class SaveActionListener extends EventListener<UITaxonomyTreeCreateChildForm> { public void execute(Event<UITaxonomyTreeCreateChildForm> event) throws Exception { UITaxonomyTreeCreateChildForm uiForm = event.getSource(); UITaxonomyTreeCreateChild uiCreateChild = uiForm.getAncestorOfType(UITaxonomyTreeCreateChild.class); UITaxonomyTreeContainer uiTaxonomyTreeContainer = uiForm.getAncestorOfType(UITaxonomyTreeContainer.class); UITaxonomyManagerTrees uiTaxonomyManageTrees = uiForm.getAncestorOfType(UITaxonomyManagerTrees.class); TaxonomyTreeData taxoTreeData = uiTaxonomyTreeContainer.getTaxonomyTreeData(); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); String title = uiForm.getUIStringInput(FIELD_NAME).getValue(); String name = Utils.cleanString(title); if (name == null || name.length() == 0) { uiApp.addMessage(new ApplicationMessage("UITaxonomyTreeCreateChildForm.msg.name-null", null, ApplicationMessage.WARNING)); return; } try { TaxonomyService taxonomyService = uiForm.getApplicationComponent(TaxonomyService.class); if (title.length() > Integer.parseInt(taxonomyService.getCategoryNameLength())) { Object[] args = { taxonomyService.getCategoryNameLength() }; uiApp.addMessage(new ApplicationMessage("UITaxonomyTreeCreateChildForm.msg.name-too-long", args, ApplicationMessage.WARNING)); return; } String parentPath = uiForm.getUIFormInputInfo(FIELD_PARENT).getValue(); taxonomyService.addTaxonomyNode(taxoTreeData .getTaxoTreeWorkspace(), parentPath, Text.escapeIllegalJcrChars(name), Util.getPortalRequestContext().getRemoteUser()); SessionProvider p = WCMCoreUtils.getSystemSessionProvider(); Session session = p.getSession(taxoTreeData.getTaxoTreeWorkspace(), WCMCoreUtils.getRepository()); Node newNode = (Node)session.getItem(parentPath + "/" + name); if (newNode.canAddMixin("exo:rss-enable")) { newNode.addMixin("exo:rss-enable"); newNode.setProperty("exo:title", title); } newNode.save(); uiCreateChild.update(); } catch (TaxonomyNodeAlreadyExistsException e) { Object[] arg = { name }; uiApp.addMessage(new ApplicationMessage("UITaxonomyTreeCreateChildForm.msg.exist", arg, ApplicationMessage.WARNING)); return; } catch (RepositoryException e) { Object[] arg = { name }; uiApp.addMessage(new ApplicationMessage("UITaxonomyTreeCreateChildForm.msg.error", arg, ApplicationMessage.WARNING)); return; } uiForm.reset(); UIPopupWindow uiPopup = uiForm.getParent(); uiPopup.setRendered(false); uiPopup.setShow(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManageTrees); } } public static class CancelActionListener extends EventListener<UITaxonomyTreeCreateChildForm> { public void execute(Event<UITaxonomyTreeCreateChildForm> event) throws Exception { UITaxonomyTreeCreateChildForm uiForm = event.getSource(); UIPopupWindow uiPopup = uiForm.getParent(); uiPopup.setRendered(false); uiPopup.setShow(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiPopup); } } }
7,012
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITaxonomyTreeBrowser.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/UITaxonomyTreeBrowser.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.admin.taxonomy; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; import org.exoplatform.ecm.webui.tree.UINodeTree; import org.exoplatform.ecm.webui.utils.PermissionUtil; 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.UIContainer; 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 * Apr 7, 2009 */ @ComponentConfig( template = "app:/groovy/webui/component/admin/taxonomy/UITaxonomyTree.gtmpl", events = @EventConfig(listeners = UITaxonomyTreeBrowser.ChangeNodeActionListener.class) ) public class UITaxonomyTreeBrowser extends UIContainer { private NodeLocation currentNode_; private NodeLocation rootNode_ = null; private String rootPath_; private String[] acceptedNodeTypes = {}; public UITaxonomyTreeBrowser() throws Exception { UINodeTree tree = addChild(UINodeTree.class, null, "UITaxonomyTreeBrowser"); tree.setBeanLabelField("name"); tree.setBeanIdField("path"); } public void update() throws Exception { UITaxonomyTreeCreateChild uiManager = getParent(); rootNode_ = NodeLocation.getNodeLocationByNode(uiManager.getRootNode()); rootPath_ = rootNode_.getPath(); } public Node getRootNode() { return NodeLocation.getNodeByLocation(rootNode_); } public String[] getAcceptedNodeTypes() { return acceptedNodeTypes; } public void setAcceptedNodeTypes(String[] acceptedNodeTypes) { this.acceptedNodeTypes = acceptedNodeTypes; } public boolean matchNodeType(Node node) throws Exception { if(acceptedNodeTypes == null || acceptedNodeTypes.length == 0) return true; for(String nodeType: acceptedNodeTypes) { if(node.isNodeType(nodeType)) return true; } return false; } public void buildTree() throws Exception { Iterator sibbling = null; Iterator children = null; UITaxonomyTreeCreateChild uiManager = getParent(); List<Node> taxonomyList = new ArrayList<Node>(); if(rootNode_ == null ) { update(); currentNode_ = rootNode_; children = getRootNode().getNodes(); changeNode(getRootNode()); } UINodeTree tree = getChildById("UITaxonomyTreeBrowser"); Node nodeSelected = getSelectedNode(); if(nodeSelected.getPath().equals(rootPath_)) { children = nodeSelected.getNodes(); } tree.setSelected(nodeSelected); if(nodeSelected.getDepth() > 0) { tree.setParentSelected(nodeSelected.getParent()); sibbling = nodeSelected.getParent().getNodes(); children = nodeSelected.getNodes(); } else { tree.setParentSelected(nodeSelected); sibbling = nodeSelected.getNodes(); } List<Node> sibblingList = new ArrayList<Node>(); List<Node> childrenList = new ArrayList<Node>(); if(nodeSelected.getPath().equals(uiManager.getTaxonomyTreeNode().getPath())) { sibbling = nodeSelected.getNodes(); } while(sibbling.hasNext()) { Node sibblingNode = (Node)sibbling.next(); if(!matchNodeType(sibblingNode)) continue; if(PermissionUtil.canRead(sibblingNode) && !sibblingNode.isNodeType("exo:hiddenable")) { sibblingList.add(sibblingNode); } } if(nodeSelected.getPath().equals(rootPath_)) { taxonomyList.add(uiManager.getTaxonomyTreeNode()); children = taxonomyList.iterator(); } if(children != null) { while(children.hasNext()) { Node childrenNode = (Node)children.next(); if(!matchNodeType(childrenNode)) continue; if(PermissionUtil.canRead(childrenNode) && !childrenNode.isNodeType("exo:hiddenable")) { childrenList.add(childrenNode); } } } if(nodeSelected.getPath().equals(rootPath_)) tree.setSibbling(childrenList); else tree.setSibbling(sibblingList); tree.setChildren(childrenList); } public void renderChildren() throws Exception { buildTree(); super.renderChildren(); } public String getRootPath() { return rootPath_; } public void setNodeSelect(String path) throws Exception { UITaxonomyTreeCreateChild uiManager = getParent(); currentNode_ = NodeLocation.getNodeLocationByNode(uiManager.getNodeByPath(path)); if (!rootNode_.getPath().equals("/")) if (getRootNode().getParent().getPath().equals(path)) currentNode_ = rootNode_; uiManager.setSelectedPath(currentNode_.getPath()); changeNode(NodeLocation.getNodeByLocation(currentNode_)); } public void changeNode(Node nodeSelected) throws Exception { List<Node> nodes = new ArrayList<Node>(); NodeIterator nodeIter = nodeSelected.getNodes(); List<Node> rootTaxonomyList = new ArrayList<Node>(); UITaxonomyTreeCreateChild uiTaxonomyManager = getParent(); while(nodeIter.hasNext()) { nodes.add(nodeIter.nextNode()); } if(nodeSelected.getPath().equals(rootPath_)) { rootTaxonomyList.add(uiTaxonomyManager.getTaxonomyTreeNode()); nodes = rootTaxonomyList; } UITaxonomyTreeCreateChild uiManager = getParent(); UITaxonomyTreeWorkingArea uiTreeWorkingArea = uiManager.getChild(UITaxonomyTreeWorkingArea.class); List<Node> lstNode = new ArrayList<Node>(); for (Node node : nodes) { if (uiTreeWorkingArea.matchNodeType(node)) lstNode.add(node); } uiTreeWorkingArea.setNodeList(lstNode); uiTreeWorkingArea.updateGrid(); } public Node getSelectedNode() { if(currentNode_ == null) return getRootNode(); return NodeLocation.getNodeByLocation(currentNode_); } public static class ChangeNodeActionListener extends EventListener<UITaxonomyTreeBrowser> { public void execute(Event<UITaxonomyTreeBrowser> event) throws Exception { UITaxonomyTreeBrowser uiTaxonomyTreeBrowser = event.getSource(); String uri = event.getRequestContext().getRequestParameter(OBJECTID) ; uiTaxonomyTreeBrowser.setNodeSelect(uri); UITaxonomyTreeCreateChild uiTaxonomyTreeCreateChild = uiTaxonomyTreeBrowser.getParent(); uiTaxonomyTreeCreateChild.onChange(uiTaxonomyTreeBrowser.getSelectedNode()); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyTreeCreateChild); } } }
7,567
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITaxonomyTreeCreateChild.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/UITaxonomyTreeCreateChild.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.admin.taxonomy; import java.util.ArrayList; import java.util.List; import javax.jcr.Node; import javax.jcr.Session; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.core.ManageableRepository; 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.ComponentConfigs; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.core.UIBreadcumbs; import org.exoplatform.webui.core.UIBreadcumbs.LocalPath; 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; 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 * Apr 5, 2009 */ @ComponentConfigs( { @ComponentConfig(lifecycle = UIContainerLifecycle.class), @ComponentConfig( type = UIBreadcumbs.class, id = "BreadcumbTaxonomyTreeECMAdmin", template = "system:/groovy/webui/core/UIBreadcumbs.gtmpl", events = @EventConfig(listeners = UITaxonomyTreeCreateChild.SelectPathActionListener.class) ) } ) public class UITaxonomyTreeCreateChild extends UIContainer { private String workspace; public static final String PERMISSION_ID_POPUP = "TaxonomyTreeViewPermissionPopup"; private String selectedPath_ = null ; private NodeLocation taxonomyTreeNode = null; public UITaxonomyTreeCreateChild() throws Exception { addChild(UIBreadcumbs.class, "BreadcumbTaxonomyTreeECMAdmin", "BreadcumbTaxonomyTreeECMAdmin"); UITaxonomyTreeBrowser uiTaxonomyTreeBrowser = addChild(UITaxonomyTreeBrowser.class, null, null); uiTaxonomyTreeBrowser.setAcceptedNodeTypes(new String[] {Utils.EXO_TAXONOMY}); UITaxonomyTreeWorkingArea uiTaxonomyTreeWorkingArea = addChild(UITaxonomyTreeWorkingArea.class, null, null); uiTaxonomyTreeWorkingArea.setAcceptedNodeTypes(new String[] {Utils.EXO_TAXONOMY}); } public void update() throws Exception { UITaxonomyTreeBrowser uiTree = getChild(UITaxonomyTreeBrowser.class); uiTree.update(); UITaxonomyTreeWorkingArea uiTaxonomyTreeWorkingArea = getChild(UITaxonomyTreeWorkingArea.class); uiTaxonomyTreeWorkingArea.update(); } public void update(String path) throws Exception { UITaxonomyTreeBrowser uiTree = getChild(UITaxonomyTreeBrowser.class); uiTree.update(); uiTree.setNodeSelect(path); UITaxonomyTreeWorkingArea uiTaxonomyTreeWorkingArea = getChild(UITaxonomyTreeWorkingArea.class); uiTaxonomyTreeWorkingArea.setSelectedPath(path); uiTaxonomyTreeWorkingArea.update(); setSelectedPath(path); } public Node getRootNode() throws Exception { return getTaxonomyTreeNode().getParent(); } public Node getTaxonomyTreeNode() { return NodeLocation.getNodeByLocation(taxonomyTreeNode); } public void setSelectedPath(String selectedPath) { selectedPath_ = selectedPath; } public String getSelectedPath() { return selectedPath_; } public Node getNodeByPath(String path) throws Exception { return (Node) getSession().getItem(path) ; } Session getSession() throws Exception { return WCMCoreUtils.getSystemSessionProvider().getSession(workspace, getRepository()); } public ManageableRepository getRepository() throws Exception { RepositoryService repositoryService = getApplicationComponent(RepositoryService.class); return repositoryService.getCurrentRepository(); } public void initPopup(String path) throws Exception { removeChildById("TaxonomyPopupCreateChild"); UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, "TaxonomyPopupCreateChild"); uiPopup.setShowMask(true); uiPopup.setWindowSize(600, 250); UITaxonomyTreeCreateChildForm uiTaxoForm = createUIComponent(UITaxonomyTreeCreateChildForm.class, null, null); uiTaxoForm.setParent(path); uiPopup.setUIComponent(uiTaxoForm); uiPopup.setRendered(true); uiPopup.setShow(true); } public UIPopupContainer initPopupPermission(String id) throws Exception { removeChildById(id) ; return addChild(UIPopupContainer.class, null, id) ; } public void onChange(Node currentNode) throws Exception { UIBreadcumbs uiBreadcumbs = getChild(UIBreadcumbs.class); List<LocalPath> listLocalPath = new ArrayList<LocalPath>(); String path = currentNode.getPath().trim(); String taxonomyPath = getTaxonomyTreeNode().getPath(); if (path.startsWith(taxonomyPath)) { String subTaxonomy = path.substring(taxonomyPath.length(), path.length()); String[] arrayPath = subTaxonomy.split("/"); if (arrayPath.length > 0) { for (int i = 0; i < arrayPath.length; i++) { if (!arrayPath[i].trim().equals("")) { UIBreadcumbs.LocalPath localPath1 = new UIBreadcumbs.LocalPath(arrayPath[i].trim(), arrayPath[i].trim()); listLocalPath.add(localPath1); } } } } uiBreadcumbs.setPath(listLocalPath); } public void changeGroup(String groupId, Object context) throws Exception { StringBuffer sbPath = new StringBuffer(); sbPath.append(getTaxonomyTreeNode().getPath()).append("/"); UIBreadcumbs uiBreadcumb = getChild(UIBreadcumbs.class); if (groupId == null) groupId = ""; List<LocalPath> listLocalPath = uiBreadcumb.getPath(); if (listLocalPath == null || listLocalPath.size() == 0) return; List<String> listLocalPathString = new ArrayList<String>(); for (LocalPath localPath : listLocalPath) { listLocalPathString.add(localPath.getId().trim()); } if (listLocalPathString.contains(groupId)) { int index = listLocalPathString.indexOf(groupId); if (index == listLocalPathString.size() - 1) return; for (int i = listLocalPathString.size() - 1; i > index; i--) { listLocalPathString.remove(i); listLocalPath.remove(i); } uiBreadcumb.setPath(listLocalPath); for (int i = 0; i < listLocalPathString.size(); i++) { String pathName = listLocalPathString.get(i); if (pathName != null && pathName.length() > 0) { sbPath.append(pathName.trim()); if (i < listLocalPathString.size() - 1) sbPath.append("/"); } } UITaxonomyTreeBrowser uiTaxonomyTree = getChild(UITaxonomyTreeBrowser.class); uiTaxonomyTree.setNodeSelect(sbPath.toString()); } } public String getWorkspace() { return workspace; } public void setWorkspace(String workspace) { this.workspace = workspace; } public void setTaxonomyTreeNode(Node taxonomyTreeNode) { this.taxonomyTreeNode = NodeLocation.getNodeLocationByNode(taxonomyTreeNode); } public static class SelectPathActionListener extends EventListener<UIBreadcumbs> { public void execute(Event<UIBreadcumbs> event) throws Exception { UIBreadcumbs uiBreadcumbs = event.getSource(); UITaxonomyTreeCreateChild uiTaxonomyTreeCreateChild = uiBreadcumbs.getParent(); String objectId = event.getRequestContext().getRequestParameter(OBJECTID); uiBreadcumbs.setSelectPath(objectId); String selectGroupId = uiBreadcumbs.getSelectLocalPath().getId(); uiTaxonomyTreeCreateChild.changeGroup(selectGroupId, event.getRequestContext()); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyTreeCreateChild); } } }
8,846
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITaxonomyTreeMainForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/UITaxonomyTreeMainForm.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.admin.taxonomy; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import org.exoplatform.ecm.webui.component.admin.taxonomy.tree.info.UIPermissionTreeManager; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.ecm.webui.form.validator.ECMNameValidator; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.BasePath; import org.exoplatform.services.cms.taxonomy.TaxonomyService; import org.exoplatform.services.cms.taxonomy.TaxonomyTreeData; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator; 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.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.UIFormInputBase; 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 : Hoang Van Hung * hunghvit@gmail.com * Apr 9, 2009 */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UITaxonomyTreeMainForm.ChangeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UITaxonomyTreeMainForm.ResetActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UITaxonomyTreeMainForm.CancelActionListener.class, phase=Phase.DECODE), @EventConfig(listeners = UITaxonomyTreeMainForm.AddPathActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UITaxonomyTreeMainForm.NextViewPermissionActionListener.class) } ) public class UITaxonomyTreeMainForm extends UIForm { public static final String FIELD_NAME = "TaxoTreeName"; public static final String FIELD_WORKSPACE = "TaxoTreeWorkspace"; public static final String FIELD_HOMEPATH = "TaxoTreeHomePath"; public UITaxonomyTreeMainForm() throws Exception { addUIFormInput(new UIFormStringInput(FIELD_NAME, FIELD_NAME, null) .addValidator(MandatoryValidator.class).addValidator(ECMNameValidator.class)); UIFormSelectBox uiSelectWorkspace = new UIFormSelectBox(FIELD_WORKSPACE, FIELD_WORKSPACE, null); addChild(uiSelectWorkspace); uiSelectWorkspace.setOnChange("Change"); UIFormInputSetWithAction uiActionHomePath = new UIFormInputSetWithAction("TaxonomyTreeHomePath"); uiActionHomePath.addUIFormInput(new UIFormStringInput(FIELD_HOMEPATH, FIELD_HOMEPATH, null) .setReadOnly(true)); uiActionHomePath.setActionInfo(FIELD_HOMEPATH, new String[] { "AddPath" }); addUIComponentInput(uiActionHomePath); setActions(new String[] {"NextViewPermission","Reset"}); } public void update(TaxonomyTreeData taxonomyTree) throws Exception { String[] wsNames = getApplicationComponent(RepositoryService.class) .getCurrentRepository().getWorkspaceNames(); List<SelectItemOption<String>> workspace = new ArrayList<SelectItemOption<String>>(); String systemWorkspace = getAncestorOfType(UITaxonomyManagerTrees.class).getSystemWorkspaceName(); String dmsSystemWorkspace = getAncestorOfType(UITaxonomyManagerTrees.class).getDmsSystemWorkspaceName(); for(String wsName : wsNames) { if (!systemWorkspace.equals(wsName)) workspace.add(new SelectItemOption<String>(wsName, wsName)); } if (taxonomyTree == null) taxonomyTree = new TaxonomyTreeData(); //sort workspace Comparator<SelectItemOption<String>> comparator = new Comparator<SelectItemOption<String>>(){ @Override public int compare(SelectItemOption<String> option1, SelectItemOption<String> option2) { try { return option1.getValue().compareToIgnoreCase(option2.getValue()); }catch (Exception ex){ return 0; } } }; Collections.sort(workspace, comparator); UIFormSelectBox uiSelectBox = getUIFormSelectBox(FIELD_WORKSPACE).setOptions(workspace); if (taxonomyTree.getTaxoTreeWorkspace() == null) { taxonomyTree.setTaxoTreeWorkspace(dmsSystemWorkspace); } uiSelectBox.setValue(taxonomyTree.getTaxoTreeWorkspace()); UIFormInputBase<String> inputName = findComponentById(FIELD_NAME); UIFormInputBase<String> inputHomePath = findComponentById(FIELD_HOMEPATH); String treeName = taxonomyTree.getTaxoTreeName(); //Check edit TaxonomyTreeData taxonomyTreeData = ((UITaxonomyTreeContainer)getParent()).getTaxonomyTreeData(); if (taxonomyTreeData == null || !taxonomyTreeData.isEdit()) inputName.setValue(treeName); else inputName.setValue(taxonomyTreeData.getTaxoTreeName()); inputHomePath.setValue(taxonomyTree.getTaxoTreeHomePath()); getUIStringInput(FIELD_NAME).setReadOnly(false); if((taxonomyTree != null && taxonomyTree.isEdit()) || (taxonomyTreeData != null && taxonomyTreeData.isEdit())) { getUIStringInput(FIELD_NAME).setReadOnly(true); } } int checkForm() throws Exception { UIFormStringInput input = getChildById(FIELD_WORKSPACE); if (input == null || input.getValue() == null || input.getValue().length() == 0) { return 1; } UIFormSelectBox selectBox = getChildById(FIELD_WORKSPACE); UIFormInputBase<String> inputHomePath = findComponentById(FIELD_HOMEPATH); String homePath = ""; if (inputHomePath != null && inputHomePath.getValue() != null) { homePath = inputHomePath.getValue().toString(); } String dmsSysWorkspace = getAncestorOfType(UITaxonomyManagerTrees.class).getDmsSystemWorkspaceName(); String workspace = selectBox.getValue(); if (homePath.length() == 0) { if (!dmsSysWorkspace.equals(workspace)) { return 2; } } return 0; } public static class AddPathActionListener extends EventListener<UITaxonomyTreeMainForm> { public void execute(Event<UITaxonomyTreeMainForm> event) throws Exception { UITaxonomyTreeMainForm uiTaxonomyTreeForm = event.getSource(); UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiTaxonomyTreeForm.getAncestorOfType(UITaxonomyManagerTrees.class); String workspace = uiTaxonomyTreeForm.getUIFormSelectBox(FIELD_WORKSPACE).getValue(); uiTaxonomyManagerTrees.initPopupJCRBrowser(workspace, true); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } } public static class ChangeActionListener extends EventListener<UITaxonomyTreeMainForm> { public void execute(Event<UITaxonomyTreeMainForm> event) throws Exception { UITaxonomyTreeMainForm uiTaxonomyTreeMainForm = event.getSource(); UITaxonomyTreeContainer uiTaxonomyTreeContainer = uiTaxonomyTreeMainForm.getParent(); UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiTaxonomyTreeMainForm.getAncestorOfType(UITaxonomyManagerTrees.class); uiTaxonomyTreeMainForm.getUIStringInput(FIELD_HOMEPATH).setValue(""); TaxonomyTreeData taxonomyTreeData = uiTaxonomyTreeContainer.getTaxonomyTreeData(); UIFormSelectBox selectBox = uiTaxonomyTreeMainForm.getChildById(FIELD_WORKSPACE); taxonomyTreeData.setTaxoTreeHomePath(""); taxonomyTreeData.setTaxoTreeWorkspace(selectBox.getValue()); String dmsSysWorkspace = uiTaxonomyManagerTrees.getDmsSystemWorkspaceName(); UIFormInputSetWithAction uiActionHomePath = uiTaxonomyTreeMainForm.getChildById("TaxonomyTreeHomePath"); uiActionHomePath.removeChildById(FIELD_HOMEPATH); if (!selectBox.getValue().equals(dmsSysWorkspace)) { uiActionHomePath.addUIFormInput(new UIFormStringInput(FIELD_HOMEPATH, FIELD_HOMEPATH, null). addValidator(MandatoryValidator.class).setReadOnly(true)); } else { uiActionHomePath.addUIFormInput(new UIFormStringInput(FIELD_HOMEPATH, FIELD_HOMEPATH, null).setReadOnly(true)); } event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } } public static class NextViewPermissionActionListener extends EventListener<UITaxonomyTreeMainForm> { public void execute(Event<UITaxonomyTreeMainForm> event) throws Exception { UITaxonomyTreeMainForm uiTaxonomyTreeMainForm = event.getSource(); UITaxonomyTreeContainer uiTaxonomyTreeContainer = uiTaxonomyTreeMainForm.getParent(); TaxonomyTreeData taxonomyTreeData = uiTaxonomyTreeContainer.getTaxonomyTreeData(); UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiTaxonomyTreeContainer.getAncestorOfType(UITaxonomyManagerTrees.class); UIApplication uiApp = uiTaxonomyTreeContainer.getAncestorOfType(UIApplication.class); int validateCode = uiTaxonomyTreeMainForm.checkForm(); if (validateCode == 1) { uiApp.addMessage(new ApplicationMessage("UITaxonomyTreeMainForm.msg.name-emty", null, ApplicationMessage.WARNING)); return; } else if (validateCode == 2) { uiApp.addMessage(new ApplicationMessage("UITaxonomyTreeMainForm.msg.homepath-emty", null, ApplicationMessage.WARNING)); return; } UIFormInputBase<String> inputName = uiTaxonomyTreeMainForm.findComponentById(FIELD_NAME); String name = inputName.getValue().toString().trim(); TaxonomyService taxonomyService = uiTaxonomyTreeMainForm.getApplicationComponent(TaxonomyService.class); if (taxonomyService.hasTaxonomyTree(name) && !taxonomyTreeData.isEdit()) { uiApp.addMessage(new ApplicationMessage("UITaxonomyTreeMainForm.msg.taxonomytree-existed", null, ApplicationMessage.WARNING)); return; } UIFormSelectBox selectBox = uiTaxonomyTreeMainForm.getChildById(FIELD_WORKSPACE); UIFormInputBase<String> inputHomePath = uiTaxonomyTreeMainForm.findComponentById(FIELD_HOMEPATH); String homePath = ""; if (inputHomePath != null && inputHomePath.getValue() != null) homePath =inputHomePath.getValue().toString(); NodeHierarchyCreator nodeHierarchyCreator = uiTaxonomyTreeMainForm.getApplicationComponent(NodeHierarchyCreator.class); String treeDefinitionPath = nodeHierarchyCreator.getJcrPath(BasePath.TAXONOMIES_TREE_DEFINITION_PATH); if ((homePath.length() > 0) && (treeDefinitionPath != null) && (treeDefinitionPath.length() > 0) && (homePath.equals(treeDefinitionPath))) { uiApp.addMessage(new ApplicationMessage("UITaxonomyTreeMainForm.msg.no-right-target-path", null, ApplicationMessage.WARNING)); return; } UIPermissionTreeManager uiPermissionManage = uiTaxonomyTreeContainer.getChild(UIPermissionTreeManager.class); taxonomyTreeData.setTaxoTreeName(name); taxonomyTreeData.setTaxoTreeHomePath(homePath.trim()); taxonomyTreeData.setTaxoTreeWorkspace(selectBox.getValue()); uiTaxonomyTreeContainer.viewStep(2); uiPermissionManage.update(); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } } public static class ResetActionListener extends EventListener<UITaxonomyTreeMainForm> { public void execute(Event<UITaxonomyTreeMainForm> event) throws Exception { UITaxonomyTreeMainForm uiTaxonomyTreeForm = event.getSource(); UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiTaxonomyTreeForm.getAncestorOfType(UITaxonomyManagerTrees.class); uiTaxonomyTreeForm.getUIStringInput(FIELD_NAME).setValue(""); uiTaxonomyTreeForm.getUIStringInput(FIELD_HOMEPATH).setValue(""); uiTaxonomyTreeForm.update(null); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } } static public class CancelActionListener extends EventListener<UITaxonomyTreeMainForm> { public void execute(Event<UITaxonomyTreeMainForm> event) throws Exception { UITaxonomyTreeMainForm uiTaxonomyTreeForm = event.getSource(); UITaxonomyTreeContainer uiContainer = uiTaxonomyTreeForm.getAncestorOfType(UITaxonomyTreeContainer.class); UIPopupWindow uiPopupWindow = uiContainer.getParent(); uiPopupWindow.setRendered(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiPopupWindow) ; } } }
14,170
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITaxonomyTreeList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/UITaxonomyTreeList.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.admin.taxonomy; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.core.UIPagingGridDecorator; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.actions.ActionServiceContainer; import org.exoplatform.services.cms.taxonomy.TaxonomyService; import org.exoplatform.services.cms.taxonomy.TaxonomyTreeData; 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.event.Event; import org.exoplatform.webui.event.EventListener; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Value; import javax.jcr.ValueFormatException; import java.util.ArrayList; import java.util.List; /** * Created by The eXo Platform SARL Author : Hoang Van Hung hunghvit@gmail.com * Apr 3, 2009 */ @ComponentConfig( template = "app:/groovy/webui/component/admin/taxonomy/UITaxonomyTreeList.gtmpl", events = { @EventConfig(listeners = UITaxonomyTreeList.DeleteActionListener.class, confirm = "UITaxonomyTreeList.msg.confirm-delete"), @EventConfig(listeners = UITaxonomyTreeList.EditTaxonomyTreeActionListener.class), @EventConfig(listeners = UITaxonomyTreeList.AddTaxonomyTreeActionListener.class) } ) public class UITaxonomyTreeList extends UIPagingGridDecorator { public static final String[] ACTIONS = { "AddTaxonomyTree" }; public static final String ST_ADD = "AddTaxonomyTreePopup"; public static final String ST_EDIT = "EditTaxonomyTreePopup"; public static final String ACCESS_PERMISSION = "exo:accessPermissions"; private boolean isTargetInTrash_ = false; private static final Log LOG = ExoLogger.getLogger(UITaxonomyTreeList.class.getName()); public UITaxonomyTreeList() throws Exception { getUIPageIterator().setId("UITaxonomyTreeListIterator"); } public String[] getActions() { return ACTIONS; } public List getTaxonomyTreeList() throws Exception { return getUIPageIterator().getCurrentPageData(); } public void refresh(int currentPage) throws Exception { this.isTargetInTrash_ = false; ListAccess<TaxonomyTreeData> taxonomyTreeList = new ListAccessImpl<TaxonomyTreeData>(TaxonomyTreeData.class, getAllTaxonomyTreeList()); LazyPageList<TaxonomyTreeData> dataPageList = new LazyPageList<TaxonomyTreeData>(taxonomyTreeList, getUIPageIterator().getItemsPerPage()); getUIPageIterator().setPageList(dataPageList); if (currentPage > getUIPageIterator().getAvailablePage()) getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage()); else getUIPageIterator().setCurrentPage(currentPage); } public boolean isTargetInTrash() { return isTargetInTrash_; } private List<TaxonomyTreeData> getAllTaxonomyTreeList() throws RepositoryException { List<TaxonomyTreeData> lstTaxonomyTreeData = new ArrayList<TaxonomyTreeData>(); TaxonomyService taxonomyService = getApplicationComponent(TaxonomyService.class); List<Node> lstTaxonomyTreeNode = taxonomyService.getAllTaxonomyTrees(); if (lstTaxonomyTreeNode != null && lstTaxonomyTreeNode.size() > 0) { for (Node node : lstTaxonomyTreeNode) { lstTaxonomyTreeData.add(setData(node)); } } return lstTaxonomyTreeData; } private TaxonomyTreeData setData(Node node) { TaxonomyTreeData taxonomyTreeData = null ; TaxonomyService taxonomyService = getApplicationComponent(TaxonomyService.class); try { if (node != null) { taxonomyTreeData = new TaxonomyTreeData(); taxonomyTreeData.setTaxoTreeName(node.getName()); if (Utils.isInTrash(node)) { taxonomyTreeData.setEdit(false); this.isTargetInTrash_ = true; } else { taxonomyTreeData.setEdit(true); } taxonomyTreeData.setTaxoTreeHomePath(node.getPath()); taxonomyTreeData.setTaxoTreeWorkspace(node.getSession().getWorkspace().getName()); Node realTreeNode = taxonomyService.getTaxonomyTree(node.getName(), true); Value[] values = realTreeNode.getProperty("exo:permissions").getValues(); StringBuffer buffer = new StringBuffer(1024); try { for (Value permission: values) { buffer.append(permission.getString()).append(';'); } } catch (ValueFormatException e) { if (LOG.isWarnEnabled()) { LOG.warn(e.getMessage()); } } catch (RepositoryException e) { if (LOG.isWarnEnabled()) { LOG.warn(e.getMessage()); } } String permission = buffer.toString(); taxonomyTreeData.setTaxoTreePermissions(permission.substring(0, permission.length() - 1)); } } catch (RepositoryException e) { if (LOG.isErrorEnabled()) { LOG.error(e.getMessage(), e); } // TODO: handle exception } return taxonomyTreeData; } public static class DeleteActionListener extends EventListener<UITaxonomyTreeList> { public void execute(Event<UITaxonomyTreeList> event) throws Exception { UITaxonomyTreeList uiTaxonomyTreeList = event.getSource(); UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiTaxonomyTreeList.getParent(); String taxoTreeName = event.getRequestContext().getRequestParameter(OBJECTID); String repository = uiTaxonomyTreeList.getAncestorOfType(UIECMAdminPortlet.class).getPreferenceRepository(); TaxonomyService taxonomyService = uiTaxonomyTreeList.getApplicationComponent(TaxonomyService.class); ActionServiceContainer actionService = uiTaxonomyTreeList.getApplicationComponent(ActionServiceContainer.class); UIApplication uiApp = uiTaxonomyTreeList.getAncestorOfType(UIApplication.class); try { // Remove all avaiable action Node taxonomyTreeNode = taxonomyService.getTaxonomyTree(taxoTreeName,true); actionService.removeAction(taxonomyTreeNode, repository); taxonomyService.removeTaxonomyTree(taxoTreeName); org.exoplatform.services.cms.impl.Utils.addEditedConfiguredData(taxoTreeName, "TaxonomyTree", "EditedConfiguredTaxonomyTree", true); } catch(RepositoryException e) { uiApp.addMessage(new ApplicationMessage("UITaxonomyTreeList.msg.remove-exception", null, ApplicationMessage.WARNING)); return; } uiTaxonomyManagerTrees.update(); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } } public static class AddTaxonomyTreeActionListener extends EventListener<UITaxonomyTreeList> { public void execute(Event<UITaxonomyTreeList> event) throws Exception { UITaxonomyManagerTrees uiTaxonomyManagerTrees = event.getSource().getParent(); uiTaxonomyManagerTrees.removeChildById(UITaxonomyTreeList.ST_EDIT); uiTaxonomyManagerTrees.initPopupTreeContainer(UITaxonomyTreeList.ST_ADD); UITaxonomyTreeContainer uiForm = uiTaxonomyManagerTrees.findFirstComponentOfType(UITaxonomyTreeContainer.class); uiForm.refresh(); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } } public static class EditTaxonomyTreeActionListener extends EventListener<UITaxonomyTreeList> { public void execute(Event<UITaxonomyTreeList> event) throws Exception { UITaxonomyManagerTrees uiTaxonomyManagerTrees = event.getSource().getParent(); uiTaxonomyManagerTrees.removeChildById(UITaxonomyTreeList.ST_ADD); uiTaxonomyManagerTrees.initPopupTreeContainer(UITaxonomyTreeList.ST_EDIT); UITaxonomyTreeContainer uiTaxoTreeContainer = uiTaxonomyManagerTrees .findFirstComponentOfType(UITaxonomyTreeContainer.class); String taxoTreeName = event.getRequestContext().getRequestParameter(OBJECTID); String repository = uiTaxonomyManagerTrees.getAncestorOfType(UIECMAdminPortlet.class) .getPreferenceRepository(); TaxonomyTreeData taxoTreeData = new TaxonomyTreeData(); taxoTreeData.setTaxoTreeName(taxoTreeName); taxoTreeData.setEdit(true); taxoTreeData.setRepository(repository); uiTaxoTreeContainer.setTaxonomyTreeData(taxoTreeData); uiTaxoTreeContainer.refresh(); uiTaxoTreeContainer.viewStep(4); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } } }
10,093
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITaxonomyTreeWorkingArea.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/UITaxonomyTreeWorkingArea.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.admin.taxonomy; import java.util.ArrayList; import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.PathNotFoundException; import javax.jcr.ReferentialIntegrityException; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.component.admin.taxonomy.action.UIActionForm; import org.exoplatform.ecm.webui.component.admin.taxonomy.action.UIActionTaxonomyManager; import org.exoplatform.ecm.webui.component.admin.taxonomy.info.UIPermissionForm; import org.exoplatform.ecm.webui.component.admin.taxonomy.info.UIPermissionInfo; import org.exoplatform.ecm.webui.component.admin.taxonomy.info.UIPermissionManager; import org.exoplatform.services.cms.clipboard.jcr.model.ClipboardCommand; import org.exoplatform.services.cms.taxonomy.TaxonomyService; import org.exoplatform.services.cms.taxonomy.TaxonomyTreeData; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; 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.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 * Apr 7, 2009 */ @ComponentConfig( template = "app:/groovy/webui/component/admin/taxonomy/UITaxonomyTreeWorkingArea.gtmpl", events = { @EventConfig(listeners = UITaxonomyTreeWorkingArea.PreviousActionListener.class), @EventConfig(listeners = UITaxonomyTreeWorkingArea.AddActionListener.class), @EventConfig(listeners = UITaxonomyTreeWorkingArea.RemoveActionListener.class, confirm = "UITaxonomyManager.msg.confirm-delete"), @EventConfig(listeners = UITaxonomyTreeWorkingArea.CopyActionListener.class), @EventConfig(listeners = UITaxonomyTreeWorkingArea.PasteActionListener.class), @EventConfig(listeners = UITaxonomyTreeWorkingArea.CutActionListener.class), @EventConfig(listeners = UITaxonomyTreeWorkingArea.ViewPermissionActionListener.class) } ) public class UITaxonomyTreeWorkingArea extends UIContainer { private UIPageIterator uiPageIterator_; private List<NodeLocation> taxonomyNodes_; private static final Log LOG = ExoLogger.getLogger(UITaxonomyTreeWorkingArea.class.getName()); private ClipboardCommand clipboard_ = new ClipboardCommand(); private String selectedPath_; private String[] acceptedNodeTypes = {}; private String[] actions_ = { "Previous" }; public UITaxonomyTreeWorkingArea() throws Exception { uiPageIterator_ = addChild(UIPageIterator.class, null, "UICategoriesSelect"); } public UIPageIterator getUIPageIterator() { return uiPageIterator_; } public void updateGrid() throws Exception { ListAccess<Object> nodeList = new ListAccessImpl<Object>(Object.class, getNodeList()); LazyPageList<Object> dataPageList = new LazyPageList<Object>(nodeList, 10); uiPageIterator_.setPageList(dataPageList); } public String[] getActions() {return actions_;} public List getListNodes() throws Exception { return NodeLocation.getNodeListByLocationList(uiPageIterator_.getCurrentPageData()); } public void setNodeList(List<Node> nodes) { taxonomyNodes_ = NodeLocation.getLocationsByNodeList(nodes); } public List getNodeList() {return taxonomyNodes_; } public boolean isRootNode() throws Exception { UITaxonomyTreeCreateChild uiManager = getParent(); String selectedPath = uiManager.getSelectedPath(); if (selectedPath == null) selectedPath = uiManager.getRootNode().getPath(); if (selectedPath.equals(uiManager.getRootNode().getPath())) return true; return false; } boolean matchNodeType(Node node) throws Exception { if(acceptedNodeTypes == null || acceptedNodeTypes.length == 0) return true; for(String nodeType: acceptedNodeTypes) { if(node.isNodeType(nodeType)) return true; } return false; } public void update() throws Exception { UITaxonomyTreeCreateChild uiManager = getParent(); if (selectedPath_ != null) { try { Node selectedTaxonomy = uiManager.getNodeByPath(selectedPath_); NodeIterator nodeIter = selectedTaxonomy.getNodes(); List<Node> listNodes = new ArrayList<Node>(); while (nodeIter.hasNext()) { Node node = nodeIter.nextNode(); if (matchNodeType(node)) listNodes.add(node); } setNodeList(listNodes); } catch (PathNotFoundException e) { if (LOG.isWarnEnabled()) { LOG.warn(e.getMessage()); } } } updateGrid(); } public String[] getAcceptedNodeTypes() { return acceptedNodeTypes; } public void setAcceptedNodeTypes(String[] acceptedNodeTypes) { this.acceptedNodeTypes = acceptedNodeTypes; } public void setSelectedPath(String selectedPath) { selectedPath_ = selectedPath; } public static class AddActionListener extends EventListener<UITaxonomyTreeWorkingArea> { public void execute(Event<UITaxonomyTreeWorkingArea> event) throws Exception { UITaxonomyTreeWorkingArea uiTreeWorkingArea = event.getSource(); String path = event.getRequestContext().getRequestParameter(OBJECTID); UITaxonomyTreeCreateChild uiTaxonomyTreeCreateChild = uiTreeWorkingArea.getParent(); uiTaxonomyTreeCreateChild.initPopup(path); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyTreeCreateChild); } } public static class RemoveActionListener extends EventListener<UITaxonomyTreeWorkingArea> { public void execute(Event<UITaxonomyTreeWorkingArea> event) throws Exception { UITaxonomyTreeWorkingArea uiTreeWorkingArea = event.getSource(); UITaxonomyTreeCreateChild uiTaxonomyTreeCreateChild = uiTreeWorkingArea.getParent(); UIApplication uiApp = uiTreeWorkingArea.getAncestorOfType(UIApplication.class); String path = event.getRequestContext().getRequestParameter(OBJECTID); Node selectedNode = uiTaxonomyTreeCreateChild.getNodeByPath(path); try { uiTreeWorkingArea.setSelectedPath(selectedNode.getParent().getPath()); uiTreeWorkingArea.getApplicationComponent(TaxonomyService.class) .removeTaxonomyNode(uiTaxonomyTreeCreateChild.getWorkspace(), path); } catch (ReferentialIntegrityException ref) { Object[] arg = { path }; uiApp.addMessage(new ApplicationMessage("UITaxonomyWorkingArea.msg.reference-exception", arg, ApplicationMessage.WARNING)); return; } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } Object[] arg = { path }; uiApp.addMessage(new ApplicationMessage("UITaxonomyWorkingArea.msg.path-error", arg, ApplicationMessage.WARNING)); return; } if (uiTaxonomyTreeCreateChild.getChildById("TaxonomyPopupCreateChild") != null) { uiTaxonomyTreeCreateChild.removeChildById("TaxonomyPopupCreateChild"); } uiTreeWorkingArea.update(); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyTreeCreateChild); } } public static class CopyActionListener extends EventListener<UITaxonomyTreeWorkingArea> { public void execute(Event<UITaxonomyTreeWorkingArea> event) throws Exception { UITaxonomyTreeWorkingArea uiManager = event.getSource(); String realPath = event.getRequestContext().getRequestParameter(OBJECTID); uiManager.clipboard_ = new ClipboardCommand(); uiManager.clipboard_.setType(ClipboardCommand.COPY); uiManager.clipboard_.setSrcPath(realPath); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } public static class PasteActionListener extends EventListener<UITaxonomyTreeWorkingArea> { public void execute(Event<UITaxonomyTreeWorkingArea> event) throws Exception { UITaxonomyTreeWorkingArea uiWorkingArea = event.getSource(); UITaxonomyTreeCreateChild uiTaxonomyTreeCreateChild = uiWorkingArea.getParent(); UITaxonomyTreeContainer uiTaxonomyTreeContainer = uiWorkingArea .getAncestorOfType(UITaxonomyTreeContainer.class); TaxonomyTreeData taxoTreeData = uiTaxonomyTreeContainer.getTaxonomyTreeData(); String realPath = event.getRequestContext().getRequestParameter(OBJECTID); UIApplication uiApp = uiWorkingArea.getAncestorOfType(UIApplication.class); String type = uiWorkingArea.clipboard_.getType(); String srcPath = uiWorkingArea.clipboard_.getSrcPath(); if (type == null || srcPath == null) { uiApp.addMessage(new ApplicationMessage("UITaxonomyWorkingArea.msg.can-not-paste", null, ApplicationMessage.WARNING)); return; } if (type.equals(ClipboardCommand.CUT) && realPath.equals(srcPath)) { Object[] arg = { realPath }; uiApp.addMessage(new ApplicationMessage("UITaxonomyWorkingArea.msg.node-is-cutting", arg, ApplicationMessage.WARNING)); return; } String destPath = realPath + srcPath.substring(srcPath.lastIndexOf("/")); Node realNode = uiTaxonomyTreeCreateChild.getNodeByPath(realPath); if (realNode.hasNode(srcPath.substring(srcPath.lastIndexOf("/") + 1))) { Object[] args = { srcPath.substring(srcPath.lastIndexOf("/") + 1) }; uiApp.addMessage(new ApplicationMessage("UITaxonomyWorkingArea.msg.exist", args, ApplicationMessage.WARNING)); return; } TaxonomyService taxonomyService = uiWorkingArea .getApplicationComponent(TaxonomyService.class); try { taxonomyService.moveTaxonomyNode(taxoTreeData.getTaxoTreeWorkspace(), srcPath, destPath, type); UITaxonomyTreeBrowser uiTaxonomyTreeBrowser = uiTaxonomyTreeCreateChild.getChild(UITaxonomyTreeBrowser.class); if ((uiTaxonomyTreeBrowser != null) && (uiTaxonomyTreeBrowser.getSelectedNode() != null)) uiWorkingArea.setSelectedPath(uiTaxonomyTreeBrowser.getSelectedNode().getPath()); uiTaxonomyTreeCreateChild.update(); } catch (Exception e) { uiApp.addMessage(new ApplicationMessage("UITaxonomyWorkingArea.msg.referential-integrity", null, ApplicationMessage.WARNING)); return; } event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyTreeCreateChild); } } public static class CutActionListener extends EventListener<UITaxonomyTreeWorkingArea> { public void execute(Event<UITaxonomyTreeWorkingArea> event) throws Exception { UITaxonomyTreeWorkingArea uiManager = event.getSource(); String realPath = event.getRequestContext().getRequestParameter(OBJECTID); uiManager.clipboard_.setType(ClipboardCommand.CUT); uiManager.clipboard_.setSrcPath(realPath); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } public static class ViewPermissionActionListener extends EventListener<UITaxonomyTreeWorkingArea> { public void execute(Event<UITaxonomyTreeWorkingArea> event) throws Exception { UITaxonomyTreeWorkingArea uiManager = event.getSource(); UITaxonomyTreeCreateChild uiTaxonomyTreeCreateChild = uiManager.getParent(); String path = event.getRequestContext().getRequestParameter(OBJECTID); UIPopupContainer uiPopupContainer = uiTaxonomyTreeCreateChild.initPopupPermission(UITaxonomyTreeCreateChild.PERMISSION_ID_POPUP); UIPermissionManager uiPerMan = uiPopupContainer.createUIComponent(UIPermissionManager.class, null, null); uiPerMan.getChild(UIPermissionInfo.class).setCurrentNode(uiTaxonomyTreeCreateChild.getNodeByPath(path)); uiPerMan.getChild(UIPermissionForm.class).setCurrentNode(uiTaxonomyTreeCreateChild.getNodeByPath(path)); uiPopupContainer.activate(uiPerMan, 650,550); uiPopupContainer.setRendered(true); uiPerMan.checkPermissonInfo(uiTaxonomyTreeCreateChild.getNodeByPath(path)); } } public static class PreviousActionListener extends EventListener<UITaxonomyTreeWorkingArea> { public void execute(Event<UITaxonomyTreeWorkingArea> event) throws Exception { UITaxonomyTreeContainer uiTaxonomyTreeContainer = event.getSource().getAncestorOfType(UITaxonomyTreeContainer.class); UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiTaxonomyTreeContainer.getAncestorOfType(UITaxonomyManagerTrees.class); TaxonomyTreeData taxonomyTreeData = uiTaxonomyTreeContainer.getTaxonomyTreeData(); UIActionTaxonomyManager uiActionTaxonomyManager = uiTaxonomyTreeContainer.getChild(UIActionTaxonomyManager.class); UIActionForm uiActionForm = uiActionTaxonomyManager.getChild(UIActionForm.class); uiActionForm.createNewAction(null, TaxonomyTreeData.ACTION_TAXONOMY_TREE, true); uiActionForm.setWorkspace(taxonomyTreeData.getTaxoTreeWorkspace()); uiTaxonomyTreeContainer.viewStep(3); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } } }
14,897
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITaxonomyManagerTrees.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/UITaxonomyManagerTrees.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.admin.taxonomy; import javax.jcr.RepositoryException; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.taxonomy.action.UIActionForm; import org.exoplatform.ecm.webui.component.admin.taxonomy.action.UIActionTaxonomyManager; import org.exoplatform.ecm.webui.selector.UIPermissionSelector; import org.exoplatform.ecm.webui.tree.selectone.UIOneNodePathSelector; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.impl.DMSConfiguration; import org.exoplatform.services.cms.impl.DMSRepositoryConfiguration; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.core.ManageableRepository; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; import org.exoplatform.webui.ext.manager.UIAbstractManager; /** * Created by The eXo Platform SARL * Author : Hoang Van Hung hunghvit@gmail.com * Apr 3, 2009 */ @ComponentConfig(lifecycle = UIContainerLifecycle.class) public class UITaxonomyManagerTrees extends UIAbstractManager { public UITaxonomyManagerTrees() throws Exception { addChild(UITaxonomyTreeList.class, null, null); } public void initPopupTreeContainer(String id) throws Exception { UITaxonomyTreeContainer uiTaxonomyTreeContainer; UIPopupWindow uiPopup = getChildById(id); if (uiPopup == null) { uiPopup = addChild(UIPopupWindow.class, null, id); uiPopup.setWindowSize(650, 250); uiTaxonomyTreeContainer = createUIComponent(UITaxonomyTreeContainer.class, null, null); } else { uiTaxonomyTreeContainer = uiPopup.findFirstComponentOfType(UITaxonomyTreeContainer.class); uiPopup.setRendered(true); } uiPopup.setUIComponent(uiTaxonomyTreeContainer); uiPopup.setShow(true); uiPopup.setShowMask(true); uiPopup.setResizable(true); } public void refresh() throws Exception { update(); } public void update() throws Exception { UITaxonomyTreeList uiTaxonomyTreeList = getChild(UITaxonomyTreeList.class); uiTaxonomyTreeList.refresh(uiTaxonomyTreeList.getUIPageIterator().getCurrentPage()); } public void initPopupPermission(String membership) throws Exception { removePopup(); UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, UITaxonomyTreeContainer.POPUP_PERMISSION); uiPopup.setShowMask(true); uiPopup.setWindowSize(560, 300); UIPermissionSelector uiTaxonomyTreePermission = createUIComponent(UIPermissionSelector.class, null, null); uiTaxonomyTreePermission.setSelectedMembership(true); if (membership != null && membership.indexOf(":/") > -1) { String[] arrMember = membership.split(":/"); uiTaxonomyTreePermission.setCurrentPermission("/" + arrMember[1]); } uiPopup.setUIComponent(uiTaxonomyTreePermission); uiPopup.setShow(true); } public String getSystemWorkspaceName() throws RepositoryException { RepositoryService repositoryService = getApplicationComponent(RepositoryService.class); ManageableRepository manageableRepository = repositoryService.getCurrentRepository(); return manageableRepository.getConfiguration().getSystemWorkspaceName(); } public String getDmsSystemWorkspaceName() { DMSConfiguration dmsConfiguration = getApplicationComponent(DMSConfiguration.class); DMSRepositoryConfiguration dmsRepoConfig = dmsConfiguration.getConfig(); return dmsRepoConfig.getSystemWorkspace(); } public void initPopupJCRBrowser(String workspace, boolean isDisable) throws Exception { removePopup(); String repository = getAncestorOfType(UIECMAdminPortlet.class).getPreferenceRepository(); UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, UITaxonomyTreeContainer.POPUP_TAXONOMYHOMEPATH); uiPopup.setShowMask(true); uiPopup.setWindowSize(610, 300); String[] filterType = {Utils.NT_FOLDER, Utils.NT_UNSTRUCTURED}; UIOneNodePathSelector uiOneNodePathSelector = createUIComponent(UIOneNodePathSelector.class, null, null); uiOneNodePathSelector.setIsDisable(workspace, isDisable); uiOneNodePathSelector.setShowRootPathSelect(true); uiOneNodePathSelector.setAcceptedNodeTypesInTree(filterType); uiOneNodePathSelector.setAcceptedNodeTypesInPathPanel(filterType); uiOneNodePathSelector.setRootNodeLocation(repository, workspace, "/"); if (WCMCoreUtils.isAnonim()) { uiOneNodePathSelector.init(WCMCoreUtils.createAnonimProvider()); } else if (workspace.equals(getSystemWorkspaceName())) { uiOneNodePathSelector.init(WCMCoreUtils.getSystemSessionProvider()); } else { uiOneNodePathSelector.init(WCMCoreUtils.getSystemSessionProvider()); } uiPopup.setUIComponent(uiOneNodePathSelector); UITaxonomyTreeContainer uiTaxonomyTreeContainer = findFirstComponentOfType(UITaxonomyTreeContainer.class); uiOneNodePathSelector.setSourceComponent(uiTaxonomyTreeContainer, new String[] { UITaxonomyTreeMainForm.FIELD_HOMEPATH }); uiPopup.setShow(true); } public void initPopupComponent(UIComponent uiComp, String id) throws Exception { removePopup(); UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, id); uiPopup.setShowMask(true); uiPopup.setUIComponent(uiComp); uiPopup.setWindowSize(640, 300); uiPopup.setShow(true); uiPopup.setResizable(true); } private void removePopup() { UIActionTaxonomyManager uiManager = getAncestorOfType(UIActionTaxonomyManager.class); if (uiManager != null) { uiManager.removeChildById(UIActionForm.POPUP_COMPONENT); } removeChildById(UIActionForm.POPUP_COMPONENT); removeChildById(UITaxonomyTreeContainer.POPUP_PERMISSION); removeChildById(UITaxonomyTreeContainer.POPUP_TAXONOMYHOMEPATH); } }
7,061
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIPermissionTreeSelectUser.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/tree/info/UIPermissionTreeSelectUser.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.admin.taxonomy.tree.info; import org.exoplatform.ecm.permission.info.UIPermissionInputSet; 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 org.exoplatform.webui.organization.account.UIUserSelector; /** * Created by The eXo Platform SARL * Author : Hoang Van Hung * hunghvit@gmail.com * Apr 17, 2009 */ @ComponentConfig( lifecycle = UIContainerLifecycle.class, events = {@EventConfig(listeners = UIPermissionTreeSelectUser.AddUserActionListener.class)} ) public class UIPermissionTreeSelectUser extends UIContainer implements UIPopupComponent { public static final String USER_SELECTOR_ID = "PermissionTreeSelectUser"; public UIPermissionTreeSelectUser() throws Exception { UIUserSelector uiUserSelector = getChildById(USER_SELECTOR_ID); if (uiUserSelector == null) { uiUserSelector = addChild(UIUserSelector.class, null, USER_SELECTOR_ID); } uiUserSelector.setMulti(false); uiUserSelector.setShowSearchUser(true); uiUserSelector.setShowSearch(true); } public void activate() { } public void deActivate() { } public static class AddUserActionListener extends EventListener<UIPermissionTreeSelectUser> { public void execute(Event<UIPermissionTreeSelectUser> event) throws Exception { UIPermissionTreeSelectUser uiUserContainer = event.getSource(); UIUserSelector uiUserSelector = uiUserContainer.getChildById(USER_SELECTOR_ID); UIPermissionTreeManager uiParent = uiUserContainer.getAncestorOfType(UIPermissionTreeManager.class); UIPermissionTreeForm uiPermissionForm = uiParent.getChild(UIPermissionTreeForm.class); uiPermissionForm.doSelect(UIPermissionInputSet.FIELD_USERORGROUP, uiUserSelector.getSelectedUsers()); UIPopupWindow uiPopup = uiParent.findComponentById(UIPermissionTreeManager.POPUP_TAXONOMY_SELECT_USER); uiPopup.setShow(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); } } }
3,318
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIPermissionTreeForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/tree/info/UIPermissionTreeForm.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.admin.taxonomy.tree.info; import java.util.ArrayList; import java.util.Iterator; 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.admin.taxonomy.UITaxonomyManagerTrees; import org.exoplatform.ecm.webui.component.admin.taxonomy.UITaxonomyTreeContainer; import org.exoplatform.ecm.webui.component.admin.taxonomy.UITaxonomyTreeList; import org.exoplatform.ecm.webui.component.admin.taxonomy.action.UIActionForm; import org.exoplatform.ecm.webui.component.admin.taxonomy.action.UIActionTaxonomyManager; import org.exoplatform.ecm.webui.component.admin.taxonomy.info.UIPermissionForm; import org.exoplatform.ecm.webui.core.UIPermissionFormBase; import org.exoplatform.ecm.webui.core.bean.PermissionBean; import org.exoplatform.ecm.webui.selector.UIAnyPermission; import org.exoplatform.ecm.webui.selector.UIGroupMemberSelector; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.ecm.utils.lock.LockUtil; import org.exoplatform.ecm.webui.utils.PermissionUtil; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.taxonomy.TaxonomyService; import org.exoplatform.services.cms.taxonomy.TaxonomyTreeData; import org.exoplatform.services.jcr.access.AccessControlEntry; 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.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.UIBreadcumbs; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.UITree; 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; /** * Created by The eXo Platform SARL * Author : Hoang Van Hung * hunghvit@gmail.com * Apr 17, 2009 */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/admin/taxonomy/UIPermissionTreeForm.gtmpl", events = { @EventConfig(listeners = UIPermissionTreeForm.SaveActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionTreeForm.NextAddActionActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionTreeForm.PreviousActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionTreeForm.ResetActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionTreeForm.SelectUserActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionTreeForm.SelectMemberActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionTreeForm.AddAnyActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionInputSet.OnChangeActionListener.class), @EventConfig(listeners = UIPermissionTreeForm.CancelActionListener.class) } ) public class UIPermissionTreeForm extends UIPermissionFormBase implements UISelectable { public static final String PERMISSION = "permission"; public static final String POPUP_SELECT = "TaxoTreeSelectUserOrGroupPopup"; public static final String[] PERMISSIONS = new String[] { PermissionType.READ, PermissionType.ADD_NODE, PermissionType.REMOVE }; public static final String SELECT_GROUP_ID = "TaxoTreeSelectUserOrGroup"; private static final Log LOG = ExoLogger.getLogger(UIPermissionTreeForm.class.getName()); private NodeLocation currentNode; private PermissionBean permBean; public UIPermissionTreeForm() throws Exception { super(); setActions(new String[] { "Previous", "NextAddAction", "Cancel"}); } public void checkAll(boolean check) { UIPermissionInputSet uiInputSet = getChildById(PERMISSION) ; for (String perm : PermissionType.ALL) { if(uiInputSet.getUICheckBoxInput(perm) != null) uiInputSet.getUICheckBoxInput(perm).setChecked(check); } } public void fillForm(String user, ExtendedNode node) throws Exception { UIPermissionInputSet uiInputSet = getChildById(PERMISSION); refresh(); uiInputSet.getUIStringInput(UIPermissionInputSet.FIELD_USERORGROUP).setValue(user); if (node != null) { if (user.equals(Utils.getNodeOwner(node))) { for (String perm : PERMISSIONS) { uiInputSet.getUICheckBoxInput(perm).setChecked(true); } } else { List<AccessControlEntry> permsList = node.getACL().getPermissionEntries(); Iterator<AccessControlEntry> perIter = permsList.iterator(); StringBuilder userPermission = new StringBuilder(); while (perIter.hasNext()) { AccessControlEntry accessControlEntry = (AccessControlEntry) perIter.next(); if (user.equals(accessControlEntry.getIdentity())) { userPermission.append(accessControlEntry.getPermission()).append(" "); } } for (String perm : PERMISSIONS) { boolean isCheck = userPermission.toString().contains(perm); uiInputSet.getUICheckBoxInput(perm).setChecked(isCheck); } } } else { UIPermissionTreeInfo uiInfo = ((UIContainer)getParent()).getChild(UIPermissionTreeInfo.class); for (PermissionBean permBeanTemp : uiInfo.getPermBeans()) { if(permBeanTemp.getUsersOrGroups().equals(user)) { getUICheckBoxInput(PermissionType.READ).setValue(permBeanTemp.isRead()); getUICheckBoxInput(PermissionType.ADD_NODE).setValue(permBeanTemp.isAddNode()); getUICheckBoxInput(PermissionType.REMOVE).setValue(permBeanTemp.isRemove()); break; } } } } protected void lockForm(boolean isLock) { UIPermissionInputSet uiInputSet = getChildById(PERMISSION); if (isLock) { setActions(new String[] { "Previous", "NextAddAction", "Cancel" }); uiInputSet.setActionInfo(UIPermissionInputSet.FIELD_USERORGROUP, null); } else { setActions(new String[] { "Previous", "NextAddAction", "Cancel" }); uiInputSet.setActionInfo(UIPermissionInputSet.FIELD_USERORGROUP, new String[] { "SelectUser", "SelectMember", "AddAny" }); } for (String perm : PERMISSIONS) { uiInputSet.getUICheckBoxInput(perm).setDisabled(isLock); } } public Node getCurrentNode() { return NodeLocation.getNodeByLocation(currentNode); } public void setCurrentNode(Node currentNode) { this.currentNode = NodeLocation.getNodeLocationByNode(currentNode); } public PermissionBean getPermBean() { return permBean; } public void setPermBean(PermissionBean permBean) { this.permBean = permBean; } 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); } } } public static class ResetActionListener extends EventListener<UIPermissionTreeForm> { public void execute(Event<UIPermissionTreeForm> event) throws Exception { UIPermissionTreeForm uiForm = event.getSource(); uiForm.lockForm(false); uiForm.refresh(); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } public static class SaveActionListener extends EventListener<UIPermissionTreeForm> { public void execute(Event<UIPermissionTreeForm> event) throws Exception { UIPermissionTreeForm uiForm = event.getSource(); Node currentNode = uiForm.getCurrentNode(); UIPermissionTreeManager uiParent = uiForm.getParent(); UITaxonomyTreeContainer uiContainer = uiForm.getAncestorOfType(UITaxonomyTreeContainer.class); 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>(); PermissionBean permBean = new PermissionBean(); permBean.setUsersOrGroups(userOrGroup); permBean.setRead(uiForm.getUICheckBoxInput(PermissionType.READ).isChecked()); permBean.setAddNode(uiForm.getUICheckBoxInput(PermissionType.ADD_NODE).isChecked()); permBean.setRemove(uiForm.getUICheckBoxInput(PermissionType.REMOVE).isChecked()); for (String perm : PERMISSIONS) { if (uiForm.getUICheckBoxInput(perm).isChecked()) { permsList.add(perm); } else { permsRemoveList.add(perm); } } if (uiForm.getUICheckBoxInput(PermissionType.ADD_NODE).isChecked() || uiForm.getUICheckBoxInput(PermissionType.REMOVE).isChecked()) { if (!permsList.contains(PermissionType.READ)) { permsList.add(PermissionType.READ); } permBean.setRead(true); } if (uiForm.getUICheckBoxInput(PermissionType.ADD_NODE).isChecked()) permsList.add(PermissionType.SET_PROPERTY); else permsRemoveList.add(PermissionType.SET_PROPERTY); if (Utils.isNameEmpty(userOrGroup)) { uiApp.addMessage(new ApplicationMessage("UIPermissionTreeForm.msg.userOrGroup-required", null, ApplicationMessage.WARNING)); return; } if (permsList.size() == 0) { uiApp.addMessage(new ApplicationMessage("UIPermissionTreeForm.msg.checkbox-require", null, ApplicationMessage.WARNING)); return; } String[] permsArray = permsList.toArray(new String[permsList.size()]); uiForm.setPermBean(permBean); if (currentNode != null) { if(currentNode.isLocked()) { String lockToken = LockUtil.getLockToken(currentNode); if(lockToken != null) currentNode.getSession().addLockToken(lockToken); } if(!currentNode.isCheckedOut()) { uiApp.addMessage(new ApplicationMessage("UIPermissionTreeForm.msg.node-checkedin", null, ApplicationMessage.WARNING)); return; } ExtendedNode node = (ExtendedNode) currentNode; if (PermissionUtil.canChangePermission(node)) { if (node.canAddMixin("exo:privilegeable")){ node.addMixin("exo:privilegeable"); node.setPermission(Utils.getNodeOwner(node),PermissionType.ALL); } for (String perm : permsRemoveList) { try { node.removePermission(userOrGroup, perm); } catch (AccessDeniedException ade) { uiApp.addMessage(new ApplicationMessage("UIPermissionTreeForm.msg.access-denied", null, ApplicationMessage.WARNING)); return; } } if(PermissionUtil.canChangePermission(node)) node.setPermission(userOrGroup, permsArray); uiParent.getChild(UIPermissionTreeInfo.class).updateGrid(); node.save(); } else { uiApp.addMessage(new ApplicationMessage("UIPermissionTreeForm.msg.not-change-permission", null, ApplicationMessage.WARNING)); return; } currentNode.getSession().save(); TaxonomyService taxonomyService = uiForm.getApplicationComponent(TaxonomyService.class); taxonomyService.updateTaxonomyTree(uiContainer.getTaxonomyTreeData().getTaxoTreeName(), currentNode); } uiForm.refresh(); UIPermissionTreeInfo uiInfo = uiParent.getChild(UIPermissionTreeInfo.class); uiInfo.updateGrid(); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); } } public static class NextAddActionActionListener extends EventListener<UIPermissionTreeForm> { public void execute(Event<UIPermissionTreeForm> event) throws Exception { UIPermissionTreeForm uiForm = event.getSource(); UIPermissionTreeInfo uiPermInfo = ((UIContainer)uiForm.getParent()).getChild(UIPermissionTreeInfo.class); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); if (uiPermInfo.getPermBeans().size() < 1) { uiApp.addMessage(new ApplicationMessage("UIPermissionTreeForm.msg.have-not-any-permission", null, ApplicationMessage.WARNING)); return; } UITaxonomyTreeContainer uiTaxonomyTreeContainer = uiForm.getAncestorOfType(UITaxonomyTreeContainer.class); UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiTaxonomyTreeContainer.getAncestorOfType(UITaxonomyManagerTrees.class); TaxonomyTreeData taxonomyTreeData = uiTaxonomyTreeContainer.getTaxonomyTreeData(); if (!taxonomyTreeData.isEdit()) { UIActionTaxonomyManager uiActionTaxonomyManager = uiTaxonomyTreeContainer.getChild(UIActionTaxonomyManager.class); UIActionForm uiActionForm = uiActionTaxonomyManager.getChild(UIActionForm.class); uiActionForm.createNewAction(null, TaxonomyTreeData.ACTION_TAXONOMY_TREE, true); uiActionForm.setWorkspace(taxonomyTreeData.getTaxoTreeWorkspace()); } uiTaxonomyTreeContainer.viewStep(3); uiTaxonomyTreeContainer.setRenderedChild(UIActionTaxonomyManager.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } } public static class SelectUserActionListener extends EventListener<UIPermissionTreeForm> { public void execute(Event<UIPermissionTreeForm> event) throws Exception { UIPermissionTreeForm uiForm = event.getSource(); ((UIPermissionTreeManager)uiForm.getParent()).initUserSelector(); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } public static class AddAnyActionListener extends EventListener<UIPermissionTreeForm> { public void execute(Event<UIPermissionTreeForm> event) throws Exception { UIPermissionTreeForm uiForm = event.getSource(); UIPermissionInputSet uiInputSet = uiForm.getChildById(UIPermissionForm.PERMISSION); uiInputSet.getUIStringInput(UIPermissionInputSet.FIELD_USERORGROUP).setValue( IdentityConstants.ANY); uiForm.checkAll(false); uiInputSet.getUICheckBoxInput(PermissionType.READ).setChecked(true); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } public static class SelectMemberActionListener extends EventListener<UIPermissionTreeForm> { public void execute(Event<UIPermissionTreeForm> event) throws Exception { UIPermissionTreeForm uiForm = event.getSource(); UIGroupMemberSelector uiGroupMember; uiGroupMember = uiForm.createUIComponent(UIGroupMemberSelector.class, null, UIPermissionTreeForm.SELECT_GROUP_ID); uiGroupMember.getChild(UIAnyPermission.class).setId("TaxoTreeAnyPermission"); uiGroupMember.getChild(UIBreadcumbs.class).setId("TaxoTreeBreadcumbMembershipSelector"); uiGroupMember.getChild(UITree.class).setId("TaxoTreeMembershipSelector"); uiGroupMember.setSourceComponent(uiForm, new String[] { UIPermissionInputSet.FIELD_USERORGROUP }); uiForm.getAncestorOfType(UIPermissionTreeManager.class).initPopupPermission(uiGroupMember); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } public static class PreviousActionListener extends EventListener<UIPermissionTreeForm> { public void execute(Event<UIPermissionTreeForm> event) throws Exception { UITaxonomyTreeContainer uiTaxonomyTreeContainer = event.getSource().getAncestorOfType(UITaxonomyTreeContainer.class); uiTaxonomyTreeContainer.viewStep(1); UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiTaxonomyTreeContainer.getAncestorOfType(UITaxonomyManagerTrees.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } } public static class CancelActionListener extends EventListener<UIPermissionTreeForm> { public void execute(Event<UIPermissionTreeForm> event) throws Exception { UIPermissionTreeForm uiForm = event.getSource(); UITaxonomyTreeContainer uiTaxonomyTreeContainer = uiForm.getAncestorOfType(UITaxonomyTreeContainer.class); UIPopupWindow uiPopup = uiTaxonomyTreeContainer.getParent(); UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiTaxonomyTreeContainer.getAncestorOfType(UITaxonomyManagerTrees.class); uiTaxonomyManagerTrees.removeChildById(UITaxonomyTreeList.ST_ADD); uiTaxonomyManagerTrees.removeChildById(UITaxonomyTreeList.ST_EDIT); uiTaxonomyManagerTrees.update(); uiPopup.setRendered(false); uiPopup.setShow(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } } }
19,205
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIPermissionTreeManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/tree/info/UIPermissionTreeManager.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.admin.taxonomy.tree.info; import javax.jcr.Node; import org.exoplatform.ecm.permission.info.UIPermissionInputSet; import org.exoplatform.ecm.utils.lock.LockUtil; import org.exoplatform.ecm.webui.core.UIPermissionManagerBase; import org.exoplatform.ecm.webui.utils.PermissionUtil; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIGrid; 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 org.exoplatform.webui.organization.account.UIUserSelector; /** * Created by The eXo Platform SARL * Author : Hoang Van Hung * hunghvit@gmail.com * Apr 17, 2009 */ @ComponentConfig(lifecycle = UIContainerLifecycle.class) public class UIPermissionTreeManager extends UIPermissionManagerBase { public static final String POPUP_TAXONOMY_SELECT_USER = "TaxoPopupUserSelector"; public UIPermissionTreeManager() throws Exception { addChild(UIPermissionTreeInfo.class, null, null); addChild(UIPermissionTreeForm.class, null, null); } public void initPopupPermission(UIComponent uiSelector) throws Exception { removeChildById(UIPermissionTreeForm.POPUP_SELECT); UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, UIPermissionTreeForm.POPUP_SELECT); uiPopup.setShowMask(true); uiPopup.setWindowSize(560, 300); uiPopup.setRendered(true); uiPopup.setUIComponent(uiSelector); uiPopup.setShow(true); uiPopup.setResizable(true); } public void initUserSelector() throws Exception { UIPopupWindow uiPopup = getChildById(POPUP_TAXONOMY_SELECT_USER); if (uiPopup == null) uiPopup = addChild(UIPopupWindow.class, null, POPUP_TAXONOMY_SELECT_USER); uiPopup.setShowMask(true); uiPopup.setWindowSize(790, 400); UIPermissionTreeSelectUser uiUserContainer = createUIComponent(UIPermissionTreeSelectUser.class, null, null); uiPopup.setUIComponent(uiUserContainer); uiPopup.setShow(true); uiPopup.setResizable(true); } public void update() throws Exception { getChild(UIPermissionTreeInfo.class).updateGrid(); } public void checkPermissonInfo(Node node) throws Exception { if (node.isLocked()) { String lockToken = LockUtil.getLockToken(node); if (lockToken != null) node.getSession().addLockToken(lockToken); if (!Utils.isLockTokenHolder(node)) { getChild(UIPermissionTreeInfo.class).getChild(UIGrid.class).configure("usersOrGroups", UIPermissionTreeInfo.PERMISSION_BEAN_FIELD, new String[] {}); getChild(UIPermissionTreeForm.class).setRendered(false); } } else { if (!PermissionUtil.canChangePermission(node)) { getChild(UIPermissionTreeInfo.class).getChild(UIGrid.class).configure("usersOrGroups", UIPermissionTreeInfo.PERMISSION_BEAN_FIELD, new String[] {}); getChild(UIPermissionTreeForm.class).setRendered(false); } } } public static class AddUserActionListener extends EventListener<UIUserSelector> { public void execute(Event<UIUserSelector> event) throws Exception { UIUserSelector uiForm = event.getSource(); UIPermissionTreeManager uiParent = uiForm.getAncestorOfType(UIPermissionTreeManager.class); UIPermissionTreeForm uiPermissionForm = uiParent.getChild(UIPermissionTreeForm.class); uiPermissionForm.doSelect(UIPermissionInputSet.FIELD_USERORGROUP, uiForm.getSelectedUsers()); UIPopupWindow uiPopup = uiParent.getChild(UIPopupWindow.class); uiPopup.setUIComponent(null); uiPopup.setShow(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); } } }
4,874
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIPermissionTreeInfo.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/tree/info/UIPermissionTreeInfo.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.admin.taxonomy.tree.info; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import javax.jcr.AccessDeniedException; 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.core.UIPermissionInfoBase; import org.exoplatform.ecm.webui.core.bean.PermissionBean; import org.exoplatform.ecm.webui.utils.PermissionUtil; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.taxonomy.TaxonomyService; import org.exoplatform.services.jcr.access.AccessControlEntry; import org.exoplatform.services.jcr.access.PermissionType; import org.exoplatform.services.jcr.core.ExtendedNode; import org.exoplatform.services.security.IdentityConstants; 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.UIContainer; 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; /** * Created by The eXo Platform SARL * Author : Hoang Van Hung * hunghvit@gmail.com * Apr 17, 2009 */ @ComponentConfig( lifecycle = UIContainerLifecycle.class, events = { @EventConfig (listeners = UIPermissionTreeInfo.DeleteActionListener.class, confirm = "UIPermissionTreeInfo.msg.confirm-delete-permission"), @EventConfig (listeners = UIPermissionTreeInfo.EditActionListener.class) } ) public class UIPermissionTreeInfo extends UIPermissionInfoBase { public static String[] PERMISSION_BEAN_FIELD = { "usersOrGroups", "read", "addNode", "remove"}; private static String[] PERMISSION_ACTION = { "Edit", "Delete" }; private NodeLocation currentNode = null; private int sizeOfListPermission = 0; private List<PermissionBean> permBeans = new ArrayList<PermissionBean>(); public UIPermissionTreeInfo() throws Exception { super(); // Set default permission tree permBeans = this.getDefaultPermissions(); } public void updateGrid() throws Exception { Map<String, List<String>> permsMap = new HashMap<String, List<String>>(); int iSystemOwner = 0; if (currentNode != null) { permBeans = new ArrayList<PermissionBean>(); ExtendedNode node = (ExtendedNode) getCurrentNode(); List permsList = node.getACL().getPermissionEntries(); Iterator perIter = permsList.iterator(); while (perIter.hasNext()) { AccessControlEntry accessControlEntry = (AccessControlEntry) perIter.next(); String currentIdentity = accessControlEntry.getIdentity(); String currentPermission = accessControlEntry.getPermission(); List<String> currentPermissionsList = permsMap.get(currentIdentity); if (!permsMap.containsKey(currentIdentity)) { permsMap.put(currentIdentity, null); } if (currentPermissionsList == null) currentPermissionsList = new ArrayList<String>(); if (!currentPermissionsList.contains(currentPermission)) { currentPermissionsList.add(currentPermission); } permsMap.put(currentIdentity, currentPermissionsList); } Set keys = permsMap.keySet(); Iterator keysIter = keys.iterator(); String owner = IdentityConstants.SYSTEM; if (getExoOwner(node) != null) owner = getExoOwner(node); if (owner.equals(IdentityConstants.SYSTEM)) iSystemOwner = -1; PermissionBean permOwnerBean = new PermissionBean(); if(!permsMap.containsKey(owner)) { permOwnerBean.setUsersOrGroups(owner); permOwnerBean.setRead(true); permOwnerBean.setAddNode(true); // permOwnerBean.setSetProperty(true); permOwnerBean.setRemove(true); permBeans.add(permOwnerBean); } while(keysIter.hasNext()) { String userOrGroup = (String) keysIter.next(); List<String> permissions = permsMap.get(userOrGroup); PermissionBean permBean = new PermissionBean(); permBean.setUsersOrGroups(userOrGroup); for(String perm : permissions) { if(PermissionType.READ.equals(perm)) permBean.setRead(true); else if(PermissionType.ADD_NODE.equals(perm)) permBean.setAddNode(true); // else if(PermissionType.SET_PROPERTY.equals(perm)) permBean.setSetProperty(true); else if(PermissionType.REMOVE.equals(perm)) permBean.setRemove(true); } permBeans.add(permBean); } } else { UIPermissionTreeForm uiForm = ((UIContainer)getParent()).getChild(UIPermissionTreeForm.class); PermissionBean permBean = uiForm.getPermBean(); if (permBean != null) { for (PermissionBean permBeanTemp : permBeans) { if(permBeanTemp.equals(permBean)) { permBeanTemp.setAddNode(permBean.isAddNode()); permBeanTemp.setRead(permBean.isRead()); permBeanTemp.setRemove(permBean.isRemove()); // permBeanTemp.setSetProperty(permBean.isSetProperty()); } } if (!permBeans.contains(permBean)) { permBeans.add(permBean); } uiForm.setPermBean(null); } } sizeOfListPermission = permBeans.size() + iSystemOwner; UIGrid uiGrid = findFirstComponentOfType(UIGrid.class); ListAccess<PermissionBean> permList = new ListAccessImpl<PermissionBean>(PermissionBean.class, permBeans); LazyPageList<PermissionBean> dataPageList = new LazyPageList<PermissionBean>(permList, 10); uiGrid.getUIPageIterator().setPageList(dataPageList); } /** * Get default permissions for taxonomy node */ private List<PermissionBean> getDefaultPermissions() { Set<PermissionBean> defaultPermissionList = new HashSet<PermissionBean>(); // From taxonomy tree default permissions TaxonomyService taxonomyService = WCMCoreUtils.getService(TaxonomyService.class); Map<String, String[]> defaultTaxonomyTreePerms = taxonomyService.getTaxonomyTreeDefaultUserPermission(); PermissionBean bean; for(Map.Entry<String, String[]> entry : defaultTaxonomyTreePerms.entrySet()) { bean = new PermissionBean(); bean.setUsersOrGroups(entry.getKey()); bean.setPermissions(entry.getValue()); defaultPermissionList.add(bean); } return new ArrayList<PermissionBean>(defaultPermissionList); } public static class DeleteActionListener extends EventListener<UIPermissionTreeInfo> { public void execute(Event<UIPermissionTreeInfo> event) throws Exception { UIPermissionTreeInfo uicomp = event.getSource(); UIPermissionTreeManager uiParent = uicomp.getParent(); Node currentNode = uicomp.getCurrentNode(); 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; String name = event.getRequestContext().getRequestParameter(OBJECTID); UIApplication uiApp = uicomp.getAncestorOfType(UIApplication.class); UIPopupContainer uiPopup = uicomp.getAncestorOfType(UIPopupContainer.class); if (currentNode != null) { if (uicomp.getSizeOfListPermission() < 2 + iSystemOwner) { uiApp.addMessage(new ApplicationMessage("UIPermissionTreeInfo.msg.no-permission-remove", null, ApplicationMessage.WARNING)); return; } 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); node.save(); } 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 ; } node.getSession().save(); node.getSession().refresh(false); } else { uiApp.addMessage(new ApplicationMessage("UIPermissionInfo.msg.no-permission-tochange", null, ApplicationMessage.WARNING)) ; return ; } if(!PermissionUtil.canRead(node)) { uiPopup.deActivate() ; } else { uicomp.updateGrid(); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); } } else { PermissionBean permBean = new PermissionBean(); permBean.setUsersOrGroups(name); if (uicomp.getPermBeans().contains(permBean)) { uicomp.getPermBeans().remove(permBean); uicomp.updateGrid(); } } event.getRequestContext().addUIComponentToUpdateByAjax(uiParent) ; } } public Node getCurrentNode() { return NodeLocation.getNodeByLocation(currentNode); } public void setCurrentNode(Node currentNode) { this.currentNode = NodeLocation.getNodeLocationByNode(currentNode); } public int getSizeOfListPermission() { return sizeOfListPermission; } public void setSizeOfListPermission(int sizeOfListPermission) { this.sizeOfListPermission = sizeOfListPermission; } public List<PermissionBean> getPermBeans() { return permBeans; } public void setPermBeans(List<PermissionBean> permBeans) { this.permBeans = permBeans; } }
11,978
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIPermissionManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/info/UIPermissionManager.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.admin.taxonomy.info; import javax.jcr.Node; import org.exoplatform.ecm.permission.info.UIPermissionInputSet; import org.exoplatform.ecm.webui.core.UIPermissionManagerBase; import org.exoplatform.ecm.utils.lock.LockUtil; 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.UIGrid; import org.exoplatform.webui.core.UIPopupComponent; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.organization.account.UIUserSelector; /** * Created by The eXo Platform SARL * Author : TrongTT * TrongTT@exoplatform.com * Sep 13, 2006 * Editor : TuanP * phamtuanchip@yahoo.de * Oct 13, 2006 */ @ComponentConfig(template = "classpath:groovy/wcm/webui/core/UIPermissionManager.gtmpl", events = { @EventConfig(listeners = UIPermissionManager.CloseActionListener.class) }) public class UIPermissionManager extends UIPermissionManagerBase implements UIPopupComponent{ private static final Log LOG = ExoLogger.getLogger(UIPermissionManager.class.getName()); public UIPermissionManager() throws Exception { addChild(UIPermissionInfo.class, null, null); addChild(UIPermissionForm.class, null, null); } public void initPopupPermission(UIComponent uiSelector) throws Exception { removeChildById(UIPermissionForm.POPUP_SELECT); UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, UIPermissionForm.POPUP_SELECT); uiPopup.setShowMask(true); uiPopup.setWindowSize(560, 300); uiPopup.setRendered(true); uiPopup.setUIComponent(uiSelector); uiPopup.setShow(true); uiPopup.setResizable(true); } public void initUserSelector() throws Exception { UIPopupWindow uiPopup = getChildById("PopupUserSelector") ; if(uiPopup == null) { uiPopup = addChild(UIPopupWindow.class, null, "PopupUserSelector"); uiPopup.setShowMask(true); } uiPopup.setWindowSize(790, 400); UIUserContainer uiUserContainer = createUIComponent(UIUserContainer.class, null, null); uiPopup.setUIComponent(uiUserContainer); uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public void activate() { try { getChild(UIPermissionInfo.class).updateGrid(); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error!", e.getMessage()); } } } public void checkPermissonInfo(Node node) throws Exception { if(node.isLocked()){ String lockToken = LockUtil.getLockToken(node); if(lockToken != null) node.getSession().addLockToken(lockToken); if(!Utils.isLockTokenHolder(node)) { getChild(UIPermissionInfo.class).getChild(UIGrid.class) .configure("usersOrGroups", UIPermissionInfo.PERMISSION_BEAN_FIELD, new String[] {}); getChild(UIPermissionForm.class).setRendered(false) ; } } else { if(!PermissionUtil.canChangePermission(node)) { getChild(UIPermissionInfo.class).getChild(UIGrid.class) .configure("usersOrGroups", UIPermissionInfo.PERMISSION_BEAN_FIELD, new String[] {}); getChild(UIPermissionForm.class).setRendered(false) ; } } } public void deActivate() {} static public class AddUserActionListener extends EventListener<UIUserSelector> { public void execute(Event<UIUserSelector> event) throws Exception { UIUserSelector uiForm = event.getSource(); UIPermissionManager uiParent = uiForm.getAncestorOfType(UIPermissionManager.class); UIPermissionForm uiPermissionForm = uiParent.getChild(UIPermissionForm.class); uiPermissionForm.doSelect(UIPermissionInputSet.FIELD_USERORGROUP, uiForm.getSelectedUsers()); UIPopupWindow uiPopup = uiParent.getChild(UIPopupWindow.class); uiPopup.setUIComponent(null); uiPopup.setShow(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); } } static public class CloseActionListener extends EventListener<UIPermissionManager> { public void execute(Event<UIPermissionManager> event) throws Exception { UIPopupWindow popupAction = event.getSource().getAncestorOfType(UIPopupWindow.class); popupAction.setRendered(false); popupAction.setShow(false); event.getRequestContext().addUIComponentToUpdateByAjax(popupAction); } } }
5,833
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-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/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.admin.taxonomy.info; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import org.exoplatform.ecm.permission.info.UIPermissionInputSet; import org.exoplatform.ecm.webui.core.UIPermissionFormBase; import org.exoplatform.ecm.webui.selector.UIGroupMemberSelector; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.ecm.utils.lock.LockUtil; import org.exoplatform.ecm.webui.utils.PermissionUtil; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.jcr.access.AccessControlEntry; 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.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.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; /** * Created by The eXo Platform SARL Author : nqhungvn * nguyenkequanghung@yahoo.com July 3, 2006 10:07:15 AM Editor : tuanp * phamtuanchip@yahoo.de Oct 13, 2006 */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "classpath:groovy/wcm/webui/core/UIPermissionForm.gtmpl", events = { @EventConfig(listeners = UIPermissionForm.SaveActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionForm.CloseActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIPermissionForm.ResetActionListener.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 static final String PERMISSION = "permission"; public static final String POPUP_SELECT = "SelectUserOrGroup"; private static final String[] PERMISSION_TYPES = {PermissionType.READ, PermissionType.ADD_NODE, PermissionType.REMOVE}; public static final String SELECT_GROUP_ID = "TaxoSelectUserOrGroup"; private static final Log LOG = ExoLogger.getLogger(UIPermissionForm.class.getName()); private NodeLocation currentNode; public UIPermissionForm() throws Exception { addChild(new UIPermissionInputSet(PERMISSION)); setActions(new String[] { "Close" }); } protected boolean isEditable(Node node) throws Exception { return PermissionUtil.canChangePermission(node); } public void fillForm(String user, ExtendedNode node) throws Exception { UIPermissionInputSet uiInputSet = getChildById(PERMISSION) ; refresh() ; uiInputSet.getUIStringInput(UIPermissionInputSet.FIELD_USERORGROUP).setValue(user) ; if(user.equals(Utils.getNodeOwner(node))) { for (String perm : PERMISSION_TYPES) { uiInputSet.getUICheckBoxInput(perm).setChecked(true) ; } } else { List<AccessControlEntry> permsList = node.getACL().getPermissionEntries() ; Iterator<AccessControlEntry> perIter = permsList.iterator() ; StringBuilder userPermission = new StringBuilder() ; while(perIter.hasNext()) { AccessControlEntry accessControlEntry = perIter.next() ; if(user.equals(accessControlEntry.getIdentity())) { userPermission.append(accessControlEntry.getPermission()).append(" "); } } for (String perm : PERMISSION_TYPES) { boolean isCheck = userPermission.toString().contains(perm) ; uiInputSet.getUICheckBoxInput(perm).setChecked(isCheck) ; } } } public void doSelect(String selectField, Object value) { try { ExtendedNode node = (ExtendedNode)this.getCurrentNode(); checkAll(false); fillForm(value.toString(), node) ; getUIStringInput(selectField).setValue(value.toString()); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } } } static public class ResetActionListener extends EventListener<UIPermissionForm> { public void execute(Event<UIPermissionForm> event) throws Exception { UIPermissionForm uiForm = event.getSource(); uiForm.refresh() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class SaveActionListener extends EventListener<UIPermissionForm> { public void execute(Event<UIPermissionForm> event) throws Exception { UIPermissionForm uiForm = event.getSource(); Node currentNode = uiForm.getCurrentNode(); UIPermissionManager 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>(); if (currentNode.isLocked()) { String lockToken = LockUtil.getLockToken(currentNode); if (lockToken != null) currentNode.getSession().addLockToken(lockToken); } if (!currentNode.isCheckedOut()) { uiApp.addMessage(new ApplicationMessage("UIActionBar.msg.node-checkedin", null, ApplicationMessage.WARNING)); 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^M 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^M if (!uiForm.getUICheckBoxInput(PermissionType.ADD_NODE).isChecked()) { if(!permsRemoveList.contains(PermissionType.SET_PROPERTY)) permsRemoveList.add(PermissionType.SET_PROPERTY); } //------------------^M if (Utils.isNameEmpty(userOrGroup)) { uiApp.addMessage(new ApplicationMessage("UIPermissionForm.msg.userOrGroup-required", null, ApplicationMessage.WARNING)); return; } if (permsList.size() == 0) { uiApp.addMessage(new ApplicationMessage("UIPermissionForm.msg.checkbox-require", null, ApplicationMessage.WARNING)); 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"); node.setPermission(Utils.getNodeOwner(node),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)); return; } } if(PermissionUtil.canChangePermission(node)) node.setPermission(userOrGroup, permsArray); node.save(); uiParent.getChild(UIPermissionInfo.class).updateGrid(); } else { uiApp.addMessage(new ApplicationMessage("UIPermissionForm.msg.not-change-permission", null, ApplicationMessage.WARNING)); return; } uiForm.refresh(); currentNode.getSession().save(); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); } } static public class SelectUserActionListener extends EventListener<UIPermissionForm> { public void execute(Event<UIPermissionForm> event) throws Exception { UIPermissionForm uiForm = event.getSource(); ((UIPermissionManager)uiForm.getParent()).initUserSelector(); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class AddAnyActionListener extends EventListener<UIPermissionForm> { public void execute(Event<UIPermissionForm> event) throws Exception { UIPermissionForm uiForm = event.getSource(); UIPermissionInputSet uiInputSet = uiForm.getChildById(UIPermissionForm.PERMISSION); uiInputSet.getUIStringInput(UIPermissionInputSet.FIELD_USERORGROUP).setValue( IdentityConstants.ANY); uiForm.checkAll(false); uiInputSet.getUICheckBoxInput(PermissionType.READ).setChecked(true); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class SelectMemberActionListener extends EventListener<UIPermissionForm> { public void execute(Event<UIPermissionForm> event) throws Exception { UIPermissionForm uiForm = event.getSource(); UIGroupMemberSelector uiGroupMemberSelector = uiForm.createUIComponent(UIGroupMemberSelector.class, null, UIPermissionForm.SELECT_GROUP_ID); uiGroupMemberSelector.setSourceComponent(uiForm, new String[] { UIPermissionInputSet.FIELD_USERORGROUP }); uiForm.getAncestorOfType(UIPermissionManager.class).initPopupPermission(uiGroupMemberSelector); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class CloseActionListener extends EventListener<UIPermissionForm> { public void execute(Event<UIPermissionForm> event) throws Exception { UIPopupContainer uiPopupContainer = event.getSource().getAncestorOfType(UIPopupContainer.class); uiPopupContainer.deActivate() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiPopupContainer) ; } } public Node getCurrentNode() { return NodeLocation.getNodeByLocation(currentNode); } public void setCurrentNode(Node currentNode) { this.currentNode = NodeLocation.getNodeLocationByNode(currentNode); } }
12,365
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-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/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.admin.taxonomy.info; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import javax.jcr.AccessDeniedException; import javax.jcr.Node; 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.core.UIPermissionInfoBase; import org.exoplatform.ecm.webui.utils.PermissionUtil; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.access.AccessControlEntry; import org.exoplatform.services.jcr.access.PermissionType; import org.exoplatform.services.jcr.core.ExtendedNode; import org.exoplatform.services.jcr.core.ManageableRepository; import org.exoplatform.services.security.IdentityConstants; 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.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; /** * Created by The eXo Platform SARL * Author : nqhungvn * nguyenkequanghung@yahoo.com * July 3, 2006 * 10:07:15 AM * Editor : TuanP * phamtuanchip@yahoo.de * Oct 13, 20006 */ @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 { private NodeLocation currentNode = null; private int sizeOfListPermission = 0; public UIPermissionInfo() throws Exception { super(); } public void updateGrid() throws Exception { List<PermissionBean> permBeans = new ArrayList<PermissionBean>(); ExtendedNode node = (ExtendedNode) getCurrentNode(); List permsList = node.getACL().getPermissionEntries() ; Map<String, List<String>> permsMap = new HashMap<String, List<String>>() ; Iterator perIter = permsList.iterator() ; while(perIter.hasNext()) { AccessControlEntry accessControlEntry = (AccessControlEntry)perIter.next() ; String currentIdentity = accessControlEntry.getIdentity(); String currentPermission = accessControlEntry.getPermission(); List<String> currentPermissionsList = permsMap.get(currentIdentity); if(!permsMap.containsKey(currentIdentity)) { permsMap.put(currentIdentity, null) ; } if(currentPermissionsList == null) currentPermissionsList = new ArrayList<String>() ; if(!currentPermissionsList.contains(currentPermission)) { currentPermissionsList.add(currentPermission) ; } permsMap.put(currentIdentity, currentPermissionsList) ; } Set keys = permsMap.keySet(); Iterator keysIter = keys.iterator() ; //TODO Utils.getExoOwner(node) has exception return SystemIdentity.SYSTEM String owner = IdentityConstants.SYSTEM ; int iSystemOwner = 0; if (getExoOwner(node) != null) owner = getExoOwner(node); if (owner.equals(IdentityConstants.SYSTEM)) iSystemOwner = -1; PermissionBean permOwnerBean = new PermissionBean(); if(!permsMap.containsKey(owner)) { permOwnerBean.setUsersOrGroups(owner); permOwnerBean.setRead(true) ; permOwnerBean.setAddNode(true) ; permOwnerBean.setRemove(true) ; permBeans.add(permOwnerBean); } while(keysIter.hasNext()) { String userOrGroup = (String) keysIter.next(); List<String> permissions = permsMap.get(userOrGroup); PermissionBean permBean = new PermissionBean(); permBean.setUsersOrGroups(userOrGroup); for(String perm : permissions) { if(PermissionType.READ.equals(perm)) permBean.setRead(true); else if(PermissionType.ADD_NODE.equals(perm)) permBean.setAddNode(true); else if(PermissionType.REMOVE.equals(perm)) permBean.setRemove(true); } permBeans.add(permBean); } sizeOfListPermission = permBeans.size() + iSystemOwner; UIGrid uiGrid = findFirstComponentOfType(UIGrid.class) ; ListAccess<PermissionBean> permList = new ListAccessImpl<PermissionBean>(PermissionBean.class, permBeans); LazyPageList<PermissionBean> dataPageList = new LazyPageList<PermissionBean>(permList, 10); uiGrid.getUIPageIterator().setPageList(dataPageList); } private Session getSession() throws Exception { RepositoryService repositoryService = getApplicationComponent(RepositoryService.class) ; String systemWorkspace = repositoryService.getCurrentRepository().getConfiguration().getSystemWorkspaceName(); ManageableRepository manageableRepository = repositoryService.getCurrentRepository(); Session session = WCMCoreUtils.getSystemSessionProvider().getSession(systemWorkspace, manageableRepository); return session; } static public class DeleteActionListener extends EventListener<UIPermissionInfo> { public void execute(Event<UIPermissionInfo> event) throws Exception { UIPermissionInfo uicomp = event.getSource() ; Node currentNode = uicomp.getCurrentNode(); 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; String name = event.getRequestContext().getRequestParameter(OBJECTID) ; UIApplication uiApp = uicomp.getAncestorOfType(UIApplication.class) ; if (uicomp.getSizeOfListPermission() < 2 + iSystemOwner) { uiApp.addMessage(new ApplicationMessage("UIPermissionInfo.msg.no-permission-remove", null, ApplicationMessage.WARNING)); return; } 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); node.save(); } try { node.removePermission(name); node.save(); } catch(AccessDeniedException ace) { uicomp.getSession().refresh(false) ; uiApp.addMessage(new ApplicationMessage("UIPermissionInfo.msg.access-denied", null, ApplicationMessage.WARNING)) ; return ; } Session session = uicomp.getSession(); session.save(); session.refresh(false); } else { uiApp.addMessage(new ApplicationMessage("UIPermissionInfo.msg.no-permission-tochange", null, ApplicationMessage.WARNING)) ; return ; } UIPopupContainer uiPopup = uicomp.getAncestorOfType(UIPopupContainer.class) ; if(!PermissionUtil.canRead(node)) { uiPopup.deActivate() ; } else { uicomp.updateGrid(); event.getRequestContext().addUIComponentToUpdateByAjax(uicomp.getParent()) ; } event.getRequestContext().addUIComponentToUpdateByAjax(uiPopup) ; } } public class PermissionBean { private String usersOrGroups ; private boolean read ; private boolean addNode ; private boolean remove ; public String getUsersOrGroups() { return usersOrGroups ; } public void setUsersOrGroups(String s) { usersOrGroups = s ; } public boolean isAddNode() { return addNode ; } public void setAddNode(boolean b) { addNode = b ; } public boolean isRead() { return read ; } public void setRead(boolean b) { read = b ; } public boolean isRemove() { return remove ; } public void setRemove(boolean b) { remove = b ; } } public Node getCurrentNode() { return NodeLocation.getNodeByLocation(currentNode); } public void setCurrentNode(Node currentNode) { this.currentNode = NodeLocation.getNodeLocationByNode(currentNode); } public int getSizeOfListPermission() { return sizeOfListPermission; } public void setSizeOfListPermission(int sizeOfListPermission) { this.sizeOfListPermission = sizeOfListPermission; } }
10,257
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIUserContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/info/UIUserContainer.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.admin.taxonomy.info; import org.exoplatform.ecm.permission.info.UIPermissionInputSet; import org.exoplatform.webui.core.UIPopupComponent; 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.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.organization.account.UIUserSelector; /** * Created by The eXo Platform SARL * Author : Hoang Van Hung * hunghvit@gmail.com * Dec 3, 2008 */ @ComponentConfig( lifecycle = UIContainerLifecycle.class, events = {@EventConfig(listeners = UIUserContainer.AddUserActionListener.class)} ) public class UIUserContainer extends UIContainer implements UIPopupComponent { public UIUserContainer() throws Exception { UIUserSelector uiUserSelector = getChild(UIUserSelector.class); if (uiUserSelector == null) { uiUserSelector = addChild(UIUserSelector.class, null, null); } uiUserSelector.setMulti(false); uiUserSelector.setShowSearchUser(true); uiUserSelector.setShowSearch(true); } public void activate() { } public void deActivate() { } static public class AddUserActionListener extends EventListener<UIUserContainer> { public void execute(Event<UIUserContainer> event) throws Exception { UIUserContainer uiUserContainer = event.getSource(); UIUserSelector uiUserSelector = uiUserContainer.getChild(UIUserSelector.class); UIPermissionManager uiParent = uiUserContainer.getAncestorOfType(UIPermissionManager.class); UIPermissionForm uiPermissionForm = uiParent.getChild(UIPermissionForm.class); uiPermissionForm.doSelect(UIPermissionInputSet.FIELD_USERORGROUP, uiUserSelector.getSelectedUsers()); UIPopupWindow uiPopup = uiParent.findComponentById("PopupUserSelector"); uiPopup.setShow(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); } } }
2,962
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIActionTaxonomyManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/action/UIActionTaxonomyManager.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.admin.taxonomy.action; import org.exoplatform.ecm.webui.component.admin.taxonomy.UITaxonomyManagerTrees; import org.exoplatform.ecm.webui.component.admin.taxonomy.UITaxonomyTreeContainer; 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 : Hoang Van Hung * hunghvit@gmail.com * Apr 5, 2009 */ @ComponentConfig( lifecycle = UIContainerLifecycle.class ) public class UIActionTaxonomyManager extends UIContainer { public UIActionTaxonomyManager() throws Exception { UIActionTypeForm uiActionTypeForm = getChild(UIActionTypeForm.class); if (uiActionTypeForm == null) { uiActionTypeForm = addChild(UIActionTypeForm.class, null, null); } addChild(UIActionForm.class, null, null); } public void setDefaultConfig() throws Exception { UIActionTypeForm uiActionType = getChild(UIActionTypeForm.class); uiActionType.setDefaultActionType(null); Class[] renderClasses = { UIActionTypeForm.class, UIActionForm.class }; setRenderedChildrenOfTypes(renderClasses); } public void initPopupComponent(UIComponent uiComp, String id) throws Exception { UITaxonomyManagerTrees uiManagerTrees = getAncestorOfType(UITaxonomyManagerTrees.class); if (uiManagerTrees != null) { uiManagerTrees.removeChildById(UITaxonomyTreeContainer.POPUP_PERMISSION); uiManagerTrees.removeChildById(UITaxonomyTreeContainer.POPUP_TAXONOMYHOMEPATH); } removeChildById(UIActionForm.POPUP_COMPONENT); UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, id); uiPopup.setShowMask(true); uiPopup.setUIComponent(uiComp); uiPopup.setWindowSize(640, 300); uiPopup.setShow(true); uiPopup.setResizable(true); } }
2,937
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-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/action/UIActionForm.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.admin.taxonomy.action; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.nodetype.ConstraintViolationException; import org.exoplatform.ecm.resolver.JCRResourceResolver; import org.exoplatform.ecm.webui.component.admin.taxonomy.UITaxonomyManagerTrees; import org.exoplatform.ecm.webui.component.admin.taxonomy.UITaxonomyTreeContainer; import org.exoplatform.ecm.webui.component.admin.taxonomy.tree.info.UIPermissionTreeInfo; 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.utils.lock.LockUtil; import org.exoplatform.ecm.webui.utils.PermissionUtil; 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.JcrInputProperty; import org.exoplatform.services.cms.actions.ActionServiceContainer; import org.exoplatform.services.cms.impl.DMSConfiguration; import org.exoplatform.services.cms.taxonomy.TaxonomyService; import org.exoplatform.services.cms.taxonomy.TaxonomyTreeData; import org.exoplatform.services.cms.taxonomy.impl.TaxonomyAlreadyExistsException; import org.exoplatform.services.cms.taxonomy.impl.TaxonomyNodeAlreadyExistsException; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.access.AccessControlEntry; import org.exoplatform.services.jcr.access.PermissionType; import org.exoplatform.services.jcr.core.ExtendedNode; import org.exoplatform.services.jcr.ext.common.SessionProvider; import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.security.IdentityConstants; 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.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.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 : Hoang Van Hung * hunghvit@gmail.com * Apr 5, 2009 */ @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 = UIActionForm.PreviousViewPermissionActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIActionForm.NextViewTreeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDialogForm.OnchangeActionListener.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 String rootPath_ = null; public static final String POPUP_COMPONENT = "PopupComponent"; public static final String EXO_ACTIONS = "exo:actions"; private static final Log LOG = ExoLogger.getLogger(UIActionForm.class.getName()); public UIActionForm() throws Exception { setActions(new String[] { "PreviousViewPermission", "Save", "NextViewTree"}); } public void createNewAction(Node parentNode, String actionType, boolean isAddNew) throws Exception { reset(); nodeTypeName_ = actionType; isAddNew_ = isAddNew; componentSelectors.clear(); properties.clear(); getChildren().clear(); if (parentNode != null) parentPath_ = parentNode.getPath(); } 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); } UIActionTaxonomyManager uiManager = getAncestorOfType(UIActionTaxonomyManager.class); uiManager.removeChildById(POPUP_COMPONENT); } public String getCurrentPath() throws Exception { return parentPath_; } public void setCurrentPath(String path) { parentPath_ = path; } public String getWorkspace() { return getTaxoTreeData().getTaxoTreeWorkspace(); } public String getRepositoryName() { return getTaxoTreeData().getRepository(); } public TaxonomyTreeData getTaxoTreeData() { return getAncestorOfType(UITaxonomyTreeContainer.class).getTaxonomyTreeData(); } private String getTaxonomyTreeHomePath() throws Exception{ TaxonomyTreeData taxoTreeData = getTaxoTreeData(); String workspace = taxoTreeData.getTaxoTreeWorkspace(); String homePath = taxoTreeData.getTaxoTreeHomePath(); String systemWorkspace = getAncestorOfType(UITaxonomyManagerTrees.class).getDmsSystemWorkspaceName(); if (workspace.equals(systemWorkspace) && homePath.length() == 0) { homePath = getJcrPath(BasePath.TAXONOMIES_TREE_STORAGE_PATH); taxoTreeData.setTaxoTreeHomePath(homePath); } return (workspace + ":" + homePath); } private String getJcrPath(String path) { NodeHierarchyCreator nodeHierarchyCreator = getApplicationComponent(NodeHierarchyCreator.class); return nodeHierarchyCreator.getJcrPath(path); } public ResourceResolver getTemplateResourceResolver(WebuiRequestContext context, String template) { DMSConfiguration dmsConfiguration = getApplicationComponent(DMSConfiguration.class); String workspace = dmsConfiguration.getConfig().getSystemWorkspace(); return new JCRResourceResolver(workspace); } public String getTemplate() { return getDialogPath(); } public String getDialogPath() { 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.isErrorEnabled()) { LOG.error("Unexpected error", e); } } } return dialogPath; } public void onchange(Event<?> event) throws Exception { setIsUpdateSelect(false); } public void renderField(String name) throws Exception { UIComponent uiInput = findComponentById(name); if ("homePath".equals(name)) { TaxonomyTreeData taxoTreeData = getTaxoTreeData(); String homPath = getTaxonomyTreeHomePath(); if (homPath.endsWith("/")) homPath = homPath.substring(0, homPath.length() - 1); ((UIFormStringInput) uiInput).setValue(homPath + "/" + taxoTreeData.getTaxoTreeName()); } super.renderField(name); } public String getTenmplateNodeType() { return nodeTypeName_; } public String getPath() { return scriptPath_; } public void setRootPath(String rootPath) { rootPath_ = rootPath; } public String getRootPath() { return rootPath_; } private void setPermissionAction(Node currentNode) throws Exception { Session session = getSession(); Node exoActionNode = currentNode.getNode(EXO_ACTIONS); if (PermissionUtil.canChangePermission(exoActionNode)) { if (exoActionNode.canAddMixin("exo:privilegeable")) { exoActionNode.addMixin("exo:privilegeable"); } Map<String, String[]> perMap = new HashMap<String, String[]>(); List<String> permsList = new ArrayList<String>(); List<String> idList = new ArrayList<String>(); String identity = null; for (AccessControlEntry accessEntry : ((ExtendedNode) currentNode).getACL().getPermissionEntries()) { identity = accessEntry.getIdentity(); if (!idList.contains(identity)) { idList.add(identity); permsList = ((ExtendedNode) currentNode).getACL().getPermissions(identity); if (IdentityConstants.SYSTEM.equals(identity)) { if (!permsList.contains(PermissionType.REMOVE)) { permsList.add(PermissionType.REMOVE); } } else { permsList.remove(PermissionType.REMOVE); } perMap.put(accessEntry.getIdentity(), permsList.toArray(new String[permsList.size()])); } } ((ExtendedNode) exoActionNode).setPermissions(perMap); currentNode.save(); session.save(); } } public static class SaveActionListener extends EventListener<UIActionForm> { public void execute(Event<UIActionForm> event) throws Exception { UIActionForm uiActionForm = event.getSource(); UITaxonomyTreeContainer uiTaxonomyTreeContainer = uiActionForm.getAncestorOfType(UITaxonomyTreeContainer.class); UIPermissionTreeInfo uiPermissionInfo = uiTaxonomyTreeContainer.findFirstComponentOfType(UIPermissionTreeInfo.class); TaxonomyTreeData taxoTreeData = uiActionForm.getTaxoTreeData(); UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiActionForm.getAncestorOfType(UITaxonomyManagerTrees.class); TaxonomyService taxonomyService = uiTaxonomyTreeContainer.getApplicationComponent(TaxonomyService.class); String repository = uiActionForm.getApplicationComponent(RepositoryService.class) .getCurrentRepository() .getConfiguration() .getName(); String dmsSysWorkspace = uiTaxonomyTreeContainer.getAncestorOfType(UITaxonomyManagerTrees.class) .getDmsSystemWorkspaceName(); UIApplication uiApp = uiTaxonomyTreeContainer.getAncestorOfType(UIApplication.class); String name = taxoTreeData.getTaxoTreeName(); String workspace = taxoTreeData.getTaxoTreeWorkspace(); String homePath = taxoTreeData.getTaxoTreeHomePath(); if (homePath == null) { homePath = ""; } boolean isEditTree = taxoTreeData.isEdit(); if (homePath.length() == 0) { if (dmsSysWorkspace.equals(workspace)) { homePath = uiActionForm.getJcrPath(BasePath.TAXONOMIES_TREE_STORAGE_PATH); } else { uiApp.addMessage(new ApplicationMessage("UITaxonomyTreeMainForm.msg.homepath-emty", null, ApplicationMessage.WARNING)); return; } } UIFormStringInput targetPathInput = uiActionForm.getUIStringInput("targetPath"); if (targetPathInput != null) { String targetPath = targetPathInput.getValue(); if ((targetPath == null) || (targetPath.length() == 0)) { uiApp.addMessage(new ApplicationMessage("UITaxonomyTreeMainForm.msg.targetPath-emty", null, ApplicationMessage.WARNING)); return; } } boolean isChangeLocation = false; try { if (!isEditTree) { uiTaxonomyTreeContainer.addTaxonomyTree(name, workspace, homePath, uiPermissionInfo.getPermBeans()); } else { isChangeLocation = uiTaxonomyTreeContainer.updateTaxonomyTree(name, workspace, homePath, taxoTreeData.getTaxoTreeActionName()); } } catch (PathNotFoundException e) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.path-invalid", null, ApplicationMessage.WARNING)); return; } catch (TaxonomyAlreadyExistsException e) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.taxonomy-existed", null, ApplicationMessage.WARNING)); return; } catch (TaxonomyNodeAlreadyExistsException e) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.taxonomy-node-existed", null, ApplicationMessage.WARNING)); return; } catch (ConstraintViolationException cViolationException) { Object[] args = {name, homePath, workspace}; uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.constraint-violation-exception", args, ApplicationMessage.WARNING)); return; } Node currentNode = taxonomyService.getTaxonomyTree(name, true); Map<String, JcrInputProperty> sortedInputs = DialogFormUtil.prepareMap(uiActionForm .getChildren(), uiActionForm.getInputProperties(), uiActionForm.getInputOptions()); ActionServiceContainer actionServiceContainer = uiActionForm.getApplicationComponent(ActionServiceContainer.class); //Check existend action of node if (uiActionForm.nodeTypeName_.equals(taxoTreeData.getTaxoTreeActionTypeName()) && !isChangeLocation) { String actionNameInput = (String) (sortedInputs.get("/node/exo:name")).getValue(); if (!Utils.isNameValid(actionNameInput, Utils.SPECIALCHARACTER)) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.name-not-allowed", null, ApplicationMessage.WARNING)); return; } //update action for taxonomy tree try { CmsService cmsService = uiActionForm.getApplicationComponent(CmsService.class); Node storedHomeNode = uiActionForm.getNode().getParent(); cmsService.storeNode(uiActionForm.nodeTypeName_, storedHomeNode, sortedInputs, false); storedHomeNode.getSession().save(); } catch (Exception e) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.canotChangeActionId", null, ApplicationMessage.WARNING)); return; } } else { //Remove action if existed if (!isChangeLocation) { if (actionServiceContainer.hasActions(currentNode)) { actionServiceContainer.removeAction(currentNode, taxoTreeData.getTaxoTreeActionName(), repository); } } // Create new action for new/edited taxonomy tree Session session = currentNode.getSession(); if (uiActionForm.getCurrentPath().length() == 0) { uiActionForm.setCurrentPath(currentNode.getPath()); } if (!PermissionUtil.canAddNode(currentNode) || !PermissionUtil.canSetProperty(currentNode)) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.no-permission-add", null)); return; } if (currentNode.isLocked()) { String lockToken = LockUtil.getLockToken(currentNode); if (lockToken != null) session.addLockToken(lockToken); } try { JcrInputProperty rootProp = sortedInputs.get("/node"); String actionName = (String) (sortedInputs.get("/node/exo:name")).getValue(); if (!Utils.isNameValid(actionName, Utils.SPECIALCHARACTER)) { if (!isEditTree) { Node taxonomyTreeNode = taxonomyService.getTaxonomyTree(name, true); actionServiceContainer.removeAction(taxonomyTreeNode, repository); taxonomyService.removeTaxonomyTree(name); } uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.name-not-allowed", null, ApplicationMessage.WARNING)); return; } if (rootProp == null) { rootProp = new JcrInputProperty(); rootProp.setJcrPath("/node"); rootProp.setValue(actionName); sortedInputs.put("/node", rootProp); } else { rootProp.setValue(actionName); } if (currentNode.hasNode(EXO_ACTIONS)) { if (currentNode.getNode(EXO_ACTIONS).hasNode(actionName)) { Object[] args = { actionName }; uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.existed-action", args, ApplicationMessage.WARNING)); return; } } if (currentNode.isNew()) { String[] args = { currentNode.getPath() }; uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.unable-add-action", args)); return; } boolean alreadyExistEXO_ACTION = currentNode.hasNode(Utils.EXO_ACTIONS); actionServiceContainer.addAction(currentNode, uiActionForm.nodeTypeName_, sortedInputs); session.save(); // Set permission for action node uiActionForm.setPermissionAction(currentNode); Node actionNode = actionServiceContainer.getAction(currentNode, actionName); taxoTreeData.setTaxoTreeActionName(actionNode.getName()); uiActionForm.setIsOnchange(false); uiActionForm.setNodePath(actionNode.getPath()); uiActionForm.createNewAction(currentNode, actionNode.getPrimaryNodeType().getName(), false); uiActionForm.reset(); if (!alreadyExistEXO_ACTION) addPermission(currentNode.getNode(Utils.EXO_ACTIONS), Utils.EXO_PERMISSIONS, Util.getPortalRequestContext().getRemoteUser(), uiActionForm); session.save(); } catch (ConstraintViolationException cex) { uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.constraint-violation-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 (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.unable-add", null)); return; } } taxoTreeData.setEdit(true); uiTaxonomyTreeContainer.refresh(); uiTaxonomyTreeContainer.viewStep(4); uiTaxonomyManagerTrees.update(); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } private void addPermission(Node node, String propertyName, String userId, UIActionForm uiForm) throws Exception { if (PermissionUtil.canChangePermission(node)) { if (node.canAddMixin("exo:privilegeable")) { node.addMixin("exo:privilegeable"); } String removePermission = PermissionType.REMOVE; List<String> permissionList = ((ExtendedNode)node).getACL().getPermissions(userId); if (permissionList == null) permissionList = new ArrayList<String>(); permissionList.add(removePermission); ((ExtendedNode)node).setPermission(userId, permissionList.toArray(new String[]{})); node.getSession().save(); } } } public static class PreviousViewPermissionActionListener extends EventListener<UIActionForm> { public void execute(Event<UIActionForm> event) throws Exception { UITaxonomyTreeContainer uiTaxonomyTreeContainer = event.getSource().getAncestorOfType(UITaxonomyTreeContainer.class); UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiTaxonomyTreeContainer.getAncestorOfType(UITaxonomyManagerTrees.class); uiTaxonomyTreeContainer.viewStep(2); event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } } public static class NextViewTreeActionListener extends EventListener<UIActionForm> { public void execute(Event<UIActionForm> event) throws Exception { UITaxonomyTreeContainer uiTaxonomyTreeContainer = event.getSource().getAncestorOfType(UITaxonomyTreeContainer.class); UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiTaxonomyTreeContainer.getAncestorOfType(UITaxonomyManagerTrees.class); TaxonomyTreeData taxoTreeData = uiTaxonomyTreeContainer.getTaxonomyTreeData(); UIApplication uiApp = uiTaxonomyTreeContainer.getAncestorOfType(UIApplication.class); if (taxoTreeData.isEdit()) { uiTaxonomyTreeContainer.viewStep(4); } else { String key = "UIActionForm.msg.not-created-tree"; uiApp.addMessage(new ApplicationMessage(key, null, ApplicationMessage.WARNING)); return; } event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees); } } public static class ShowComponentActionListener extends EventListener<UIActionForm> { public void execute(Event<UIActionForm> event) throws Exception { UIActionForm uiForm = event.getSource(); UIActionTaxonomyManager uiManager = uiForm.getAncestorOfType(UIActionTaxonomyManager.class); uiForm.isShowingComponent = true; 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 = uiManager.createUIComponent(clazz, null, null); String repositoryName = uiForm.getApplicationComponent(RepositoryService.class) .getCurrentRepository() .getConfiguration() .getName(); String selectorParams = (String) fieldPropertiesMap.get("selectorParams"); if (uiComp instanceof UIOneNodePathSelector) { SessionProvider provider = WCMCoreUtils.getSystemSessionProvider(); String wsFieldName = (String) fieldPropertiesMap.get("workspaceField"); String wsName = ""; if (wsFieldName != null && wsFieldName.length() > 0) { wsName = (String) uiForm.<UIFormInputBase> getUIInput(wsFieldName).getValue(); ((UIOneNodePathSelector) uiComp).setIsDisable(wsName, true); } String[] filterType = new String[] {Utils.NT_FOLDER, Utils.NT_UNSTRUCTURED}; ((UIOneNodePathSelector) uiComp).setAcceptedNodeTypesInPathPanel(filterType); ((UIOneNodePathSelector) uiComp).setAcceptedNodeTypesInTree(filterType); if (selectorParams != null) { String[] arrParams = selectorParams.split(","); if (arrParams.length == 4) { 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) { ((UINodeTypeSelector)uiComp).setRepositoryName(repositoryName); UIFormMultiValueInputSet uiFormMultiValueInputSet = uiForm.getChildById(fieldName); List values = uiFormMultiValueInputSet.getValue(); ((UINodeTypeSelector)uiComp).init(1, values); } uiManager.initPopupComponent(uiComp, UIActionForm.POPUP_COMPONENT); 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 = uiManager.getParent(); uiParent.setRenderedChild(uiManager.getId()); } event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } public static 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(); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } }
29,443
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-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/taxonomy/action/UIActionTypeForm.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.admin.taxonomy.action; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.nodetype.NodeType; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.taxonomy.UITaxonomyTreeContainer; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.cms.actions.ActionServiceContainer; import org.exoplatform.services.cms.taxonomy.TaxonomyService; import org.exoplatform.services.cms.taxonomy.TaxonomyTreeData; import org.exoplatform.services.cms.templates.TemplateService; 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.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 : Hoang Van Hung hunghvit@gmail.com * Apr 5, 2009 */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/admin/taxonomy/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 static final Log LOG = ExoLogger.getLogger(UIActionTypeForm.class.getName()); private List<SelectItemOption<String>> typeList_; public String defaultActionType_; public UIActionTypeForm() throws Exception { UIFormSelectBox uiSelectBox = new UIFormSelectBox(ACTION_TYPE, ACTION_TYPE, new ArrayList<SelectItemOption<String>>()); uiSelectBox.setOnChange(CHANGE_ACTION); addUIFormInput(uiSelectBox); } private Iterator getCreatedActionTypes() throws Exception { ActionServiceContainer actionService = getApplicationComponent(ActionServiceContainer.class); String repository = getAncestorOfType(UIECMAdminPortlet.class).getPreferenceRepository(); return actionService.getCreatedActionTypes(repository).iterator(); } public void setDefaultActionType(String actionType) throws Exception { defaultActionType_ = actionType; if (actionType == null) { defaultActionType_ = "exo:taxonomyAction"; } List<SelectItemOption<String>> actionTypeList = new ArrayList<SelectItemOption<String>>(); actionTypeList.add(new SelectItemOption<String>(defaultActionType_, defaultActionType_)); getUIFormSelectBox(ACTION_TYPE).setOptions(actionTypeList); getUIFormSelectBox(ACTION_TYPE).setValue(defaultActionType_); } public void update() throws Exception { Iterator actions = getCreatedActionTypes(); if (actions != null && actions.hasNext()) { typeList_ = new ArrayList<SelectItemOption<String>>(); while (actions.hasNext()) { String action = ((NodeType) actions.next()).getName(); typeList_.add(new SelectItemOption<String>(action, action)); } getUIFormSelectBox(ACTION_TYPE).setOptions(typeList_); setDefaultActionType(defaultActionType_); } } public static class ChangeActionTypeActionListener extends EventListener<UIActionTypeForm> { public void execute(Event<UIActionTypeForm> event) throws Exception { UIActionTypeForm uiActionType = event.getSource(); UITaxonomyTreeContainer uiTaxonomyTreeContainer = uiActionType .getAncestorOfType(UITaxonomyTreeContainer.class); String actionType = uiActionType.getUIFormSelectBox(ACTION_TYPE).getValue(); TemplateService templateService = uiActionType.getApplicationComponent(TemplateService.class); UIActionTaxonomyManager uiActionTaxonomyManager = uiActionType .getAncestorOfType(UIActionTaxonomyManager.class); String userName = Util.getPortalRequestContext().getRemoteUser(); UIApplication uiApp = uiActionType.getAncestorOfType(UIApplication.class); UIActionForm uiActionForm = uiActionTaxonomyManager.getChild(UIActionForm.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)); actionType = TaxonomyTreeData.ACTION_TAXONOMY_TREE; uiActionType.getUIFormSelectBox(UIActionTypeForm.ACTION_TYPE).setValue(actionType); } } catch (PathNotFoundException path) { Object[] arg = { actionType }; uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.not-support", arg, ApplicationMessage.WARNING)); actionType = TaxonomyTreeData.ACTION_TAXONOMY_TREE; uiActionType.getUIFormSelectBox(UIActionTypeForm.ACTION_TYPE).setValue(actionType); } TaxonomyTreeData taxoTreeData = uiTaxonomyTreeContainer.getTaxonomyTreeData(); TaxonomyService taxonomyService = uiTaxonomyTreeContainer.getApplicationComponent(TaxonomyService.class); Node taxoTreeNode = null; try { taxoTreeNode = taxonomyService.getTaxonomyTree(taxoTreeData.getTaxoTreeName(), true); } catch (RepositoryException re) { if (LOG.isWarnEnabled()) { LOG.warn(re.getMessage()); } } uiActionForm.createNewAction(taxoTreeNode, actionType, true); uiActionTaxonomyManager.setRendered(true); event.getRequestContext().addUIComponentToUpdateByAjax(uiActionTaxonomyManager); } } }
7,207
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIScriptForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/script/UIScriptForm.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.admin.script; import org.exoplatform.ecm.jcr.model.VersionNode; import org.exoplatform.ecm.webui.component.admin.script.UIScriptList.ScriptData; import org.exoplatform.ecm.webui.form.validator.ECMNameValidator; import org.exoplatform.ecm.webui.form.validator.XSSValidator; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.scripts.ScriptService; 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.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.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 org.exoplatform.webui.form.input.UICheckBoxInput; import org.exoplatform.webui.form.validator.MandatoryValidator; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import javax.jcr.version.VersionHistory; import java.util.ArrayList; import java.util.List; /** * Created by The eXo Platform SARL * September 27, 2006 10:27:15 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UIScriptForm.SaveActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UIScriptForm.RestoreActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UIScriptForm.CancelActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UIScriptForm.RefreshActionListener.class) } ) public class UIScriptForm extends UIForm implements UIPopupComponent { private static final Log LOG = ExoLogger.getLogger(UIScriptForm.class.getName()); final static public String FIELD_SELECT_VERSION = "selectVersion" ; final static public String FIELD_SCRIPT_CONTENT = "scriptContent" ; final static public String FIELD_SCRIPT_NAME = "scriptName" ; final static public String FIELD_SCRIPT_LABEL = "scriptLabel" ; final static public String FIELD_ENABLE_VERSION = "enableVersion" ; final static public String SCRIPT_FILE_TYPE = ".groovy" ; private List<String> listVersion = new ArrayList<String>() ; private boolean isAddNew_ = true ; private ScriptService scriptService; public UIScriptForm() throws Exception { scriptService = WCMCoreUtils.getService(ScriptService.class); List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>() ; UIFormSelectBox versions = new UIFormSelectBox(FIELD_SELECT_VERSION , FIELD_SELECT_VERSION, options) ; UIFormTextAreaInput contents = new UIFormTextAreaInput(FIELD_SCRIPT_CONTENT , FIELD_SCRIPT_CONTENT, null) ; contents.addValidator(MandatoryValidator.class) ; UICheckBoxInput isVersion = new UICheckBoxInput(FIELD_ENABLE_VERSION , FIELD_ENABLE_VERSION, null) ; UIFormStringInput scriptLabel = new UIFormStringInput(FIELD_SCRIPT_LABEL, FIELD_SCRIPT_LABEL, null) ; UIFormStringInput scriptName = new UIFormStringInput(FIELD_SCRIPT_NAME, FIELD_SCRIPT_NAME, null) ; scriptName.addValidator(MandatoryValidator.class).addValidator(ECMNameValidator.class).addValidator(XSSValidator.class); versions.setOnChange("Change") ; versions.setRendered(false) ; isVersion.setRendered(false) ; addUIFormInput(versions) ; addUIFormInput(contents) ; addUIFormInput(isVersion) ; addUIFormInput(scriptLabel) ; addUIFormInput(scriptName) ; } private VersionNode getRootVersion(Node node) throws Exception{ VersionHistory vH = node.getVersionHistory() ; return (vH == null) ? null : new VersionNode(vH.getRootVersion(), node.getSession()) ; } private List<String> getNodeVersions(List<VersionNode> children) throws Exception { List<VersionNode> child = new ArrayList<VersionNode>() ; for(int i = 0; i < children.size(); i ++){ listVersion.add(children.get(i).getName()); child = children.get(i).getChildren() ; if(!child.isEmpty()) getNodeVersions(child) ; } return listVersion ; } private List<SelectItemOption<String>> getVersionValues(Node node) throws Exception { List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>() ; List<VersionNode> children = getRootVersion(node).getChildren() ; listVersion.clear() ; List<String> versionList = getNodeVersions(children) ; for(int i = 0; i < versionList.size(); i++) { for(int j = i + 1; j < versionList.size(); j ++) { if(Integer.parseInt(versionList.get(j)) < Integer.parseInt(versionList.get(i))) { String temp = versionList.get(i) ; versionList.set(i, versionList.get(j)) ; versionList.set(j, temp) ; } } options.add(new SelectItemOption<String>(versionList.get(i), versionList.get(i))) ; } return options ; } public void update(Node script, boolean isAddNew) throws Exception{ isAddNew_ = isAddNew ; if(script != null) { String scriptContent = scriptService.getScriptAsText(script); getUICheckBoxInput(FIELD_ENABLE_VERSION).setRendered(true) ; boolean isVersioned = script.isNodeType(Utils.MIX_VERSIONABLE) ; if(isVersioned) { getUIFormSelectBox(FIELD_SELECT_VERSION).setRendered(true) ; getUIFormSelectBox(FIELD_SELECT_VERSION).setOptions(getVersionValues(script)) ; getUIFormSelectBox(FIELD_SELECT_VERSION).setValue(script.getBaseVersion().getName()) ; getUICheckBoxInput(FIELD_ENABLE_VERSION).setDisabled(true); getUICheckBoxInput(FIELD_ENABLE_VERSION).setChecked(true) ; setActions(new String[]{"Save", "Restore", "Refresh", "Cancel"}) ; } else { getUIFormSelectBox(FIELD_SELECT_VERSION).setRendered(false) ; getUICheckBoxInput(FIELD_ENABLE_VERSION).setDisabled(false) ; getUICheckBoxInput(FIELD_ENABLE_VERSION).setChecked(false) ; setActions( new String[]{"Save", "Refresh", "Cancel"}) ; } getUIFormTextAreaInput(FIELD_SCRIPT_CONTENT).setValue(scriptContent) ; Node content = script.getNode(NodetypeConstant.JCR_CONTENT); String scriptLabel = content.getProperty(NodetypeConstant.DC_DESCRIPTION).getValues()[0].getString(); getUIStringInput(FIELD_SCRIPT_LABEL).setValue(scriptLabel) ; getUIStringInput(FIELD_SCRIPT_NAME).setValue(script.getName()) ; getUIStringInput(FIELD_SCRIPT_NAME).setDisabled(true) ; return ; } if(!isAddNew_) { getUIFormTextAreaInput(FIELD_SCRIPT_CONTENT).setValue(null) ; return ; } getUIFormSelectBox(FIELD_SELECT_VERSION).setRendered(false) ; getUICheckBoxInput(FIELD_ENABLE_VERSION).setRendered(false) ; getUICheckBoxInput(FIELD_ENABLE_VERSION).setChecked(false) ; getUIStringInput(FIELD_SCRIPT_LABEL).setValue(null) ; getUIStringInput(FIELD_SCRIPT_NAME).setDisabled(false); getUIStringInput(FIELD_SCRIPT_NAME).setValue(null) ; getUIFormTextAreaInput(FIELD_SCRIPT_CONTENT).setValue(null) ; setActions( new String[]{"Save", "Refresh", "Cancel"}) ; } public void activate() { } public void deActivate() { } static public class SaveActionListener extends EventListener<UIScriptForm> { public void execute(Event<UIScriptForm> event) throws Exception { UIScriptForm uiForm = event.getSource() ; ScriptService scriptService = uiForm.getApplicationComponent(ScriptService.class) ; UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class) ; StringBuilder name = new StringBuilder(); name.append(uiForm.getUIStringInput(FIELD_SCRIPT_NAME).getValue().trim()); String content = uiForm.getUIFormTextAreaInput(FIELD_SCRIPT_CONTENT).getValue().trim(); String label = uiForm.getUIStringInput(FIELD_SCRIPT_LABEL).getValue(); if (name.indexOf(SCRIPT_FILE_TYPE) < 0) { name.append(SCRIPT_FILE_TYPE); } UIScriptList currentList = null ; UIScriptManager uiManager = uiForm.getAncestorOfType(UIScriptManager.class) ; List<String> listScript = new ArrayList<String>() ; List<ScriptData> scriptData = new ArrayList<ScriptData>() ; String namePrefix = null ; UIScriptContainer uiContainer = uiManager.getChildById(uiManager.getSelectedTabId()); currentList = uiContainer.getChild(UIScriptList.class); namePrefix = currentList.getScriptCategory() ; String subNamePrefix = namePrefix.substring(namePrefix.lastIndexOf("/") + 1, namePrefix.length()) ; scriptData = currentList.getScript(subNamePrefix) ; for(ScriptData data : scriptData) { listScript.add(data.getName()) ; } if(listScript.contains(name.toString()) && uiForm.isAddNew_) { Object[] args = { name } ; ApplicationMessage appMessage = new ApplicationMessage("UIScriptForm.msg.name-exist", args, ApplicationMessage.WARNING); appMessage.setArgsLocalized(false); uiApp.addMessage(appMessage) ; return ; } boolean isEnableVersioning = uiForm.getUICheckBoxInput(FIELD_ENABLE_VERSION).isChecked() ; if(label == null) label = name.toString(); else label = label.trim(); if(uiForm.isAddNew_ || !isEnableVersioning) { try { scriptService.addScript(namePrefix + "/" + name, label, content, WCMCoreUtils.getSystemSessionProvider()); } catch(AccessDeniedException ace) { uiApp.addMessage(new ApplicationMessage("UIECMAdminControlPanel.msg.access-denied", null, ApplicationMessage.WARNING)) ; return ; } } else { try { Node node = currentList.getScriptNode(currentList.getTemplateFilter(), name.toString()) ; if(!node.isNodeType(Utils.MIX_VERSIONABLE)) node.addMixin(Utils.MIX_VERSIONABLE) ; else node.checkout() ; scriptService.addScript(namePrefix + "/" + name, label, content, WCMCoreUtils.getSystemSessionProvider()); node.save() ; node.checkin() ; } catch (PathNotFoundException pathNotFoundException) { Object[] args = { namePrefix }; uiApp.addMessage(new ApplicationMessage("UIScriptForm.msg.PathNotFoundException", args, ApplicationMessage.WARNING)); return; } } uiForm.reset() ; UIPopupWindow uiPopup = uiManager.getChild(UIPopupWindow.class); uiPopup.setRendered(false); event.getRequestContext().addUIComponentToUpdateByAjax(currentList) ; currentList.refresh(currentList.getTemplateFilter(),1) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class RestoreActionListener extends EventListener<UIScriptForm> { public void execute(Event<UIScriptForm> event) throws Exception { UIScriptForm uiForm = event.getSource(); String name = uiForm.getUIStringInput(FIELD_SCRIPT_NAME).getValue() ; UIScriptManager uiManager = uiForm.getAncestorOfType(UIScriptManager.class) ; UIScriptContainer uiContainer = uiManager.getChildById(uiManager.getSelectedTabId()); UIScriptList uiScriptList = uiContainer.getChild(UIScriptList.class); try { Node node = uiScriptList.getScriptNode(uiScriptList.getTemplateFilter(), name); String version = uiForm.getUIFormSelectBox(FIELD_SELECT_VERSION).getValue(); String baseVersion = node.getBaseVersion().getName() ; if(!version.equals(baseVersion)) { node.checkout() ; node.restore(version, true) ; uiScriptList.refresh(uiScriptList.getTemplateFilter(), 1) ; } UIPopupWindow uiPopup = uiManager.getChild(UIPopupWindow.class); uiPopup.setRendered(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } catch (PathNotFoundException pne) { if (LOG.isWarnEnabled()) { LOG.warn(pne.getMessage()); } } } } static public class RefreshActionListener extends EventListener<UIScriptForm> { public void execute(Event<UIScriptForm> event) throws Exception { UIScriptForm uiForm = event.getSource() ; String scriptName = uiForm.getUIStringInput(UIScriptForm.FIELD_SCRIPT_NAME).getValue() ; if(uiForm.isAddNew_) { uiForm.update(null, true) ; } else { UIScriptManager uiScriptManager = uiForm.getAncestorOfType(UIScriptManager.class); UIScriptContainer uiScriptContainer = uiScriptManager.getChildById(uiScriptManager.getSelectedTabId()); UIScriptList uiScriptList = uiScriptContainer.getChild(UIScriptList.class); try { Node script = uiScriptList.getScriptNode(uiScriptList.getTemplateFilter(), scriptName) ; uiForm.update(script, false) ; } catch (PathNotFoundException pathNotFoundException) { String namePrefix = uiScriptList.getScriptCategory(); Object[] args = { namePrefix }; UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UIScriptForm.msg.PathNotFoundException", args, ApplicationMessage.WARNING)); return; } } event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getAncestorOfType(UIScriptManager.class)) ; } } static public class CancelActionListener extends EventListener<UIScriptForm> { public void execute(Event<UIScriptForm> event) throws Exception { UIScriptForm uiForm = event.getSource(); uiForm.reset() ; UIScriptManager uiManager = uiForm.getAncestorOfType(UIScriptManager.class) ; UIPopupWindow uiPopup = uiManager.getChildById(UIScriptManager.POPUP_TEMPLATE_ID); uiPopup.setRendered(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } }
15,697
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIScriptList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/script/UIScriptList.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.admin.script; import org.apache.commons.lang3.StringEscapeUtils; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.services.cms.impl.Utils; import org.exoplatform.services.cms.scripts.ScriptService; import org.exoplatform.services.wcm.core.NodetypeConstant; 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.UIComponentDecorator; import org.exoplatform.webui.core.UIPageIterator; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.exception.MessageException; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * September 27, 2006 * 10:37:15 AM */ @ComponentConfig( template = "app:/groovy/webui/component/admin/script/UIScriptList.gtmpl", events = { @EventConfig(listeners = UIScriptList.EditActionListener.class), @EventConfig(listeners = UIScriptList.DeleteActionListener.class, confirm="UIScriptList.msg.confirm-delete"), @EventConfig(listeners = UIScriptList.AddNewActionListener.class) } ) public class UIScriptList extends UIComponentDecorator { private UIPageIterator uiPageIterator_; public static final String ACTION_SCRIPT_TYPE = "action"; public static final String INTERCEPTOR_SCRIPT_TYPE = "interceptor"; public static final String WIDGET_SCRIPT_TYPE = "widget"; private static final String EDITED_CONFIGURED_SCRIPTS = "EditedConfiguredScripts"; private String filter = ACTION_SCRIPT_TYPE; public void setTemplateFilter(String filter) { this.filter = filter; } public String getTemplateFilter() { return this.filter; } public UIScriptList() throws Exception { uiPageIterator_ = createUIComponent(UIPageIterator.class, null, "ScriptListIterator"); setUIComponent(uiPageIterator_); } public void updateGrid(List<ScriptData> scriptData, int currentPage) throws Exception { Collections.sort(scriptData, new ScriptComparator()); ListAccess<ScriptData> scriptList = new ListAccessImpl<ScriptData>(ScriptData.class, scriptData); LazyPageList<ScriptData> dataPageList = new LazyPageList<ScriptData>(scriptList, 10); uiPageIterator_.setPageList(dataPageList); if (currentPage > uiPageIterator_.getAvailablePage()) uiPageIterator_.setCurrentPage(uiPageIterator_.getAvailablePage()); else uiPageIterator_.setCurrentPage(currentPage); } public UIPageIterator getUIPageIterator() { return uiPageIterator_; } public List getScriptList() throws Exception { return uiPageIterator_.getCurrentPageData(); } public String getScriptCategory() throws Exception { ScriptService scriptService = getApplicationComponent(ScriptService.class); UIScriptManager uiManager = getAncestorOfType(UIScriptManager.class); UIScriptContainer uiContainer = uiManager.getChildById(uiManager.getSelectedTabId()); UIScriptList uiScriptList = uiContainer.getChild(UIScriptList.class); Node script = scriptService.getECMScriptHome(WCMCoreUtils.getSystemSessionProvider()).getNode(uiScriptList.getTemplateFilter()); String basePath = scriptService.getBaseScriptPath() + "/"; return script.getPath().substring(basePath.length()); } public void refresh(String templateFilter, int currentPage) throws Exception { this.updateGrid(getScript(templateFilter), currentPage); } public List<ScriptData> getScript(String name) throws Exception { List <ScriptData> scriptData = new ArrayList <ScriptData>() ; List<Node> scripts = new ArrayList<Node> () ; if(name.equals(ACTION_SCRIPT_TYPE)) { scripts = getApplicationComponent(ScriptService.class).getECMActionScripts(WCMCoreUtils.getSystemSessionProvider()); }else if(name.equals(WIDGET_SCRIPT_TYPE)){ scripts = getApplicationComponent(ScriptService.class).getECMWidgetScripts(WCMCoreUtils.getSystemSessionProvider()); }else if(name.equals(INTERCEPTOR_SCRIPT_TYPE)) { scripts = getApplicationComponent(ScriptService.class).getECMInterceptorScripts(WCMCoreUtils.getSystemSessionProvider()); } for(Node scriptNode : scripts) { Node content = scriptNode.getNode(NodetypeConstant.JCR_CONTENT); String scriptDescription; try { scriptDescription = content.getProperty(NodetypeConstant.DC_DESCRIPTION).getValues()[0].getString(); } catch(ArrayIndexOutOfBoundsException are) { scriptDescription = scriptNode.getName(); } catch(PathNotFoundException pne) { scriptDescription = scriptNode.getName(); } scriptData.add(new ScriptData(scriptNode.getName(), scriptNode.getPath(), StringEscapeUtils.escapeHtml4(scriptDescription))); } return scriptData ; } public String[] getActions() {return new String[]{"AddNew"};} public Node getScriptNode(String templateFilter, String nodeName) throws Exception { ScriptService scriptService = getApplicationComponent(ScriptService.class); Node category = scriptService.getECMScriptHome(WCMCoreUtils.getSystemSessionProvider()).getNode(templateFilter); return category.getNode(nodeName); } static public class ScriptComparator implements Comparator<ScriptData> { public int compare(ScriptData o1, ScriptData o2) throws ClassCastException { String name1 = o1.getName(); String name2 = o2.getName(); return name1.compareToIgnoreCase(name2); } } static public class AddNewActionListener extends EventListener<UIScriptList> { public void execute(Event<UIScriptList> event) throws Exception { UIScriptList uiScriptList = event.getSource(); UIScriptManager uiManager = uiScriptList.getAncestorOfType(UIScriptManager.class); UIScriptContainer uiScriptContainer = uiManager.getChildById(uiManager.getSelectedTabId()); UIScriptForm uiScriptForm = uiScriptContainer.createUIComponent(UIScriptForm.class, null, null) ; uiManager.initPopup(uiScriptForm); uiScriptForm.update(null, true); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } static public class EditActionListener extends EventListener<UIScriptList> { public void execute(Event<UIScriptList> event) throws Exception { UIScriptManager uiManager = event.getSource().getAncestorOfType(UIScriptManager.class); UIScriptContainer uiScriptContainer = uiManager.getChildById(uiManager.getSelectedTabId()); UIScriptList uiScriptList = uiScriptContainer.getChild(UIScriptList.class); String scriptName = event.getRequestContext().getRequestParameter(OBJECTID); UIScriptForm uiScriptForm = uiScriptContainer.createUIComponent(UIScriptForm.class, null, null) ; uiScriptForm.update(uiScriptList.getScriptNode(uiScriptList.getTemplateFilter(), scriptName), false); uiManager.initPopup(uiScriptForm); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } static public class DeleteActionListener extends EventListener<UIScriptList> { public void execute(Event<UIScriptList> event) throws Exception { UIScriptManager uiManager = event.getSource().getAncestorOfType(UIScriptManager.class); UIScriptContainer uiScriptContainer = uiManager.getChildById(uiManager.getSelectedTabId()); UIScriptList uiScriptList = uiScriptContainer.getChild(UIScriptList.class); ScriptService scriptService = uiScriptList.getApplicationComponent(ScriptService.class); String scriptName = event.getRequestContext().getRequestParameter(OBJECTID); String namePrefix = uiScriptList.getScriptCategory(); try { scriptService.removeScript(namePrefix + "/" + scriptName, WCMCoreUtils.getSystemSessionProvider()); Utils.addEditedConfiguredData(namePrefix + "/" + scriptName, "ScriptServiceImpl", EDITED_CONFIGURED_SCRIPTS, true); } catch(AccessDeniedException ace) { throw new MessageException(new ApplicationMessage("UIECMAdminControlPanel.msg.access-denied", null, ApplicationMessage.WARNING)); } uiScriptList.refresh(uiScriptList.getTemplateFilter(), uiScriptList.uiPageIterator_.getCurrentPage()); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } public static class ScriptData { private String name; private String path; private String label; public ScriptData(String scriptName, String scriptParth, String label) { this.name = scriptName; this.path = scriptParth; this.label = label; } public String getName() { return name; } public String getPath() { return path; } public String getLabel() { return label; } } }
10,048
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIScriptContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/script/UIScriptContainer.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.admin.script; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.ComponentConfigs; 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 : Ha Quang Tan * tanhq@exoplatform.com * Jan 27, 2013 * 2:09:18 PM */ @ComponentConfigs( { @ComponentConfig(lifecycle = UIContainerLifecycle.class) }) public class UIScriptContainer extends UIContainer { public UIScriptContainer() throws Exception { addChild(UIScriptList.class, null, null) ; } public void initPopup(UIComponent uiComponent, String popupId) throws Exception { removeChildById(popupId) ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, popupId) ; uiPopup.setShowMask(true); uiPopup.setWindowSize(600,300) ; uiPopup.setUIComponent(uiComponent) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public void update() throws Exception { UIScriptList uiScriptList = getChild(UIScriptList.class); uiScriptList.refresh(uiScriptList.getTemplateFilter(), uiScriptList.getUIPageIterator().getCurrentPage()); } }
2,072
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIScriptManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/script/UIScriptManager.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.admin.script; 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.UIPopupWindow; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.ext.manager.UIAbstractManager; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * September 27, 2006 * 09:13:15 AM */ @ComponentConfig(template = "app:/groovy/webui/component/admin/script/UIScriptManager.gtmpl", events = { @EventConfig(listeners = UIScriptManager.SelectTabActionListener.class) }) public class UIScriptManager extends UIAbstractManager { private String selectedTabId = "UIScriptContainer"; final static public String POPUP_TEMPLATE_ID = "ScriptContainerPopup"; final static public String ACTION_TEMPLATE_ID = "UIActionScriptContainer"; final static public String INTERCEPTOR_TEMPLATE_ID = "UIInterceptorScriptContainer"; final static public String WIDGET_TEMPLATE_ID = "UIWidgetScriptContainer"; final static public String ACTION_TEMPLATE_LIST_ID = "UIActionTemplateList"; final static public String INTERCEPTOR_TEMPLATE_LIST_ID = "UIInterceptorTemplateList"; final static public String WIDGET_TEMPLATE_LIST_ID = "UIWidgetTemplateList"; public String getSelectedTabId() { return selectedTabId; } public void setSelectedTab(String renderTabId) { selectedTabId = renderTabId; } public void setSelectedTab(int index) { selectedTabId = getChild(index - 1).getId(); } public UIScriptManager() throws Exception { UIScriptContainer uiActionTemp = addChild(UIScriptContainer.class, null, ACTION_TEMPLATE_ID) ; uiActionTemp.getChild(UIScriptList.class).setTemplateFilter(UIScriptList.ACTION_SCRIPT_TYPE); UIScriptContainer uiInterceptorTemp = addChild(UIScriptContainer.class, null, INTERCEPTOR_TEMPLATE_ID) ; uiInterceptorTemp.getChild(UIScriptList.class).setTemplateFilter(UIScriptList.INTERCEPTOR_SCRIPT_TYPE); UIScriptContainer uiWidgetTemp = addChild(UIScriptContainer.class, null, WIDGET_TEMPLATE_ID) ; uiWidgetTemp.getChild(UIScriptList.class).setTemplateFilter(UIScriptList.WIDGET_SCRIPT_TYPE); UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, POPUP_TEMPLATE_ID) ; setSelectedTab(ACTION_TEMPLATE_ID); } public void initPopup(UIComponent uiComponent) throws Exception { UIPopupWindow uiPopup = getChildById(POPUP_TEMPLATE_ID); uiPopup.setRendered(true); uiPopup.setShowMask(true); uiPopup.setWindowSize(600,270) ; uiPopup.setUIComponent(uiComponent) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public void refresh()throws Exception { UIScriptContainer actionContainer = ((UIScriptContainer)getChildById(ACTION_TEMPLATE_ID)); actionContainer.update(); actionContainer.getChild(UIScriptList.class).refresh(UIScriptList.ACTION_SCRIPT_TYPE, 1); UIScriptContainer interceptorContainer = ((UIScriptContainer)getChildById(INTERCEPTOR_TEMPLATE_ID)); interceptorContainer.update(); interceptorContainer.getChild(UIScriptList.class).refresh(UIScriptList.INTERCEPTOR_SCRIPT_TYPE, 1); UIScriptContainer widgetContainer = ((UIScriptContainer)getChildById(WIDGET_TEMPLATE_ID)); widgetContainer.update(); widgetContainer.getChild(UIScriptList.class).refresh(UIScriptList.WIDGET_SCRIPT_TYPE, 1); } static public class SelectTabActionListener extends EventListener<UIScriptManager> { public void execute(Event<UIScriptManager> 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); } } } }
5,009
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIECMScripts.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/script/UIECMScripts.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.admin.script; import java.util.ArrayList; import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; import org.exoplatform.ecm.webui.component.admin.script.UIScriptList.ScriptData; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.scripts.ScriptService; import org.exoplatform.services.wcm.utils.WCMCoreUtils; 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; import org.exoplatform.webui.core.model.SelectItemOption; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * September 27, 2006 * 09:22:15 AM */ @ComponentConfig(lifecycle = UIContainerLifecycle.class) public class UIECMScripts extends UIContainer { public static String SCRIPTLIST_NAME = "ecmScriptList" ; public static String SCRIPTFORM_NAME = "ecmScriptForm" ; public static String SCRIPT_PAGE = "PageIterator" ; public UIECMScripts() throws Exception { addChild(UIECMFilterForm.class, null, null) ; UIScriptList list = addChild(UIScriptList.class, null, SCRIPTLIST_NAME) ; list.getUIPageIterator().setId(SCRIPTLIST_NAME + SCRIPT_PAGE) ; } private List<SelectItemOption<String>> getECMCategoryOptions() throws Exception { List<SelectItemOption<String>> ecmOptions = new ArrayList<SelectItemOption<String>>() ; Node ecmScriptHome = getApplicationComponent(ScriptService.class).getECMScriptHome(WCMCoreUtils.getSystemSessionProvider()); NodeIterator categories = ecmScriptHome.getNodes() ; while(categories.hasNext()) { Node script = categories.nextNode() ; ecmOptions.add(new SelectItemOption<String>(script.getName(),script.getName())) ; } return ecmOptions ; } public void refresh(int currentPage) throws Exception { UIECMFilterForm ecmFilterForm = getChild(UIECMFilterForm.class) ; String categoryName = ecmFilterForm.getUIFormSelectBox(UIECMFilterForm.FIELD_SELECT_SCRIPT).getValue() ; if (categoryName == null) { ecmFilterForm.setOptions(getECMCategoryOptions()) ; categoryName = ecmFilterForm.getUIFormSelectBox(UIECMFilterForm.FIELD_SELECT_SCRIPT).getValue() ; } UIScriptList uiScriptList = getChildById(SCRIPTLIST_NAME); uiScriptList.updateGrid(getECMScript(categoryName), currentPage); } public List<ScriptData> getECMScript(String name) throws Exception { List <ScriptData> scriptData = new ArrayList <ScriptData>() ; List<Node> scripts = new ArrayList<Node> () ; if(name.equals("action")) { scripts = getApplicationComponent(ScriptService.class).getECMActionScripts(WCMCoreUtils.getSystemSessionProvider()); }else if(name.equals("widget")){ scripts = getApplicationComponent(ScriptService.class).getECMWidgetScripts(WCMCoreUtils.getSystemSessionProvider()); }else if(name.equals("interceptor")) { scripts = getApplicationComponent(ScriptService.class).getECMInterceptorScripts(WCMCoreUtils.getSystemSessionProvider()); } for(Node scriptNode : scripts) { String version = "" ; if(scriptNode.isNodeType(Utils.MIX_VERSIONABLE) && !scriptNode.isNodeType(Utils.NT_FROZEN)){ version = scriptNode.getBaseVersion().getName(); } scriptData.add(new ScriptData(scriptNode.getName(), scriptNode.getPath(), version)) ; } return scriptData ; } public void initFormPopup(String id) throws Exception { removeChildById(id); UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, id); uiPopup.setShowMask(true); uiPopup.setWindowSize(600, 250); UIScriptForm uiForm = createUIComponent(UIScriptForm.class, null, null); uiPopup.setUIComponent(uiForm); uiPopup.setRendered(true); uiPopup.setShow(true); uiPopup.setResizable(true); } }
4,798
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIECMFilterForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/script/UIECMFilterForm.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.admin.script; import java.util.ArrayList; import java.util.List; 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.form.UIForm; import org.exoplatform.webui.form.UIFormSelectBox; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de September 27, 2006 10:27:15 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/admin/script/UIECMFilterForm.gtmpl", events = {@EventConfig(listeners = UIECMFilterForm.ChangeActionListener.class)} ) public class UIECMFilterForm extends UIForm { final static public String FIELD_SELECT_SCRIPT = "selectScript" ; public UIECMFilterForm() throws Exception { UIFormSelectBox scriptSelect = new UIFormSelectBox(FIELD_SELECT_SCRIPT, FIELD_SELECT_SCRIPT, new ArrayList <SelectItemOption<String>>()) ; scriptSelect.setOnChange("Change") ; addUIFormInput(scriptSelect) ; } public void setOptions(List <SelectItemOption<String>> options) { getUIFormSelectBox(FIELD_SELECT_SCRIPT).setOptions(options) ; } static public class ChangeActionListener extends EventListener<UIECMFilterForm> { public void execute(Event<UIECMFilterForm> event) throws Exception { UIECMFilterForm uiForm = event.getSource() ; UIECMScripts uiECMScripts = uiForm.getParent() ; UIScriptList uiScriptList = uiECMScripts.getChildById(UIECMScripts.SCRIPTLIST_NAME) ; String categoryName = uiForm.getUIFormSelectBox(FIELD_SELECT_SCRIPT).getValue() ; uiScriptList.updateGrid(uiECMScripts.getECMScript(categoryName), 1); UIScriptManager sManager = uiForm.getAncestorOfType(UIScriptManager.class) ; sManager.setRenderedChild(UIECMScripts.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiECMScripts) ; } } }
2,868
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UICLVTemplatesManagerComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UICLVTemplatesManagerComponent.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.admin.manager; import javax.jcr.AccessDeniedException; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.UIECMAdminWorkingArea; import org.exoplatform.ecm.webui.component.admin.listener.UIECMAdminControlPanelActionListener; import org.exoplatform.ecm.webui.component.admin.templates.clv.UICLVTemplatesManager; 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.exception.MessageException; import org.exoplatform.webui.ext.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jan 22, 2013 * 9:48:15 AM */ @ComponentConfig( events = { @EventConfig(listeners = UICLVTemplatesManagerComponent.UICLVTemplatesManagerActionListener.class) } ) public class UICLVTemplatesManagerComponent extends UIAbstractManagerComponent { public static class UICLVTemplatesManagerActionListener extends UIECMAdminControlPanelActionListener<UICLVTemplatesManagerComponent> { public void processEvent(Event<UICLVTemplatesManagerComponent> event) throws Exception { UIECMAdminPortlet portlet = event.getSource().getAncestorOfType(UIECMAdminPortlet.class); UIECMAdminWorkingArea uiWorkingArea = portlet.getChild(UIECMAdminWorkingArea.class); try { uiWorkingArea.getChild(UICLVTemplatesManager.class).refresh() ; uiWorkingArea.setChild(UICLVTemplatesManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingArea) ; } catch(AccessDeniedException ace) { throw new MessageException(new ApplicationMessage("UIECMAdminControlPanel.msg.access-denied", null, ApplicationMessage.WARNING)) ; } } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return UICLVTemplatesManager.class; } }
3,112
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIUnLockManagerComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UIUnLockManagerComponent.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.admin.manager; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.UIECMAdminWorkingArea; import org.exoplatform.ecm.webui.component.admin.listener.UIECMAdminControlPanelActionListener; import org.exoplatform.ecm.webui.component.admin.unlock.UILockHolderContainer; import org.exoplatform.ecm.webui.component.admin.unlock.UIPermissionSelector; import org.exoplatform.ecm.webui.component.admin.unlock.UIUnLockManager; 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.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 15 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = UIUnLockManagerComponent.UIUnLockManagerActionListener.class) } ) public class UIUnLockManagerComponent extends UIAbstractManagerComponent { public static class UIUnLockManagerActionListener extends UIECMAdminControlPanelActionListener<UIUnLockManagerComponent> { public void processEvent(Event<UIUnLockManagerComponent> event) throws Exception { UIECMAdminPortlet portlet = event.getSource().getAncestorOfType(UIECMAdminPortlet.class); UIECMAdminWorkingArea uiWorkingArea = portlet.getChild(UIECMAdminWorkingArea.class); UIUnLockManager uiUnLockManager = uiWorkingArea.getChild(UIUnLockManager.class); uiUnLockManager.update(); UILockHolderContainer uiLockHolderContainer = uiUnLockManager.getChild(UILockHolderContainer.class); uiLockHolderContainer.getChild(UIPermissionSelector.class).changeGroup(null); uiWorkingArea.setChild(UIUnLockManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingArea) ; } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return UIUnLockManager.class; } }
2,907
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIActionManagerComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UIActionManagerComponent.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.admin.manager; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.UIECMAdminWorkingArea; import org.exoplatform.ecm.webui.component.admin.action.UIActionManager; import org.exoplatform.ecm.webui.component.admin.listener.UIECMAdminControlPanelActionListener; 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.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 15 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = UIActionManagerComponent.UIActionManagerActionListener.class) } ) public class UIActionManagerComponent extends UIAbstractManagerComponent { public static class UIActionManagerActionListener extends UIECMAdminControlPanelActionListener<UIActionManagerComponent> { public void processEvent(Event<UIActionManagerComponent> event) throws Exception { UIECMAdminPortlet portlet = event.getSource().getAncestorOfType(UIECMAdminPortlet.class); UIECMAdminWorkingArea uiWorkingArea = portlet.getChild(UIECMAdminWorkingArea.class); uiWorkingArea.getChild(UIActionManager.class).refresh() ; uiWorkingArea.setChild(UIActionManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingArea) ; } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return UIActionManager.class; } }
2,499
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIMetadataManagerComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UIMetadataManagerComponent.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.admin.manager; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.UIECMAdminWorkingArea; import org.exoplatform.ecm.webui.component.admin.listener.UIECMAdminControlPanelActionListener; import org.exoplatform.ecm.webui.component.admin.metadata.UIMetadataList; import org.exoplatform.ecm.webui.component.admin.metadata.UIMetadataManager; 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.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 15 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = UIMetadataManagerComponent.UIMetadataManagerActionListener.class) } ) public class UIMetadataManagerComponent extends UIAbstractManagerComponent { public static class UIMetadataManagerActionListener extends UIECMAdminControlPanelActionListener<UIMetadataManagerComponent> { public void processEvent(Event<UIMetadataManagerComponent> event) throws Exception { UIECMAdminPortlet portlet = event.getSource().getAncestorOfType(UIECMAdminPortlet.class); UIECMAdminWorkingArea uiWorkingArea = portlet.getChild(UIECMAdminWorkingArea.class); uiWorkingArea.setChild(UIMetadataManager.class) ; UIMetadataManager uiManager = uiWorkingArea.getChild(UIMetadataManager.class) ; uiManager.getChild(UIMetadataList.class).refresh(1); event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingArea) ; } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return UIMetadataManager.class; } }
2,676
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIDriveManagerComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UIDriveManagerComponent.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.admin.manager; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.UIECMAdminWorkingArea; import org.exoplatform.ecm.webui.component.admin.drives.UIDriveManager; import org.exoplatform.ecm.webui.component.admin.listener.UIECMAdminControlPanelActionListener; 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.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 15 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = UIDriveManagerComponent.UIDriveManagerActionListener.class) } ) public class UIDriveManagerComponent extends UIAbstractManagerComponent { public static class UIDriveManagerActionListener extends UIECMAdminControlPanelActionListener<UIDriveManagerComponent> { public void processEvent(Event<UIDriveManagerComponent> event) throws Exception { UIECMAdminPortlet portlet = event.getSource().getAncestorOfType(UIECMAdminPortlet.class); UIECMAdminWorkingArea uiWorkingArea = portlet.getChild(UIECMAdminWorkingArea.class); uiWorkingArea.getChild(UIDriveManager.class).update() ; uiWorkingArea.setChild(UIDriveManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingArea) ; } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return UIDriveManager.class; } }
2,488
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINodeTypeManagerComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UINodeTypeManagerComponent.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.admin.manager; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.UIECMAdminWorkingArea; import org.exoplatform.ecm.webui.component.admin.listener.UIECMAdminControlPanelActionListener; import org.exoplatform.ecm.webui.component.admin.nodetype.UINodeTypeManager; 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.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 15 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = UINodeTypeManagerComponent.UINodeTypeManagerActionListener.class) } ) public class UINodeTypeManagerComponent extends UIAbstractManagerComponent { public static class UINodeTypeManagerActionListener extends UIECMAdminControlPanelActionListener<UINodeTypeManagerComponent> { public void processEvent(Event<UINodeTypeManagerComponent> event) throws Exception { UIECMAdminPortlet portlet = event.getSource().getAncestorOfType(UIECMAdminPortlet.class); UIECMAdminWorkingArea uiWorkingArea = portlet.getChild(UIECMAdminWorkingArea.class); uiWorkingArea.getChild(UINodeTypeManager.class).update() ; uiWorkingArea.setChild(UINodeTypeManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingArea) ; } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return UINodeTypeManager.class; } }
2,520
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIQueriesManagerComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UIQueriesManagerComponent.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.admin.manager; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.UIECMAdminWorkingArea; import org.exoplatform.ecm.webui.component.admin.listener.UIECMAdminControlPanelActionListener; import org.exoplatform.ecm.webui.component.admin.queries.UIQueriesManager; 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.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 15 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = UIQueriesManagerComponent.UIQueriesManagerActionListener.class) } ) public class UIQueriesManagerComponent extends UIAbstractManagerComponent { public static class UIQueriesManagerActionListener extends UIECMAdminControlPanelActionListener<UIQueriesManagerComponent> { public void processEvent(Event<UIQueriesManagerComponent> event) throws Exception { UIECMAdminPortlet portlet = event.getSource().getAncestorOfType(UIECMAdminPortlet.class); UIECMAdminWorkingArea uiWorkingArea = portlet.getChild(UIECMAdminWorkingArea.class); uiWorkingArea.getChild(UIQueriesManager.class).update() ; uiWorkingArea.setChild(UIQueriesManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingArea) ; } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return UIQueriesManager.class; } }
2,509
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIViewManagerComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UIViewManagerComponent.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.admin.manager; import javax.jcr.AccessDeniedException; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.UIECMAdminWorkingArea; import org.exoplatform.ecm.webui.component.admin.listener.UIECMAdminControlPanelActionListener; import org.exoplatform.ecm.webui.component.admin.views.UIViewManager; 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.exception.MessageException; 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 * 15 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = UIViewManagerComponent.UIViewManagerActionListener.class) } ) public class UIViewManagerComponent extends UIAbstractManagerComponent { public static class UIViewManagerActionListener extends UIECMAdminControlPanelActionListener<UIViewManagerComponent> { public void processEvent(Event<UIViewManagerComponent> event) throws Exception { UIECMAdminPortlet portlet = event.getSource().getAncestorOfType(UIECMAdminPortlet.class); UIECMAdminWorkingArea uiWorkingArea = portlet.getChild(UIECMAdminWorkingArea.class); try { uiWorkingArea.getChild(UIViewManager.class).update() ; uiWorkingArea.setChild(UIViewManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingArea) ; } catch(AccessDeniedException ace) { throw new MessageException(new ApplicationMessage("UIECMAdminControlPanel.msg.access-denied", null, ApplicationMessage.WARNING)) ; } } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return UIViewManager.class; } }
2,909
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITaxonomyManagerTreesComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UITaxonomyManagerTreesComponent.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.admin.manager; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.UIECMAdminWorkingArea; import org.exoplatform.ecm.webui.component.admin.listener.UIECMAdminControlPanelActionListener; import org.exoplatform.ecm.webui.component.admin.taxonomy.UITaxonomyManagerTrees; 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.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 15 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = UITaxonomyManagerTreesComponent.UITaxonomyManagerTreesActionListener.class) } ) public class UITaxonomyManagerTreesComponent extends UIAbstractManagerComponent { public static class UITaxonomyManagerTreesActionListener extends UIECMAdminControlPanelActionListener<UITaxonomyManagerTreesComponent> { public void processEvent(Event<UITaxonomyManagerTreesComponent> event) throws Exception { UIECMAdminPortlet portlet = event.getSource().getAncestorOfType(UIECMAdminPortlet.class); UIECMAdminWorkingArea uiWorkingArea = portlet.getChild(UIECMAdminWorkingArea.class); uiWorkingArea.getChild(UITaxonomyManagerTrees.class).update(); uiWorkingArea.setChild(UITaxonomyManagerTrees.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingArea); } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return UITaxonomyManagerTrees.class; } }
2,685
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINamespaceManagerComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UINamespaceManagerComponent.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.admin.manager; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.UIECMAdminWorkingArea; import org.exoplatform.ecm.webui.component.admin.listener.UIECMAdminControlPanelActionListener; import org.exoplatform.ecm.webui.component.admin.namespace.UINamespaceManager; 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.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 15 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = UINamespaceManagerComponent.UINamespaceManagerActionListener.class) } ) public class UINamespaceManagerComponent extends UIAbstractManagerComponent { public static class UINamespaceManagerActionListener extends UIECMAdminControlPanelActionListener<UINamespaceManagerComponent> { public void processEvent(Event<UINamespaceManagerComponent> event) throws Exception { UIECMAdminPortlet portlet = event.getSource().getAncestorOfType(UIECMAdminPortlet.class); UIECMAdminWorkingArea uiWorkingArea = portlet.getChild(UIECMAdminWorkingArea.class); uiWorkingArea.getChild(UINamespaceManager.class).refresh() ; uiWorkingArea.setChild(UINamespaceManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingArea) ; } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return UINamespaceManager.class; } }
2,532
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIScriptManagerComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UIScriptManagerComponent.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.admin.manager; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.UIECMAdminWorkingArea; import org.exoplatform.ecm.webui.component.admin.listener.UIECMAdminControlPanelActionListener; import org.exoplatform.ecm.webui.component.admin.script.UIScriptManager; 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.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 15 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = UIScriptManagerComponent.UIScriptManagerActionListener.class) } ) public class UIScriptManagerComponent extends UIAbstractManagerComponent { public static class UIScriptManagerActionListener extends UIECMAdminControlPanelActionListener<UIScriptManagerComponent> { public void processEvent(Event<UIScriptManagerComponent> event) throws Exception { UIECMAdminPortlet portlet = event.getSource().getAncestorOfType(UIECMAdminPortlet.class); UIECMAdminWorkingArea uiWorkingArea = portlet.getChild(UIECMAdminWorkingArea.class); uiWorkingArea.setChild(UIScriptManager.class) ; uiWorkingArea.getChild(UIScriptManager.class).refresh() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingArea) ; } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return UIScriptManager.class; } }
2,505
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITemplatesManagerComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UITemplatesManagerComponent.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.admin.manager; import javax.jcr.AccessDeniedException; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.UIECMAdminWorkingArea; import org.exoplatform.ecm.webui.component.admin.listener.UIECMAdminControlPanelActionListener; import org.exoplatform.ecm.webui.component.admin.templates.UITemplatesManager; 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.exception.MessageException; 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 * 15 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = UITemplatesManagerComponent.UITemplatesManagerActionListener.class) } ) public class UITemplatesManagerComponent extends UIAbstractManagerComponent { public static class UITemplatesManagerActionListener extends UIECMAdminControlPanelActionListener<UITemplatesManagerComponent> { public void processEvent(Event<UITemplatesManagerComponent> event) throws Exception { UIECMAdminPortlet portlet = event.getSource().getAncestorOfType(UIECMAdminPortlet.class); UIECMAdminWorkingArea uiWorkingArea = portlet.getChild(UIECMAdminWorkingArea.class); try { uiWorkingArea.getChild(UITemplatesManager.class).refresh() ; uiWorkingArea.setChild(UITemplatesManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingArea) ; } catch(AccessDeniedException ace) { throw new MessageException(new ApplicationMessage("UIECMAdminControlPanel.msg.access-denied", null, ApplicationMessage.WARNING)) ; } } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return UITemplatesManager.class; } }
2,964
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIAbstractManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UIAbstractManager.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.admin.manager; import org.exoplatform.webui.core.UIContainer; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 15 mai 2009 */ public abstract class UIAbstractManager extends UIContainer { /** * This method is used to refresh the content of the UI component related to the manager * @throws Exception if any error occurs */ public abstract void refresh() throws Exception; /** * This method is used to initialize the content of the UI component related to the manager * @throws Exception if any error occurs */ public void init() throws Exception { refresh(); } }
1,453
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIAbstractManagerComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UIAbstractManagerComponent.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.admin.manager; import org.exoplatform.webui.core.UIComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 15 mai 2009 */ public abstract class UIAbstractManagerComponent extends UIComponent { /** * The name of the related UIExtension */ private String uiExtensionName; /** * The category of the related UIExtension */ private String uiExtensionCategory; public String getUIExtensionName() { return uiExtensionName; } public void setUIExtensionName(String uiExtensionName) { this.uiExtensionName = uiExtensionName; } public String getUIExtensionCategory() { return uiExtensionCategory; } public void setUIExtensionCategory(String uiExtensionCategory) { this.uiExtensionCategory = uiExtensionCategory; } /** * Gives the class related to manager */ public abstract Class<? extends UIAbstractManager> getUIAbstractManagerClass(); }
1,775
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIFolksonomyManagerComponent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/manager/UIFolksonomyManagerComponent.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.admin.manager; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.component.admin.UIECMAdminWorkingArea; import org.exoplatform.ecm.webui.component.admin.folksonomy.UIFolksonomyManager; import org.exoplatform.ecm.webui.component.admin.listener.UIECMAdminControlPanelActionListener; 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.manager.UIAbstractManager; import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent; /** * Created by The eXo Platform SAS * Author : eXoPlatform * nicolas.filotto@exoplatform.com * 15 mai 2009 */ @ComponentConfig( events = { @EventConfig(listeners = UIFolksonomyManagerComponent.UIFolksonomyManagerActionListener.class) } ) public class UIFolksonomyManagerComponent extends UIAbstractManagerComponent { public static class UIFolksonomyManagerActionListener extends UIECMAdminControlPanelActionListener<UIFolksonomyManagerComponent> { public void processEvent(Event<UIFolksonomyManagerComponent> event) throws Exception { UIECMAdminPortlet portlet = event.getSource().getAncestorOfType(UIECMAdminPortlet.class); UIECMAdminWorkingArea uiWorkingArea = portlet.getChild(UIECMAdminWorkingArea.class); uiWorkingArea.setChild(UIFolksonomyManager.class); UIFolksonomyManager uiFolksonomyManager = uiWorkingArea.getChild(UIFolksonomyManager.class); uiFolksonomyManager.update(); event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingArea); } } @Override public Class<? extends UIAbstractManager> getUIAbstractManagerClass() { return UIFolksonomyManager.class; } }
2,721
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIDialogTab.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/templates/UIDialogTab.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.admin.templates; import java.util.ArrayList; import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.Value; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.templates.TemplateService; 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; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * Oct 03, 2006 * 9:43:23 AM */ @ComponentConfig( lifecycle = UIContainerLifecycle.class, events = { @EventConfig(listeners = UIDialogTab.EditActionListener.class), @EventConfig(listeners = UIDialogTab.DeleteActionListener.class, confirm = "UIDialogTab.msg.confirm-delete") } ) public class UIDialogTab extends UIContainer { final private static String[] BEAN_FIELD = {"name", "roles", "baseVersion"} ; final private static String[] ACTIONS = {"Edit", "Delete"} ; final public static String DIALOG_LIST_NAME = "DialogList" ; final public static String DIALOG_FORM_NAME = "DialogForm" ; private List<String> listDialog_ = new ArrayList<String>() ; public UIDialogTab() throws Exception { UIGrid uiGrid = addChild(UIGrid.class, null, DIALOG_LIST_NAME) ; uiGrid.getUIPageIterator().setId("DialogListIterator") ; uiGrid.configure("name", BEAN_FIELD, ACTIONS) ; UITemplateContent uiForm = addChild(UITemplateContent.class, null , DIALOG_FORM_NAME) ; uiForm.setTemplateType(TemplateService.DIALOGS); uiForm.update(null) ; } public List<String> getListDialog() { return listDialog_ ; } public void updateGrid(String nodeName) throws Exception { TemplateService tempService = getApplicationComponent(TemplateService.class) ; NodeIterator iter = tempService.getAllTemplatesOfNodeType(true, nodeName, WCMCoreUtils.getSystemSessionProvider()) ; List<DialogData> data = new ArrayList<DialogData>() ; DialogData item ; if(iter == null) return; while (iter.hasNext()){ Node node = (Node) iter.next() ; String version = "" ; StringBuilder rule = new StringBuilder() ; Value[] rules = node.getNode(Utils.JCR_CONTENT).getProperty(Utils.EXO_ROLES).getValues() ; for(int i = 0; i < rules.length; i++) { rule.append("["+rules[i].getString()+"]") ; } if(node.isNodeType(Utils.MIX_VERSIONABLE) && !node.isNodeType(Utils.NT_FROZEN)){ version = node.getBaseVersion().getName() ; } listDialog_.add(node.getName()) ; item = new DialogData(node.getName(), rule.toString(), version) ; data.add(item) ; } UIGrid uiGrid = getChild(UIGrid.class) ; ListAccess<DialogData> dialogDataList = new ListAccessImpl<DialogData>(DialogData.class, data); LazyPageList<DialogData> dataPageList = new LazyPageList<DialogData>(dialogDataList, 4); uiGrid.getUIPageIterator().setPageList(dataPageList); } public void setTabRendered() { UIViewTemplate uiViewTemplate = getAncestorOfType(UIViewTemplate.class) ; uiViewTemplate.setSelectedTab(UIDialogTab.class.getSimpleName()) ; } static public class EditActionListener extends EventListener<UIDialogTab> { public void execute(Event<UIDialogTab> event) throws Exception { UIDialogTab dialogTab = event.getSource() ; String dialogName = event.getRequestContext().getRequestParameter(OBJECTID) ; UITemplateContent uiForm = dialogTab.getChild(UITemplateContent.class) ; uiForm.update(dialogName) ; dialogTab.setTabRendered() ; UITemplatesManager uiManager = dialogTab.getAncestorOfType(UITemplatesManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class DeleteActionListener extends EventListener<UIDialogTab> { public void execute(Event<UIDialogTab> event) throws Exception { UIDialogTab dialogTab = event.getSource() ; UIViewTemplate uiViewTemplate = event.getSource().getAncestorOfType(UIViewTemplate.class) ; String nodeTypeName = uiViewTemplate.getNodeTypeName() ; String templateName = event.getRequestContext().getRequestParameter(OBJECTID) ; TemplateService templateService = dialogTab.getApplicationComponent(TemplateService.class) ; UITemplateContent uiForm = dialogTab.findFirstComponentOfType(UITemplateContent.class) ; for(String template : TemplateService.UNDELETABLE_TEMPLATES) { if(template.equals(templateName)) { UIApplication app = dialogTab.getAncestorOfType(UIApplication.class) ; Object[] args = {template} ; app.addMessage(new ApplicationMessage("UIDialogTab.msg.undeletable", args, ApplicationMessage.WARNING)) ; dialogTab.setTabRendered() ; return ; } } templateService.removeTemplate(TemplateService.DIALOGS, nodeTypeName, templateName) ; uiForm.update(null); uiForm.reset(); dialogTab.updateGrid(nodeTypeName) ; dialogTab.setTabRendered() ; UITemplatesManager uiManager = dialogTab.getAncestorOfType(UITemplatesManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } public static class DialogData { private String name ; private String roles ; private String baseVersion ; public DialogData(String name, String roles, String version) { this.name = name ; this.roles = roles ; baseVersion = version ; } public String getName(){return name ;} public String getRoles(){return roles ;} public String getBaseVersion(){return baseVersion ;} } }
7,107
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITemplateContent.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/templates/UITemplateContent.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.admin.templates; import java.io.ByteArrayInputStream; import java.util.ArrayList; import java.util.List; import javax.jcr.Node; import javax.jcr.Value; import javax.jcr.version.VersionHistory; import org.exoplatform.ecm.jcr.model.VersionNode; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.ecm.webui.form.validator.ECMNameValidator; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.templates.TemplateService; 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.config.annotation.EventConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.UIComponent; 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 org.exoplatform.webui.form.input.UICheckBoxInput; import org.exoplatform.webui.form.validator.MandatoryValidator; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * Oct 03, 2006 * 9:43:23 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UITemplateContent.SaveActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UITemplateContent.ChangeActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UITemplateContent.CancelActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UITemplateContent.RestoreActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UITemplateContent.RefreshActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UITemplateContent.AddPermissionActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UITemplateContent.RemovePermissionActionListener.class) } ) public class UITemplateContent extends UIForm implements UISelectable { final static public String FIELD_SELECT_VERSION = "selectVersion" ; final static public String FIELD_CONTENT = "content" ; final static public String FIELD_NAME = "name" ; final static public String FIELD_VIEWPERMISSION = "viewPermission" ; final static public String FIELD_ENABLE_VERSION = "enableVersion" ; final static public String[] REG_EXPRESSION = {"[", "]", ":", "&", "%"} ; private boolean isAddNew_ = true ; private String nodeTypeName_ ; private List<String> listVersion_ = new ArrayList<String>() ; private String templateType; final static public String TEMPLATE_PERMISSION = "TemplatePermission" ; public UITemplateContent() throws Exception { List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>() ; UIFormSelectBox versions = new UIFormSelectBox(FIELD_SELECT_VERSION, FIELD_SELECT_VERSION, options) ; versions.setOnChange("Change") ; versions.setRendered(false) ; addUIFormInput(versions) ; addUIFormInput(new UIFormTextAreaInput(FIELD_CONTENT, FIELD_CONTENT, null).addValidator(MandatoryValidator.class)) ; addUIFormInput(new UIFormStringInput(FIELD_NAME, FIELD_NAME, null).addValidator(MandatoryValidator.class). addValidator(ECMNameValidator.class)) ; UICheckBoxInput isVersion = new UICheckBoxInput(FIELD_ENABLE_VERSION , FIELD_ENABLE_VERSION, null) ; isVersion.setRendered(false) ; addUIFormInput(isVersion) ; UIFormInputSetWithAction uiActionTab = new UIFormInputSetWithAction("UITemplateContent"); uiActionTab.addUIFormInput(new UIFormStringInput(FIELD_VIEWPERMISSION, FIELD_VIEWPERMISSION, null).setDisabled(true).addValidator(MandatoryValidator.class)); uiActionTab.setActionInfo(FIELD_VIEWPERMISSION, new String[] { "AddPermission", "RemovePermission" }); addUIComponentInput(uiActionTab) ; } public void setTemplateType(String templateType) { this.templateType = templateType; } public String getTemplateType() { return templateType; } public void setNodeTypeName (String nodeType) {nodeTypeName_ = nodeType ;} public void update(String templateName) throws Exception { if(templateName != null) { isAddNew_ = false ; TemplateService templateService = getApplicationComponent(TemplateService.class) ; String templateContent = templateService.getTemplate(templateType, nodeTypeName_, templateName) ; Node template = templateService.getTemplateNode(templateType, nodeTypeName_, templateName, WCMCoreUtils.getSystemSessionProvider()) ; getUICheckBoxInput(FIELD_ENABLE_VERSION).setRendered(true) ; String templateRole = templateService.getTemplateRoles(template) ; boolean isVersioned = template.isNodeType(Utils.MIX_VERSIONABLE) ; if(isVersioned) { getUIFormSelectBox(FIELD_SELECT_VERSION).setRendered(true) ; getUIFormSelectBox(FIELD_SELECT_VERSION).setOptions(getVersionValues(template)) ; getUIFormSelectBox(FIELD_SELECT_VERSION).setValue(template.getBaseVersion().getName()) ; getUICheckBoxInput(FIELD_ENABLE_VERSION).setDisabled(true); getUICheckBoxInput(FIELD_ENABLE_VERSION).setChecked(true) ; setActions(new String[]{"Save", "Restore", "Refresh", "Cancel"}) ; } else { getUIFormSelectBox(FIELD_SELECT_VERSION).setRendered(false) ; getUICheckBoxInput(FIELD_ENABLE_VERSION).setDisabled(false); getUICheckBoxInput(FIELD_ENABLE_VERSION).setChecked(false) ; setActions( new String[]{"Save", "Refresh", "Cancel"}) ; } getUIFormTextAreaInput(FIELD_CONTENT).setValue(templateContent) ; getUIStringInput(FIELD_NAME).setValue(template.getName()) ; getUIStringInput(FIELD_NAME).setDisabled(true); getUIStringInput(FIELD_VIEWPERMISSION).setValue(templateRole) ; return ; } isAddNew_ = true ; getUIFormSelectBox(FIELD_SELECT_VERSION).setRendered(false) ; getUICheckBoxInput(FIELD_ENABLE_VERSION).setRendered(false) ; getUIStringInput(FIELD_NAME).setDisabled(false); setActions( new String[]{"Save", "Refresh", "Cancel"}) ; } private void refresh() throws Exception { UIViewTemplate uiViewTemplate = getAncestorOfType(UIViewTemplate.class) ; uiViewTemplate.refresh() ; UIComponent parent = getParent() ; if(parent instanceof UIDialogTab) { uiViewTemplate.setSelectedTab(UIDialogTab.class.getSimpleName()) ; } else if(parent instanceof UIViewTab) { uiViewTemplate.setSelectedTab(UIViewTab.class.getSimpleName()) ; } else if(parent instanceof UISkinTab) { uiViewTemplate.setSelectedTab(UISkinTab.class.getSimpleName()) ; } update(null) ; reset() ; } private VersionNode getRootVersion(Node node) throws Exception{ VersionHistory vH = node.getVersionHistory() ; if(vH != null) return new VersionNode(vH.getRootVersion(), node.getSession()) ; return null ; } private List<String> getNodeVersions(List<VersionNode> children) throws Exception { List<VersionNode> child = new ArrayList<VersionNode>() ; for(VersionNode version : children) { listVersion_.add(version.getName()) ; child = version.getChildren() ; if(!child.isEmpty()) getNodeVersions(child) ; } return listVersion_ ; } private List<SelectItemOption<String>> getVersionValues(Node node) throws Exception { List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>() ; List<VersionNode> children = getRootVersion(node).getChildren() ; listVersion_.clear() ; List<String> versionList = getNodeVersions(children) ; for(int i = 0; i < versionList.size(); i++) { for(int j = i + 1; j < versionList.size(); j ++) { if( Integer.parseInt(versionList.get(j)) < Integer.parseInt(versionList.get(i))) { String temp = versionList.get(i) ; versionList.set(i, versionList.get(j)) ; versionList.set(j, temp) ; } } options.add(new SelectItemOption<String>(versionList.get(i), versionList.get(i))) ; } return options ; } @SuppressWarnings("unused") public void doSelect(String selectField, Object value) { String viewPermission = getUIStringInput(FIELD_VIEWPERMISSION).getValue(); if (viewPermission == null) viewPermission = ""; if ((viewPermission != null) && (viewPermission.length() == 0)) { viewPermission = value.toString(); } else { StringBuffer sb = new StringBuffer(); sb.append(viewPermission).append(",").append(value.toString()); viewPermission = sb.toString(); } getUIStringInput(FIELD_VIEWPERMISSION).setValue(viewPermission) ; } static public class RestoreActionListener extends EventListener<UITemplateContent> { public void execute(Event<UITemplateContent> event) throws Exception { UITemplateContent uiForm = event.getSource() ; UITemplatesManager uiManager = uiForm.getAncestorOfType(UITemplatesManager.class) ; String name = uiForm.getUIStringInput(FIELD_NAME).getValue() ; TemplateService templateService = uiForm.getApplicationComponent(TemplateService.class) ; Node node = templateService.getTemplateNode(uiForm.getTemplateType(), uiForm.nodeTypeName_, name, WCMCoreUtils.getSystemSessionProvider()) ; String vesion = uiForm.getUIFormSelectBox(FIELD_SELECT_VERSION).getValue() ; String baseVesion = node.getBaseVersion().getName() ; UIApplication app = uiForm.getAncestorOfType(UIApplication.class) ; if(vesion.equals(baseVesion)) return ; node.checkout() ; node.restore(vesion, true) ; Object[] args = {uiForm.getUIStringInput(FIELD_SELECT_VERSION).getValue()} ; app.addMessage(new ApplicationMessage("UITemplateContent.msg.version-restored", args)) ; uiForm.refresh() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class SaveActionListener extends EventListener<UITemplateContent> { public void execute(Event<UITemplateContent> event) throws Exception { UITemplateContent uiForm = event.getSource() ; UITemplatesManager uiManager = uiForm.getAncestorOfType(UITemplatesManager.class) ; UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class) ; String name = uiForm.getUIStringInput(FIELD_NAME).getValue() ; if(name == null || name.trim().length() == 0) { Object[] args = { FIELD_NAME } ; uiApp.addMessage(new ApplicationMessage("ECMNameValidator.msg.empty-input", args, ApplicationMessage.WARNING)) ; return ; } if(!Utils.isNameValid(name, UITemplateContent.REG_EXPRESSION)){ uiApp.addMessage(new ApplicationMessage("UITemplateContent.msg.name-invalid", null, ApplicationMessage.WARNING)) ; return ; } String content = uiForm.getUIFormTextAreaInput(FIELD_CONTENT).getValue() ; if(content == null) content = "" ; UIFormInputSetWithAction permField = uiForm.getChildById("UITemplateContent") ; String role = permField.getUIStringInput(FIELD_VIEWPERMISSION).getValue() ; if ((role == null) || (role.trim().length() == 0)) { uiApp.addMessage(new ApplicationMessage("UITemplateForm.msg.role-require", null, ApplicationMessage.WARNING)); return; } UIViewTemplate uiViewTemplate = uiForm.getAncestorOfType(UIViewTemplate.class) ; if(uiForm.getId().equals(UIDialogTab.DIALOG_FORM_NAME)) { UIDialogTab uiDialogTab = uiViewTemplate.getChild(UIDialogTab.class) ; if(uiDialogTab.getListDialog().contains(name) && uiForm.isAddNew_) { Object[] args = { name } ; uiApp.addMessage(new ApplicationMessage("UITemplateContent.msg.name-exist", args, ApplicationMessage.WARNING)) ; return ; } } else if(uiForm.getId().equals(UIViewTab.VIEW_FORM_NAME)) { UIViewTab uiViewTab = uiViewTemplate.getChild(UIViewTab.class) ; if(uiViewTab.getListView().contains(name) && uiForm.isAddNew_) { Object[] args = { name } ; uiApp.addMessage(new ApplicationMessage("UITemplateContent.msg.name-exist", args, ApplicationMessage.WARNING)) ; return ; } } else if(uiForm.getId().equals(UISkinTab.SKIN_FORM_NAME)) { UISkinTab uiSkinTab = uiViewTemplate.getChild(UISkinTab.class) ; if(uiSkinTab.getListSkin().contains(name) && uiForm.isAddNew_) { Object[] args = { name } ; uiApp.addMessage(new ApplicationMessage("UITemplateContent.msg.name-exist", args, ApplicationMessage.WARNING)) ; return ; } } TemplateService templateService = uiForm.getApplicationComponent(TemplateService.class) ; boolean isEnableVersioning = uiForm.getUICheckBoxInput(FIELD_ENABLE_VERSION).isChecked() ; if(uiForm.isAddNew_){ templateService.addTemplate(uiForm.getTemplateType(), uiForm.nodeTypeName_, null, false, name, new String[] {role}, new ByteArrayInputStream(content.getBytes("utf-8"))); } else { Node node = templateService.getTemplateNode(uiForm.getTemplateType(), uiForm.nodeTypeName_, name, WCMCoreUtils.getSystemSessionProvider()) ; if(isEnableVersioning && !node.isNodeType(Utils.MIX_VERSIONABLE)) { node.addMixin(Utils.MIX_VERSIONABLE) ; } if (areValidPermissions(role, uiForm)) { templateService.addTemplate(uiForm.getTemplateType(), uiForm.nodeTypeName_, null, false, name, new String[] { role }, new ByteArrayInputStream(content.getBytes("utf-8"))); } else { return; } node.save() ; if(isEnableVersioning) { node.checkin() ; node.checkout(); } } uiForm.refresh() ; uiForm.isAddNew_ = true ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class ChangeActionListener extends EventListener<UITemplateContent> { public void execute(Event<UITemplateContent> event) throws Exception { UITemplateContent uiForm = event.getSource() ; UITemplatesManager uiManager = uiForm.getAncestorOfType(UITemplatesManager.class) ; String name = uiForm.getUIStringInput(FIELD_NAME).getValue() ; TemplateService templateService = uiForm.getApplicationComponent(TemplateService.class) ; Node node = templateService.getTemplateNode(uiForm.getTemplateType(), uiForm.nodeTypeName_, name, WCMCoreUtils.getSystemSessionProvider()) ; String version = uiForm.getUIFormSelectBox(FIELD_SELECT_VERSION).getValue() ; String path = node.getVersionHistory().getVersion(version).getPath() ; VersionNode versionNode = uiForm.getRootVersion(node).findVersionNode(path) ; Node frozenNode = versionNode.getNode(Utils.JCR_FROZEN) ; String content = templateService.getTemplate(frozenNode); uiForm.getUIFormTextAreaInput(FIELD_CONTENT).setValue(content) ; if (frozenNode.hasProperty(Utils.EXO_ROLES)) { StringBuilder rule = new StringBuilder() ; Value[] rules = frozenNode.getProperty(Utils.EXO_ROLES).getValues() ; for(int i = 0; i < rules.length; i++) { rule.append(rules[i].getString()); } uiForm.getUIStringInput(FIELD_VIEWPERMISSION).setValue(rule.toString()); } event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class AddPermissionActionListener extends EventListener<UITemplateContent> { public void execute(Event<UITemplateContent> event) throws Exception { UITemplateContent uiTempContent = event.getSource() ; UITemplatesManager uiManager = uiTempContent.getAncestorOfType(UITemplatesManager.class) ; UIViewTemplate uiViewTemp = uiTempContent.getAncestorOfType(UIViewTemplate.class) ; String membership = uiTempContent.getUIStringInput(FIELD_VIEWPERMISSION).getValue() ; uiManager.initPopupPermission(uiTempContent.getId(), membership) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; if(uiTempContent.getId().equals(UIDialogTab.DIALOG_FORM_NAME)) { uiViewTemp.setSelectedTab(UIDialogTab.class.getSimpleName()) ; } else if(uiTempContent.getId().equals(UIViewTab.VIEW_FORM_NAME)) { uiViewTemp.setSelectedTab(UIViewTab.class.getSimpleName()) ; } else if(uiTempContent.getId().equals(UISkinTab.SKIN_FORM_NAME)) { uiViewTemp.setSelectedTab(UISkinTab.class.getSimpleName()) ; } UIPopupWindow uiPopup = uiManager.getChildById(UITemplateContent.TEMPLATE_PERMISSION); event.getRequestContext().addUIComponentToUpdateByAjax(uiPopup) ; } } static public class RemovePermissionActionListener extends EventListener<UITemplateContent> { public void execute(Event<UITemplateContent> event) throws Exception { UITemplateContent uiTemplateContent = event.getSource(); uiTemplateContent.getUIStringInput(FIELD_VIEWPERMISSION).setValue(null); event.getRequestContext().addUIComponentToUpdateByAjax(uiTemplateContent); } } static public class RefreshActionListener extends EventListener<UITemplateContent> { public void execute(Event<UITemplateContent> event) throws Exception { UITemplateContent uiForm = event.getSource() ; UITemplatesManager uiManager = uiForm.getAncestorOfType(UITemplatesManager.class) ; if(!uiForm.isAddNew_) { uiForm.update(uiForm.getUIStringInput(UITemplateContent.FIELD_NAME).getValue()) ; return ; } uiForm.update(null) ; uiForm.reset() ; uiForm.refresh() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class CancelActionListener extends EventListener<UITemplateContent> { public void execute(Event<UITemplateContent> event) throws Exception { UITemplateContent uiTemplateContent = event.getSource() ; UITemplatesManager uiManager = uiTemplateContent.getAncestorOfType(UITemplatesManager.class) ; uiManager.removeChildById(UIDialogTab.DIALOG_FORM_NAME + TEMPLATE_PERMISSION) ; uiManager.removeChildById(UIViewTab.VIEW_FORM_NAME + TEMPLATE_PERMISSION) ; uiManager.removeChildById(UISkinTab.SKIN_FORM_NAME + TEMPLATE_PERMISSION) ; uiTemplateContent.reset() ; UIPopupWindow uiPopupWindow = uiManager.getChildById(UITemplatesManager.POPUP_TEMPLATE_ID) ; uiPopupWindow.setShow(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } private static boolean areValidPermissions(String permissions, UITemplateContent uiTemplateContent) throws Exception { Boolean areValidPermissions = false; UIApplication uiApp = uiTemplateContent.getAncestorOfType(UIApplication.class); if (permissions == null || permissions.trim().length() == 0) { uiApp.addMessage(new ApplicationMessage("UIDriveForm.msg.permission-null", null, ApplicationMessage.WARNING)); areValidPermissions = false; return areValidPermissions; } OrganizationService oservice = WCMCoreUtils.getService(OrganizationService.class); String[] arrPermissions = permissions.split(","); for (String itemPermission : arrPermissions) { if (itemPermission.length() == 0) { uiApp.addMessage(new ApplicationMessage("UIDriveForm.msg.permission-path-invalid", null, ApplicationMessage.WARNING)); areValidPermissions = false; return areValidPermissions; } if (itemPermission.contains(":")) { String[] permission = itemPermission.split(":"); if ((permission[0] == null) || (permission[0].length() == 0)) { uiApp.addMessage(new ApplicationMessage("UIDriveForm.msg.permission-path-invalid", null, ApplicationMessage.WARNING)); areValidPermissions = false; return areValidPermissions; } else if (!permission[0].equals("*") && (oservice.getMembershipTypeHandler().findMembershipType(permission[0]) == null)) { uiApp.addMessage(new ApplicationMessage("UIDriveForm.msg.permission-path-invalid", null, ApplicationMessage.WARNING)); areValidPermissions = false; return areValidPermissions; } if ((permission[1] == null) || (permission[1].length() == 0)) { uiApp.addMessage(new ApplicationMessage("UIDriveForm.msg.permission-path-invalid", null, ApplicationMessage.WARNING)); areValidPermissions = false; return areValidPermissions; } else if (oservice.getGroupHandler().findGroupById(permission[1]) == null) { uiApp.addMessage(new ApplicationMessage("UIDriveForm.msg.permission-path-invalid", null, ApplicationMessage.WARNING)); areValidPermissions = false; return areValidPermissions; } } else { if (!itemPermission.equals("*")) { uiApp.addMessage(new ApplicationMessage("UIDriveForm.msg.permission-path-invalid", null, ApplicationMessage.WARNING)); areValidPermissions = false; return areValidPermissions; } } } areValidPermissions = true; return areValidPermissions; } }
24,469
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIViewTab.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/templates/UIViewTab.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.admin.templates; import java.util.ArrayList; import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.Value; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.templates.TemplateService; 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; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * Oct 03, 2006 * 9:43:23 AM */ @ComponentConfig( lifecycle = UIContainerLifecycle.class, events = { @EventConfig(listeners = UIViewTab.EditActionListener.class), @EventConfig(listeners = UIViewTab.DeleteActionListener.class, confirm = "UIViewTab.msg.confirm-delete") } ) public class UIViewTab extends UIContainer { final private static String[] BEAN_FIELD = {"name", "roles", "baseVersion"} ; final private static String[] ACTIONS = {"Edit", "Delete"} ; final public static String VIEW_LIST_NAME = "VewList" ; final public static String VIEW_FORM_NAME = "ViewForm" ; private List<String> listView_ = new ArrayList<String>() ; public UIViewTab() throws Exception { UIGrid uiGrid = addChild(UIGrid.class, null, VIEW_LIST_NAME) ; uiGrid.getUIPageIterator().setId("ViewListIterator") ; uiGrid.configure("name", BEAN_FIELD, ACTIONS) ; UITemplateContent uiForm = addChild(UITemplateContent.class, null , VIEW_FORM_NAME) ; uiForm.setTemplateType(TemplateService.VIEWS); uiForm.update(null); } public List<String> getListView() { return listView_ ; } public void updateGrid(String nodeName) throws Exception { TemplateService tempService = getApplicationComponent(TemplateService.class) ; NodeIterator iter = tempService.getAllTemplatesOfNodeType(false, nodeName, WCMCoreUtils.getSystemSessionProvider()) ; List<ViewData> data = new ArrayList<ViewData>() ; ViewData item ; if(iter == null) return; while(iter.hasNext()) { Node node = (Node) iter.next() ; String version = "" ; StringBuilder rule = new StringBuilder() ; Value[] rules = node.getNode(Utils.JCR_CONTENT).getProperty(Utils.EXO_ROLES).getValues() ; for(int i = 0; i < rules.length; i++) { rule.append("["+rules[i].getString()+"]") ; } if(node.isNodeType(Utils.MIX_VERSIONABLE) && !node.isNodeType(Utils.NT_FROZEN)) { version = node.getBaseVersion().getName(); } listView_.add(node.getName()) ; item = new ViewData(node.getName(), rule.toString(), version) ; data.add(item); } UIGrid uiGrid = getChild(UIGrid.class) ; ListAccess<ViewData> viewDataList = new ListAccessImpl<ViewData>(ViewData.class, data); LazyPageList<ViewData> dataPageList = new LazyPageList<ViewData>(viewDataList, 4); uiGrid.getUIPageIterator().setPageList(dataPageList); } public void setTabRendered() { UIViewTemplate uiViewTemplate = getAncestorOfType(UIViewTemplate.class) ; uiViewTemplate.setSelectedTab(UIViewTab.class.getSimpleName()) ; } static public class EditActionListener extends EventListener<UIViewTab> { public void execute(Event<UIViewTab> event) throws Exception { UIViewTab viewTab = event.getSource() ; String viewName = event.getRequestContext().getRequestParameter(OBJECTID) ; UITemplateContent uiForm = viewTab.getChild(UITemplateContent.class) ; uiForm.update(viewName) ; viewTab.setTabRendered() ; UITemplatesManager uiManager = viewTab.getAncestorOfType(UITemplatesManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class DeleteActionListener extends EventListener<UIViewTab> { public void execute(Event<UIViewTab> event) throws Exception { UIViewTab viewTab = event.getSource() ; UIViewTemplate uiViewTemplate = event.getSource().getAncestorOfType(UIViewTemplate.class) ; String nodeTypeName = uiViewTemplate.getNodeTypeName() ; String templateName = event.getRequestContext().getRequestParameter(OBJECTID) ; TemplateService templateService = viewTab.getApplicationComponent(TemplateService.class) ; for(String template : TemplateService.UNDELETABLE_TEMPLATES) { if(template.equals(templateName)){ UIApplication app = viewTab.getAncestorOfType(UIApplication.class) ; Object[] args = {template} ; app.addMessage(new ApplicationMessage("UIViewTab.msg.undeletable", args, ApplicationMessage.WARNING)) ; viewTab.setTabRendered() ; return ; } } templateService.removeTemplate(TemplateService.VIEWS, nodeTypeName, templateName) ; UITemplateContent uiForm = viewTab.findFirstComponentOfType(UITemplateContent.class) ; uiForm.update(null); uiForm.reset(); viewTab.updateGrid(nodeTypeName) ; viewTab.setTabRendered() ; UITemplatesManager uiManager = viewTab.getAncestorOfType(UITemplatesManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } public static class ViewData { private String name ; private String roles ; private String baseVersion ; public ViewData(String name, String roles, String version) { this.name = name ; this.roles = roles ; baseVersion = version ; } public String getName(){return name ; } public String getRoles(){return roles ; } public String getBaseVersion(){return baseVersion ; } } }
6,997
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITemplatesManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/templates/UITemplatesManager.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.admin.templates; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.selector.UIPermissionSelector; 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.UIComponent; import org.exoplatform.webui.core.UIPopupContainer; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.ext.manager.UIAbstractManager; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * Oct 03, 2006 * 9:43:23 AM */ @ComponentConfigs( { @ComponentConfig(template = "app:/groovy/webui/component/admin/template/UITemplatesManager.gtmpl", events = { @EventConfig(listeners = UITemplatesManager.SelectTabActionListener.class) }) }) public class UITemplatesManager extends UIAbstractManager { final static public String POPUP_TEMPLATE_ID = "TemplateContainerPopup"; final static public String ACTIONS_TEMPLATE_ID = "UIActionsTemplateContainer"; final static public String OTHERS_TEMPLATE_ID = "UIOthersTemplateContainer"; final static public String ACTIONS_TEMPLATE_LIST_ID = "UIActionsTemplateList"; final static public String OTHERS_TEMPLATE_LIST_ID = "UIOthersTemplateList"; final static public String ACTIONS_ITERATOR_ID = "ActionsNodeTypeListIterator"; final static public String OTHERS_ITERATOR_ID = "OthersNodeTypeListIterator"; private String selectedTabId = "UITemplateContainer"; public String getSelectedTabId() { return selectedTabId; } public void setSelectedTab(String renderTabId) { selectedTabId = renderTabId; } public void setSelectedTab(int index) { selectedTabId = getChild(index - 1).getId(); } public UITemplatesManager() throws Exception { UITemplateContainer uiTemp = addChild(UITemplateContainer.class, null, null) ; uiTemp.getChild(UITemplateList.class).setTemplateFilter(UITemplateList.DOCUMENTS_TEMPLATE_TYPE); UITemplateContainer uiActionsTemp = addChild(UITemplateContainer.class, null, ACTIONS_TEMPLATE_ID) ; uiActionsTemp.getChild(UITemplateList.class).setTemplateFilter(UITemplateList.ACTIONS_TEMPLATE_TYPE); uiActionsTemp.getChild(UITemplateList.class).setId(ACTIONS_TEMPLATE_LIST_ID); UITemplateContainer uiOthersTemp = addChild(UITemplateContainer.class, null, OTHERS_TEMPLATE_ID) ; uiOthersTemp.getChild(UITemplateList.class).setTemplateFilter(UITemplateList.OTHERS_TEMPLATE_TYPE); uiOthersTemp.getChild(UITemplateList.class).setId(OTHERS_TEMPLATE_LIST_ID); addChild(UIPopupWindow.class, null, POPUP_TEMPLATE_ID) ; addChild(UIPopupWindow.class, null, UITemplateContent.TEMPLATE_PERMISSION) ; setSelectedTab("UITemplateContainer"); } public void initPopup(UIComponent uiComponent) throws Exception { UIPopupWindow uiPopup = getChildById(POPUP_TEMPLATE_ID); uiPopup.setRendered(true); uiPopup.setShowMask(true); uiPopup.setWindowSize(600,300) ; uiPopup.setUIComponent(uiComponent) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public void initPopupPermission(String id, String membership) throws Exception { UIPopupWindow uiPopup = getChildById(UITemplateContent.TEMPLATE_PERMISSION); uiPopup.setWindowSize(560, 300); UIPermissionSelector uiECMPermission = createUIComponent(UIPermissionSelector.class, null, null); uiECMPermission.setSelectedMembership(true); if (membership != null && membership.indexOf(":/") > -1) { String[] arrMember = membership.split(":/"); uiECMPermission.setCurrentPermission("/" + arrMember[1]); } if (id.equals("AddNew")) { UITemplateForm uiForm = findFirstComponentOfType(UITemplateForm.class); uiECMPermission.setSourceComponent(uiForm, null); } else { UITemplateContent uiTemContent = findComponentById(id); uiECMPermission.setSourceComponent(uiTemContent, null); } uiPopup.setUIComponent(uiECMPermission); uiPopup.setRendered(true); uiPopup.setShow(true); uiPopup.setResizable(true); } public boolean isEditingTemplate() { UIECMAdminPortlet adminPortlet = this.getAncestorOfType(UIECMAdminPortlet.class); UIPopupContainer popupContainer = adminPortlet.getChild(UIPopupContainer.class); UIPopupWindow uiPopup = popupContainer.getChild(UIPopupWindow.class); uiPopup.setId(POPUP_TEMPLATE_ID); return (uiPopup != null && uiPopup.isShow() && uiPopup.isRendered()); } public void refresh() throws Exception { UITemplateContainer templateContainer = ((UITemplateContainer)getChildById("UITemplateContainer")); UITemplateContainer templateActionsContainer = ((UITemplateContainer)getChildById(ACTIONS_TEMPLATE_ID)); UITemplateContainer templateOthersContainer = ((UITemplateContainer)getChildById(OTHERS_TEMPLATE_ID)); templateContainer.getChild(UITemplateList.class).getUIPageIterator().setId(ACTIONS_ITERATOR_ID); templateOthersContainer.getChild(UITemplateList.class).getUIPageIterator().setId(OTHERS_ITERATOR_ID); templateContainer.update(); templateActionsContainer.update(); templateOthersContainer.update(); } static public class SelectTabActionListener extends EventListener<UITemplatesManager> { public void execute(Event<UITemplatesManager> 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 static class CloseActionListener extends EventListener<UIPopupWindow> { public void execute(Event<UIPopupWindow> event) throws Exception { UITemplatesManager uiManager = event.getSource().getAncestorOfType(UITemplatesManager.class) ; UIPopupWindow uiPopupWindow = uiManager.getChild(UIPopupWindow.class) ; uiPopupWindow.setRendered(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } }
7,347
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIViewTemplate.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/templates/UIViewTemplate.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.admin.templates; 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.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * Oct 03, 2006 * 9:43:23 AM */ @ComponentConfig(template = "system:/groovy/webui/core/UITabPane_New.gtmpl", events = { @EventConfig(listeners = UIViewTemplate.SelectTabActionListener.class) }) public class UIViewTemplate extends UIContainer { private String nodeTypeName_ ; private String selectedTabId = ""; public String getSelectedTabId() { return selectedTabId; } public void setSelectedTab(String renderTabId) { selectedTabId = renderTabId; } public void setSelectedTab(int index) { selectedTabId = getChild(index - 1).getId(); } public UIViewTemplate() throws Exception { addChild(UITemplateEditForm.class, null, null) ; setSelectedTab("UITemplateEditForm"); addChild(UIDialogTab.class, null, null); addChild(UIViewTab.class, null, null); addChild(UISkinTab.class, null, null); } public void refresh() throws Exception { getChild(UIDialogTab.class).updateGrid(nodeTypeName_); getChild(UIViewTab.class).updateGrid(nodeTypeName_); getChild(UISkinTab.class).updateGrid(nodeTypeName_); } public void setNodeTypeName(String nodeType) { nodeTypeName_ = nodeType ; } public String getNodeTypeName() { return nodeTypeName_ ; } static public class SelectTabActionListener extends EventListener<UIViewTemplate> { public void execute(Event<UIViewTemplate> 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); } } } }
3,134
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITemplateEditForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/templates/UITemplateEditForm.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.admin.templates; import javax.jcr.Node; import org.exoplatform.services.cms.templates.TemplateService; 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.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.input.UICheckBoxInput; /** * Created by The eXo Platform SARL * Author : Pham Tuan * phamtuanchip@yahoo.de * Dec 4, 2006 9:50:06 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UITemplateEditForm.SaveActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UITemplateEditForm.CancelActionListener.class) } ) public class UITemplateEditForm extends UIForm { final static public String FIELD_NAME = "name" ; final static public String FIELD_LABEL = "label" ; final static public String FIELD_ISTEMPLATE = "isDocumentTemplate" ; public UITemplateEditForm() { addChild(new UIFormStringInput(FIELD_NAME, null)) ; addChild(new UIFormStringInput(FIELD_LABEL, null)) ; addChild(new UICheckBoxInput(FIELD_ISTEMPLATE, null, null)) ; } private boolean isDocumentTemplate(String nodeType)throws Exception { TemplateService templateService = getApplicationComponent(TemplateService.class) ; return templateService.getDocumentTemplates().contains(nodeType) ; } public void update(String nodeType) throws Exception { TemplateService tempService = getApplicationComponent(TemplateService.class) ; Node node = tempService.getTemplatesHome(WCMCoreUtils.getSystemSessionProvider()).getNode(nodeType) ; String label = null ; if(node.hasProperty(TemplateService.TEMPLATE_LABEL)) { label = node.getProperty(TemplateService.TEMPLATE_LABEL).getString() ; } getUICheckBoxInput(FIELD_ISTEMPLATE).setChecked(isDocumentTemplate(nodeType)) ; getUIStringInput(FIELD_NAME).setValue(nodeType) ; getUIStringInput(FIELD_LABEL).setValue(label) ; getUICheckBoxInput(FIELD_ISTEMPLATE).setDisabled(true); getUIStringInput(FIELD_NAME).setDisabled(true); } static public class SaveActionListener extends EventListener<UITemplateEditForm> { public void execute(Event<UITemplateEditForm> event) throws Exception { UITemplateEditForm uiForm = event.getSource() ; TemplateService tempService = uiForm.getApplicationComponent(TemplateService.class) ; String nodeType = ((UIFormStringInput)(event.getSource().getChildById("name"))).getValue(); Node node = tempService.getTemplatesHome(WCMCoreUtils.getSystemSessionProvider()).getNode(nodeType) ; node.setProperty(TemplateService.TEMPLATE_LABEL,uiForm.getUIStringInput(FIELD_LABEL).getValue()) ; node.save() ; uiForm.reset() ; UITemplatesManager uiManager = uiForm.getAncestorOfType(UITemplatesManager.class) ; UITemplateContainer uiTemplateContainer = uiManager.getChildById(uiManager.getSelectedTabId()); UITemplateList uiList = uiTemplateContainer.getChild(UITemplateList.class); uiList.refresh(uiList.getUIPageIterator().getCurrentPage()); UIPopupWindow uiPopupWindow = uiManager.getChildById(UITemplatesManager.POPUP_TEMPLATE_ID) ; uiPopupWindow.setShow(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class CancelActionListener extends EventListener<UITemplateEditForm> { public void execute(Event<UITemplateEditForm> event) throws Exception { UITemplatesManager uiManager = event.getSource().getAncestorOfType(UITemplatesManager.class) ; UIPopupWindow uiPopupWindow = uiManager.getChildById(UITemplatesManager.POPUP_TEMPLATE_ID) ; uiPopupWindow.setShow(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } }
5,078
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITemplateList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/templates/UITemplateList.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.admin.templates; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.PathNotFoundException; import javax.jcr.nodetype.NodeType; import javax.jcr.nodetype.NodeTypeIterator; import javax.jcr.nodetype.NodeTypeManager; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.core.UIPagingGrid; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.context.DocumentContext; 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.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * Oct 03, 2006 * 9:43:23 AM */ @ComponentConfig( template = "app:/groovy/webui/component/admin/template/UITemplateList.gtmpl", events = { @EventConfig(listeners = UITemplateList.EditActionListener.class), @EventConfig(listeners = UITemplateList.DeleteActionListener.class, confirm = "UITemplateList.msg.confirm-delete"), @EventConfig(listeners = UITemplateList.AddNewActionListener.class) } ) public class UITemplateList extends UIPagingGrid { private static String[] NODETYPE_BEAN_FIELD = {"icon", "label", "name"} ; private static String[] NODETYPE_ACTION = {"Edit", "Delete"} ; public static final String DOCUMENTS_TEMPLATE_TYPE = "templates"; public static final String ACTIONS_TEMPLATE_TYPE = "actions"; public static final String OTHERS_TEMPLATE_TYPE = "others"; public static final String LABEL_PROPERTY = "label"; public static final String ICON_FIELD = "icon"; public static final String LABEL_FIELD = "label"; private String filter = DOCUMENTS_TEMPLATE_TYPE; public void setTemplateFilter(String filter) { this.filter = filter; } public String getTemplateFilter() { return this.filter; } public UITemplateList() throws Exception { configure("name", NODETYPE_BEAN_FIELD, NODETYPE_ACTION) ; } public String[] getActions() { return new String[] {"AddNew"} ; } static public class TemplateComparator implements Comparator<TemplateData> { public int compare(TemplateData t1, TemplateData t2) throws ClassCastException { String name1 = t1.getName(); String name2 = t2.getName(); return name1.compareToIgnoreCase(name2); } } static public class EditActionListener extends EventListener<UITemplateList> { public void execute(Event<UITemplateList> event) throws Exception { UITemplateList nodeTemplateList = event.getSource() ; UITemplatesManager uiManager = nodeTemplateList.getAncestorOfType(UITemplatesManager.class); UITemplateContainer uiTemplateContainer = uiManager.getChildById(uiManager.getSelectedTabId()) ; String nodeType = event.getRequestContext().getRequestParameter(OBJECTID) ; UIViewTemplate uiViewTemplate = uiTemplateContainer.createUIComponent(UIViewTemplate.class, null, "UIViewTemplate" + "_" + uiManager.getSelectedTabId()) ; uiViewTemplate.getChild(UITemplateEditForm.class).update(nodeType) ; uiViewTemplate.setNodeTypeName(nodeType) ; UIDialogTab uiDialogTab = uiViewTemplate.findFirstComponentOfType(UIDialogTab.class) ; uiDialogTab.updateGrid(nodeType) ; UITemplateContent uiDialogTabForm = uiViewTemplate.findComponentById(UIDialogTab.DIALOG_FORM_NAME) ; uiDialogTabForm.setNodeTypeName(nodeType) ; uiDialogTabForm.update(null) ; UIViewTab uiViewTab = uiViewTemplate.findFirstComponentOfType(UIViewTab.class) ; uiViewTab.updateGrid(nodeType) ; UITemplateContent uiViewTabForm = uiViewTemplate.findComponentById(UIViewTab.VIEW_FORM_NAME) ; uiViewTabForm.setNodeTypeName(nodeType) ; uiViewTabForm.update(null) ; UISkinTab uiSkinTab = uiViewTemplate.findFirstComponentOfType(UISkinTab.class) ; uiSkinTab.updateGrid(nodeType) ; UITemplateContent uiSkinTabForm = uiViewTemplate.findComponentById(UISkinTab.SKIN_FORM_NAME) ; uiSkinTabForm.setNodeTypeName(nodeType) ; uiSkinTabForm.update(null); uiManager.initPopup(uiViewTemplate); UIPopupWindow uiPopup = uiManager.getChildById(UITemplatesManager.POPUP_TEMPLATE_ID); event.getRequestContext().addUIComponentToUpdateByAjax(uiPopup) ; } } static public class DeleteActionListener extends EventListener<UITemplateList> { public void execute(Event<UITemplateList> event) throws Exception { UITemplatesManager uiTemplatesManager = event.getSource().getAncestorOfType(UITemplatesManager.class); UITemplateContainer uiTemplateContainer = uiTemplatesManager.getChildById(uiTemplatesManager.getSelectedTabId()); UITemplateList uiTemplateList = uiTemplateContainer.getChild(UITemplateList.class); if (uiTemplatesManager.isEditingTemplate()) { UIApplication uiApp = event.getSource().getAncestorOfType(UIApplication.class) ; uiApp.addMessage(new ApplicationMessage("UITemplateList.msg.editing-template", null, ApplicationMessage.WARNING)) ; return; } String nodeType = event.getRequestContext().getRequestParameter(OBJECTID); TemplateService templateService = uiTemplateList.getApplicationComponent(TemplateService.class); try { DocumentContext.getCurrent().getAttributes().put(DocumentContext.IS_SKIP_RAISE_ACT, true); templateService.removeManagedNodeType(nodeType); } catch (PathNotFoundException ex) { UIApplication uiApp = event.getSource().getAncestorOfType(UIApplication.class) ; uiApp.addMessage(new ApplicationMessage("UITemplateList.msg.template-not-exist", null, ApplicationMessage.WARNING)) ; return; } uiTemplateList.refresh(uiTemplateList.getUIPageIterator().getCurrentPage()); event.getRequestContext().addUIComponentToUpdateByAjax(uiTemplatesManager); } } static public class AddNewActionListener extends EventListener<UITemplateList> { public void execute(Event<UITemplateList> event) throws Exception { UITemplatesManager uiTemplatesManager = event.getSource().getAncestorOfType(UITemplatesManager.class) ; UITemplateContainer uiTemplateContainer = uiTemplatesManager.getChildById(uiTemplatesManager.getSelectedTabId()); UITemplateList uiList = uiTemplateContainer.getChild(UITemplateList.class); UITemplateForm uiTemplateForm = uiTemplateContainer.createUIComponent(UITemplateForm.class, null, null) ; uiTemplateForm.setFilter(uiList.getTemplateFilter()); uiTemplateForm.refresh(); uiTemplatesManager.initPopup(uiTemplateForm); UIPopupWindow uiPopup = uiTemplatesManager.getChildById(UITemplatesManager.POPUP_TEMPLATE_ID); event.getRequestContext().addUIComponentToUpdateByAjax(uiPopup) ; } } static public class TemplateData { private String name ; private String label; private String icon; public TemplateData(String dataName, String dataLabel, String dataIcon) { name = dataName ; label = dataLabel; icon = dataIcon; } public String getName() { return name ; } public String getLabel() { return label; } public String getIcon() { return icon; } } @Override public void refresh(int currentPage) throws Exception { TemplateService templateService = getApplicationComponent(TemplateService.class); List<String> documentNodeTypes = templateService.getAllDocumentNodeTypes(); Node templatesHome = templateService.getTemplatesHome(WCMCoreUtils.getSystemSessionProvider()); List<TemplateData> templateData = new ArrayList<TemplateData>(); if (templatesHome != null) { NodeTypeManager ntManager = templatesHome.getSession().getWorkspace().getNodeTypeManager(); NodeTypeIterator nodetypeIter = ntManager.getAllNodeTypes(); List<String> listNodeTypeName = new ArrayList<String>(); while (nodetypeIter.hasNext()) { NodeType n1 = nodetypeIter.nextNodeType(); listNodeTypeName.add(n1.getName()); } NodeIterator nodes = templatesHome.getNodes(); String label = ""; String icon = ""; while (nodes.hasNext()) { Node node = nodes.nextNode(); if (listNodeTypeName.contains(node.getName())) { label = node.hasProperty(LABEL_PROPERTY) ? node.getProperty(LABEL_PROPERTY).getString() : node.getName(); icon = "uiIcon16x16Template" + label.replaceAll(" ", ""); icon = icon + " uiIconFile"; if(filter.equals(DOCUMENTS_TEMPLATE_TYPE)) { if(documentNodeTypes.contains(node.getName())) templateData.add(new TemplateData(node.getName(), label, icon)); } else if(filter.equals(ACTIONS_TEMPLATE_TYPE)) { if(ntManager.getNodeType(node.getName()).isNodeType("exo:action")) templateData.add(new TemplateData(node.getName(), label, icon )); } else { if(!ntManager.getNodeType(node.getName()).isNodeType("exo:action") && !documentNodeTypes.contains(node.getName())) templateData.add(new TemplateData(node.getName(), label, icon )); } } } Collections.sort(templateData, new TemplateComparator()); } ListAccess<TemplateData> dataList = new ListAccessImpl<TemplateData>(TemplateData.class, templateData); LazyPageList<TemplateData> pageList = new LazyPageList<TemplateData>(dataList, getUIPageIterator().getItemsPerPage()); getUIPageIterator().setTotalItems(templateData.size()); getUIPageIterator().setPageList(pageList); if (currentPage > getUIPageIterator().getAvailablePage()) getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage()); else getUIPageIterator().setCurrentPage(currentPage); } }
11,340
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITemplateForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/templates/UITemplateForm.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.admin.templates; import java.io.ByteArrayInputStream; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.nodetype.NodeType; import javax.jcr.nodetype.NodeTypeIterator; import javax.jcr.nodetype.NodeTypeManager; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.wcm.publication.WCMComposer; import org.exoplatform.services.wcm.utils.WCMCoreUtils; import org.exoplatform.wcm.webui.form.UIFormInputSetWithNoLabel; 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.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.UIFormSelectBox; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.UIFormTabPane; import org.exoplatform.webui.form.UIFormTextAreaInput; import org.exoplatform.webui.form.input.UICheckBoxInput; import org.exoplatform.webui.form.validator.MandatoryValidator; /** * Created by The eXo Platform SARL * Author : pham tuan * phamtuanchip@yahoo.de * Oct 03, 2006 * 9:43:23 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/admin/template/UITemplateForm.gtmpl", events = { @EventConfig(listeners = UITemplateForm.SaveActionListener.class), @EventConfig(listeners = UITemplateForm.RefreshActionListener.class, phase=Phase.DECODE), @EventConfig(listeners = UITemplateForm.CancelActionListener.class, phase=Phase.DECODE), @EventConfig(listeners = UITemplateForm.AddPermissionActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UITemplateForm.OnChangeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIViewTemplate.SelectTabActionListener.class) } ) public class UITemplateForm extends UIFormTabPane implements UISelectable { final static public String FIELD_NAME = "name" ; final static public String FIELD_LABEL = "label" ; final static public String FIELD_ISTEMPLATE = "isDocumentTemplate" ; final static public String FIELD_DIALOG = "dialog" ; final static public String FIELD_VIEW = "view" ; final static public String FIELD_SKIN = "skin"; final static public String FIELD_TAB_TEMPLATE = "UITemplateForm" ; final static public String FIELD_TAB_DIALOG = "UIDialogTab" ; final static public String FIELD_TAB_VIEW = "UIViewTab" ; final static public String FIELD_TAB_SKIN = "UISkinTab" ; final static public String FIELD_PERMISSION = "permission" ; final static public String POPUP_PERMISSION = "PopupViewPermission" ; public static final String DOCUMENTS_TEMPLATE_TYPE = "templates"; public static final String ACTIONS_TEMPLATE_TYPE = "actions"; public static final String OTHERS_TEMPLATE_TYPE = "others"; private String selectedTabId = ""; private String filter = ""; //DOCUMENTS_TEMPLATE_TYPE; public String getSelectedTabId() { return selectedTabId; } public void setSelectedTab(String renderTabId) { selectedTabId = renderTabId; } public String getFilter() { return filter; } public void setFilter(String filter) { this.filter = filter; } public void setSelectedTab(int index) { selectedTabId = getChild(index - 1).getId(); } public UITemplateForm() throws Exception { super("UITemplateForm") ; UIFormInputSetWithAction templateTab = new UIFormInputSetWithAction(FIELD_TAB_TEMPLATE); UIFormSelectBox uiSelectBox = new UIFormSelectBox(FIELD_NAME, FIELD_NAME, getOption()); uiSelectBox.setOnChange("OnChange"); templateTab.addUIFormInput(uiSelectBox); templateTab.addUIFormInput(new UIFormStringInput(FIELD_LABEL, FIELD_LABEL, null). addValidator(MandatoryValidator.class)) ; templateTab.addUIFormInput(new UICheckBoxInput(FIELD_ISTEMPLATE, FIELD_ISTEMPLATE, null).setChecked(true)); templateTab.addUIFormInput(new UIFormStringInput(FIELD_PERMISSION, FIELD_PERMISSION, null).setDisabled(true).addValidator(MandatoryValidator.class)); templateTab.setActionInfo(FIELD_PERMISSION, new String[] {"AddPermission"}) ; addUIComponentInput(templateTab) ; setSelectedTab(templateTab.getId()) ; UIFormInputSetWithNoLabel defaultDialogTab = new UIFormInputSetWithNoLabel(FIELD_TAB_DIALOG) ; defaultDialogTab.addUIFormInput(new UIFormTextAreaInput(FIELD_DIALOG, FIELD_DIALOG, null). addValidator(MandatoryValidator.class)) ; addUIFormInput(defaultDialogTab) ; UIFormInputSetWithNoLabel defaultViewTab = new UIFormInputSetWithNoLabel(FIELD_TAB_VIEW) ; defaultViewTab.addUIFormInput(new UIFormTextAreaInput(FIELD_VIEW, FIELD_VIEW, null). addValidator(MandatoryValidator.class)) ; addUIFormInput(defaultViewTab) ; UIFormInputSetWithNoLabel defaultSkinTab = new UIFormInputSetWithNoLabel(FIELD_TAB_SKIN) ; defaultSkinTab.addUIFormInput(new UIFormTextAreaInput(FIELD_SKIN, FIELD_SKIN, null)) ; addUIFormInput(defaultSkinTab) ; setActions(new String[]{"Save", "Refresh", "Cancel"}) ; setSelectedTab(FIELD_TAB_TEMPLATE); } public void refresh()throws Exception { getUIFormSelectBox(FIELD_NAME).setOptions(getOption()); String nodeType = getUIFormSelectBox(FIELD_NAME).getValue(); getUIStringInput(FIELD_LABEL).setValue(""); if(filter.equals(DOCUMENTS_TEMPLATE_TYPE)) getUICheckBoxInput(FIELD_ISTEMPLATE).setChecked(true); else getUICheckBoxInput(FIELD_ISTEMPLATE).setChecked(false); getUICheckBoxInput(FIELD_ISTEMPLATE).setDisabled(true); initTemplate(nodeType); getUIStringInput(FIELD_PERMISSION).setValue(""); } private void initTemplate(String nodeType)throws Exception { getUIFormTextAreaInput(FIELD_VIEW).setValue(getDefaultView(nodeType)); getUIFormTextAreaInput(FIELD_DIALOG).setValue(getDefaultDialog(nodeType)); getUIFormTextAreaInput(FIELD_SKIN).setValue(getDefaultStyleSheet(nodeType)); } private String getDefaultStyleSheet(String nodeType) throws Exception { TemplateService templateService = getApplicationComponent(TemplateService.class); return templateService.buildStyleSheet(nodeType); } private String getDefaultView(String nodeType) throws Exception { TemplateService templateService = getApplicationComponent(TemplateService.class); return templateService.buildViewForm(nodeType); } private String getDefaultDialog(String nodeType) throws Exception { TemplateService templateService = getApplicationComponent(TemplateService.class); return templateService.buildDialogForm(nodeType); } static public class TemplateNameComparator implements Comparator<SelectItemOption<String>> { public int compare(SelectItemOption<String> o1, SelectItemOption<String> o2) throws ClassCastException { try { String name1 = o1.getValue().toString() ; String name2 = o2.getValue().toString() ; return name1.compareToIgnoreCase(name2) ; } catch(Exception e) { return 0; } } } public List<SelectItemOption<String>> getOption() throws Exception { List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>() ; NodeTypeManager nodeTypeManager = getApplicationComponent(RepositoryService.class).getCurrentRepository().getNodeTypeManager() ; Node templatesHome = getApplicationComponent(TemplateService.class). getTemplatesHome(WCMCoreUtils.getSystemSessionProvider()); if(templatesHome != null) { NodeIterator templateIter = templatesHome.getNodes() ; List<String> templates = new ArrayList<String>() ; while (templateIter.hasNext()) { templates.add(templateIter.nextNode().getName()) ; } NodeTypeIterator iter = nodeTypeManager.getAllNodeTypes() ; while (iter.hasNext()) { NodeType nodeType = iter.nextNodeType(); if (nodeType.isMixin()) continue; String nodeTypeName = nodeType.getName(); if (!templates.contains(nodeTypeName)) { if(filter.equals(ACTIONS_TEMPLATE_TYPE) && nodeTypeManager.getNodeType(nodeTypeName).isNodeType("exo:action")) { options.add(new SelectItemOption<String>(nodeTypeName, nodeTypeName)); } else { options.add(new SelectItemOption<String>(nodeTypeName, nodeTypeName)); } } } Collections.sort(options, new TemplateNameComparator()) ; } return options ; } public void doSelect(String selectField, Object value) { UIFormInputSetWithAction uiFormAction = getChildById(FIELD_TAB_TEMPLATE) ; uiFormAction.getUIStringInput(FIELD_PERMISSION).setValue(value.toString()) ; } static public class SaveActionListener extends EventListener<UITemplateForm> { public void execute(Event<UITemplateForm> event) throws Exception { UITemplateForm uiForm = event.getSource() ; UITemplatesManager uiManager = event.getSource().getAncestorOfType(UITemplatesManager.class) ; String name = uiForm.getUIFormSelectBox(FIELD_NAME).getValue().trim() ; String label = uiForm.getUIStringInput(FIELD_LABEL).getValue().trim() ; String dialog = uiForm.getUIFormTextAreaInput(FIELD_DIALOG).getValue() ; String view = uiForm.getUIFormTextAreaInput(FIELD_VIEW).getValue(); String skin = uiForm.getUIFormTextAreaInput(FIELD_SKIN).getValue(); if(skin == null) skin = ""; boolean isDocumentTemplate = uiForm.getUICheckBoxInput(FIELD_ISTEMPLATE).isChecked() ; UIFormInputSetWithAction permField = uiForm.getChildById(UITemplateForm.FIELD_TAB_TEMPLATE) ; String role = permField.getUIStringInput(FIELD_PERMISSION).getValue(); if ((role == null) || (role.trim().length() == 0)) { UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UITemplateForm.msg.role-require", null, ApplicationMessage.WARNING)); return; } String[] roles = {role} ; if (dialog == null) dialog = ""; if (view == null) view = ""; TemplateService templateService = uiForm.getApplicationComponent(TemplateService.class) ; templateService.addTemplate(TemplateService.DIALOGS, name, label, isDocumentTemplate, TemplateService.DEFAULT_DIALOG, roles, new ByteArrayInputStream(dialog.getBytes())) ; templateService.addTemplate(TemplateService.VIEWS, name, label, isDocumentTemplate, TemplateService.DEFAULT_VIEW, roles, new ByteArrayInputStream(view.getBytes())) ; templateService.addTemplate(TemplateService.SKINS, name, label, isDocumentTemplate, TemplateService.DEFAULT_SKIN, roles, new ByteArrayInputStream(skin.getBytes())) ; WCMComposer composer = WCMCoreUtils.getService(WCMComposer.class); composer.updateTemplatesSQLFilter(); uiManager.refresh() ; //uiForm.refresh() ; UIPopupWindow uiPopupWindow = uiManager.getChildById(UITemplatesManager.POPUP_TEMPLATE_ID) ; uiPopupWindow.setShow(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class CancelActionListener extends EventListener<UITemplateForm> { public void execute(Event<UITemplateForm> event) throws Exception { UITemplatesManager uiManager = event.getSource().getAncestorOfType(UITemplatesManager.class) ; UIPopupWindow uiPopupWindow = uiManager.getChildById(UITemplatesManager.POPUP_TEMPLATE_ID) ; uiPopupWindow.setShow(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class RefreshActionListener extends EventListener<UITemplateForm> { public void execute(Event<UITemplateForm> event) throws Exception { UITemplateForm uiForm = event.getSource() ; uiForm.refresh() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()) ; } } static public class OnChangeActionListener extends EventListener<UITemplateForm> { public void execute(Event<UITemplateForm> event) throws Exception { UITemplateForm uiFormTabPane = event.getSource() ; String nodeType = uiFormTabPane.getUIFormSelectBox(FIELD_NAME).getValue(); uiFormTabPane.getUIStringInput(FIELD_LABEL).setValue(""); uiFormTabPane.initTemplate(nodeType); uiFormTabPane.getUIStringInput(FIELD_PERMISSION).setValue(""); event.getRequestContext().addUIComponentToUpdateByAjax(uiFormTabPane.getParent()) ; } } static public class AddPermissionActionListener extends EventListener<UITemplateForm> { public void execute(Event<UITemplateForm> event) throws Exception { UITemplateForm uiTemplateForm = event.getSource() ; UITemplatesManager uiManager = uiTemplateForm.getAncestorOfType(UITemplatesManager.class) ; String membership = uiTemplateForm.getUIStringInput(FIELD_PERMISSION).getValue() ; uiManager.initPopupPermission("AddNew", membership) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; UIPopupWindow uiPopup = uiManager.getChildById(UITemplateContent.TEMPLATE_PERMISSION); event.getRequestContext().addUIComponentToUpdateByAjax(uiPopup) ; } } }
15,124
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITemplateContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/templates/UITemplateContainer.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.admin.templates; import org.exoplatform.ecm.webui.selector.UIPermissionSelector; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.ComponentConfigs; 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; 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 23, 2006 * 2:09:18 PM */ @ComponentConfigs( { @ComponentConfig(lifecycle = UIContainerLifecycle.class) }) public class UITemplateContainer extends UIContainer { public UITemplateContainer() throws Exception { addChild(UITemplateList.class, null, null) ; } public void initPopup(UIComponent uiComponent, String popupId) throws Exception { removeChildById(popupId) ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, popupId) ; uiPopup.setShowMask(true); uiPopup.setWindowSize(600,300) ; uiPopup.setUIComponent(uiComponent) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public void update() throws Exception { UITemplateList uiTemplateList = getChild(UITemplateList.class); uiTemplateList.refresh(uiTemplateList.getUIPageIterator().getCurrentPage()); } public void initPopupPermission(String id, String membership) throws Exception { String popupId = id.concat(UITemplateContent.TEMPLATE_PERMISSION); UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, popupId); uiPopup.setShowMask(true); uiPopup.setWindowSize(560, 300); UIPermissionSelector uiECMPermission = createUIComponent(UIPermissionSelector.class, null, null); uiECMPermission.setSelectedMembership(true); if (membership != null && membership.indexOf(":/") > -1) { String[] arrMember = membership.split(":/"); uiECMPermission.setCurrentPermission("/" + arrMember[1]); } if (id.equals("AddNew")) { UITemplateForm uiForm = findFirstComponentOfType(UITemplateForm.class); uiECMPermission.setSourceComponent(uiForm, null); } else { UITemplateContent uiTemContent = findComponentById(id); uiECMPermission.setSourceComponent(uiTemContent, null); } uiPopup.setUIComponent(uiECMPermission); uiPopup.setRendered(true); uiPopup.setShow(true); uiPopup.setResizable(true); } public static class CloseActionListener extends EventListener<UIPopupWindow> { public void execute(Event<UIPopupWindow> event) throws Exception { UITemplatesManager uiManager = event.getSource().getAncestorOfType(UITemplatesManager.class) ; UITemplateContainer uiTemplateContainer = uiManager.getChildById(uiManager.getSelectedTabId()); UIPopupWindow uiPopupWindow = uiTemplateContainer.getChild(UIPopupWindow.class) ; uiPopupWindow.setRendered(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } }
3,894
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UISkinTab.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/templates/UISkinTab.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.admin.templates; import java.util.ArrayList; import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.Value; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.templates.TemplateService; 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; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Nov 18, 2009 * 10:37:42 AM */ @ComponentConfig( lifecycle = UIContainerLifecycle.class, events = { @EventConfig(listeners = UISkinTab.EditActionListener.class), @EventConfig(listeners = UISkinTab.DeleteActionListener.class, confirm = "UIDialogTab.msg.confirm-delete") } ) public class UISkinTab extends UIContainer { final private static String[] BEAN_FIELD = {"name", "roles", "baseVersion"} ; final private static String[] ACTIONS = {"Edit", "Delete"} ; final public static String SKIN_LIST_NAME = "SkinList" ; final public static String SKIN_FORM_NAME = "SkinForm" ; private List<String> listSkin_ = new ArrayList<String>() ; public UISkinTab() throws Exception { UIGrid uiGrid = addChild(UIGrid.class, null, SKIN_LIST_NAME) ; uiGrid.getUIPageIterator().setId("SkinListIterator") ; uiGrid.configure("name", BEAN_FIELD, ACTIONS) ; UITemplateContent uiForm = addChild(UITemplateContent.class, null , SKIN_FORM_NAME) ; uiForm.setTemplateType(TemplateService.SKINS); uiForm.update(null); } public void setTabRendered() { UIViewTemplate uiViewTemplate = getAncestorOfType(UIViewTemplate.class) ; uiViewTemplate.setSelectedTab(UISkinTab.class.getSimpleName()) ; } public List<String> getListSkin() { return listSkin_ ; } public void updateGrid(String nodeName) throws Exception { TemplateService tempService = getApplicationComponent(TemplateService.class) ; Node templateHome = tempService.getTemplatesHome(WCMCoreUtils.getSystemSessionProvider()).getNode(nodeName); if(!templateHome.hasNode(TemplateService.SKINS)) return; NodeIterator iter = templateHome.getNode(TemplateService.SKINS).getNodes(); List<SkinData> data = new ArrayList<SkinData>() ; SkinData item ; Node node = null; while (iter.hasNext()){ node = (Node) iter.next() ; String version = "" ; StringBuilder rule = new StringBuilder() ; Value[] rules = node.getNode(Utils.JCR_CONTENT).getProperty(Utils.EXO_ROLES).getValues() ; for(int i = 0; i < rules.length; i++) { rule.append("["+rules[i].getString()+"]") ; } if(node.isNodeType(Utils.MIX_VERSIONABLE) && !node.isNodeType(Utils.NT_FROZEN)){ version = node.getBaseVersion().getName() ; } listSkin_.add(node.getName()) ; item = new SkinData(node.getName(), rule.toString(), version) ; data.add(item) ; } UIGrid uiGrid = getChild(UIGrid.class) ; ListAccess<SkinData> skinDataList = new ListAccessImpl<SkinData>(SkinData.class, data); LazyPageList<SkinData> dataPageList = new LazyPageList<SkinData>(skinDataList, 4); uiGrid.getUIPageIterator().setPageList(dataPageList); } static public class EditActionListener extends EventListener<UISkinTab> { public void execute(Event<UISkinTab> event) throws Exception { UISkinTab skinTab = event.getSource() ; String skinName = event.getRequestContext().getRequestParameter(OBJECTID) ; UITemplateContent uiForm = skinTab.getChild(UITemplateContent.class) ; uiForm.update(skinName) ; skinTab.setTabRendered() ; UITemplatesManager uiManager = skinTab.getAncestorOfType(UITemplatesManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class DeleteActionListener extends EventListener<UISkinTab> { public void execute(Event<UISkinTab> event) throws Exception { UISkinTab skinTab = event.getSource() ; UIViewTemplate uiViewTemplate = event.getSource().getAncestorOfType(UIViewTemplate.class) ; String nodeTypeName = uiViewTemplate.getNodeTypeName() ; String templateName = event.getRequestContext().getRequestParameter(OBJECTID) ; TemplateService templateService = skinTab.getApplicationComponent(TemplateService.class) ; UITemplateContent uiForm = skinTab.findFirstComponentOfType(UITemplateContent.class) ; for(String template : TemplateService.UNDELETABLE_TEMPLATES) { if(template.equals(templateName)) { UIApplication app = skinTab.getAncestorOfType(UIApplication.class) ; Object[] args = {template} ; app.addMessage(new ApplicationMessage("UIDialogTab.msg.undeletable", args)) ; skinTab.setTabRendered() ; return ; } } templateService.removeTemplate(TemplateService.SKINS, nodeTypeName, templateName) ; uiForm.update(null); uiForm.reset(); skinTab.updateGrid(nodeTypeName) ; skinTab.setTabRendered() ; UITemplatesManager uiManager = skinTab.getAncestorOfType(UITemplatesManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } public static class SkinData { private String name ; private String roles ; private String baseVersion ; public SkinData(String name, String roles, String version) { this.name = name ; this.roles = roles ; baseVersion = version ; } public String getName(){return name ;} public String getRoles(){return roles ;} public String getBaseVersion(){return baseVersion ;} } }
7,110
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UICLVTemplatesManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/templates/clv/UICLVTemplatesManager.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.admin.templates.clv; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; 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.UIPopupContainer; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.ext.manager.UIAbstractManager; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jan 22, 2013 * 9:47:27 AM */ @ComponentConfig(template = "system:/groovy/webui/core/UITabPane_New.gtmpl", events = { @EventConfig(listeners = UICLVTemplatesManager.SelectTabActionListener.class) }) public class UICLVTemplatesManager extends UIAbstractManager{ public static final String NEW_TEMPLATE = "CLVTemplatePopup" ; public static final String EDIT_CLV_TEMPLATE = "EditCLVTemplatePopup" ; public static final String CONTENT_TEMPLATE_ID = "ContentTemplateContainer"; public static final String CATE_TEMPLATE_ID = "CateTemplateContainer"; public static final String PAGE_TEMPLATE_ID = "PageTemplateContainer"; public static final String CATE_TEMPLATE_LIST_ID = "CateTemplateList"; public static final String PAGE_TEMPLATE_LIST_ID = "PageTemplateList"; public static final String CONTENT_TEMPLATE_TYPE = "contents"; public static final String CATEGORY_TEMPLATE_TYPE = "category"; public static final String PAGINATOR_TEMPLATE_TYPE = "paginators"; private String selectedTabId = "ContentTemplateContainer"; public UICLVTemplatesManager() throws Exception { UICLVTemplateContainer uiContentTemp = addChild(UICLVTemplateContainer.class, null, CONTENT_TEMPLATE_ID) ; uiContentTemp.getChild(UICLVTemplateList.class).setTemplateFilter(CONTENT_TEMPLATE_TYPE); UICLVTemplateContainer uiCateTemp = addChild(UICLVTemplateContainer.class, null, CATE_TEMPLATE_ID) ; uiCateTemp.getChild(UICLVTemplateList.class).setTemplateFilter(CATEGORY_TEMPLATE_TYPE); uiCateTemp.getChild(UICLVTemplateList.class).setId(CATE_TEMPLATE_LIST_ID); UICLVTemplateContainer uiPageTemp = addChild(UICLVTemplateContainer.class, null, PAGE_TEMPLATE_ID) ; uiPageTemp.getChild(UICLVTemplateList.class).setTemplateFilter(PAGINATOR_TEMPLATE_TYPE); uiPageTemp.getChild(UICLVTemplateList.class).setId(PAGE_TEMPLATE_LIST_ID); setSelectedTab(CONTENT_TEMPLATE_ID); } @Override public void refresh() throws Exception { UICLVTemplateContainer templateContainer = ((UICLVTemplateContainer)getChildById(CONTENT_TEMPLATE_ID)); templateContainer.update(); templateContainer.getChild(UICLVTemplateList.class).getUIPageIterator().setId(CONTENT_TEMPLATE_ID + "PageIterator"); templateContainer.getChild(UICLVTemplateList.class).refresh( templateContainer.getChild(UICLVTemplateList.class).getUIPageIterator().getCurrentPage()); UICLVTemplateContainer templateCateContainer = ((UICLVTemplateContainer)getChildById(CATE_TEMPLATE_ID)); templateCateContainer.update(); templateCateContainer.getChild(UICLVTemplateList.class).getUIPageIterator().setId(CATE_TEMPLATE_ID + "PageIterator"); templateCateContainer.getChild(UICLVTemplateList.class).refresh( templateCateContainer.getChild(UICLVTemplateList.class).getUIPageIterator().getCurrentPage()); UICLVTemplateContainer templatePageContainer = ((UICLVTemplateContainer)getChildById(PAGE_TEMPLATE_ID)); templatePageContainer.update(); templatePageContainer.getChild(UICLVTemplateList.class).getUIPageIterator().setId(PAGE_TEMPLATE_ID + "PageIterator"); templatePageContainer.getChild(UICLVTemplateList.class).refresh( templatePageContainer.getChild(UICLVTemplateList.class).getUIPageIterator().getCurrentPage()); } public String getSelectedTabId() { return selectedTabId; } public void setSelectedTab(String renderTabId) { selectedTabId = renderTabId; } public void setSelectedTab(int index) { selectedTabId = getChild(index - 1).getId(); } public boolean isEditingTemplate() { UIECMAdminPortlet adminPortlet = this.getAncestorOfType(UIECMAdminPortlet.class); UIPopupContainer popupContainer = adminPortlet.getChild(UIPopupContainer.class); UIPopupWindow uiPopup = popupContainer.getChild(UIPopupWindow.class); uiPopup.setId(EDIT_CLV_TEMPLATE); return (uiPopup != null && uiPopup.isShow() && uiPopup.isRendered()); } static public class SelectTabActionListener extends EventListener<UICLVTemplatesManager> { public void execute(Event<UICLVTemplatesManager> 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); } } } }
6,270
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UICLVTemplateForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/templates/clv/UICLVTemplateForm.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.admin.templates.clv; import org.apache.commons.lang3.StringUtils; import org.exoplatform.ecm.webui.form.validator.ECMNameValidator; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.cms.views.ApplicationTemplateManagerService; import org.exoplatform.services.wcm.core.NodetypeConstant; import org.exoplatform.services.wcm.utils.WCMCoreUtils; 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.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 org.exoplatform.webui.form.validator.MandatoryValidator; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import java.io.ByteArrayInputStream; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jan 22, 2013 * 9:55:24 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UICLVTemplateForm.SaveActionListener.class), @EventConfig(listeners = UICLVTemplateForm.ResetActionListener.class, phase=Phase.DECODE), @EventConfig(listeners = UICLVTemplateForm.CancelActionListener.class, phase=Phase.DECODE) } ) public class UICLVTemplateForm extends UIForm { final static public String FIELD_TITLE = "title" ; final static public String FIELD_TEMPLATE_NAME = "template" ; final static public String FIELD_CONTENT = "content" ; final static public String FIELD_CONTENT_TYPE = "type" ; private boolean isAddNew; private String selectedCategory; public UICLVTemplateForm() throws Exception { UIFormTextAreaInput contentInput = new UIFormTextAreaInput(FIELD_CONTENT, FIELD_CONTENT, null); addUIFormInput(contentInput); UIFormStringInput nameInput = new UIFormStringInput(FIELD_TITLE, FIELD_TITLE, null); nameInput.addValidator(ECMNameValidator.class); addUIFormInput(nameInput); UIFormStringInput tempateNameInput = new UIFormStringInput(FIELD_TEMPLATE_NAME, FIELD_TEMPLATE_NAME, null); tempateNameInput.addValidator(MandatoryValidator.class).addValidator(ECMNameValidator.class); addUIFormInput(tempateNameInput); List<SelectItemOption<String>> templateOptions = new ArrayList<SelectItemOption<String>>(); RequestContext context = RequestContext.getCurrentInstance(); ResourceBundle res = context.getApplicationResourceBundle(); templateOptions.add(new SelectItemOption<String>( res.getString("UICLVTemplateForm.label." + ApplicationTemplateManagerService.CLV_LIST_TEMPLATE_CATEGORY), ApplicationTemplateManagerService.CLV_LIST_TEMPLATE_CATEGORY)); templateOptions.add(new SelectItemOption<String>( res.getString("UICLVTemplateForm.label." + ApplicationTemplateManagerService.CLV_NAVIGATION_TEMPLATE_CATEGORY), ApplicationTemplateManagerService.CLV_NAVIGATION_TEMPLATE_CATEGORY)); templateOptions.add(new SelectItemOption<String>( res.getString("UICLVTemplateForm.label." + ApplicationTemplateManagerService.CLV_PAGINATOR_TEMPLATE_CATEGORY), ApplicationTemplateManagerService.CLV_PAGINATOR_TEMPLATE_CATEGORY )); UIFormSelectBox templateType = new UIFormSelectBox(FIELD_CONTENT_TYPE, FIELD_CONTENT_TYPE, templateOptions); addUIFormInput(templateType); } public void refresh(String category) throws Exception { isAddNew = true; selectedCategory = category; setActions(new String[] {"Save", "Reset", "Cancel"}); getUIStringInput(FIELD_TITLE).setValue(StringUtils.EMPTY); getUIStringInput(FIELD_TEMPLATE_NAME).setValue(StringUtils.EMPTY); getUIStringInput(FIELD_TEMPLATE_NAME).setDisabled(false); getUIFormTextAreaInput(FIELD_CONTENT).setValue(StringUtils.EMPTY); getUIFormSelectBox(FIELD_CONTENT_TYPE).setValue(selectedCategory); } public void update(String category, String name) throws Exception { this.isAddNew = false; selectedCategory = category; setActions(new String[] {"Save", "Cancel"}); ApplicationTemplateManagerService templateManager = WCMCoreUtils.getService(ApplicationTemplateManagerService.class); Node templateNode = templateManager.getTemplateByName(ApplicationTemplateManagerService.CLV_TEMPLATE_STORAGE_FOLDER, category, name, WCMCoreUtils.getSystemSessionProvider()); Node content = templateNode.getNode(Utils.JCR_CONTENT); try { getUIStringInput(FIELD_TITLE).setValue(content.getProperty(NodetypeConstant.DC_TITLE).getValues()[0].getString()); } catch(PathNotFoundException pne) { getUIStringInput(FIELD_TITLE).setValue(templateNode.getName()); } catch(ArrayIndexOutOfBoundsException aoe) { getUIStringInput(FIELD_TITLE).setValue(templateNode.getName()); } getUIStringInput(FIELD_TEMPLATE_NAME).setValue(templateNode.getName()); getUIStringInput(FIELD_TEMPLATE_NAME).setDisabled(true); getUIFormTextAreaInput(FIELD_CONTENT).setValue(content.getProperty(Utils.JCR_DATA).getString()); getUIFormSelectBox(FIELD_CONTENT_TYPE).setValue(category); } private void addTemplate(String category, String title, String template, String content) throws Exception { TemplateService templateService = WCMCoreUtils.getService(TemplateService.class); ApplicationTemplateManagerService appTemplateManager = WCMCoreUtils.getService(ApplicationTemplateManagerService.class); if(content == null) content = StringUtils.EMPTY; if(isAddNew) { if(!template.contains(".gtmpl")) template = template + ".gtmpl"; if(title == null || title.length() == 0) title = template; templateService.createTemplate(getCategoryByName(category), title, template, new ByteArrayInputStream(content.getBytes()), new String[] { "*" }); } else { if(hasTemplate(category, template)) { if(!selectedCategory.equals(category)) { UIApplication uiApp = getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UICLVTemplateForm.msg.template-existing", null, ApplicationMessage.WARNING)); return; } else { Node templateNode = getCategoryByName(category).getNode(template); Node contentNode = templateNode.getNode(NodetypeConstant.JCR_CONTENT); contentNode.setProperty(NodetypeConstant.JCR_DATA, new ByteArrayInputStream(content.getBytes())); if(title == null || title.length() == 0) title = templateNode.getName(); contentNode.setProperty(NodetypeConstant.DC_TITLE, new String[] { title }); templateNode.save(); } } else { templateService.createTemplate(getCategoryByName(category), title, template, new ByteArrayInputStream(content.getBytes()), new String[] { "*" }); appTemplateManager.removeTemplate(ApplicationTemplateManagerService.CLV_TEMPLATE_STORAGE_FOLDER, selectedCategory, template, WCMCoreUtils.getSystemSessionProvider()); } } } private boolean hasTemplate(String category, String template) throws Exception { if(!template.contains(".gtmpl")) template = template + ".gtmpl"; return getCategoryByName(category).hasNode(template); } private Node getCategoryByName(String category) throws Exception { ApplicationTemplateManagerService templateManager = WCMCoreUtils.getService(ApplicationTemplateManagerService.class); Node templateHome = templateManager.getApplicationTemplateHome( ApplicationTemplateManagerService.CLV_TEMPLATE_STORAGE_FOLDER, WCMCoreUtils.getSystemSessionProvider()); return templateHome.getNode(category); } static public class SaveActionListener extends EventListener<UICLVTemplateForm> { public void execute(Event<UICLVTemplateForm> event) throws Exception { UICLVTemplateForm uiForm = event.getSource() ; UICLVTemplatesManager uiManager = uiForm.getAncestorOfType(UICLVTemplatesManager.class); String title = uiForm.getUIStringInput(FIELD_TITLE).getValue(); if(title != null) title = title.trim(); String template = uiForm.getUIStringInput(FIELD_TEMPLATE_NAME).getValue(); if(template != null) template = template.trim(); String category = uiForm.getUIFormSelectBox(FIELD_CONTENT_TYPE).getValue(); String content = uiForm.getUIFormTextAreaInput(FIELD_CONTENT).getValue(); if(content != null) content = content.trim(); if(uiForm.isAddNew & uiForm.hasTemplate(category, template)) { UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UICLVTemplateForm.msg.template-existing", null, ApplicationMessage.WARNING)); return; } uiForm.addTemplate(category, title, template, content); uiManager.refresh(); UIPopupWindow uiPopup = uiForm.getParent(); uiPopup.setRendered(false); uiPopup.setShow(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } static public class ResetActionListener extends EventListener<UICLVTemplateForm> { public void execute(Event<UICLVTemplateForm> event) throws Exception { UICLVTemplateForm uiForm = event.getSource() ; uiForm.refresh(uiForm.selectedCategory); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class CancelActionListener extends EventListener<UICLVTemplateForm> { public void execute(Event<UICLVTemplateForm> event) throws Exception { UICLVTemplateForm uiForm = event.getSource() ; UICLVTemplatesManager uiManager = uiForm.getAncestorOfType(UICLVTemplatesManager.class); UIPopupWindow uiPopup = uiForm.getParent(); uiPopup.setRendered(false); uiPopup.setShow(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } }
11,593
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UICLVTemplateContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/templates/clv/UICLVTemplateContainer.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.admin.templates.clv; 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.UIComponent; import org.exoplatform.webui.core.UIContainer; 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; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jan 22, 2013 * 9:55:37 AM */ @ComponentConfigs( { @ComponentConfig(lifecycle = UIContainerLifecycle.class), @ComponentConfig( type = UIPopupWindow.class, id="UICLVTemplateContainer", template = "system:/groovy/webui/core/UIPopupWindow.gtmpl", events = @EventConfig(listeners = UICLVTemplateContainer.CloseActionListener.class))}) public class UICLVTemplateContainer extends UIContainer { public UICLVTemplateContainer() throws Exception { addChild(UICLVTemplateList.class, null, null); } public void initPopup(UIComponent uiComponent, String popupId) throws Exception { removeChildById(popupId) ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, popupId) ; uiPopup.setShowMask(true); uiPopup.setWindowSize(600,300) ; uiPopup.setUIComponent(uiComponent) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public void update() throws Exception { UICLVTemplateList uiTemplateList = getChild(UICLVTemplateList.class); uiTemplateList.refresh(uiTemplateList.getUIPageIterator().getCurrentPage()); } public static class CloseActionListener extends EventListener<UIPopupWindow> { public void execute(Event<UIPopupWindow> event) throws Exception { UICLVTemplatesManager uiTemplateManager = event.getSource().getAncestorOfType(UICLVTemplatesManager.class) ; UICLVTemplateContainer uiTemplateContainer = uiTemplateManager.getChildById(uiTemplateManager.getSelectedTabId()); UIPopupWindow uiPopupWindow = uiTemplateContainer.getChild(UIPopupWindow.class) ; uiPopupWindow.setRendered(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiTemplateManager) ; } } }
3,256
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UICLVTemplateList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/templates/clv/UICLVTemplateList.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.admin.templates.clv; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import javax.jcr.Node; import javax.jcr.PathNotFoundException; 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.core.UIPagingGrid; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.views.ApplicationTemplateManagerService; import org.exoplatform.services.cms.views.impl.ApplicationTemplateManagerServiceImpl; import org.exoplatform.services.wcm.core.NodetypeConstant; 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.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jan 22, 2013 * 9:55:06 AM */ @ComponentConfig( template = "system:/groovy/ecm/webui/UIGridWithButton.gtmpl", events = { @EventConfig(listeners = UICLVTemplateList.DeleteActionListener.class, confirm = "UICLVTemplateList.msg.confirm-delete"), @EventConfig(listeners = UICLVTemplateList.EditActionListener.class), @EventConfig(listeners = UICLVTemplateList.AddTemplateActionListener.class) }) public class UICLVTemplateList extends UIPagingGrid { private static String[] NODETYPE_BEAN_FIELD = {"title", "template"} ; private static String[] NODETYPE_ACTION = {"Edit", "Delete"} ; private String filter = UICLVTemplatesManager.CONTENT_TEMPLATE_TYPE; public UICLVTemplateList() throws Exception { configure("template", NODETYPE_BEAN_FIELD, NODETYPE_ACTION) ; } public void setTemplateFilter(String filter) { this.filter = filter; } public String getTemplateFilter() { return this.filter; } public String[] getActions() { return new String[] {"AddTemplate"} ; } @Override public void refresh(int currentPage) throws Exception { ApplicationTemplateManagerService templateService = WCMCoreUtils.getService(ApplicationTemplateManagerService.class); List<CLVTemplateData> templateData = new ArrayList<CLVTemplateData>(); if(filter.equals(UICLVTemplatesManager.CONTENT_TEMPLATE_TYPE)) { templateData = convetListNodeToListData(templateService.getTemplatesByCategory( ApplicationTemplateManagerService.CLV_TEMPLATE_STORAGE_FOLDER, ApplicationTemplateManagerService.CLV_LIST_TEMPLATE_CATEGORY, WCMCoreUtils.getSystemSessionProvider())); } else if(filter.equals(UICLVTemplatesManager.CATEGORY_TEMPLATE_TYPE)) { templateData = convetListNodeToListData(templateService.getTemplatesByCategory( ApplicationTemplateManagerService.CLV_TEMPLATE_STORAGE_FOLDER, ApplicationTemplateManagerService.CLV_NAVIGATION_TEMPLATE_CATEGORY, WCMCoreUtils.getSystemSessionProvider())); } else if(filter.equals(UICLVTemplatesManager.PAGINATOR_TEMPLATE_TYPE)){ templateData = convetListNodeToListData(templateService.getTemplatesByCategory( ApplicationTemplateManagerService.CLV_TEMPLATE_STORAGE_FOLDER, ApplicationTemplateManagerService.CLV_PAGINATOR_TEMPLATE_CATEGORY, WCMCoreUtils.getSystemSessionProvider())); } Collections.sort(templateData, new CLVTemplateComparator()); ListAccess<CLVTemplateData> dataList = new ListAccessImpl<CLVTemplateData>(CLVTemplateData.class, templateData); LazyPageList<CLVTemplateData> pageList = new LazyPageList<CLVTemplateData>(dataList, getUIPageIterator().getItemsPerPage()); getUIPageIterator().setTotalItems(templateData.size()); getUIPageIterator().setPageList(pageList); if (currentPage > getUIPageIterator().getAvailablePage()) getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage()); else getUIPageIterator().setCurrentPage(currentPage); } private List<CLVTemplateData> convetListNodeToListData(List<Node> list) throws RepositoryException { List<CLVTemplateData> templateDatas = new ArrayList<CLVTemplateData>(); for(Node node : list) { Node content = node.getNode(Utils.JCR_CONTENT); try { templateDatas.add(new CLVTemplateData(content.getProperty( NodetypeConstant.DC_TITLE).getValues()[0].getString(), node.getName())); } catch(PathNotFoundException pne) { templateDatas.add(new CLVTemplateData(node.getName(), node.getName())); } catch(ArrayIndexOutOfBoundsException aoe) { templateDatas.add(new CLVTemplateData(node.getName(), node.getName())); } } return templateDatas; } static public class EditActionListener extends EventListener<UICLVTemplateList> { public void execute(Event<UICLVTemplateList> event) throws Exception { UICLVTemplateList clvTemplateList = event.getSource(); UICLVTemplatesManager uiTemplatesManager = clvTemplateList.getAncestorOfType(UICLVTemplatesManager.class) ; UICLVTemplateContainer uiTemplateContainer = uiTemplatesManager.getChildById(uiTemplatesManager.getSelectedTabId()); UICLVTemplateForm uiTemplateForm = uiTemplateContainer.createUIComponent(UICLVTemplateForm.class, null, "UICLVTemplateForm_" + uiTemplatesManager.getSelectedTabId()); String template = event.getRequestContext().getRequestParameter(OBJECTID); uiTemplateForm.update(clvTemplateList.getCategoryFromFilter(), template); uiTemplateContainer.removeChildById(UICLVTemplatesManager.NEW_TEMPLATE + "_" + uiTemplatesManager.getSelectedTabId()); uiTemplateContainer.initPopup(uiTemplateForm, UICLVTemplatesManager.EDIT_CLV_TEMPLATE + "_" + uiTemplatesManager.getSelectedTabId()); event.getRequestContext().addUIComponentToUpdateByAjax(uiTemplatesManager); } } static public class AddTemplateActionListener extends EventListener<UICLVTemplateList> { public void execute(Event<UICLVTemplateList> event) throws Exception { UICLVTemplateList uiList = event.getSource(); UICLVTemplatesManager uiTemplatesManager = uiList.getAncestorOfType(UICLVTemplatesManager.class) ; UICLVTemplateContainer uiTemplateContainer = uiTemplatesManager.getChildById(uiTemplatesManager.getSelectedTabId()); UICLVTemplateForm uiTemplateForm = uiTemplateContainer.createUIComponent(UICLVTemplateForm.class, null, "UICLVTemplateForm_" + uiTemplatesManager.getSelectedTabId()) ; uiTemplateContainer.removeChildById(UICLVTemplatesManager.EDIT_CLV_TEMPLATE + "_" + uiTemplatesManager.getSelectedTabId()) ; uiTemplateForm.refresh(uiList.getCategoryFromFilter()); uiTemplateContainer.initPopup(uiTemplateForm, UICLVTemplatesManager.NEW_TEMPLATE + "_" + uiTemplatesManager.getSelectedTabId()) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiTemplatesManager) ; } } static public class DeleteActionListener extends EventListener<UICLVTemplateList> { public void execute(Event<UICLVTemplateList> event) throws Exception { UICLVTemplateList clvTemplateList = event.getSource(); UICLVTemplatesManager uiTemplatesManager = clvTemplateList.getAncestorOfType(UICLVTemplatesManager.class); if (uiTemplatesManager.isEditingTemplate()) { UIApplication uiApp = event.getSource().getAncestorOfType(UIApplication.class) ; uiApp.addMessage(new ApplicationMessage("UICLVTemplateList.msg.editing-template", null, ApplicationMessage.WARNING)) ; return; } String template = event.getRequestContext().getRequestParameter(OBJECTID); ApplicationTemplateManagerService templateService = clvTemplateList.getApplicationComponent(ApplicationTemplateManagerService.class); try { templateService.removeTemplate( ApplicationTemplateManagerService.CLV_TEMPLATE_STORAGE_FOLDER, clvTemplateList.getCategoryFromFilter(), template, WCMCoreUtils.getSystemSessionProvider()); StringBuilder tBuilder = new StringBuilder(); tBuilder.append(clvTemplateList.getCategoryFromFilter()).append("/").append(template); org.exoplatform.services.cms.impl.Utils.addEditedConfiguredData(tBuilder.toString(), ApplicationTemplateManagerServiceImpl.class.getSimpleName(), ApplicationTemplateManagerServiceImpl.EDITED_CONFIGURED_TEMPLATES, true); } catch (PathNotFoundException ex) { UIApplication uiApp = event.getSource().getAncestorOfType(UIApplication.class) ; uiApp.addMessage(new ApplicationMessage("UITCLVemplateList.msg.template-not-exist", null, ApplicationMessage.WARNING)) ; return; } clvTemplateList.refresh(clvTemplateList.getUIPageIterator().getCurrentPage()); event.getRequestContext().addUIComponentToUpdateByAjax(uiTemplatesManager); } } static public class CLVTemplateComparator implements Comparator<CLVTemplateData> { public int compare(CLVTemplateData t1, CLVTemplateData t2) throws ClassCastException { String title1 = t1.getTitle(); String title2 = t2.getTitle(); return title1.compareToIgnoreCase(title2); } } static public class CLVTemplateData { private String title ; private String template; public CLVTemplateData(String title, String template) { this.title = title ; this.template = template; } public String getTitle() { return title ; } public String getTemplate() { return template; } } private String getCategoryFromFilter() { if(filter.equals(UICLVTemplatesManager.CONTENT_TEMPLATE_TYPE)) { return ApplicationTemplateManagerService.CLV_LIST_TEMPLATE_CATEGORY; } else if(filter.equals(UICLVTemplatesManager.CATEGORY_TEMPLATE_TYPE)) { return ApplicationTemplateManagerService.CLV_NAVIGATION_TEMPLATE_CATEGORY; } else if(filter.equals(UICLVTemplatesManager.PAGINATOR_TEMPLATE_TYPE)){ return ApplicationTemplateManagerService.CLV_PAGINATOR_TEMPLATE_CATEGORY; } return null; } }
11,647
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIMetadataManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/metadata/UIMetadataManager.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.admin.metadata; import javax.jcr.nodetype.NodeType; import org.exoplatform.ecm.webui.selector.UIAnyPermission; import org.exoplatform.ecm.webui.selector.UIPermissionSelector; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIBreadcumbs; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.UITree; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; import org.exoplatform.webui.ext.manager.UIAbstractManager; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Sep 19, 2006 * 11:45:11 AM */ @ComponentConfig(lifecycle = UIContainerLifecycle.class) public class UIMetadataManager extends UIAbstractManager { final static public String METADATA_POPUP = "MetadataPopupEdit" ; final static public String VIEW_METADATA_POPUP = "ViewMetadataPopup" ; final static public String PERMISSION_POPUP = "MetataPermissionPopup" ; public UIMetadataManager() throws Exception { addChild(UIMetadataList.class, null, null) ; } public void processRender(WebuiRequestContext context) throws Exception { super.processRender(context); refresh(); } public void refresh() throws Exception { update(); } public void update() throws Exception { getChild(UIMetadataList.class).refresh(1); } public void initPopup() throws Exception { removeChildById(METADATA_POPUP) ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, METADATA_POPUP); uiPopup.setShowMask(true); uiPopup.setWindowSize(650, 330); UIMetadataForm uiMetaForm = createUIComponent(UIMetadataForm.class, null, null) ; uiPopup.setUIComponent(uiMetaForm) ; uiPopup.setRendered(true); uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public void initViewPopup(String metadataName) throws Exception { UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, VIEW_METADATA_POPUP); uiPopup.setShowMask(true); uiPopup.setShow(true) ; uiPopup.setWindowSize(600, 300); uiPopup.setRendered(true); RepositoryService repositoryService = getApplicationComponent(RepositoryService.class) ; ExtendedNodeTypeManager ntManager = repositoryService.getCurrentRepository().getNodeTypeManager() ; NodeType nodeType = ntManager.getNodeType(metadataName) ; UIMetadataView uiView = uiPopup.createUIComponent(UIMetadataView.class, null, null) ; uiView.setMetadata(nodeType) ; uiPopup.setUIComponent(uiView) ; uiPopup.setResizable(true) ; } public void initPopupPermission(String membership) throws Exception { removeChildById(PERMISSION_POPUP) ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, PERMISSION_POPUP); uiPopup.setShowMask(true); uiPopup.setWindowSize(560, 300); UIPermissionSelector uiECMPermission = createUIComponent(UIPermissionSelector.class, null, "MetadataPermission") ; uiECMPermission.getChild(UIAnyPermission.class).setId("UIMetadataAnyPermission"); uiECMPermission.getChild(UIBreadcumbs.class).setId("MetadataBreadcumbGroupSelector"); uiECMPermission.getChild(UITree.class).setId("UIMetadataTreeGroupSelector"); uiECMPermission.setSelectedMembership(true); if(membership != null && membership.indexOf(":/") > -1) { String[] arrMember = membership.split(":/") ; uiECMPermission.setCurrentPermission("/" + arrMember[1]) ; } uiPopup.setUIComponent(uiECMPermission); UIMetadataForm uiForm = findFirstComponentOfType(UIMetadataForm.class) ; uiECMPermission.setSourceComponent(uiForm, null) ; uiPopup.setRendered(true) ; uiPopup.setShow(true) ; } }
4,696
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIMetadataForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/metadata/UIMetadataForm.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.admin.metadata; import org.exoplatform.commons.utils.HTMLSanitizer; import org.exoplatform.ecm.resolver.JCRResourceResolver; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.groovyscript.text.TemplateService; import org.exoplatform.services.cms.metadata.MetadataService; import org.exoplatform.wcm.webui.form.UIFormInputSetWithNoLabel; 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.Event.Phase; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.UIFormTabPane; import org.exoplatform.webui.form.UIFormTextAreaInput; import org.exoplatform.webui.form.validator.MandatoryValidator; /** * Created by The eXo Platform SARL Author : Dang Van Minh * minh.dang@exoplatform.com Sep 19, 2006 5:31:04 PM */ @ComponentConfig(lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIFormTabPane.gtmpl", events = { @EventConfig(listeners = UIMetadataForm.SaveActionListener.class), @EventConfig(listeners = UIMetadataForm.CancelActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIMetadataForm.AddPermissionActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIMetadataForm.SelectTabActionListener.class, phase = Phase.DECODE) }) public class UIMetadataForm extends UIFormTabPane implements UISelectable { final static public String METADATA_PATH = "metadataPath"; final static public String MAPPING = "mapping"; final static public String METADATA_MAPPING = "metadataMapping"; final static public String NT_UNSTRUCTURED = "nt:unstructured"; final static public String DIALOG_TEMPLATE = "dialogTemplate"; final static public String VIEW_TEMPLATE = "viewTemplate"; final static public String METADATA_NAME = "metadataName"; final static public String METADATA_LABEL = "metadataLabel"; final static public String VIEW_PERMISSION = "viewPermission"; final static public String METADATA_TAB = "metadataTypeTab"; final static public String DIALOG_TAB = "dialogTab"; final static public String VIEW_TAB = "viewTab"; private boolean isAddNew_ = false; private String metadataName_; private String workspaceName_; public UIMetadataForm() throws Exception { super("UIMetadataForm"); UIFormInputSetWithAction uiMetadataType = new UIFormInputSetWithAction(METADATA_TAB); uiMetadataType.addUIFormInput(new UIFormStringInput(METADATA_NAME, METADATA_NAME, null)); uiMetadataType.addUIFormInput(new UIFormStringInput(VIEW_PERMISSION, VIEW_PERMISSION, null).addValidator(MandatoryValidator.class) .setDisabled(true)); uiMetadataType.addUIFormInput(new UIFormStringInput(METADATA_LABEL, METADATA_LABEL, null)); uiMetadataType.setActionInfo(VIEW_PERMISSION, new String[] { "AddPermission" }); addUIComponentInput(uiMetadataType); setSelectedTab(uiMetadataType.getId()); UIFormInputSetWithNoLabel uiDialogTab = new UIFormInputSetWithNoLabel(DIALOG_TAB); uiDialogTab.addUIFormInput(new UIFormTextAreaInput(DIALOG_TEMPLATE, DIALOG_TEMPLATE, null)); addUIComponentInput(uiDialogTab); UIFormInputSetWithNoLabel uiViewTab = new UIFormInputSetWithNoLabel(VIEW_TAB); uiViewTab.addUIFormInput(new UIFormTextAreaInput(VIEW_TEMPLATE, VIEW_TEMPLATE, null)); addUIComponentInput(uiViewTab); setActions(new String[] { "Save", "Cancel" }); } public void doSelect(String selectField, Object value) { getUIStringInput(VIEW_PERMISSION).setValue(value.toString()); UIMetadataManager uiManager = getAncestorOfType(UIMetadataManager.class); uiManager.removeChildById(UIMetadataManager.PERMISSION_POPUP); } public void update(String metadata) throws Exception { metadataName_ = metadata; MetadataService metadataService = getApplicationComponent(MetadataService.class); workspaceName_ = getAncestorOfType(UIECMAdminPortlet.class).getPreferenceWorkspace(); getUIStringInput(METADATA_NAME).setValue(metadata); getUIStringInput(METADATA_LABEL).setValue(metadataService.getMetadataLabel(metadata)); String dialogTemplate = metadataService.getMetadataTemplate(metadata, true); String viewTemplate = metadataService.getMetadataTemplate(metadata, false); String role = metadataService.getMetadataRoles(metadata, true); getUIStringInput(METADATA_NAME).setDisabled(true); getUIStringInput(VIEW_PERMISSION).setValue(role); getUIFormTextAreaInput(DIALOG_TEMPLATE).setValue(dialogTemplate); getUIFormTextAreaInput(VIEW_TEMPLATE).setValue(viewTemplate); } static public class SaveActionListener extends EventListener<UIMetadataForm> { public void execute(Event<UIMetadataForm> event) throws Exception { UIMetadataForm uiForm = event.getSource(); UIMetadataManager uiMetaManager = uiForm.getAncestorOfType(UIMetadataManager.class); MetadataService metadataService = uiForm.getApplicationComponent(MetadataService.class); String roles = uiForm.getUIStringInput(VIEW_PERMISSION).getValue(); String dialogTemplate = uiForm.getUIFormTextAreaInput(DIALOG_TEMPLATE).getValue(); if (dialogTemplate == null) dialogTemplate = ""; String viewTemplate = uiForm.getUIFormTextAreaInput(VIEW_TEMPLATE).getValue(); if (viewTemplate == null) viewTemplate = ""; if (!metadataService.hasMetadata(uiForm.metadataName_)) uiForm.isAddNew_ = true; else uiForm.isAddNew_ = false; String metaLabel = HTMLSanitizer.sanitize(uiForm.getUIStringInput(METADATA_LABEL).getValue()); JCRResourceResolver resourceResolver = new JCRResourceResolver(uiForm.workspaceName_); TemplateService templateService = uiForm.getApplicationComponent(TemplateService.class); String path = metadataService.addMetadata(uiForm.metadataName_, true, roles, dialogTemplate, metaLabel, uiForm.isAddNew_); if (path != null) templateService.invalidateTemplate(path, resourceResolver); path = metadataService.addMetadata(uiForm.metadataName_, false, roles, viewTemplate, metaLabel, uiForm.isAddNew_); if (path != null) templateService.invalidateTemplate(path, resourceResolver); uiForm.reset(); uiMetaManager.getChild(UIMetadataList.class).refresh(1); uiMetaManager.removeChildById(UIMetadataManager.METADATA_POPUP); event.getRequestContext().addUIComponentToUpdateByAjax(uiMetaManager); } } static public class AddPermissionActionListener extends EventListener<UIMetadataForm> { public void execute(Event<UIMetadataForm> event) throws Exception { UIMetadataForm uiView = event.getSource(); UIMetadataManager uiManager = uiView.getAncestorOfType(UIMetadataManager.class); String membership = uiView.getUIStringInput(VIEW_PERMISSION).getValue(); uiManager.initPopupPermission(membership); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } static public class CancelActionListener extends EventListener<UIMetadataForm> { public void execute(Event<UIMetadataForm> event) throws Exception { UIMetadataForm uiView = event.getSource(); UIMetadataManager uiMetaManager = uiView.getAncestorOfType(UIMetadataManager.class); uiMetaManager.removeChildById(UIMetadataManager.METADATA_POPUP); event.getRequestContext().addUIComponentToUpdateByAjax(uiMetaManager); } } static public class SelectTabActionListener extends EventListener<UIMetadataForm> { public void execute(Event<UIMetadataForm> event) throws Exception { UIMetadataForm uiView = event.getSource(); UIMetadataManager uiMetaManager = uiView.getAncestorOfType(UIMetadataManager.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiMetaManager); } } }
9,232
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIMetadataList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/metadata/UIMetadataList.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.admin.metadata; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.core.UIPagingGridDecorator; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.metadata.MetadataService; 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.event.Event; import org.exoplatform.webui.event.EventListener; import javax.jcr.PathNotFoundException; import javax.jcr.nodetype.NodeType; import javax.jcr.nodetype.PropertyDefinition; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Sep 19, 2006 * 11:57:24 AM */ @ComponentConfig( template = "app:/groovy/webui/component/admin/metadata/UIMetadataList.gtmpl", events = { @EventConfig(listeners = UIMetadataList.ViewActionListener.class), @EventConfig(listeners = UIMetadataList.EditActionListener.class), @EventConfig(listeners = UIMetadataList.DeleteActionListener.class, confirm="UIMetadataList.msg.confirm-delete") } ) public class UIMetadataList extends UIPagingGridDecorator { final static public String INTERNAL_USE = "exo:internalUse" ; public UIMetadataList() throws Exception { getUIPageIterator().setId("MetaDataListIterator"); } public void refresh(int currentPage) throws Exception { ListAccess<Metadata> metaDataList = new ListAccessImpl<Metadata>(Metadata.class, getAllMetadatas()); LazyPageList<Metadata> pageList = new LazyPageList<Metadata>(metaDataList, getUIPageIterator().getItemsPerPage()); getUIPageIterator().setPageList(pageList); if (currentPage > getUIPageIterator().getAvailablePage()) getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage()); else getUIPageIterator().setCurrentPage(currentPage); } public List<Metadata> getAllMetadatas() throws Exception { List<Metadata> metadatas = new ArrayList<Metadata>() ; MetadataService metadataService = getApplicationComponent(MetadataService.class) ; List<NodeType> nodetypes = metadataService.getAllMetadatasNodeType() ; Collections.sort(nodetypes, new Utils.NodeTypeNameComparator()) ; for(NodeType nt : nodetypes) { Metadata mt = new Metadata() ; mt.setName(nt.getName()) ; mt.isTemplate(metadataService.hasMetadata(nt.getName())) ; mt.setLabel(metadataService.getMetadataLabel(nt.getName())); for(PropertyDefinition def : nt.getPropertyDefinitions()) { if(def.getName().equals(INTERNAL_USE)) { if(def.getDefaultValues() != null && def.getDefaultValues()[0].getBoolean()) { mt.setInternalUse("True") ; } else { mt.setInternalUse("False") ; } metadatas.add(mt) ; break; } } } return metadatas ; } public List getListMetadata() throws Exception { return getUIPageIterator().getCurrentPageData() ; } static public class ViewActionListener extends EventListener<UIMetadataList> { public void execute(Event<UIMetadataList> event) throws Exception { UIMetadataList uiMetaList = event.getSource() ; String metadataName = event.getRequestContext().getRequestParameter(OBJECTID) ; UIMetadataManager uiManager = uiMetaList.getParent() ; uiManager.removeChildById(UIMetadataManager.VIEW_METADATA_POPUP) ; uiManager.initViewPopup(metadataName) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class EditActionListener extends EventListener<UIMetadataList> { public void execute(Event<UIMetadataList> event) throws Exception { UIMetadataList uiMetaList = event.getSource() ; String metadataName = event.getRequestContext().getRequestParameter(OBJECTID) ; UIMetadataManager uiManager = uiMetaList.getParent() ; uiManager.initPopup() ; UIMetadataForm uiForm = uiManager.findFirstComponentOfType(UIMetadataForm.class) ; uiForm.update(metadataName) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class DeleteActionListener extends EventListener<UIMetadataList> { public void execute(Event<UIMetadataList> event) throws Exception { UIMetadataList uiMetaList = event.getSource() ; String metadataName = event.getRequestContext().getRequestParameter(OBJECTID) ; UIMetadataManager uiManager = uiMetaList.getParent() ; MetadataService metadataService = uiMetaList.getApplicationComponent(MetadataService.class) ; UIApplication uiApp = uiMetaList.getAncestorOfType(UIApplication.class); try { metadataService.removeMetadata(metadataName); org.exoplatform.services.cms.impl.Utils.addEditedConfiguredData(metadataName, "ContentTemplateList", "EditedConfiguredTemplateList", true); } catch(PathNotFoundException ex) { uiApp.addMessage(new ApplicationMessage("UIMetadataList.msg.path-not-found-exception", null, ApplicationMessage.WARNING)); return; } uiMetaList.refresh(uiMetaList.getUIPageIterator().getCurrentPage()); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; Object[] args = {metadataName} ; uiApp.addMessage(new ApplicationMessage("UIMetadataList.msg.delete-successful", args)) ; } } public class Metadata{ private String name ; private String internalUse ; private boolean hasTemplate = false; private String label; public Metadata() {} public String getName() { return name ;} public void setName(String n) { name = n ; } public String getInternalUse() { return internalUse ;} public void setInternalUse(String inter) { internalUse = inter ; } public boolean hasTemplate() { return hasTemplate ; } public void isTemplate(boolean isTemplate) { hasTemplate = isTemplate ; } public String getLabel() { return label; } public void setLabel(String label) { this.label = label; } } }
7,346
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIMetadataView.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/metadata/UIMetadataView.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.admin.metadata; import javax.jcr.nodetype.NodeType; import org.exoplatform.services.jcr.core.ExtendedPropertyType; 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.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Sep 20, 2006 * 8:59:13 AM */ @ComponentConfig( template = "app:/groovy/webui/component/admin/metadata/UIMetadataView.gtmpl", events = { @EventConfig(listeners = UIMetadataView.CancelActionListener.class), @EventConfig(listeners = UIMetadataView.SelectTabActionListener.class) }) public class UIMetadataView extends UIContainer{ private NodeType metadataType_ ; private String selectedTabId = METADATA_VIEW; static public final String METADATA_VIEW = "Metadata"; static public final String ELEMENT_VIEW = "Element"; public String getSelectedTabId() { return selectedTabId; } public void setSelectedTab(String renderTabId) { selectedTabId = renderTabId; } public void setSelectedTab(int index) { selectedTabId = ((UIComponent)getChild(index - 1)).getId(); } public UIMetadataView() throws Exception { } public void setMetadata(NodeType nodetype) { metadataType_ = nodetype ; } public NodeType getMetadata() { return metadataType_ ; } public String resolveType(int type) { return ExtendedPropertyType.nameFromValue(type); } static public class CancelActionListener extends EventListener<UIMetadataView> { public void execute(Event<UIMetadataView> event) throws Exception { UIMetadataView uiView = event.getSource() ; UIMetadataManager uiManager = uiView.getAncestorOfType(UIMetadataManager.class) ; uiManager.removeChildById(UIMetadataManager.VIEW_METADATA_POPUP) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class SelectTabActionListener extends EventListener<UIMetadataView> { public void execute(Event<UIMetadataView> 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); } } } }
3,698
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIQueriesManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/queries/UIQueriesManager.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.admin.queries; import org.exoplatform.ecm.webui.selector.UIGroupMemberSelector; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; import org.exoplatform.webui.ext.manager.UIAbstractManager; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Dec 29, 2006 * 11:27:14 AM */ @ComponentConfig(lifecycle = UIContainerLifecycle.class) public class UIQueriesManager extends UIAbstractManager { public UIQueriesManager() throws Exception { addChild(UIQueriesList.class, null, null) ; } public void refresh() throws Exception { update(); } public void update() throws Exception { getChild(UIQueriesList.class).refresh(1) ; } public void initFormPopup(String id) throws Exception { removeChildById(id) ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, id) ; uiPopup.setShowMask(true); uiPopup.setWindowSize(600, 325) ; UIQueriesForm uiForm = createUIComponent(UIQueriesForm.class, null, null) ; uiForm.setIsAddNew(true) ; uiPopup.setUIComponent(uiForm) ; uiPopup.setRendered(true) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public void initPermissionPopup(String membership) throws Exception { removeChildById("PermissionPopup") ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, "PermissionPopup"); uiPopup.setShowMask(true); uiPopup.setWindowSize(560, 250); UIGroupMemberSelector uiECMPermission = createUIComponent(UIGroupMemberSelector.class, null, null) ; uiECMPermission.setSelectedMembership(true); if(membership != null && membership.indexOf(":/") > -1) { String[] arrMember = membership.split(":/") ; uiECMPermission.changeGroup("/" + arrMember[1]) ; } uiPopup.setUIComponent(uiECMPermission); UIQueriesForm uiForm = findFirstComponentOfType(UIQueriesForm.class) ; uiECMPermission.setSourceComponent(uiForm, new String[] {UIQueriesForm.PERMISSIONS}) ; uiPopup.setRendered(true) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } }
3,011
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIQueriesForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/queries/UIQueriesForm.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.admin.queries; import java.util.ArrayList; import java.util.List; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.Value; import javax.jcr.query.InvalidQueryException; import javax.jcr.query.Query; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.ecm.webui.form.validator.ECMNameValidator; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.ecm.webui.utils.Utils; 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.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.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 org.exoplatform.webui.form.input.UICheckBoxInput; import org.exoplatform.webui.form.validator.MandatoryValidator; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Dec 29, 2006 * 11:30:29 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UIQueriesForm.SaveActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIQueriesForm.CancelActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIQueriesForm.ChangeQueryTypeActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIQueriesForm.AddPermissionActionListener.class) } ) public class UIQueriesForm extends UIForm implements UISelectable { final static public String QUERY_NAME = "name" ; final static public String QUERY_TYPE = "type" ; final static public String STATEMENT = "statement" ; final static public String PERMISSIONS = "permissions" ; final static public String CACHE_RESULT = "cache" ; final static public String[] ACTIONS = {"Save", "Cancel"} ; final static public String SQL_QUERY = "select * from nt:file where jcr:path like '/Documents/Live/%'" ; final static public String XPATH_QUERY = "/jcr:root/Documents/Live//element(*, nt:file)" ; final static public String[] REG_EXPRESSION = {"[", "]", ":", "&"} ; private boolean isAddNew_ = false ; public UIQueriesForm() throws Exception { addUIFormInput(new UIFormStringInput(QUERY_NAME, QUERY_NAME, null). addValidator(MandatoryValidator.class).addValidator(ECMNameValidator.class)) ; List<SelectItemOption<String>> ls = new ArrayList<SelectItemOption<String>>() ; ls.add(new SelectItemOption<String>("xPath", "xpath")) ; ls.add(new SelectItemOption<String>("SQL", "sql")) ; UIFormSelectBox uiSelectBox = new UIFormSelectBox(QUERY_TYPE, QUERY_TYPE, ls) ; uiSelectBox.setOnChange("ChangeQueryType") ; addUIFormInput(uiSelectBox) ; UIFormTextAreaInput uiStatement = new UIFormTextAreaInput(STATEMENT, STATEMENT, null) ; uiStatement.setValue(XPATH_QUERY) ; uiStatement.addValidator(MandatoryValidator.class) ; addUIFormInput(uiStatement) ; addUIFormInput(new UICheckBoxInput(CACHE_RESULT, CACHE_RESULT, null)) ; UIFormInputSetWithAction uiInputAct = new UIFormInputSetWithAction("PermissionButton") ; uiInputAct.addUIFormInput(new UIFormStringInput(PERMISSIONS, PERMISSIONS, null).setDisabled(true) .addValidator(MandatoryValidator.class)); uiInputAct.setActionInfo(PERMISSIONS, new String[] {"AddPermission"}) ; addUIComponentInput(uiInputAct) ; } public String[] getActions() { return ACTIONS ; } public void doSelect(String selectField, Object value) { getUIStringInput(selectField).setValue(value.toString()); UIQueriesManager uiManager = getAncestorOfType(UIQueriesManager.class); UIPopupWindow uiPopup = uiManager.getChildById("PermissionPopup"); uiPopup.setShowMask(true); uiManager.removeChildById("PermissionPopup"); } public void setIsAddNew(boolean isAddNew) { isAddNew_ = isAddNew ; } public void update(String queryName)throws Exception{ isAddNew_ = false ; QueryService queryService = getApplicationComponent(QueryService.class) ; if(queryName == null) { isAddNew_ = true ; reset() ; return ; } Node query = queryService.getSharedQuery(queryName, WCMCoreUtils.getSystemSessionProvider()); getUIStringInput(QUERY_NAME).setValue(queryName) ; getUIStringInput(QUERY_NAME).setDisabled(true); if(query.hasProperty("exo:cachedResult")) { getUICheckBoxInput(CACHE_RESULT).setChecked(query.getProperty("exo:cachedResult").getBoolean()) ; } else { getUICheckBoxInput(CACHE_RESULT).setChecked(false) ; } if(query.hasProperty("jcr:statement")) { getUIFormTextAreaInput(STATEMENT).setValue(query.getProperty("jcr:statement").getString()) ; } if(query.hasProperty("jcr:language")) { getUIFormSelectBox(QUERY_TYPE).setValue(query.getProperty("jcr:language").getString()) ; } if(query.hasProperty("exo:accessPermissions")) { Value[] values = query.getProperty("exo:accessPermissions").getValues() ; StringBuilder strValues = new StringBuilder() ; for(int i = 0; i < values.length; i ++) { if(strValues.length() > 0) strValues = strValues.append(",") ; strValues = strValues.append(values[i].getString()) ; } getUIStringInput(PERMISSIONS).setValue(strValues.toString()) ; } } static public class CancelActionListener extends EventListener<UIQueriesForm> { public void execute(Event<UIQueriesForm> event) throws Exception { UIQueriesForm uiForm = event.getSource() ; UIQueriesManager uiManager = uiForm.getAncestorOfType(UIQueriesManager.class) ; uiManager.removeChildById(UIQueriesList.ST_ADD) ; uiManager.removeChildById(UIQueriesList.ST_EDIT); event.getRequestContext().getJavascriptManager() .require("SHARED/jquery", "gj") .addScripts("gj(document).ready(function() { gj(\"*[rel='tooltip']\").tooltip();});"); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class SaveActionListener extends EventListener<UIQueriesForm> { public void execute(Event<UIQueriesForm> event) throws Exception { UIQueriesForm uiForm = event.getSource() ; QueryService queryService = uiForm.getApplicationComponent(QueryService.class) ; UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class) ; String queryName = uiForm.getUIStringInput(QUERY_NAME).getValue().trim(); if(uiForm.isAddNew_) { for(Node queryNode : queryService.getSharedQueries(WCMCoreUtils.getSystemSessionProvider())) { if(queryNode.getName().equals(queryName)) { uiApp.addMessage(new ApplicationMessage("UIQueriesForm.msg.name-existing", null, ApplicationMessage.WARNING)) ; return ; } } } String statement = uiForm.getUIFormTextAreaInput(STATEMENT).getValue() ; UIFormInputSetWithAction permField = uiForm.getChildById("PermissionButton") ; String permissions = permField.getUIStringInput(PERMISSIONS).getValue() ; if((permissions == null)||(permissions.trim().length() == 0)) { uiApp.addMessage(new ApplicationMessage("UIQueriesForm.msg.permission-require", null, ApplicationMessage.WARNING)) ; return ; } String queryType = uiForm.getUIFormSelectBox(QUERY_TYPE).getValue() ; boolean cacheResult = uiForm.getUICheckBoxInput(CACHE_RESULT).isChecked() ; try { if(permissions.indexOf(",") > -1) { queryService.addSharedQuery(queryName, statement, queryType, permissions.split(","), cacheResult); } else { queryService.addSharedQuery(queryName, statement, queryType, new String[] { permissions }, cacheResult); } } catch(InvalidQueryException qe) { uiApp.addMessage(new ApplicationMessage("UIQueriesForm.msg.invalid-query", null, ApplicationMessage.WARNING)) ; return ; } catch (AccessDeniedException ade) { uiApp.addMessage(new ApplicationMessage("UIQueriesForm.msg.access-denied", null, ApplicationMessage.WARNING)) ; return ; } UIQueriesManager uiManager = uiForm.getAncestorOfType(UIQueriesManager.class) ; uiManager.getChild(UIQueriesList.class).refresh(1); uiManager.removeChildById(UIQueriesList.ST_ADD) ; uiManager.removeChildById(UIQueriesList.ST_EDIT) ; event.getRequestContext().getJavascriptManager() .require("SHARED/jquery", "gj") .addScripts("gj(document).ready(function() { gj(\"*[rel='tooltip']\").tooltip();});"); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class ChangeQueryTypeActionListener extends EventListener<UIQueriesForm> { public void execute(Event<UIQueriesForm> event) throws Exception { UIQueriesForm uiForm= event.getSource() ; String queryType = uiForm.getUIFormSelectBox(QUERY_TYPE).getValue() ; if(queryType.equals(Query.XPATH)) { uiForm.getUIFormTextAreaInput(STATEMENT).setValue(XPATH_QUERY) ; } else { uiForm.getUIFormTextAreaInput(STATEMENT).setValue(SQL_QUERY) ; } } } static public class AddPermissionActionListener extends EventListener<UIQueriesForm> { public void execute(Event<UIQueriesForm> event) throws Exception { UIQueriesManager uiManager = event.getSource().getAncestorOfType(UIQueriesManager.class) ; String membership = event.getSource().getUIStringInput(PERMISSIONS).getValue() ; uiManager.initPermissionPopup(membership) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } }
11,873
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIQueriesList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/queries/UIQueriesList.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.admin.queries; import java.util.Collections; import java.util.Comparator; import java.util.List; import javax.jcr.Node; import javax.jcr.PathNotFoundException; 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.core.UIPagingGridDecorator; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.cms.queries.QueryService; import org.exoplatform.services.jcr.access.PermissionType; 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.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.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Dec 29, 2006 * 11:30:17 AM */ @ComponentConfig( template = "app:/groovy/webui/component/admin/queries/UIQueriesList.gtmpl", events = { @EventConfig(listeners = UIQueriesList.AddQueryActionListener.class), @EventConfig(listeners = UIQueriesList.EditActionListener.class), @EventConfig(listeners = UIQueriesList.DeleteActionListener.class, confirm = "UIQueriesList.msg.confirm-delete") } ) public class UIQueriesList extends UIPagingGridDecorator { private static final Log LOG = ExoLogger.getLogger(UIQueriesList.class.getName()); final static public String[] ACTIONS = {"AddQuery"} ; final static public String ST_ADD = "AddQueryForm" ; final static public String ST_EDIT = "EditQueryForm" ; public UIQueriesList() throws Exception { getUIPageIterator().setId("QueriesListIterator"); } public String[] getActions() { return ACTIONS ; } public void refresh(int currentPage) throws Exception { ListAccess<Object> sharedQueryList = new ListAccessImpl<Object>(Object.class, NodeLocation.getLocationsByNodeList(getAllSharedQueries())); LazyPageList<Object> pageList = new LazyPageList<Object>(sharedQueryList, getUIPageIterator().getItemsPerPage()); getUIPageIterator().setPageList(pageList); if (currentPage > getUIPageIterator().getAvailablePage()) getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage()); else getUIPageIterator().setCurrentPage(currentPage); } public boolean canEditNode(Node node) { SessionProvider sProvider = WCMCoreUtils.getSystemSessionProvider(); try { ManageableRepository manageableRepository = ((ManageableRepository)node.getSession().getRepository()); Session session = sProvider.getSession(node.getSession().getWorkspace().getName(), manageableRepository); session.checkPermission(node.getPath(), PermissionType.SET_PROPERTY); }catch (Exception e){ return false; } return true; } public boolean canRemoveNode(Node node) { SessionProvider sProvider = WCMCoreUtils.getSystemSessionProvider(); try { ManageableRepository manageableRepository = ((ManageableRepository)node.getSession().getRepository()); Session session = sProvider.getSession(node.getSession().getWorkspace().getName(), manageableRepository); session.checkPermission(node.getPath(), PermissionType.REMOVE); }catch (Exception e){ return false; } return true; } public List getQueryList() throws Exception { return NodeLocation.getNodeListByLocationList(getUIPageIterator().getCurrentPageData()); } @SuppressWarnings("unchecked") public List<Node> getAllSharedQueries() throws Exception { QueryService queryService = getApplicationComponent(QueryService.class) ; List<Node> queries = queryService.getSharedQueries(WCMCoreUtils.getSystemSessionProvider()) ; Collections.sort(queries, new QueryComparator()) ; return queries ; } static public class QueryComparator implements Comparator { public int compare(Object o1, Object o2) throws ClassCastException { try { String name1 = ((Node) o1).getName() ; String name2 = ((Node) o2).getName() ; return name1.compareToIgnoreCase(name2) ; } catch(Exception e) { return 0; } } } static public class AddQueryActionListener extends EventListener<UIQueriesList> { public void execute(Event<UIQueriesList> event) throws Exception { UIQueriesManager uiQueriesMan = event.getSource().getParent() ; uiQueriesMan.removeChildById(UIQueriesList.ST_EDIT) ; uiQueriesMan.initFormPopup(UIQueriesList.ST_ADD) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiQueriesMan) ; } } static public class EditActionListener extends EventListener<UIQueriesList> { public void execute(Event<UIQueriesList> event) throws Exception { UIQueriesManager uiQueriesMan = event.getSource().getParent() ; uiQueriesMan.removeChildById(UIQueriesList.ST_ADD) ; uiQueriesMan.initFormPopup(UIQueriesList.ST_EDIT ) ; String queryPath = event.getRequestContext().getRequestParameter(OBJECTID) ; UIQueriesForm uiForm = uiQueriesMan.findFirstComponentOfType(UIQueriesForm.class) ; String queryName = queryPath.substring(queryPath.lastIndexOf("/") + 1) ; uiForm.update(queryName) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiQueriesMan) ; } } static public class DeleteActionListener extends EventListener<UIQueriesList> { public void execute(Event<UIQueriesList> event) throws Exception { UIQueriesList uiQueriesList = event.getSource(); UIApplication uiApp = uiQueriesList.getAncestorOfType(UIApplication.class); UIQueriesManager uiQueriesMan = event.getSource().getParent() ; String userName = Util.getPortalRequestContext().getRemoteUser() ; String queryName = event.getRequestContext().getRequestParameter(OBJECTID) ; QueryService queryService = event.getSource().getApplicationComponent(QueryService.class) ; try { queryService.removeQuery(queryName, userName) ; } catch (PathNotFoundException pe) { uiApp.addMessage(new ApplicationMessage("UIQueriesList.msg.query-not-existed", null,ApplicationMessage.WARNING)); return; } catch (Exception ex) { if (LOG.isErrorEnabled()) { LOG.error("cannot remove the query", ex); } uiApp.addMessage(new ApplicationMessage("UIQueriesList.msg.can-not-remove", null,ApplicationMessage.ERROR)); return; } event.getSource().refresh(uiQueriesList.getUIPageIterator().getCurrentPage()); event.getRequestContext().addUIComponentToUpdateByAjax(uiQueriesMan) ; } } }
8,077
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINodeTypeForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/nodetype/UINodeTypeForm.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.admin.nodetype; 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.NodeDefinition; import javax.jcr.nodetype.NodeType; import javax.jcr.nodetype.NodeTypeManager; import javax.jcr.nodetype.PropertyDefinition; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.ecm.webui.form.validator.ECMNameValidator; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.core.ManageableRepository; import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager; import org.exoplatform.services.jcr.core.nodetype.NodeDefinitionValue; import org.exoplatform.services.jcr.core.nodetype.NodeTypeValue; import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionValue; 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.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.UIFormInputInfo; import org.exoplatform.webui.form.UIFormSelectBox; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.UIFormTabPane; import org.exoplatform.webui.form.validator.MandatoryValidator; import org.exoplatform.webui.form.validator.Validator; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Sep 20, 2006 * 5:33:13 PM */ @ComponentConfigs ({ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/admin/nodetype/UINodeTypeForm.gtmpl", events = { @EventConfig(listeners = UINodeTypeForm.CancelActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UINodeTypeForm.CloseActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UINodeTypeOptionList.CancelTabActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UINodeTypeForm.SaveDraftActionListener.class), @EventConfig(listeners = UINodeTypeForm.SaveActionListener.class), @EventConfig(listeners = UINodeTypeForm.SelectTabActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UINodeTypeForm.IsMixinActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIPropertyDefinitionForm.AddPropertyActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIChildNodeDefinitionForm.AddChildActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UINodeTypeForm.ViewChildNodeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UINodeTypeForm.ViewPropertyActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UINodeTypeForm.AddSuperTypeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIChildNodeDefinitionForm.AddDefaultTypeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIChildNodeDefinitionForm.AddRequiredTypeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UINodeTypeOptionList.AddTypeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIChildNodeDefinitionForm.RemoveChildNodeActionListener.class, confirm = "UINodeTypeForm.msg.confirm-delete-child", phase = Phase.DECODE), @EventConfig(listeners = UIChildNodeDefinitionForm.EditChildNodeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIPropertyDefinitionForm.EditPropertyActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIPropertyDefinitionForm.RemovePropertyActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIChildNodeDefinitionForm.UpdateChildActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIChildNodeDefinitionForm.CancelChildActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIPropertyDefinitionForm.UpdatePropertyActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIPropertyDefinitionForm.CancelPropertyActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIPropertyDefinitionForm.ChangeRequiredTypeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIPropertyDefinitionForm.AddConstraintsActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIPropertyDefinitionForm.AddValueActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIPropertyDefinitionForm.CancelConstraintsActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIPropertyDefinitionForm.AddActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIPropertyDefinitionForm.RemoveActionListener.class, phase = Phase.DECODE, confirm = "UINodeTypeForm.msg.confirm-delete-property") } ) }) public class UINodeTypeForm extends UIFormTabPane { final static public String NAMESPACE = "namespace" ; final static public String NODETYPE_NAME = "nodeTypeName" ; final static public String MIXIN_TYPE = "mixinType" ; final static public String HAS_ORDERABLE_CHILDNODES = "hasOrderableChildNodes" ; final static public String PRIMARY_ITEMNAME = "primaryItemName" ; final static public String PROPERTY_DEFINITIONS = "propertiesDefinitions" ; final static public String CHILDNODE_DEFINITIONS = "childDefinitions" ; final static public String SUPER_TYPE = "superTypes" ; final static public String SUPER_TYPE_TAB = "superTypeTab" ; final static public String DEFAULT_PRIMARY_TYPE_TAB = "DefaultTypeTab" ; final static public String REQUIRED_PRIMARY_TYPE_TAB = "RequiredTypeTab" ; final static public String NODETYPE_DEFINITION = "nodeTypeDefinition" ; final static public String PROPERTY_DEFINITION = "propertyDefinition" ; final static public String CHILDNODE_DEFINITION = "childNodeDefinition" ; final static public String NT_UNSTRUCTURED = "nt:unstructured" ; final static public String PROPERTY_DEFINITIONS_NODE = "propertyDefinitions" ; final static public String CHILD_NODE_DEFINITIONS = "childNodeDefinitions" ; final static public String IS_MIX_IN = "isMixin" ; final static public String PROPERTY_NAME = "name" ; final static public String ON_PARENT_VERSION = "onParentVersion" ; final static public String JCR_NODETYPE_DRAFT = "jcr:nodetypesDraft" ; final static public String TRUE = "true" ; final static public String FALSE = "false" ; final static public String ADD_CHILD = "AddChild" ; final static public String ADD_PROPERTY = "AddProperty" ; final static public String ACTION_SAVE = "Save" ; final static public String ACTION_SAVEDRAFT = "SaveDraft" ; final static public String ACTION_CANCEL = "Cancel" ; final static public String ACTION_CANCEL_TAB = "CancelTab" ; final static public String[] ACTION_BACK = {"Back"} ; final static public String ADD_TYPE = "AddType" ; private boolean isDraft_ = false ; public List<PropertyDefinitionValue> addedPropertiesDef_ = new ArrayList<PropertyDefinitionValue>(); public List<NodeDefinitionValue> addedChildDef_ = new ArrayList<NodeDefinitionValue>(); private List<SelectItemOption<String>> namespacesOptions_ = new ArrayList<SelectItemOption<String>>(); private List<SelectItemOption<String>> mixinTypeOptions_ = new ArrayList<SelectItemOption<String>>(); private List<SelectItemOption<String>> orderAbleOptions_ = new ArrayList<SelectItemOption<String>>(); private PropertyDefinition[] propertyDefinitions_ ; private NodeDefinition[] childNodeDefinitions_ ; private NodeType nodeType_ ; public UINodeTypeForm() throws Exception { super("UINodeTypeForm"); UIFormSelectBox mixinSelectBox = new UIFormSelectBox(MIXIN_TYPE, MIXIN_TYPE, null); mixinSelectBox.setOnChange("IsMixin"); UIFormInputSetWithAction nodeTypeTab = new UIFormInputSetWithAction(NODETYPE_DEFINITION); nodeTypeTab.addUIFormInput(new UIFormSelectBox(NAMESPACE, NAMESPACE, null)) .addUIFormInput(new UIFormStringInput(NODETYPE_NAME, NODETYPE_NAME, null).addValidator(MandatoryValidator.class) .addValidator(ECMNameValidator.class)) .addUIFormInput(mixinSelectBox) .addUIFormInput(new UIFormSelectBox(HAS_ORDERABLE_CHILDNODES, HAS_ORDERABLE_CHILDNODES, null)) .addUIFormInput(new UIFormStringInput(PRIMARY_ITEMNAME, PRIMARY_ITEMNAME, null)) .addUIFormInput(new UIFormStringInput(SUPER_TYPE, SUPER_TYPE, null) .addValidator(MandatoryValidator.class)) .addUIFormInput(new UIFormInputInfo(PROPERTY_DEFINITIONS, PROPERTY_DEFINITIONS, null)) .addUIFormInput(new UIFormInputInfo(CHILDNODE_DEFINITIONS, CHILDNODE_DEFINITIONS, null)); setActionInTab(nodeTypeTab) ; addUIComponentInput(nodeTypeTab) ; UIFormInputSetWithAction propertiesTab = new UIPropertyDefinitionForm(PROPERTY_DEFINITION) ; setActionInTab(propertiesTab) ; addUIComponentInput(propertiesTab) ; UIFormInputSetWithAction childTab = new UIChildNodeDefinitionForm(CHILDNODE_DEFINITION) ; setActionInTab(childTab) ; addUIComponentInput(childTab) ; setSelectedTab(NODETYPE_DEFINITION); } public void setActionInTab(UIFormInputSetWithAction tab) { if(tab.getId().equals(NODETYPE_DEFINITION)) { tab.setActionInfo(SUPER_TYPE, new String[] {"AddSuperType"}) ; tab.setActions(new String[] {ACTION_SAVE, ACTION_SAVEDRAFT, ACTION_CANCEL}, null) ; setSelectedTab(tab.getId()) ; } else if(tab.getId().equals(CHILDNODE_DEFINITION)) { tab.setActionInfo(UIChildNodeDefinitionForm.DEFAULT_PRIMARY_TYPE, new String[] {"AddDefaultType"}) ; tab.setActionInfo(UIChildNodeDefinitionForm.REQUIRED_PRIMARY_TYPE, new String[] {"AddRequiredType"}) ; tab.setActions(new String[] {ADD_CHILD}, null) ; } else if(tab.getId().equals(PROPERTY_DEFINITION)) { tab.setActionInfo(UIPropertyDefinitionForm.VALUE_CONSTRAINTS, new String[] {"AddConstraints"}) ; tab.setActions(new String[] {ADD_PROPERTY}, null) ; } } public String[] getActions() { return null ; } public String getLabel(ResourceBundle res, String id) { String label = getId() + ".label." + id ; try { return res.getString(label) ; } catch(Exception e) { return id ; } } public List<SelectItemOption<String>> getNamespaces() throws Exception { if (namespacesOptions_.size() == 0) { String[] namespaces = getApplicationComponent(RepositoryService.class) .getCurrentRepository().getNamespaceRegistry().getPrefixes() ; for(int i = 0; i < namespaces.length; i ++){ namespacesOptions_.add(new SelectItemOption<String>(namespaces[i], namespaces[i])) ; } } return namespacesOptions_ ; } public void setChildValue(List<NodeDefinitionValue> listChildNode) throws Exception { StringBuilder childNodes = new StringBuilder() ; if(listChildNode == null) return ; for(NodeDefinitionValue node : listChildNode) { if(childNodes.length() > 0) childNodes.append(",") ; childNodes.append(node.getName()) ; } UIFormInputSetWithAction nodeTypeTab = getChildById(NODETYPE_DEFINITION) ; nodeTypeTab.setInfoField(CHILDNODE_DEFINITIONS, childNodes.toString()) ; String[] actionInfor = {"EditChildNode", "RemoveChildNode"} ; nodeTypeTab.setActionInfo(CHILDNODE_DEFINITIONS, actionInfor) ; } public void removeChildTabs(String[] tabNames) { for(int i = 0; i < tabNames.length ; i++) { removeChildById(tabNames[i]) ; } } public void setPropertyValue(List<PropertyDefinitionValue> listProperty) throws Exception { StringBuilder propertyValues = new StringBuilder() ; if(listProperty == null) return ; for(PropertyDefinitionValue property : listProperty) { if(propertyValues.length() > 0) propertyValues.append(",") ; propertyValues.append(property.getName()) ; } UIFormInputSetWithAction nodeTypeTab = getChildById(NODETYPE_DEFINITION) ; nodeTypeTab.setInfoField(PROPERTY_DEFINITIONS, propertyValues.toString()); String[] actionInfor = {"EditProperty", "RemoveProperty"} ; nodeTypeTab.setActionInfo(PROPERTY_DEFINITIONS, actionInfor) ; } private void setChildDefinitions(NodeDefinition[] childDef) throws Exception { StringBuilder childDefinitions = new StringBuilder() ; if(childDef != null) { for(int i = 0 ; i < childDef.length ; i++) { if(childDefinitions.length() > 0) childDefinitions.append(",") ; childDefinitions.append(childDef[i].getName()) ; } } UIFormInputSetWithAction nodeTypeTab = getChildById(NODETYPE_DEFINITION) ; nodeTypeTab.setInfoField(CHILDNODE_DEFINITIONS, childDefinitions.toString()); String[] actionInfor = {"ViewChildNode"} ; nodeTypeTab.setIsView(true) ; nodeTypeTab.setActionInfo(CHILDNODE_DEFINITIONS, actionInfor) ; } private void setPropertyDefinitions(PropertyDefinition[] propertyDef) throws Exception { StringBuilder propertyDefinitions = new StringBuilder() ; if(propertyDef != null) { for(int i = 0; i < propertyDef.length; i++) { if(propertyDefinitions.length() > 0) propertyDefinitions.append(",") ; propertyDefinitions.append(propertyDef[i].getName()) ; } } UIFormInputSetWithAction nodeTypeTab = getChildById(NODETYPE_DEFINITION) ; nodeTypeTab.setInfoField(PROPERTY_DEFINITIONS, propertyDefinitions.toString()); String[] actionInfor = {"ViewProperty"} ; nodeTypeTab.setIsView(true) ; nodeTypeTab.setActionInfo(PROPERTY_DEFINITIONS, actionInfor) ; } public void update(NodeType nodeType, boolean isView) throws Exception{ namespacesOptions_.clear() ; mixinTypeOptions_.add(new SelectItemOption<String>(FALSE, FALSE)) ; mixinTypeOptions_.add(new SelectItemOption<String>(TRUE, TRUE)) ; orderAbleOptions_.add(new SelectItemOption<String>(FALSE, FALSE)) ; orderAbleOptions_.add(new SelectItemOption<String>(TRUE, TRUE)) ; if(nodeType == null) { refresh() ; setActionInTab((UIFormInputSetWithAction)getChildById(NODETYPE_DEFINITION)) ; setActionInTab((UIFormInputSetWithAction)getChildById(CHILDNODE_DEFINITION)) ; setActionInTab((UIFormInputSetWithAction)getChildById(PROPERTY_DEFINITION)) ; return ; } String fullName = nodeType.getName() ; String nodeTypeName = fullName ; String namespacesPrefix = ""; if(fullName.indexOf(":") > -1) { nodeTypeName = fullName.substring(fullName.indexOf(":") + 1) ; namespacesPrefix = fullName.substring(0, fullName.indexOf(":")) ; } getUIStringInput(NODETYPE_NAME).setValue(nodeTypeName) ; getUIFormSelectBox(NAMESPACE).setOptions(getNamespaces()) ; getUIFormSelectBox(NAMESPACE).setValue(namespacesPrefix) ; getUIStringInput(PRIMARY_ITEMNAME).setValue(nodeType.getPrimaryItemName()) ; getUIFormSelectBox(MIXIN_TYPE).setValue(String.valueOf(nodeType.isMixin())) ; String orderableChildNodes = String.valueOf(nodeType.hasOrderableChildNodes()) ; getUIFormSelectBox(HAS_ORDERABLE_CHILDNODES).setValue(orderableChildNodes) ; NodeType[] superType = nodeType.getSupertypes() ; StringBuilder types = new StringBuilder(); for(int i = 0; i < superType.length; i++){ if(types.length() > 0) types.append(", ") ; types.append(superType[i].getName()) ; } getUIStringInput(SUPER_TYPE).setValue(types.toString()) ; if (nodeType.isMixin() && getUIStringInput(SUPER_TYPE).getValidators().size() > 0) { removeMandatoryValidator(); } if(isView) { getUIFormSelectBox(NAMESPACE).setDisabled(true) ; getUIStringInput(NODETYPE_NAME).setReadOnly(true); getUIStringInput(PRIMARY_ITEMNAME).setReadOnly(true); getUIFormSelectBox(MIXIN_TYPE).setDisabled(true) ; getUIFormSelectBox(HAS_ORDERABLE_CHILDNODES).setDisabled(true); getUIStringInput(SUPER_TYPE).setReadOnly(true); UIPropertyDefinitionForm uiPropertyForm = getChild(UIPropertyDefinitionForm.class) ; uiPropertyForm.update(nodeType, null) ; UIChildNodeDefinitionForm uiChildNodeForm = getChild(UIChildNodeDefinitionForm.class) ; uiChildNodeForm.update(nodeType, null) ; UIFormInputSetWithAction uiNodeTypeTab = getChildById(CHILDNODE_DEFINITION) ; uiNodeTypeTab.setIsView(true) ; } propertyDefinitions_ = nodeType.getPropertyDefinitions() ; childNodeDefinitions_ = nodeType.getChildNodeDefinitions() ; setChildDefinitions(childNodeDefinitions_) ; setPropertyDefinitions(propertyDefinitions_) ; nodeType_ = nodeType ; } public void setChildDraftNode(Node draftNodeType) throws Exception { addedChildDef_ = new ArrayList<NodeDefinitionValue>() ; if(!draftNodeType.hasNode(CHILD_NODE_DEFINITIONS)) return ; Node childNodeHome = draftNodeType.getNode(CHILD_NODE_DEFINITIONS) ; NodeIterator childIter = childNodeHome.getNodes() ; while(childIter.hasNext()) { Node childDef = childIter.nextNode() ; NodeDefinitionValue nodeTypeValue = new NodeDefinitionValue(); nodeTypeValue.setName(childDef.getName()) ; String defaultPriType = childDef.getProperty(UIChildNodeDefinitionForm.DEFAULT_PRIMARY_TYPE).getString() ; nodeTypeValue.setDefaultNodeTypeName(defaultPriType) ; String sameName = childDef.getProperty(UIChildNodeDefinitionForm.SAME_NAME).getString() ; nodeTypeValue.setSameNameSiblings(Boolean.parseBoolean(sameName)) ; String mandatory = childDef.getProperty(UIChildNodeDefinitionForm.MANDATORY).getString() ; nodeTypeValue.setMandatory(Boolean.parseBoolean(mandatory)) ; String autoCreate = childDef.getProperty(UIChildNodeDefinitionForm.AUTOCREATED).getString() ; nodeTypeValue.setAutoCreate(Boolean.parseBoolean(autoCreate)) ; String isProtected = childDef.getProperty(UIChildNodeDefinitionForm.PROTECTED).getString() ; nodeTypeValue.setReadOnly(Boolean.parseBoolean(isProtected)) ; String parentVer = childDef.getProperty(ON_PARENT_VERSION).getString() ; nodeTypeValue.setOnVersion(Integer.parseInt(parentVer)) ; String requiredTypes = childDef.getProperty(UIChildNodeDefinitionForm.REQUIRED_PRIMARY_TYPE).getString() ; List<String> requiredList = new ArrayList<String>() ; if(requiredTypes != null && requiredTypes.length() > 0) { if(requiredTypes.indexOf(",") > -1){ String[] array = requiredTypes.split(",") ; for(int i = 0; i < array.length; i ++) { requiredList.add(array[i].trim()) ; } } else { requiredList.add(requiredTypes) ; } } nodeTypeValue.setRequiredNodeTypeNames(requiredList) ; addedChildDef_.add(nodeTypeValue) ; setChildValue(addedChildDef_) ; } } public void setPropertyDraftNode(Node draftNodeType) throws Exception { addedPropertiesDef_ = new ArrayList<PropertyDefinitionValue>() ; if(!draftNodeType.hasNode(PROPERTY_DEFINITIONS_NODE)) return ; Node propertiesHome = draftNodeType.getNode(PROPERTY_DEFINITIONS_NODE) ; NodeIterator proIter = propertiesHome.getNodes() ; while (proIter.hasNext()) { Node proDef = proIter.nextNode() ; PropertyDefinitionValue propertyInfo = new PropertyDefinitionValue() ; propertyInfo.setName(proDef.getName()) ; String requiredType = proDef.getProperty(UIPropertyDefinitionForm.REQUIRED_TYPE).getString() ; propertyInfo.setRequiredType(Integer.parseInt(requiredType)) ; String multiple = proDef.getProperty(UIPropertyDefinitionForm.MULTIPLE).getString() ; propertyInfo.setMultiple(Boolean.parseBoolean(multiple)) ; String mandatory = proDef.getProperty(UIPropertyDefinitionForm.MANDATORY).getString() ; propertyInfo.setMandatory(Boolean.parseBoolean(mandatory)) ; String autoCreate = proDef.getProperty(UIPropertyDefinitionForm.AUTOCREATED).getString() ; propertyInfo.setAutoCreate(Boolean.parseBoolean(autoCreate)) ; String isProtected = proDef.getProperty(UIPropertyDefinitionForm.PROTECTED).getString() ; propertyInfo.setReadOnly(Boolean.parseBoolean(isProtected)) ; String onParent = proDef.getProperty(ON_PARENT_VERSION).getString() ; propertyInfo.setOnVersion(Integer.parseInt(onParent)) ; String constraints = proDef.getProperty(UIPropertyDefinitionForm.CONSTRAINTS).getString() ; List<String> valueConst = new ArrayList<String>() ; if(constraints != null && constraints.length() > 0) { if(constraints.indexOf(",") > -1) { String[] array = constraints.split(",") ; for(int i = 0; i < array.length; i ++) { valueConst.add(array[i].trim()) ; } } else { valueConst.add(constraints) ; } } propertyInfo.setValueConstraints(valueConst) ; addedPropertiesDef_.add(propertyInfo) ; setPropertyValue(addedPropertiesDef_) ; } } public void updateEdit(Node draftNodeType, boolean isDraft) throws Exception{ isDraft_ = isDraft ; getUIFormSelectBox(NAMESPACE).setOptions(getNamespaces()) ; String name = draftNodeType.getName() ; String noteTypeName = name ; String namespacesPrefix = ""; if(name.indexOf(":") > -1) { noteTypeName = name.substring(name.indexOf(":") + 1) ; namespacesPrefix = name.substring(0, name.indexOf(":")) ; } getUIStringInput(NODETYPE_NAME).setValue(noteTypeName) ; getUIFormSelectBox(NAMESPACE).setValue(namespacesPrefix) ; getUIStringInput(NODETYPE_NAME).setReadOnly(true); if (draftNodeType.hasProperty(PRIMARY_ITEMNAME)) { String primaryItem = draftNodeType.getProperty(PRIMARY_ITEMNAME).getString() ; getUIStringInput(PRIMARY_ITEMNAME).setValue(primaryItem) ; } getUIFormSelectBox(MIXIN_TYPE).setValue(draftNodeType.getProperty(IS_MIX_IN).getString()) ; String hasOrderable = draftNodeType.getProperty(HAS_ORDERABLE_CHILDNODES).getString() ; getUIFormSelectBox(HAS_ORDERABLE_CHILDNODES).setValue(hasOrderable) ; if (draftNodeType.hasProperty(SUPER_TYPE)) { getUIStringInput(SUPER_TYPE).setValue(draftNodeType.getProperty(SUPER_TYPE).getString()) ; } getUIFormSelectBox(NAMESPACE).setDisabled(true) ; getUIStringInput(NODETYPE_NAME).setReadOnly(true); getUIStringInput(PRIMARY_ITEMNAME).setReadOnly(false); getUIFormSelectBox(MIXIN_TYPE).setDisabled(false) ; getUIFormSelectBox(HAS_ORDERABLE_CHILDNODES).setDisabled(false); getUIStringInput(SUPER_TYPE).setReadOnly(false); setChildDraftNode(draftNodeType) ; setPropertyDraftNode(draftNodeType) ; setActionInTab((UIFormInputSetWithAction)getChildById(NODETYPE_DEFINITION)) ; setActionInTab((UIFormInputSetWithAction)getChildById(CHILDNODE_DEFINITION)) ; setActionInTab((UIFormInputSetWithAction)getChildById(PROPERTY_DEFINITION)) ; } public void refresh() throws Exception{ UIChildNodeDefinitionForm uiChildNodeTab = getChild(UIChildNodeDefinitionForm.class) ; UIPropertyDefinitionForm uiPropertyTab = getChild(UIPropertyDefinitionForm.class) ; getUIFormSelectBox(NAMESPACE).setOptions(getNamespaces()).setDisabled(false) ; getUIStringInput(NODETYPE_NAME).setReadOnly(false).setValue(null) ; getUIStringInput(PRIMARY_ITEMNAME).setReadOnly(false).setValue(null) ; getUIStringInput(SUPER_TYPE).setReadOnly(false).setValue(null) ; getUIFormSelectBox(MIXIN_TYPE).setOptions(mixinTypeOptions_).setDisabled(false) ; getUIFormSelectBox(HAS_ORDERABLE_CHILDNODES).setOptions(orderAbleOptions_).setDisabled(false) ; getUIFormInputInfo(PROPERTY_DEFINITIONS).setValue(null) ; getUIFormInputInfo(CHILDNODE_DEFINITIONS).setValue(null) ; addedPropertiesDef_ = new ArrayList<PropertyDefinitionValue>(); addedChildDef_ = new ArrayList<NodeDefinitionValue>(); UIFormInputSetWithAction uiNodeTypeTab = getChildById(NODETYPE_DEFINITION) ; setSelectedTab(uiNodeTypeTab.getId()) ; //uiNodeTypeTab.setRendered(true) ; uiNodeTypeTab.setIsView(false) ; setActionInTab(uiNodeTypeTab) ; setChildDefinitions(null) ; setPropertyDefinitions(null) ; setChildValue(null) ; setPropertyValue(null) ; uiChildNodeTab.refresh() ; uiPropertyTab.refresh() ; } public void setTabRender(String tabName) { for(UIComponent uiComp : getChildren()) { UIFormInputSetWithAction tab = getChildById(uiComp.getId()) ; if(tab.getId().equals(tabName)) setSelectedTab(tab.getId()) ; } } static public class CancelActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource() ; uiForm.update(null, false) ; uiForm.refresh() ; UIPopupWindow uiPopup = uiForm.getParent() ; uiPopup.setRendered(false) ; uiPopup.setShow(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm) ; } } static public class CloseActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource() ; uiForm.update(null, false) ; uiForm.refresh() ; UIPopupWindow uiPopup = uiForm.getParent() ; uiPopup.setRendered(false) ; uiPopup.setShow(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()) ; } } static public class ViewPropertyActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource() ; String propertyName = event.getRequestContext().getRequestParameter(OBJECTID) ; UIPropertyDefinitionForm uiPropertyForm = uiForm.getChild(UIPropertyDefinitionForm.class) ; uiPropertyForm.update(uiForm.nodeType_, propertyName) ; uiPropertyForm.setRendered(true) ; uiForm.setTabRender(PROPERTY_DEFINITION) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()) ; } } static public class ViewChildNodeActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource() ; String childNodeName = event.getRequestContext().getRequestParameter(OBJECTID) ; UIChildNodeDefinitionForm uiChildNodeForm = uiForm.getChild(UIChildNodeDefinitionForm.class) ; uiChildNodeForm.update(uiForm.nodeType_, childNodeName) ; uiChildNodeForm.setRendered(true) ; uiForm.setTabRender(CHILDNODE_DEFINITION) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()) ; } } static public class SaveActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource() ; UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class) ; NodeTypeManager ntManager = uiForm.getApplicationComponent(RepositoryService.class) .getCurrentRepository().getNodeTypeManager() ; String prefix = uiForm.getUIFormSelectBox(NAMESPACE).getValue() ; String nodeTypeName = uiForm.getUIStringInput(NODETYPE_NAME).getValue() ; if(nodeTypeName == null || nodeTypeName.trim().length() == 0) { uiApp.addMessage(new ApplicationMessage("UINodeTypeForm.msg.nodeType-name", null, ApplicationMessage.WARNING)) ; uiForm.setTabRender(NODETYPE_DEFINITION) ; return ; } if (prefix != null && prefix.length() > 0) { StringBuffer sb = new StringBuffer(); sb.append(prefix).append(":").append(nodeTypeName); nodeTypeName = sb.toString(); } String superTypes = uiForm.getUIStringInput(SUPER_TYPE).getValue() ; if(uiForm.getUIFormSelectBox(MIXIN_TYPE).getValue().equals("false")) { if(superTypes == null || superTypes.trim().length() == 0) { uiApp.addMessage(new ApplicationMessage("UINodeTypeForm.msg.supertype-is-madatory", null, ApplicationMessage.WARNING)) ; uiForm.setTabRender(NODETYPE_DEFINITION) ; return ; } } List<String> listTypes = new ArrayList<String>() ; if(superTypes != null) { if(superTypes.indexOf(",") > -1) { String[] arrayTypes = superTypes.split(",") ; for(String type :arrayTypes ) { listTypes.add(type.trim()) ; } } else { listTypes.add(superTypes.trim()) ; } } String primaryItemName = uiForm.getUIStringInput(PRIMARY_ITEMNAME).getValue() ; NodeTypeValue newNodeType = new NodeTypeValue() ; newNodeType.setName(nodeTypeName) ; newNodeType.setPrimaryItemName(primaryItemName) ; newNodeType.setMixin(Boolean.parseBoolean(uiForm.getUIFormSelectBox(MIXIN_TYPE).getValue())) ; String orderableChild = uiForm.getUIFormSelectBox(HAS_ORDERABLE_CHILDNODES).getValue() ; newNodeType.setOrderableChild(Boolean.parseBoolean(orderableChild)) ; newNodeType.setDeclaredSupertypeNames(listTypes) ; newNodeType.setDeclaredPropertyDefinitionValues(uiForm.addedPropertiesDef_) ; newNodeType.setDeclaredChildNodeDefinitionValues(uiForm.addedChildDef_) ; ExtendedNodeTypeManager extNTManager = (ExtendedNodeTypeManager)ntManager ; try { extNTManager.registerNodeType(newNodeType, ExtendedNodeTypeManager.FAIL_IF_EXISTS) ; } catch(Exception e) { uiApp.addMessage(new ApplicationMessage("UINodeTypeForm.msg.register-failed", null, ApplicationMessage.WARNING)) ; uiForm.setTabRender(NODETYPE_DEFINITION) ; return ; } UINodeTypeManager uiManager = uiForm.getAncestorOfType(UINodeTypeManager.class) ; UINodeTypeList nodeTypeList = uiManager.getChild(UINodeTypeList.class) ; if(uiForm.isDraft_){ uiForm.isDraft_ = false ; nodeTypeList.refresh(nodeTypeName, nodeTypeList.getUIPageIterator().getCurrentPage()); } else { nodeTypeList.refresh(null, nodeTypeList.getUIPageIterator().getCurrentPage()); } uiForm.refresh() ; uiForm.setTabRender(NODETYPE_DEFINITION) ; UIPopupWindow uiPopup = uiForm.getParent() ; uiPopup.setRendered(false) ; uiPopup.setShowMask(true); Object[] args = { newNodeType.getName() } ; uiApp.addMessage(new ApplicationMessage("UINodeTypeForm.msg.register-successfully", args)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class SaveDraftActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource() ; UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class) ; ManageableRepository mRepository = uiForm.getApplicationComponent(RepositoryService.class).getCurrentRepository() ; String systemWorkspace = mRepository.getConfiguration().getDefaultWorkspaceName() ; Session session = mRepository.getSystemSession(systemWorkspace) ; String prefix = uiForm.getUIFormSelectBox(NAMESPACE).getValue() ; String nodeTypeName = uiForm.getUIStringInput(NODETYPE_NAME).getValue().trim(); if(nodeTypeName == null || nodeTypeName.trim().length() == 0) { uiApp.addMessage(new ApplicationMessage("UINodeTypeForm.msg.nodeType-name", null, ApplicationMessage.WARNING)) ; uiForm.setTabRender(NODETYPE_DEFINITION) ; session.logout(); return ; } if (prefix != null && prefix.length() > 0) { StringBuffer sb = new StringBuffer(); sb.append(prefix).append(":").append(nodeTypeName); nodeTypeName = sb.toString(); } Node systemNode = (Node)session.getItem("/jcr:system") ; Node nodeTypeDraft ; if(systemNode.hasNode(JCR_NODETYPE_DRAFT)) { nodeTypeDraft = systemNode.getNode(JCR_NODETYPE_DRAFT) ; } else { nodeTypeDraft = systemNode.addNode(JCR_NODETYPE_DRAFT, NT_UNSTRUCTURED) ; } systemNode.save() ; Node newNode ; if(nodeTypeDraft.hasNode(nodeTypeName)) newNode = nodeTypeDraft.getNode(nodeTypeName) ; else newNode = nodeTypeDraft.addNode(nodeTypeName, NT_UNSTRUCTURED) ; nodeTypeDraft.save() ; newNode.setProperty(PRIMARY_ITEMNAME, uiForm.getUIStringInput(PRIMARY_ITEMNAME).getValue()) ; newNode.setProperty(IS_MIX_IN, uiForm.getUIFormSelectBox(MIXIN_TYPE).getValue()) ; String hasOrderable = uiForm.getUIFormSelectBox(HAS_ORDERABLE_CHILDNODES).getValue() ; newNode.setProperty(HAS_ORDERABLE_CHILDNODES, hasOrderable) ; String superTypes = uiForm.getUIStringInput(SUPER_TYPE).getValue() ; newNode.setProperty(SUPER_TYPE, superTypes) ; newNode.save() ; nodeTypeDraft.save() ; if(uiForm.addedPropertiesDef_ .size() > 0) { Node propertyDef ; if(newNode.hasNode(PROPERTY_DEFINITIONS_NODE)) { propertyDef = newNode.getNode(PROPERTY_DEFINITIONS_NODE) ; } else { propertyDef = newNode.addNode(PROPERTY_DEFINITIONS_NODE, NT_UNSTRUCTURED) ; } newNode.save() ; propertyDef.save() ; for(int i = 0; i < uiForm.addedPropertiesDef_.size(); i ++) { PropertyDefinitionValue property = uiForm.addedPropertiesDef_.get(i) ; Node propertyNode ; if(propertyDef.hasNode(property.getName())) { propertyNode = propertyDef.getNode(property.getName()) ; } else { propertyNode = propertyDef.addNode(property.getName(), NT_UNSTRUCTURED) ; propertyNode.setProperty(PROPERTY_NAME, property.getName()) ; } String requiredType = String.valueOf(property.getRequiredType()) ; propertyNode.setProperty(UIPropertyDefinitionForm.REQUIRED_TYPE, requiredType) ; String autoCreate = String.valueOf(property.isAutoCreate()) ; propertyNode.setProperty(UIPropertyDefinitionForm.AUTOCREATED, autoCreate) ; String isProtected = String.valueOf(property.isReadOnly()) ; propertyNode.setProperty(UIPropertyDefinitionForm.PROTECTED, isProtected) ; String mandatory = String.valueOf(property.isMandatory()) ; propertyNode.setProperty(UIPropertyDefinitionForm.MANDATORY, mandatory) ; propertyNode.setProperty(ON_PARENT_VERSION, String.valueOf(property.getOnVersion())) ; String multiple = String.valueOf(property.isMultiple()) ; propertyNode.setProperty(UIPropertyDefinitionForm.MULTIPLE, multiple) ; List<String> valueConstraint = property.getValueConstraints() ; StringBuilder values = new StringBuilder() ; for(int j = 0; j < valueConstraint.size(); j ++) { if(values.length() > 0) values.append(", ") ; values.append(valueConstraint.get(j).toString()) ; } propertyNode.setProperty(UIPropertyDefinitionForm.CONSTRAINTS, values.toString()) ; propertyDef.save() ; propertyNode.save() ; } } if(uiForm.addedChildDef_.size() > 0) { Node childDef ; if(newNode.hasNode(CHILD_NODE_DEFINITIONS)) { childDef = newNode.getNode(CHILD_NODE_DEFINITIONS) ; } else { childDef = newNode.addNode(CHILD_NODE_DEFINITIONS, NT_UNSTRUCTURED) ; } newNode.save() ; childDef.save() ; for(int i = 0; i < uiForm.addedChildDef_.size(); i ++ ){ NodeDefinitionValue nodeDef = uiForm.addedChildDef_.get(i) ; Node childNode ; if(childDef.hasNode(nodeDef.getName())) { childNode = childDef.getNode(nodeDef.getName()) ; } else { childNode = childDef.addNode(nodeDef.getName(), NT_UNSTRUCTURED) ; childNode.setProperty(PROPERTY_NAME, nodeDef.getName()) ; } String defaultPrimaryType = nodeDef.getDefaultNodeTypeName() ; childNode.setProperty(UIChildNodeDefinitionForm.DEFAULT_PRIMARY_TYPE, defaultPrimaryType) ; String autoCreate = String.valueOf(nodeDef.isAutoCreate()) ; childNode.setProperty(UIChildNodeDefinitionForm.AUTOCREATED, autoCreate) ; String isProtected = String.valueOf(nodeDef.isReadOnly()) ; childNode.setProperty(UIChildNodeDefinitionForm.PROTECTED, isProtected) ; String mandatory = String.valueOf(nodeDef.isMandatory()) ; childNode.setProperty(UIChildNodeDefinitionForm.MANDATORY, mandatory) ; childNode.setProperty(ON_PARENT_VERSION, String.valueOf(nodeDef.getOnVersion())) ; String sameName = String.valueOf(nodeDef.isSameNameSiblings()) ; childNode.setProperty(UIChildNodeDefinitionForm.SAME_NAME, sameName) ; if(nodeDef.getRequiredNodeTypeNames().size() > 0 ) { StringBuilder requiredTypes = new StringBuilder("") ; for(int j = 0; j < nodeDef.getRequiredNodeTypeNames().size(); j ++) { if( requiredTypes.length() > 0) requiredTypes.append(",") ; requiredTypes.append(nodeDef.getRequiredNodeTypeNames().get(j).toString()) ; } childNode.setProperty(UIChildNodeDefinitionForm.REQUIRED_PRIMARY_TYPE, requiredTypes.toString()) ; } else { childNode.setProperty(UIChildNodeDefinitionForm.REQUIRED_PRIMARY_TYPE, "") ; } childDef.save() ; childNode.save() ; } } session.save() ; session.logout(); UINodeTypeManager uiManager = uiForm.getAncestorOfType(UINodeTypeManager.class) ; UINodeTypeList nodeTypeList = uiManager.getChild(UINodeTypeList.class) ; nodeTypeList.refresh(null, nodeTypeList.getUIPageIterator().getCurrentPage()); uiForm.refresh() ; uiForm.setTabRender(NODETYPE_DEFINITION) ; UIPopupWindow uiPopup = uiForm.getParent() ; uiPopup.setRendered(false) ; uiPopup.setShowMask(true); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class AddSuperTypeActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource() ; UIFormInputSetWithAction superTypeTab = new UINodeTypeOptionList(SUPER_TYPE_TAB) ; uiForm.removeChildTabs(new String[] {DEFAULT_PRIMARY_TYPE_TAB, REQUIRED_PRIMARY_TYPE_TAB}) ; if(superTypeTab.isRendered()) uiForm.removeChildById(SUPER_TYPE_TAB) ; String[] actionNames = new String[] {ADD_TYPE, ACTION_CANCEL_TAB} ; String[] fieldNames = new String[] {SUPER_TYPE, SUPER_TYPE_TAB} ; superTypeTab.setActions(actionNames, fieldNames) ; uiForm.addUIComponentInput(superTypeTab) ; uiForm.setTabRender(SUPER_TYPE_TAB) ; UINodeTypeOptionList uiOptionList = uiForm.getChild(UINodeTypeOptionList.class) ; String superTypeValue = uiForm.getUIStringInput(SUPER_TYPE).getValue() ; uiOptionList.update(superTypeValue) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()) ; } } static public class SelectTabActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> 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); } } } static public class IsMixinActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); if (uiForm.getUIFormSelectBox(MIXIN_TYPE).getValue().equals("true") && uiForm.getUIStringInput(SUPER_TYPE).getValidators().size() > 0) { uiForm.removeMandatoryValidator(); } if (uiForm.getUIFormSelectBox(MIXIN_TYPE).getValue().equals("false")) { if (uiForm.getUIStringInput(SUPER_TYPE).getValidators().size() == 0) { uiForm.getUIStringInput(SUPER_TYPE).addValidator(MandatoryValidator.class); } else { boolean isMandatoryValidator = false; List<Validator> validators = uiForm.getUIStringInput(SUPER_TYPE).getValidators(); for (Object obj: validators) { if (obj instanceof MandatoryValidator) { isMandatoryValidator = true; } } if (!isMandatoryValidator) { uiForm.getUIStringInput(SUPER_TYPE).addValidator(MandatoryValidator.class); } } } } } private void removeMandatoryValidator() { List<Validator> validators = getUIStringInput(SUPER_TYPE).getValidators(); int index = -1; for (int i = 0; i < validators.size(); i++) { if ((validators.get(i) instanceof MandatoryValidator)) { index = i; break; } } if (index > -1) { validators.remove(index); } } }
44,782
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINodeTypeImport.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/nodetype/UINodeTypeImport.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.admin.nodetype; import java.util.ArrayList; import java.util.List; import javax.jcr.NamespaceException; import javax.jcr.RepositoryException; import javax.jcr.nodetype.NoSuchNodeTypeException; import javax.jcr.nodetype.NodeType; import javax.jcr.nodetype.NodeTypeManager; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager; import org.exoplatform.services.jcr.core.nodetype.NodeTypeValue; 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.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.UIFormInputInfo; import org.exoplatform.webui.form.UIFormInputSet; import org.exoplatform.webui.form.UIFormTableInputSet; import org.exoplatform.webui.form.input.UICheckBoxInput; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Sep 29, 2006 * 12:02:38 PM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "classpath:groovy/ecm/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UINodeTypeImport.ImportActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UINodeTypeImport.UploadActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UINodeTypeImport.CancelActionListener.class) } ) public class UINodeTypeImport extends UIForm { private List<NodeTypeValue> nodeTypeList_ = new ArrayList<NodeTypeValue>() ; final static String TABLE_NAME = "uiTableInputSetName"; final static String [] TABLE_COLUMNS = {"label", "input"}; private static final Log LOG = ExoLogger.getLogger(UINodeTypeImport.class.getName()); private List<String> undefinedNodeType = new ArrayList<String>(); private List<String> registeredNodeType = new ArrayList<String>(); private List<String> undefinedNamespace = new ArrayList<String>(); public List<String> getUndefinedNamespace() { return undefinedNamespace; } public void setUndefinedNamespace(List<String> undefinedNamespace) { this.undefinedNamespace = undefinedNamespace; } public List<String> getUndefinedNodeTypes() { return undefinedNodeType; } public void setUndefinedNodeType(List<String> undefinedNodeType) { this.undefinedNodeType = undefinedNodeType; } public UINodeTypeImport() throws Exception { } public void update(ArrayList<NodeTypeValue> nodeTypeList) throws Exception { UIFormTableInputSet uiTableInputSet = getChild(UIFormTableInputSet.class) ; if(uiTableInputSet == null ) { uiTableInputSet = createUIComponent(UIFormTableInputSet.class, null, "uiTableInputSetID") ; addUIComponentInput(uiTableInputSet) ; } else { uiTableInputSet.getChildren().clear() ; } NodeTypeManager ntManager = getApplicationComponent(RepositoryService.class). getCurrentRepository().getNodeTypeManager() ; UIFormInputSet uiInputSet ; uiTableInputSet.setName(TABLE_NAME); uiTableInputSet.setColumns(TABLE_COLUMNS); getUndefinedNodeTypes().clear(); getUndefinedNamespace().clear(); getRegisteredNodeType().clear(); nodeTypeList_ = nodeTypeList ; UIFormInputInfo uiInfo; String nodeTypeName; NodeTypeValue nodeTypeValue; UICheckBoxInput checkbox; NodeType register = null; for(int i = 0 ; i < nodeTypeList_.size() ; i ++) { nodeTypeValue = (NodeTypeValue)nodeTypeList_.get(i) ; nodeTypeName = nodeTypeValue.getName() ; uiInputSet = new UIFormInputSet(nodeTypeName) ; uiInfo = new UIFormInputInfo("label", null, nodeTypeName); uiInputSet.addChild(uiInfo); checkbox = new UICheckBoxInput(nodeTypeName, nodeTypeName, null) ; try { register = ntManager.getNodeType(nodeTypeName) ; uiInputSet.addChild(checkbox); uiTableInputSet.addChild(uiInputSet); if(register != null) { getRegisteredNodeType().add(nodeTypeName); checkbox.setDisabled(true); } } catch (NamespaceException e) { if (nodeTypeName != null && nodeTypeName.contains(":")) { getUndefinedNamespace().add( nodeTypeName.substring(0, nodeTypeName.indexOf(":"))); } } catch (NoSuchNodeTypeException e) { getUndefinedNodeTypes().add(nodeTypeName); uiInputSet.addChild(checkbox); uiTableInputSet.addChild(uiInputSet); checkbox.setDisabled(false); } catch (RepositoryException e) { if (NamespaceException.class.isInstance(e.getCause())) { if (nodeTypeName != null && nodeTypeName.contains(":")) { getUndefinedNamespace().add( nodeTypeName.substring(0, nodeTypeName.indexOf(":"))); } } else { throw e; } } } } public String getLabel(String id) { return "label" + id ; } public void setRegisteredNodeType(List<String> registeredNodeType) { this.registeredNodeType = registeredNodeType; } public List<String> getRegisteredNodeType() { return registeredNodeType; } static public class CancelActionListener extends EventListener<UINodeTypeImport> { public void execute(Event<UINodeTypeImport> event) throws Exception { UINodeTypeImport uiImport = event.getSource() ; UINodeTypeImportPopup uiImportPopup = uiImport.getParent() ; uiImportPopup.setRenderedChild(UINodeTypeUpload.class) ; UIPopupWindow uiPopup = uiImportPopup.getParent() ; uiPopup.setRendered(false) ; } } static public class UploadActionListener extends EventListener<UINodeTypeImport> { public void execute(Event<UINodeTypeImport> event) throws Exception { UINodeTypeImport uiImport = event.getSource() ; UINodeTypeManager uiManager = uiImport.getAncestorOfType(UINodeTypeManager.class) ; UIPopupWindow uiPopup = uiManager.findComponentById(UINodeTypeManager.IMPORT_POPUP) ; UINodeTypeImportPopup uiImportPopup = uiImport.getParent() ; uiImportPopup.setRenderedChild(UINodeTypeUpload.class) ; uiPopup.setShow(true) ; } } static public class ImportActionListener extends EventListener<UINodeTypeImport> { public void execute(Event<UINodeTypeImport> event) throws Exception { UINodeTypeImport uiImport = event.getSource() ; RepositoryService repositoryService = uiImport.getApplicationComponent(RepositoryService.class) ; NodeTypeManager ntManager = repositoryService.getCurrentRepository().getNodeTypeManager() ; UINodeTypeManager uiManager = uiImport.getAncestorOfType(UINodeTypeManager.class) ; UINodeTypeImportPopup uiImportPopup = uiImport.getParent() ; uiImportPopup.setRenderedChild(UINodeTypeUpload.class) ; UIApplication uiApp = uiImport.getAncestorOfType(UIApplication.class) ; ExtendedNodeTypeManager extManager = (ExtendedNodeTypeManager) ntManager ; int counter = 0 ; List<UICheckBoxInput> listCheckbox = new ArrayList<UICheckBoxInput>(); uiImport.findComponentOfType(listCheckbox, UICheckBoxInput.class); for(int i = 0 ; i < uiImport.nodeTypeList_.size() ; i ++){ NodeTypeValue nodeTypeValue = (NodeTypeValue)uiImport.nodeTypeList_.get(i) ; if(listCheckbox.get(i).isChecked()) { try { extManager.registerNodeType(nodeTypeValue, ExtendedNodeTypeManager.IGNORE_IF_EXISTS) ; counter += 1 ; } catch(RepositoryException re) { if (LOG.isErrorEnabled()) { LOG.error("Cannot register nodetype " + nodeTypeValue + " cause by: " + re.getMessage()); } } } } if(counter > 0) { String[] count = {String.valueOf(counter)} ; UINodeTypeList uiNodeTypeList = uiManager.getChild(UINodeTypeList.class) ; uiNodeTypeList.refresh(uiNodeTypeList.getUIPageIterator().getCurrentPage()); UIPopupWindow uiPopup = uiManager.findComponentById(UINodeTypeManager.IMPORT_POPUP) ; uiPopup.setRendered(false) ; uiApp.addMessage(new ApplicationMessage("UINodeTypeImport.msg.nodetype-registered", count)) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; return ; } uiApp.addMessage(new ApplicationMessage("UINodeTypeImport.msg.no-nodetype-registered", null)) ; } } }
9,699
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINodeTypeSearchForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/nodetype/UINodeTypeSearchForm.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.admin.nodetype; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import javax.jcr.Node; import org.exoplatform.ecm.webui.nodetype.selector.UINodeTypeSearch; 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; /** * Created by The eXo Platform SARL * Author : Hoang Van Hung * hunghvit@gmail.com * Dec 23, 2009 */ @ComponentConfig ( lifecycle = UIFormLifecycle.class, events = { @EventConfig(listeners = UINodeTypeSearchForm.SearchNodeTypeActionListener.class) } ) public class UINodeTypeSearchForm extends UIForm { public UINodeTypeSearchForm() throws Exception { addChild(UINodeTypeSearch.class, null, "NodeTypeSearch").init(); } @SuppressWarnings("unchecked") public static class SearchNodeTypeActionListener extends EventListener<UINodeTypeSearchForm> { public void execute(Event<UINodeTypeSearchForm> event) throws Exception { UINodeTypeSearchForm uiForm = event.getSource(); UINodeTypeManager uiNodeTypeManager = uiForm.getAncestorOfType(UINodeTypeManager.class); UINodeTypeList uiNodeTypeList = uiNodeTypeManager.getChild(UINodeTypeList.class); try { UIFormStringInput uiInputNodeType = (UIFormStringInput)uiForm.findComponentById("NodeTypeText"); String nodeTypeName = uiInputNodeType.getValue(); if (nodeTypeName == null || nodeTypeName.length() == 0) return; if (nodeTypeName.contains("*") && !nodeTypeName.contains(".*")) { nodeTypeName = nodeTypeName.replace("*", ".*"); } Pattern p = Pattern.compile(".*".concat(nodeTypeName.trim()).concat(".*"), Pattern.CASE_INSENSITIVE); List lstAllNodetype = uiNodeTypeList.getAllNodeTypes(); List lstNodetype = new ArrayList<UINodeTypeList.NodeTypeBean>(); for (Object nodeType : lstAllNodetype) { if (nodeType instanceof UINodeTypeList.NodeTypeBean) { if (p.matcher(((UINodeTypeList.NodeTypeBean) nodeType).getName()).find()) { lstNodetype.add(nodeType); } } else if (nodeType instanceof Node) { if (p.matcher(((Node) nodeType).getName()).find()) { lstNodetype.add(nodeType); } } } uiNodeTypeList.refresh(null, 1, lstNodetype); event.getRequestContext().addUIComponentToUpdateByAjax(uiNodeTypeManager) ; } catch (PatternSyntaxException pSyntaxException) { uiNodeTypeList.refresh(null, 1, new ArrayList<UINodeTypeList.NodeTypeBean>()); event.getRequestContext().addUIComponentToUpdateByAjax(uiNodeTypeManager) ; } } } }
4,032
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINodeTypeExport.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/nodetype/UINodeTypeExport.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.admin.nodetype; import java.io.ByteArrayInputStream; import java.util.ArrayList; import java.util.List; import javax.jcr.nodetype.NodeDefinition; import javax.jcr.nodetype.NodeType; import javax.jcr.nodetype.NodeTypeIterator; import javax.jcr.nodetype.NodeTypeManager; import javax.jcr.nodetype.PropertyDefinition; import org.exoplatform.download.DownloadResource; import org.exoplatform.download.DownloadService; import org.exoplatform.download.InputStreamDownloadResource; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.web.application.ApplicationMessage; 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.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.UIFormInputInfo; import org.exoplatform.webui.form.UIFormInputSet; import org.exoplatform.webui.form.UIFormTableInputSet; import org.exoplatform.webui.form.input.UICheckBoxInput; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Sep 29, 2006 * 12:01:58 PM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "classpath:groovy/ecm/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UINodeTypeExport.ExportActionListener.class), @EventConfig(phase=Phase.DECODE, listeners = UINodeTypeExport.CancelActionListener.class), @EventConfig(listeners = UINodeTypeExport.UncheckAllActionListener.class), @EventConfig(listeners = UINodeTypeExport.CheckAllActionListener.class) } ) public class UINodeTypeExport extends UIForm { final static String TABLE_NAME = "UINodeTypeExport" ; final static String LABEL = "label" ; final static String INPUT = "input" ; final static String[] TABLE_COLUMNS = {LABEL, INPUT} ; private List<NodeType> nodeTypeList_ = new ArrayList<NodeType>() ; public UINodeTypeExport() throws Exception { } public void update() throws Exception { UIFormTableInputSet uiTableInputSet = createUIComponent(UIFormTableInputSet.class, null, null) ; NodeTypeManager ntManager = getApplicationComponent(RepositoryService.class) .getCurrentRepository().getNodeTypeManager() ; NodeTypeIterator nodeTypeIter = ntManager.getAllNodeTypes() ; UIFormInputSet uiInputSet ; uiTableInputSet.setName(TABLE_NAME); uiTableInputSet.setColumns(TABLE_COLUMNS); while(nodeTypeIter.hasNext()){ NodeType nt = nodeTypeIter.nextNodeType() ; nodeTypeList_.add(nt) ; String ntName = nt.getName() ; uiInputSet = new UIFormInputSet(ntName) ; UIFormInputInfo uiInfo = new UIFormInputInfo(LABEL, null, ntName); uiInputSet.addChild(uiInfo); UICheckBoxInput uiCheckbox = new UICheckBoxInput(ntName, ntName, true); uiInputSet.addChild(uiCheckbox); uiTableInputSet.addChild(uiInputSet); } setActions(new String[] {"Export", "Cancel", "UncheckAll"}) ; addUIFormInput(uiTableInputSet) ; } public String getLabel(String id) { return id ; } public NodeType getNodeTypeByName(String nodeTypeName) throws Exception { NodeType nodeTypeSelected = null ; for(NodeType node : nodeTypeList_) { if(node.getName().equals(nodeTypeName)) { nodeTypeSelected = node ; break ; } } return nodeTypeSelected ; } static public class ExportActionListener extends EventListener<UINodeTypeExport> { public void execute(Event<UINodeTypeExport> event) throws Exception { UINodeTypeExport uiExport = event.getSource() ; UINodeTypeManager uiManager = uiExport.getAncestorOfType(UINodeTypeManager.class) ; UIApplication uiApp = uiExport.getAncestorOfType(UIApplication.class) ; List<NodeType> selectedNodes = new ArrayList<NodeType>() ; List<UICheckBoxInput> listCheckbox = new ArrayList<UICheckBoxInput>(); uiExport.findComponentOfType(listCheckbox, UICheckBoxInput.class); for(int i = 0; i < listCheckbox.size(); i ++) { boolean checked = listCheckbox.get(i).isChecked() ; if(checked) selectedNodes.add(uiExport.getNodeTypeByName(listCheckbox.get(i).getName())) ; } if(selectedNodes.size() == 0) { uiApp.addMessage(new ApplicationMessage("UINodeTypeExport.msg.item-null", null)) ; return ; } String nodeTypeXML = getNodeTypeXML(selectedNodes) ; ByteArrayInputStream is = new ByteArrayInputStream(nodeTypeXML.getBytes()) ; DownloadResource dresource = new InputStreamDownloadResource(is, "text/xml") ; DownloadService dservice = uiExport.getApplicationComponent(DownloadService.class) ; dresource.setDownloadName("nodetype_export.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 + "');"); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; UIPopupWindow uiPopup = uiManager.findComponentById(UINodeTypeManager.EXPORT_POPUP) ; uiPopup.setShowMask(true); uiPopup.setRendered(false) ; } private String getNodeTypeXML(List<NodeType> selectedNodes) { StringBuilder nodeTypeXML = new StringBuilder() ; nodeTypeXML.append("<nodeTypes xmlns:nt=").append("\"") ; nodeTypeXML.append("http://www.jcp.org/jcr/nt/1.5").append("\" ") ; nodeTypeXML.append("xmlns:mix=").append("\"") ; nodeTypeXML.append("http://www.jcp.org/jcr/mix/1.5").append("\" ") ; nodeTypeXML.append("xmlns:jcr=").append("\"").append("http://www.jcp.org/jcr/1.5") ; nodeTypeXML.append("\" >").append("\n") ; for(int i = 0; i < selectedNodes.size(); i++) { NodeType nodeType = selectedNodes.get(i) ; nodeTypeXML.append("<nodeType ") ; nodeTypeXML.append("name=").append("\"").append(nodeType.getName()).append("\" ") ; String isMixIn = String.valueOf(nodeType.isMixin()) ; nodeTypeXML.append("isMixin=").append("\"").append(String.valueOf(isMixIn)).append("\" ") ; String hasOrderable = String.valueOf(nodeType.hasOrderableChildNodes()) ; nodeTypeXML.append("hasOrderableChildNodes=\"").append(hasOrderable).append("\" ") ; String primaryItemName = ""; if(nodeType.getPrimaryItemName() != null) primaryItemName = nodeType.getPrimaryItemName() ; nodeTypeXML.append("primaryItemName=").append("\"").append(primaryItemName).append("\" >") ; nodeTypeXML.append("\n") ; // represent supertypes String representSuperType = representSuperTypes(nodeType) ; nodeTypeXML.append(representSuperType) ; // represent PropertiesDefinition String representPropertiesXML = representPropertyDefinition(nodeType) ; nodeTypeXML.append(representPropertiesXML) ; // represent ChildNodeDefinition String representChildXML = representChildNodeDefinition(nodeType) ; nodeTypeXML.append(representChildXML) ; nodeTypeXML.append("</nodeType>").append("\n") ; } nodeTypeXML.append("</nodeTypes>") ; return nodeTypeXML.toString() ; } private String representSuperTypes(NodeType nodeType){ StringBuilder superTypeXML = new StringBuilder() ; NodeType[] superType = nodeType.getDeclaredSupertypes() ; if(superType != null && superType.length > 0){ superTypeXML.append("<supertypes>").append("\n") ; for(int i = 0 ; i < superType.length ; i ++){ String typeName = superType[i].getName() ; superTypeXML.append("<supertype>").append(typeName).append("</supertype>").append("\n") ; } superTypeXML.append("</supertypes>").append("\n") ; } return superTypeXML.toString() ; } private String representPropertyDefinition(NodeType nodeType) { String[] requireType = {"undefined", "String", "Binary", "Long", "Double", "Date", "Boolean", "Name", "Path", "Reference"} ; String[] onparentVersion = {"", "COPY", "VERSION", "INITIALIZE", "COMPUTE", "IGNORE", "ABORT"} ; StringBuilder propertyXML = new StringBuilder() ; propertyXML.append("<propertyDefinitions>").append("\n") ; PropertyDefinition[] proDef = nodeType.getPropertyDefinitions() ; for(int j = 0 ; j < proDef.length; j ++) { propertyXML.append("<propertyDefinition ") ; propertyXML.append("name=").append("\"").append(proDef[j].getName()).append("\" ") ; String requiredValue = null ; if(proDef[j].getRequiredType() == 100) requiredValue = "Permission" ; else requiredValue = requireType[proDef[j].getRequiredType()] ; propertyXML.append("requiredType=").append("\"").append(requiredValue).append("\" ") ; String autoCreate = String.valueOf(proDef[j].isAutoCreated()) ; propertyXML.append("autoCreated=").append("\"").append(autoCreate).append("\" ") ; String mandatory = String.valueOf(proDef[j].isMandatory()) ; propertyXML.append("mandatory=").append("\"").append(mandatory).append("\" ") ; String onVersion = onparentVersion[proDef[j].getOnParentVersion()] ; propertyXML.append("onParentVersion=").append("\"").append(onVersion).append("\" ") ; String protect = String.valueOf(proDef[j].isProtected()) ; propertyXML.append("protected=").append("\"").append(protect).append("\" ") ; String multiple = String.valueOf(proDef[j].isMultiple()) ; propertyXML.append("multiple=").append("\"").append(multiple).append("\" >").append("\n") ; String[] constraints = proDef[j].getValueConstraints() ; if(constraints != null && constraints.length > 0) { propertyXML.append("<valueConstraints>").append("\n") ; for(int k = 0; k < constraints.length ; k ++) { String cons = constraints[k].toString() ; propertyXML.append("<valueConstraint>").append(cons).append("</valueConstraint>") ; propertyXML.append("\n") ; } propertyXML.append("</valueConstraints>").append("\n") ; } else { propertyXML.append("<valueConstraints/>").append("\n") ; } propertyXML.append("</propertyDefinition>").append("\n") ; } propertyXML.append("</propertyDefinitions>").append("\n") ; return propertyXML.toString() ; } private String representChildNodeDefinition(NodeType nodeType) { String[] onparentVersion = {"","COPY","VERSION","INITIALIZE","COMPUTE","IGNORE","ABORT"} ; StringBuilder childNodeXML = new StringBuilder() ; NodeDefinition[] childDef = nodeType.getChildNodeDefinitions() ; if(childDef != null && childDef.length > 0) { childNodeXML.append("<childNodeDefinitions>").append("\n") ; for(int j = 0 ; j < childDef.length ; j ++){ childNodeXML.append("<childNodeDefinition ") ; childNodeXML.append("name=").append("\"").append(childDef[j].getName()).append("\" ") ; NodeType defaultType = childDef[j].getDefaultPrimaryType() ; if(defaultType != null) { String defaultName = defaultType.getName() ; childNodeXML.append("defaultPrimaryType=").append("\"").append(defaultName).append("\" ") ; } else { childNodeXML.append("defaultPrimaryType=").append("\"").append("\" ") ; } String autoCreate = String.valueOf(childDef[j].isAutoCreated()) ; childNodeXML.append("autoCreated=").append("\"").append(autoCreate).append("\" ") ; String mandatory = String.valueOf(childDef[j].isMandatory()) ; childNodeXML.append("mandatory=").append("\"").append(mandatory).append("\" ") ; String onVersion = onparentVersion[childDef[j].getOnParentVersion()] ; childNodeXML.append("onParentVersion=").append("\"").append(onVersion).append("\" ") ; String protect = String.valueOf(childDef[j].isProtected()) ; childNodeXML.append("protected=").append("\"").append(protect).append("\" ") ; String sameName = String.valueOf(childDef[j].allowsSameNameSiblings()) ; childNodeXML.append("sameNameSiblings=").append("\"").append(sameName).append("\" >") ; childNodeXML.append("\n") ; NodeType[] requiredType = childDef[j].getRequiredPrimaryTypes() ; if(requiredType != null && requiredType.length > 0 ) { childNodeXML.append("<requiredPrimaryTypes>").append("\n") ; for(int k = 0 ; k < requiredType.length ; k ++) { String requiredName = requiredType[k].getName() ; childNodeXML.append("<requiredPrimaryType>").append(requiredName) ; childNodeXML.append("</requiredPrimaryType>").append("\n") ; } childNodeXML.append("</requiredPrimaryTypes>").append("\n") ; } childNodeXML.append("</childNodeDefinition>").append("\n") ; } childNodeXML.append("</childNodeDefinitions>").append("\n") ; } return childNodeXML.toString() ; } } static public class CancelActionListener extends EventListener<UINodeTypeExport> { public void execute(Event<UINodeTypeExport> event) throws Exception { UINodeTypeExport uiExport = event.getSource() ; UINodeTypeManager uiManager = uiExport.getAncestorOfType(UINodeTypeManager.class) ; UIPopupWindow uiPopup = uiManager.findComponentById(UINodeTypeManager.EXPORT_POPUP) ; uiPopup.setShowMask(true); uiPopup.setRendered(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class UncheckAllActionListener extends EventListener<UINodeTypeExport> { public void execute(Event<UINodeTypeExport> event) throws Exception { UINodeTypeExport uiExport = event.getSource() ; List<UICheckBoxInput> listCheckbox = new ArrayList<UICheckBoxInput>(); uiExport.findComponentOfType(listCheckbox, UICheckBoxInput.class); for(int i = 0; i < listCheckbox.size(); i ++) { listCheckbox.get(i).setChecked(false) ; } uiExport.setActions(new String[] {"Export", "Cancel", "CheckAll"}) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiExport.getParent()) ; } } static public class CheckAllActionListener extends EventListener<UINodeTypeExport> { public void execute(Event<UINodeTypeExport> event) throws Exception { UINodeTypeExport uiExport = event.getSource() ; List<UICheckBoxInput> listCheckbox = new ArrayList<UICheckBoxInput>(); uiExport.findComponentOfType(listCheckbox, UICheckBoxInput.class); for(int i = 0; i < listCheckbox.size(); i ++) { listCheckbox.get(i).setChecked(true) ; } uiExport.setActions(new String[] {"Export", "Cancel", "UncheckAll"}) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiExport.getParent()) ; } } }
16,453
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIPropertyDefinitionForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/nodetype/UIPropertyDefinitionForm.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.admin.nodetype; import java.util.ArrayList; import java.util.List; import javax.jcr.nodetype.NodeType; import javax.jcr.nodetype.PropertyDefinition; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionValue; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; 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; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Sep 21, 2006 * 3:36:17 PM */ @ComponentConfig( template = "classpath:groovy/ecm/webui/form/UIFormInputSetWithAction.gtmpl" ) public class UIPropertyDefinitionForm extends UIFormInputSetWithAction { final static public String NAMESPACE = "propertyNamespace"; final static public String DEFINITION_NAME = "propertyname"; final static public String REQUIRED_TYPE = "requiredType"; final static public String MULTIPLE = "multiple"; final static public String MANDATORY = "mandatory"; final static public String AUTOCREATED = "autoCreated"; final static public String PROTECTED = "protected"; final static public String PARENTVERSION = "parentversion"; final static public String CONSTRAINTS = "constraints"; final static public String VALUE_CONSTRAINTS = "valueconstraints"; final static public String TRUE = "true"; final static public String FALSE = "false"; final static public String ACTION_UPDATE_PROPERTY = "UpdateProperty"; final static public String ACTION_CANCEL_PROPERTY = "CancelProperty"; private String requiredValue_; public UIPropertyDefinitionForm(String name) throws Exception { super(name); setComponentConfig(getClass(), null); List<SelectItemOption<String>> autoListItem = new ArrayList<SelectItemOption<String>>(); autoListItem.add(new SelectItemOption<String>(FALSE, FALSE)); autoListItem.add(new SelectItemOption<String>(TRUE, TRUE)); List<SelectItemOption<String>> mandoListItem = new ArrayList<SelectItemOption<String>>(); mandoListItem.add(new SelectItemOption<String>(FALSE, FALSE)); mandoListItem.add(new SelectItemOption<String>(TRUE, TRUE)); List<SelectItemOption<String>> multiListItem = new ArrayList<SelectItemOption<String>>(); multiListItem.add(new SelectItemOption<String>(FALSE, FALSE)); multiListItem.add(new SelectItemOption<String>(TRUE, TRUE)); List<SelectItemOption<String>> protectedItem = new ArrayList<SelectItemOption<String>>(); protectedItem.add(new SelectItemOption<String>(FALSE, FALSE)); protectedItem.add(new SelectItemOption<String>(TRUE, TRUE)); addUIFormInput(new UIFormSelectBox(NAMESPACE, NAMESPACE, getNamespaces())); addUIFormInput(new UIFormStringInput(DEFINITION_NAME, DEFINITION_NAME, null)); UIFormSelectBox uiRequired = new UIFormSelectBox(REQUIRED_TYPE, REQUIRED_TYPE, getRequiredTypes()); uiRequired.setOnChange("ChangeRequiredType"); addUIFormInput(uiRequired); addUIFormInput(new UIFormSelectBox(AUTOCREATED, AUTOCREATED, autoListItem)); addUIFormInput(new UIFormSelectBox(MANDATORY, MANDATORY, mandoListItem)); addUIFormInput(new UIFormSelectBox(PARENTVERSION, PARENTVERSION, getParentVersions())); addUIFormInput(new UIFormSelectBox(PROTECTED, PROTECTED, protectedItem)); addUIFormInput(new UIFormSelectBox(MULTIPLE, MULTIPLE, multiListItem)); addUIFormInput(new UIFormStringInput(VALUE_CONSTRAINTS, VALUE_CONSTRAINTS, null)); } public void processRender(WebuiRequestContext context) throws Exception { super.processRender(context); } private List<SelectItemOption<String>> getParentVersions() { List<SelectItemOption<String>> versionItem = new ArrayList<SelectItemOption<String>>(); versionItem.add(new SelectItemOption<String>("COPY", "1")); versionItem.add(new SelectItemOption<String>("VERSION", "2")); versionItem.add(new SelectItemOption<String>("INITIALIZE", "3")); versionItem.add(new SelectItemOption<String>("COMPUTE", "4")); versionItem.add(new SelectItemOption<String>("IGNORE", "5")); versionItem.add(new SelectItemOption<String>("ABORT", "6")); return versionItem; } private List<SelectItemOption<String>> getRequiredTypes() { List<SelectItemOption<String>> requireType = new ArrayList<SelectItemOption<String>>(); requireType.add(new SelectItemOption<String>("STRING", "1")); requireType.add(new SelectItemOption<String>("BINARY", "2")); requireType.add(new SelectItemOption<String>("LONG", "3")); requireType.add(new SelectItemOption<String>("DOUBLE", "4")); requireType.add(new SelectItemOption<String>("DATE", "5")); requireType.add(new SelectItemOption<String>("BOOLEAN", "6")); requireType.add(new SelectItemOption<String>("NAME", "7")); requireType.add(new SelectItemOption<String>("PATH", "8")); requireType.add(new SelectItemOption<String>("REFERENCE", "9")); requireType.add(new SelectItemOption<String>("UNDEFINED", "0")); return requireType; } public List<SelectItemOption<String>> getNamespaces() throws Exception { List<SelectItemOption<String>> namespacesOptions = new ArrayList<SelectItemOption<String>>(); String[] namespaces = getApplicationComponent(RepositoryService.class) .getCurrentRepository().getNamespaceRegistry().getPrefixes(); for(int i = 0; i < namespaces.length; i ++){ namespacesOptions.add(new SelectItemOption<String>(namespaces[i], namespaces[i])); } return namespacesOptions; } public void refresh() throws Exception { List<SelectItemOption<String>> autoListItem = new ArrayList<SelectItemOption<String>>(); autoListItem.add(new SelectItemOption<String>(FALSE, FALSE)); autoListItem.add(new SelectItemOption<String>(TRUE, TRUE)); List<SelectItemOption<String>> mandoListItem = new ArrayList<SelectItemOption<String>>(); mandoListItem.add(new SelectItemOption<String>(FALSE, FALSE)); mandoListItem.add(new SelectItemOption<String>(TRUE, TRUE)); List<SelectItemOption<String>> multiListItem = new ArrayList<SelectItemOption<String>>(); multiListItem.add(new SelectItemOption<String>(FALSE, FALSE)); multiListItem.add(new SelectItemOption<String>(TRUE, TRUE)); List<SelectItemOption<String>> protectedItem = new ArrayList<SelectItemOption<String>>(); protectedItem.add(new SelectItemOption<String>(FALSE, FALSE)); protectedItem.add(new SelectItemOption<String>(TRUE, TRUE)); getUIFormSelectBox(NAMESPACE).setOptions(getNamespaces()).setDisabled(false); getUIStringInput(DEFINITION_NAME).setReadOnly(false).setValue(null); getUIFormSelectBox(REQUIRED_TYPE).setOptions(getRequiredTypes()).setDisabled(false); getUIFormSelectBox(AUTOCREATED).setOptions(autoListItem).setDisabled(false); getUIFormSelectBox(MANDATORY).setOptions(mandoListItem).setDisabled(false); getUIFormSelectBox(PARENTVERSION).setOptions(getParentVersions()).setDisabled(false); getUIFormSelectBox(PROTECTED).setOptions(protectedItem).setDisabled(false); getUIFormSelectBox(MULTIPLE).setOptions(multiListItem).setDisabled(false); getUIStringInput(VALUE_CONSTRAINTS).setReadOnly(false).setValue(null); UINodeTypeForm uiForm = getParent(); UIFormInputSetWithAction uiPropertyTab = uiForm.getChildById(UINodeTypeForm.PROPERTY_DEFINITION); uiForm.setActionInTab(uiPropertyTab); } private void setRequiredValue(String requiredValue) { requiredValue_ = requiredValue; } private String getRequiredValue() { return requiredValue_ == null ? "1" : requiredValue_; } public void update(NodeType nodeType, String propertyName) throws Exception { if(propertyName != null) { PropertyDefinition[] propertyDefinitions = nodeType.getPropertyDefinitions(); for(int i = 0; i < propertyDefinitions.length; i++) { String name = propertyDefinitions[i].getName(); if(name.equals(propertyName)) { if (propertyName.indexOf(":") > -1) { getUIStringInput(DEFINITION_NAME). setValue(propertyName.substring(propertyName.indexOf(":") + 1)); getUIFormSelectBox(NAMESPACE). setValue(propertyName.substring(0, propertyName.indexOf(":"))); } else { getUIStringInput(DEFINITION_NAME).setValue(propertyName); getUIFormSelectBox(NAMESPACE).setValue(""); } String requiredType = Integer.toString(propertyDefinitions[i].getRequiredType()); getUIFormSelectBox(REQUIRED_TYPE).setValue(requiredType); getUIFormSelectBox(MULTIPLE). setValue(String.valueOf(propertyDefinitions[i].isMultiple())); getUIFormSelectBox(MANDATORY). setValue(String.valueOf(propertyDefinitions[i].isMandatory())); getUIFormSelectBox(AUTOCREATED). setValue(String.valueOf(propertyDefinitions[i].isAutoCreated())); getUIFormSelectBox(PROTECTED). setValue(String.valueOf(propertyDefinitions[i].isProtected())); String[] cons = propertyDefinitions[i].getValueConstraints(); StringBuilder conValues = new StringBuilder(); if(cons != null && cons.length > 0) { for(int j = 0; j < cons.length; j ++) { if(conValues.length() > 0) conValues.append(", "); conValues.append(cons[j]); } } getUIStringInput(VALUE_CONSTRAINTS).setValue(conValues.toString()); String parentVersion = Integer.toString(propertyDefinitions[i].getOnParentVersion()); getUIFormSelectBox(PARENTVERSION).setValue(parentVersion); break; } } } getUIFormSelectBox(NAMESPACE).setDisabled(true); getUIStringInput(DEFINITION_NAME).setReadOnly(true); getUIFormSelectBox(REQUIRED_TYPE).setDisabled(true); getUIFormSelectBox(AUTOCREATED).setDisabled(true); getUIFormSelectBox(MANDATORY).setDisabled(true); getUIFormSelectBox(PARENTVERSION).setDisabled(true); getUIFormSelectBox(PROTECTED).setDisabled(true); getUIFormSelectBox(MULTIPLE).setDisabled(true); getUIStringInput(VALUE_CONSTRAINTS).setReadOnly(true); } private PropertyDefinitionValue getPropertyByName(String propertyName, List<PropertyDefinitionValue> listProperty) { for(PropertyDefinitionValue property : listProperty) { if(property.getName().equals(propertyName)) return property; } return null; } private void setValues(PropertyDefinitionValue property) throws Exception { String propertyName = property.getName(); if (propertyName.indexOf(":") > -1) { getUIStringInput(DEFINITION_NAME). setValue(propertyName.substring(propertyName.indexOf(":") + 1)); getUIFormSelectBox(NAMESPACE).setValue(propertyName.substring(0, propertyName.indexOf(":"))); } else { getUIStringInput(DEFINITION_NAME).setValue(propertyName); getUIFormSelectBox(NAMESPACE).setValue(""); } String requiredType = Integer.toString(property.getRequiredType()); getUIFormSelectBox(REQUIRED_TYPE).setValue(requiredType); getUIFormSelectBox(MULTIPLE).setValue(String.valueOf(property.isMultiple())); getUIFormSelectBox(MANDATORY).setValue(String.valueOf(property.isMandatory())); getUIFormSelectBox(AUTOCREATED).setValue(String.valueOf(property.isAutoCreate())); getUIFormSelectBox(PROTECTED).setValue(String.valueOf(property.isReadOnly())); List<String> cons = property.getValueConstraints(); StringBuffer valueConstraints = null; for (String value : cons) { if (valueConstraints == null) { valueConstraints = new StringBuffer(value); } else { valueConstraints.append(",").append(value); } } getUIStringInput(VALUE_CONSTRAINTS).setValue(valueConstraints.toString()); String parentVersion = Integer.toString(property.getOnVersion()); getUIFormSelectBox(PARENTVERSION).setValue(parentVersion); } static public class RemovePropertyActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); String propertyName = event.getRequestContext().getRequestParameter(OBJECTID); if(propertyName == null || propertyName.trim().length() == 0) { uiForm.setTabRender(UINodeTypeForm.PROPERTY_DEFINITION); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UIPropertyDefinitionForm.msg.property-name", null)); return; } for(PropertyDefinitionValue property : uiForm.addedPropertiesDef_) { if(property.getName().equals(propertyName)) { uiForm.addedPropertiesDef_.remove(property); break; } } uiForm.setPropertyValue(uiForm.addedPropertiesDef_); uiForm.setTabRender(UINodeTypeForm.NODETYPE_DEFINITION); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class EditPropertyActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); UIPropertyDefinitionForm uiPropertyForm = uiForm.getChild(UIPropertyDefinitionForm.class); String propertyName = event.getRequestContext().getRequestParameter(OBJECTID); if(propertyName == null || propertyName.trim().length() == 0) { uiForm.setTabRender(UINodeTypeForm.PROPERTY_DEFINITION); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UIPropertyDefinitionForm.msg.property-name", null)); return; } PropertyDefinitionValue property = uiPropertyForm.getPropertyByName(propertyName, uiForm.addedPropertiesDef_); uiPropertyForm.setValues(property); uiPropertyForm.setRequiredValue(Integer.toString(property.getRequiredType())); UIFormInputSetWithAction propertyTab = uiForm.getChildById(UINodeTypeForm.PROPERTY_DEFINITION); String[] actionNames = {ACTION_UPDATE_PROPERTY, ACTION_CANCEL_PROPERTY}; String[] fieldNames = {propertyName, null}; propertyTab.setActions(actionNames, fieldNames); uiForm.setTabRender(UINodeTypeForm.PROPERTY_DEFINITION); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class UpdatePropertyActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); UIPropertyDefinitionForm uiPropertyForm = uiForm.getChild(UIPropertyDefinitionForm.class); String propertyName = event.getRequestContext().getRequestParameter(OBJECTID); PropertyDefinitionValue propertyInfo = uiPropertyForm.getPropertyByName(propertyName, uiForm.addedPropertiesDef_); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); String prefix = uiForm.getUIFormSelectBox(NAMESPACE).getValue(); String name = uiPropertyForm.getUIStringInput(DEFINITION_NAME).getValue(); if(name == null || name.trim().length() == 0) { uiForm.setTabRender(UINodeTypeForm.PROPERTY_DEFINITION); uiApp.addMessage(new ApplicationMessage("UIPropertyDefinitionForm.msg.property-name", null)); return; } for (int i = 0; i < name.length(); i++) { char c = name.charAt(i); if(Character.isLetter(c) || Character.isDigit(c) || Character.isSpaceChar(c) || c=='_' || c=='-' || c=='.' || c==':' || c=='@' || c=='^' || c=='[' || c==']' || c==',') { continue ; } uiApp.addMessage(new ApplicationMessage("UIPropertyDefinitionForm.msg.property-name", null, ApplicationMessage.WARNING)); return; } if (propertyInfo == null) { propertyInfo = new PropertyDefinitionValue(); } if (prefix != null && prefix.length() > 0) { propertyInfo.setName(prefix + ":" + name); } else { propertyInfo.setName(name); } String requiredType = uiForm.getUIFormSelectBox(REQUIRED_TYPE).getValue(); propertyInfo.setRequiredType(Integer.parseInt(requiredType)); String isMultiple = uiForm.getUIFormSelectBox(MULTIPLE).getValue(); propertyInfo.setMultiple(Boolean.parseBoolean(isMultiple)); String isMandatory = uiForm.getUIFormSelectBox(MANDATORY).getValue(); propertyInfo.setMandatory(Boolean.parseBoolean(isMandatory)); String autoCreate = uiForm.getUIFormSelectBox(AUTOCREATED).getValue(); propertyInfo.setAutoCreate(Boolean.parseBoolean(autoCreate)); String isProtected = uiForm.getUIFormSelectBox(PROTECTED).getValue(); propertyInfo.setReadOnly(Boolean.parseBoolean(isProtected)); String onParent = uiForm.getUIFormSelectBox(PARENTVERSION).getValue(); propertyInfo.setOnVersion(Integer.parseInt(onParent)); String valueConstraints = uiForm.getUIStringInput(VALUE_CONSTRAINTS).getValue(); List<String> constraintValues = new ArrayList<String>(); if(valueConstraints != null) { if(valueConstraints.indexOf(",") > -1) { String[] arrValues = valueConstraints.split(","); for(int i = 0; i < arrValues.length; i++) { constraintValues.add(arrValues[i]); } } else { constraintValues.add(valueConstraints); } } propertyInfo.setValueConstraints(constraintValues); uiForm.setPropertyValue(uiForm.addedPropertiesDef_); uiPropertyForm.refresh(); UIFormInputSetWithAction propertyTab = uiForm.getChildById(UINodeTypeForm.PROPERTY_DEFINITION); propertyTab.setActions(new String[] {UINodeTypeForm.ADD_PROPERTY}, null); uiForm.setTabRender(UINodeTypeForm.NODETYPE_DEFINITION); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class AddPropertyActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); String prefix = uiForm.getUIFormSelectBox(NAMESPACE).getValue(); String propertyName = uiForm.getUIStringInput(DEFINITION_NAME).getValue(); if(propertyName == null || propertyName.trim().length() == 0) { uiForm.setTabRender(UINodeTypeForm.PROPERTY_DEFINITION); uiApp.addMessage(new ApplicationMessage("UIPropertyDefinitionForm.msg.property-name", null)); return; } for(int i = 0; i < propertyName.length(); i ++){ char c = propertyName.charAt(i); if(Character.isLetter(c) || Character.isDigit(c) || Character.isSpaceChar(c) || c=='_' || c=='-' || c=='.' || c==':' || c=='@' || c=='^' || c=='[' || c==']' || c==',') { continue ; } uiApp.addMessage(new ApplicationMessage("UIPropertyDefinitionForm.msg.property-name", null, ApplicationMessage.WARNING)); return; } PropertyDefinitionValue propertyInfo = new PropertyDefinitionValue(); if (prefix != null && prefix.length() > 0) { propertyInfo.setName(prefix + ":" + propertyName); } else { propertyInfo.setName(propertyName); } UIPropertyDefinitionForm uiPropertyForm = uiForm.getChild(UIPropertyDefinitionForm.class); String requiredType = uiForm.getUIFormSelectBox(REQUIRED_TYPE).getValue(); propertyInfo.setRequiredType(Integer.parseInt(requiredType)); String multipleValue = uiForm.getUIFormSelectBox(MULTIPLE).getValue(); propertyInfo.setMultiple(Boolean.parseBoolean(multipleValue)); String mandatory = uiForm.getUIFormSelectBox(MANDATORY).getValue(); propertyInfo.setMandatory(Boolean.parseBoolean(mandatory)); String autoCreate = uiForm.getUIFormSelectBox(AUTOCREATED).getValue(); propertyInfo.setAutoCreate(Boolean.parseBoolean(autoCreate)); String isProtected = uiForm.getUIFormSelectBox(PROTECTED).getValue(); propertyInfo.setReadOnly(Boolean.parseBoolean(isProtected)); String onParent = uiForm.getUIFormSelectBox(PARENTVERSION).getValue(); propertyInfo.setOnVersion(Integer.parseInt(onParent)); String valueConstraints = uiForm.getUIStringInput(VALUE_CONSTRAINTS).getValue(); List<String> constraintValues = new ArrayList<String>(); if(valueConstraints != null) { if(valueConstraints.indexOf(",") > -1) { String[] arrValues = valueConstraints.split(","); for(int i = 0; i < arrValues.length; i++) { constraintValues.add(arrValues[i].toString()); } } else { constraintValues.add(valueConstraints); } } propertyInfo.setValueConstraints(constraintValues); uiForm.addedPropertiesDef_.add(propertyInfo); uiForm.setPropertyValue(uiForm.addedPropertiesDef_); uiPropertyForm.refresh(); uiForm.setTabRender(UINodeTypeForm.NODETYPE_DEFINITION); UIFormInputSetWithAction nodeTypeTab = uiForm.getChildById(UINodeTypeForm.NODETYPE_DEFINITION); nodeTypeTab.setIsView(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class ChangeRequiredTypeActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); UIPropertyDefinitionForm uiPropertyForm = uiForm.getChild(UIPropertyDefinitionForm.class); String value = uiForm.getUIFormSelectBox(REQUIRED_TYPE).getValue(); uiPropertyForm.setRequiredValue(value); if(value.equals("1") || value.equals("9")) { uiForm.getUIStringInput(VALUE_CONSTRAINTS).setReadOnly(false); } else { uiForm.getUIStringInput(VALUE_CONSTRAINTS).setReadOnly(true); } uiForm.getUIStringInput(VALUE_CONSTRAINTS).setValue(null); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class AddConstraintsActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); UIPropertyDefinitionForm uiPropertyForm = uiForm.getChild(UIPropertyDefinitionForm.class); uiForm.removeChildById("Contraints"); String values = uiForm.getUIStringInput(VALUE_CONSTRAINTS).getValue(); UIFormInputSetWithAction constraintTab = null; if(uiPropertyForm.getRequiredValue().equals("9")) { constraintTab = new UINodeTypeOptionList("Contraints"); uiForm.addUIComponentInput(constraintTab); uiForm.setSelectedTab(constraintTab.getId()); UINodeTypeOptionList uiOptionList = uiForm.getChild(UINodeTypeOptionList.class); uiOptionList.update(values); } else if(uiPropertyForm.getRequiredValue().equals("1")) { constraintTab = new UIFormInputSetWithAction("Contraints"); UIFormMultiValueInputSet valuesConstraint = uiPropertyForm.createUIComponent(UIFormMultiValueInputSet.class, null, CONSTRAINTS); valuesConstraint.setType(UIFormStringInput.class); constraintTab.addUIFormInput(valuesConstraint); uiForm.addUIComponentInput(constraintTab); uiForm.setSelectedTab(constraintTab.getId()); } else { UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); String message = "UIPropertyDefinitionForm.msg.not-supported-value-constraints"; uiApp.addMessage(new ApplicationMessage(message, null)); return; } uiForm.setSelectedTab("Contraints"); String[] actionNames = new String[] {"AddValue", "CancelConstraints"}; constraintTab.setActions(actionNames, null); } } static public class CancelPropertyActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); UIPropertyDefinitionForm uiPropertyForm = uiForm.getChild(UIPropertyDefinitionForm.class); uiPropertyForm.refresh(); UIFormInputSetWithAction childTab = uiForm.getChildById(UINodeTypeForm.PROPERTY_DEFINITION); childTab.setActions(new String[] {UINodeTypeForm.ADD_PROPERTY} , null); uiForm.setTabRender(UINodeTypeForm.NODETYPE_DEFINITION); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class AddActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); uiForm.setSelectedTab("Contraints"); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class RemoveActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); uiForm.setSelectedTab("Contraints"); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } @SuppressWarnings("unchecked") static public class AddValueActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); UIPropertyDefinitionForm uiPropertyForm = uiForm.getChild(UIPropertyDefinitionForm.class); StringBuffer strValues = null; if(uiPropertyForm.getRequiredValue().equals("9")) { List<String> selectedNodes = new ArrayList<String>(); List<UICheckBoxInput> listCheckbox = new ArrayList<UICheckBoxInput>(); uiForm.findComponentOfType(listCheckbox, UICheckBoxInput.class); for(int i = 0; i < listCheckbox.size(); i ++) { if(listCheckbox.get(i).isChecked()) { selectedNodes.add(listCheckbox.get(i).getName()); } } for (int i = 0; i < selectedNodes.size(); i++) { if (strValues == null) { strValues = new StringBuffer(selectedNodes.get(i)); } else { strValues.append(",").append(selectedNodes.get(i)); } } } else if(uiPropertyForm.getRequiredValue().equals("1")) { UIFormMultiValueInputSet uiMulti = uiForm.getUIInput(CONSTRAINTS); List<String> constraintValues = (List<String>)uiMulti.getValue(); if(constraintValues == null) constraintValues = new ArrayList<String>(); for (int i = 0; i < constraintValues.size(); i++) { if (strValues == null) { strValues = new StringBuffer(constraintValues.get(i)); } else { strValues.append(",").append(constraintValues.get(i)); } } } uiForm.getUIStringInput(VALUE_CONSTRAINTS).setValue(strValues.toString()); uiForm.removeChildById("Contraints"); uiForm.setTabRender(UINodeTypeForm.PROPERTY_DEFINITION); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class CancelConstraintsActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); uiForm.removeChildById("Contraints"); uiForm.setTabRender(UINodeTypeForm.PROPERTY_DEFINITION); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } }
29,779
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINodeTypeUpload.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/nodetype/UINodeTypeUpload.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.admin.nodetype; import java.io.BufferedInputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.zip.ZipInputStream; import javax.jcr.RepositoryException; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.mimetype.DMSMimeTypeResolver; import org.exoplatform.services.jcr.core.nodetype.NodeTypeValue; import org.exoplatform.services.jcr.core.nodetype.NodeTypeValuesList; import org.exoplatform.upload.UploadService; 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.EventListener; import org.exoplatform.webui.form.UIForm; import org.exoplatform.webui.form.input.UIUploadInput; import org.jibx.runtime.BindingDirectory; import org.jibx.runtime.IBindingFactory; import org.jibx.runtime.IUnmarshallingContext; import org.jibx.runtime.JiBXException; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Oct 2, 2006 * 9:39:51 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "classpath:groovy/ecm/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UINodeTypeUpload.UploadActionListener.class), @EventConfig(listeners = UINodeTypeUpload.CancelActionListener.class) } ) public class UINodeTypeUpload extends UIForm { final static public String FIELD_UPLOAD = "upload" ; public UINodeTypeUpload() throws Exception { this.setMultiPart(true) ; UIUploadInput uiInput = new UIUploadInput(FIELD_UPLOAD, FIELD_UPLOAD); addUIFormInput(uiInput) ; } @SuppressWarnings("unchecked") static public class UploadActionListener extends EventListener<UINodeTypeUpload> { public void execute(Event<UINodeTypeUpload> event) throws Exception { UINodeTypeUpload uiUploadForm = event.getSource() ; UINodeTypeManager uiManager = uiUploadForm.getAncestorOfType(UINodeTypeManager.class) ; UIPopupWindow uiPopup = uiManager.findComponentById(UINodeTypeManager.IMPORT_POPUP) ; UINodeTypeImportPopup uiImportPopup = uiManager.findComponentById("UINodeTypeImportPopup") ; UIApplication uiApp = uiUploadForm.getAncestorOfType(UIApplication.class) ; UIUploadInput input = uiUploadForm.getUIInput(FIELD_UPLOAD); String uploadId = input.getUploadIds()[0]; if(input.getUploadResource(uploadId) == null) { uiApp.addMessage(new ApplicationMessage("UINodeTypeUpload.msg.filename-error", null)) ; return ; } String fileName = input.getUploadResource(uploadId).getFileName(); if(fileName == null || fileName.trim().length() == 0) { uiApp.addMessage(new ApplicationMessage("UINodeTypeUpload.msg.filename-error", null)) ; return ; } DMSMimeTypeResolver resolver = DMSMimeTypeResolver.getInstance(); String mimeType = resolver.getMimeType(fileName); InputStream is = null; UINodeTypeImport uiNodeTypeImport = uiImportPopup.getChild(UINodeTypeImport.class); try { if(mimeType.trim().equals("text/xml")) { is = new BufferedInputStream(input.getUploadDataAsStream(uploadId)); }else if(mimeType.trim().equals("application/zip")) { ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(input.getUploadDataAsStream(uploadId))) ; is = Utils.extractFirstEntryFromZipFile(zipInputStream); }else { uiApp.addMessage(new ApplicationMessage("UINodeTypeUpload.msg.data-file-error", null)) ; return; } IBindingFactory factory = BindingDirectory.getFactory(NodeTypeValuesList.class); IUnmarshallingContext uctx = factory.createUnmarshallingContext(); NodeTypeValuesList nodeTypeValuesList = (NodeTypeValuesList)uctx.unmarshalDocument(is, null); ArrayList<NodeTypeValue> ntvList = nodeTypeValuesList.getNodeTypeValuesList(); uiNodeTypeImport.update(ntvList); if (uiNodeTypeImport.getRegisteredNodeType().size() > 0 || uiNodeTypeImport.getUndefinedNodeTypes().size() > 0) { Class<?>[] childrenToRender = {UINodeTypeImport.class, UIPopupWindow.class} ; uiImportPopup.setRenderedChildrenOfTypes(childrenToRender) ; uiPopup.setShow(true); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } if (uiNodeTypeImport.getRegisteredNodeType().size() > 0) { uiApp.addMessage(new ApplicationMessage("UINodeTypeUpload.msg.nodetype-exist", new Object[] {uiNodeTypeImport.getRegisteredNodeType().toString()}, ApplicationMessage.WARNING )) ; } if (uiNodeTypeImport.getUndefinedNamespace().size() > 0) { uiApp.addMessage(new ApplicationMessage("UINodeTypeUpload.msg.namespace-invalid", new Object[] { uiNodeTypeImport.getUndefinedNamespace().toString() }, ApplicationMessage.WARNING)); } } catch(JiBXException e) { uiApp.addMessage(new ApplicationMessage("UINodeTypeUpload.msg.data-invalid", null, ApplicationMessage.ERROR )) ; return ; } catch(RepositoryException e) { uiApp.addMessage(new ApplicationMessage("UINodeTypeUpload.msg.data-invalid", null, ApplicationMessage.ERROR )) ; return ; } finally { UploadService uploadService = uiUploadForm.getApplicationComponent(UploadService.class); uploadService.removeUploadResource(uploadId); if (is != null) is.close(); } } } static public class CancelActionListener extends EventListener<UINodeTypeUpload> { public void execute(Event<UINodeTypeUpload> event) throws Exception { UINodeTypeUpload uiUpload = event.getSource() ; UIPopupWindow uiPopup = uiUpload.getAncestorOfType(UIPopupWindow.class) ; uiPopup.setRendered(false) ; uiPopup.setShow(false) ; UINodeTypeManager uiManager = uiUpload.getAncestorOfType(UINodeTypeManager.class) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } }
7,149
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINodeTypeImportPopup.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/nodetype/UINodeTypeImportPopup.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.admin.nodetype; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIContainer; import org.exoplatform.webui.core.lifecycle.Lifecycle; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Oct 2, 2006 * 5:35:40 PM */ @ComponentConfig (lifecycle = Lifecycle.class, template = "classpath:groovy/ecm/webui/container/UIContainer.gtmpl" ) public class UINodeTypeImportPopup extends UIContainer { public UINodeTypeImportPopup() throws Exception { addChild(UINodeTypeUpload.class, null, null) ; addChild(UINodeTypeImport.class, null, null).setRendered(false) ; } }
1,483
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIChildNodeDefinitionForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/nodetype/UIChildNodeDefinitionForm.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.admin.nodetype; import java.util.ArrayList; import java.util.List; import javax.jcr.nodetype.NodeDefinition; import javax.jcr.nodetype.NodeType; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.core.nodetype.NodeDefinitionValue; import org.exoplatform.web.application.ApplicationMessage; import org.exoplatform.webui.application.WebuiRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIApplication; import org.exoplatform.webui.core.model.SelectItemOption; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIFormSelectBox; import org.exoplatform.webui.form.UIFormStringInput; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Sep 22, 2006 * 11:50:10 AM */ @ComponentConfig(template = "classpath:groovy/ecm/webui/form/UIFormInputSetWithAction.gtmpl") public class UIChildNodeDefinitionForm extends UIFormInputSetWithAction { final static public String NAMESPACE = "childNamespace"; final static public String CHILD_NAME = "childNodename"; final static public String REQUIRED_PRIMARY_TYPE = "requiredPrimaryType"; final static public String MULTIPLE = "childMultiple"; final static public String MANDATORY = "childMandatory"; final static public String AUTOCREATED = "childAutocreated"; final static public String PROTECTED = "childProtected"; final static public String PARENTVERSION = "childParentversion"; final static public String DEFAULT_PRIMARY_TYPE = "defaultPrimaryType"; final static public String SAME_NAME = "sameNameSiblings"; final static public String TRUE = "true"; final static public String FALSE = "false"; final static public String ACTION_UPDATE_CHILD = "UpdateChild"; final static public String ACTION_CANCEL_CHILD = "CancelChild"; public UIChildNodeDefinitionForm(String name) throws Exception { super(name); setComponentConfig(getClass(), null); List<SelectItemOption<String>> autoListItem = new ArrayList<SelectItemOption<String>>(); autoListItem.add(new SelectItemOption<String>(FALSE, FALSE)); autoListItem.add(new SelectItemOption<String>(TRUE, TRUE)); List<SelectItemOption<String>> mandoListItem = new ArrayList<SelectItemOption<String>>(); mandoListItem.add(new SelectItemOption<String>(FALSE, FALSE)); mandoListItem.add(new SelectItemOption<String>(TRUE, TRUE)); List<SelectItemOption<String>> sameNameListItem = new ArrayList<SelectItemOption<String>>(); sameNameListItem.add(new SelectItemOption<String>(FALSE, FALSE)); sameNameListItem.add(new SelectItemOption<String>(TRUE, TRUE)); List<SelectItemOption<String>> protectedItem = new ArrayList<SelectItemOption<String>>(); protectedItem.add(new SelectItemOption<String>(FALSE, FALSE)); protectedItem.add(new SelectItemOption<String>(TRUE, TRUE)); addUIFormInput(new UIFormSelectBox(NAMESPACE, NAMESPACE, getNamespaces())); addUIFormInput(new UIFormStringInput(CHILD_NAME, CHILD_NAME, null)); addUIFormInput(new UIFormStringInput(DEFAULT_PRIMARY_TYPE, DEFAULT_PRIMARY_TYPE, null)); addUIFormInput(new UIFormSelectBox(AUTOCREATED, AUTOCREATED, autoListItem)); addUIFormInput(new UIFormSelectBox(MANDATORY, MANDATORY, mandoListItem)); addUIFormInput(new UIFormSelectBox(PARENTVERSION, PARENTVERSION, getParentVersions())); addUIFormInput(new UIFormSelectBox(PROTECTED, PROTECTED, protectedItem)); addUIFormInput(new UIFormSelectBox(SAME_NAME, SAME_NAME, sameNameListItem)); addUIFormInput(new UIFormStringInput(REQUIRED_PRIMARY_TYPE, REQUIRED_PRIMARY_TYPE, null)); } public void processRender(WebuiRequestContext context) throws Exception { super.processRender(context); } private List<SelectItemOption<String>> getParentVersions() { List<SelectItemOption<String>> versionItem = new ArrayList<SelectItemOption<String>>(); versionItem.add(new SelectItemOption<String>("COPY", "1")); versionItem.add(new SelectItemOption<String>("VERSION", "2")); versionItem.add(new SelectItemOption<String>("INITIALIZE", "3")); versionItem.add(new SelectItemOption<String>("COMPUTE", "4")); versionItem.add(new SelectItemOption<String>("IGNORE", "5")); versionItem.add(new SelectItemOption<String>("ABORT", "6")); return versionItem; } private List<SelectItemOption<String>> getNamespaces() throws Exception { List<SelectItemOption<String>> namespacesOptions = new ArrayList<SelectItemOption<String>>(); String[] namespaces = getApplicationComponent(RepositoryService.class) .getCurrentRepository().getNamespaceRegistry().getPrefixes(); for( int i = 0; i < namespaces.length; i ++){ namespacesOptions.add(new SelectItemOption<String>(namespaces[i], namespaces[i])); } return namespacesOptions; } public void refresh() throws Exception { List<SelectItemOption<String>> autoListItem = new ArrayList<SelectItemOption<String>>(); autoListItem.add(new SelectItemOption<String>(FALSE, FALSE)); autoListItem.add(new SelectItemOption<String>(TRUE, TRUE)); List<SelectItemOption<String>> mandoListItem = new ArrayList<SelectItemOption<String>>(); mandoListItem.add(new SelectItemOption<String>(FALSE, FALSE)); mandoListItem.add(new SelectItemOption<String>(TRUE, TRUE)); List<SelectItemOption<String>> sameNameListItem = new ArrayList<SelectItemOption<String>>(); sameNameListItem.add(new SelectItemOption<String>(FALSE, FALSE)); sameNameListItem.add(new SelectItemOption<String>(TRUE, TRUE)); List<SelectItemOption<String>> protectedItem = new ArrayList<SelectItemOption<String>>(); protectedItem.add(new SelectItemOption<String>(FALSE, FALSE)); protectedItem.add(new SelectItemOption<String>(TRUE, TRUE)); getUIFormSelectBox(NAMESPACE).setOptions(getNamespaces()).setDisabled(false); getUIStringInput(CHILD_NAME).setReadOnly(false).setValue(null); getUIStringInput(DEFAULT_PRIMARY_TYPE).setReadOnly(false).setValue(null); getUIFormSelectBox(AUTOCREATED).setOptions(autoListItem).setDisabled(false); getUIFormSelectBox(MANDATORY).setOptions(mandoListItem).setDisabled(false); getUIFormSelectBox(PARENTVERSION).setOptions(getParentVersions()).setDisabled(false); getUIFormSelectBox(PROTECTED).setOptions(protectedItem).setDisabled(false); getUIFormSelectBox(SAME_NAME).setOptions(sameNameListItem).setDisabled(false); getUIStringInput(REQUIRED_PRIMARY_TYPE).setReadOnly(false).setValue(null); UINodeTypeForm uiForm = getParent(); UIFormInputSetWithAction uiChildTab = uiForm.getChildById(UINodeTypeForm.CHILDNODE_DEFINITION); uiForm.setActionInTab(uiChildTab); } public void update(NodeType nodeType, String childNodeName) throws Exception { if(childNodeName != null) { NodeDefinition[] nodeDefinitions = nodeType.getChildNodeDefinitions(); for(int i = 0; i < nodeDefinitions.length; i++) { String name = nodeDefinitions[i].getName(); if(name.equals(childNodeName)) { if(childNodeName.indexOf(":") > -1) { String[] arr = childNodeName.split(":"); getUIFormSelectBox(NAMESPACE).setValue(arr[0].trim()); getUIStringInput(CHILD_NAME).setValue(arr[1].trim()); } else { getUIFormSelectBox(NAMESPACE).setValue(""); getUIStringInput(CHILD_NAME).setValue(childNodeName); } NodeType defaultNodeType = nodeDefinitions[i].getDefaultPrimaryType(); if(defaultNodeType != null) { getUIStringInput(DEFAULT_PRIMARY_TYPE).setValue(defaultNodeType.getName()); } String sameName = String.valueOf(nodeDefinitions[i].allowsSameNameSiblings()); getUIFormSelectBox(SAME_NAME).setValue(sameName); getUIFormSelectBox(MANDATORY).setValue(String.valueOf(nodeDefinitions[i].isMandatory())); getUIFormSelectBox(AUTOCREATED).setValue(String.valueOf(nodeDefinitions[i].isAutoCreated())); getUIFormSelectBox(PROTECTED).setValue(String.valueOf(nodeDefinitions[i].isProtected())); String parentVersion = Integer.toString(nodeDefinitions[i].getOnParentVersion()); getUIFormSelectBox(PARENTVERSION).setValue(parentVersion); StringBuilder requiredType = new StringBuilder(); NodeType[] requiredPrimaryType = nodeDefinitions[i].getRequiredPrimaryTypes(); for(int j = 0; j < requiredPrimaryType.length; j ++){ if(requiredType.length() > 0) requiredType.append(" , "); requiredType.append(requiredPrimaryType[j].getName()); } getUIStringInput(REQUIRED_PRIMARY_TYPE).setValue(requiredType.toString()); break; } } } getUIFormSelectBox(NAMESPACE).setDisabled(true); getUIStringInput(CHILD_NAME).setReadOnly(true); getUIStringInput(DEFAULT_PRIMARY_TYPE).setReadOnly(true); getUIFormSelectBox(AUTOCREATED).setDisabled(true); getUIFormSelectBox(MANDATORY).setDisabled(true); getUIFormSelectBox(PARENTVERSION).setDisabled(true); getUIFormSelectBox(PROTECTED).setDisabled(true); getUIFormSelectBox(SAME_NAME).setDisabled(true); getUIStringInput(REQUIRED_PRIMARY_TYPE).setReadOnly(true); } private void setValues(NodeDefinitionValue node) { String childNodeName = node.getName(); if(childNodeName.indexOf(":") > -1) { String[] arr = childNodeName.split(":"); getUIFormSelectBox(NAMESPACE).setValue(arr[0].trim()); getUIStringInput(CHILD_NAME).setValue(arr[1].trim()); } else { getUIFormSelectBox(NAMESPACE).setValue(""); getUIStringInput(CHILD_NAME).setValue(childNodeName); } getUIStringInput(DEFAULT_PRIMARY_TYPE).setValue(node.getDefaultNodeTypeName()); getUIFormSelectBox(SAME_NAME).setValue(String.valueOf(node.isSameNameSiblings())); getUIFormSelectBox(MANDATORY).setValue(String.valueOf(node.isMandatory())); getUIFormSelectBox(AUTOCREATED).setValue(String.valueOf(node.isAutoCreate())); getUIFormSelectBox(PROTECTED).setValue(String.valueOf(node.isReadOnly())); String parentVersion = Integer.toString(node.getOnVersion()); getUIFormSelectBox(PARENTVERSION).setValue(parentVersion); List<String> requiredPrimaryType = node.getRequiredNodeTypeNames(); StringBuilder listRequired = new StringBuilder(); for(int j = 0; j < requiredPrimaryType.size(); j ++){ if(listRequired.length() < 1) { listRequired.append(requiredPrimaryType.get(j)); } else { listRequired.append(",").append(requiredPrimaryType.get(j)); } } getUIStringInput(REQUIRED_PRIMARY_TYPE).setValue(listRequired.toString()); } private NodeDefinitionValue getChildNodeByName(String nodeName, List<NodeDefinitionValue> listNode) { for(NodeDefinitionValue node : listNode) { if(node.getName().equals(nodeName)) return node; } return null; } static public class RemoveChildNodeActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); String nodeName = event.getRequestContext().getRequestParameter(OBJECTID); for(NodeDefinitionValue node : uiForm.addedChildDef_) { if(node.getName().equals(nodeName)) { uiForm.addedChildDef_.remove(node); break; } } uiForm.setChildValue(uiForm.addedChildDef_); uiForm.setTabRender(UINodeTypeForm.NODETYPE_DEFINITION); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class EditChildNodeActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); UIChildNodeDefinitionForm uiChildNodeForm = uiForm.getChild(UIChildNodeDefinitionForm.class); String nodeName = event.getRequestContext().getRequestParameter(OBJECTID); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); if(nodeName == null || nodeName.trim().length() == 0) { uiForm.setTabRender(UINodeTypeForm.CHILDNODE_DEFINITION); uiApp.addMessage(new ApplicationMessage("UIChildNodeDefinitionForm.msg.child-name", null)); return; } for(int i = 0; i < nodeName.length(); i ++){ char c = nodeName.charAt(i); if(Character.isLetter(c) || Character.isDigit(c) || Character.isSpaceChar(c) || c=='_' || c=='-' || c=='.' || c==':' || c=='@' || c=='^' || c=='[' || c==']' || c==',' || nodeName.equals("*")) { continue ; } uiApp.addMessage(new ApplicationMessage( "UIChildNodeDefinitionForm.msg.child-invalid", null, ApplicationMessage.WARNING)); return; } NodeDefinitionValue nodeDefValue = uiChildNodeForm.getChildNodeByName(nodeName, uiForm.addedChildDef_); uiChildNodeForm.setValues(nodeDefValue); UIFormInputSetWithAction childTab = uiForm.getChildById(UINodeTypeForm.CHILDNODE_DEFINITION); String[] actionNames = {ACTION_UPDATE_CHILD, ACTION_CANCEL_CHILD}; String[] fieldNames = {nodeName, null}; childTab.setActions(actionNames , fieldNames); uiForm.setTabRender(UINodeTypeForm.CHILDNODE_DEFINITION); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class UpdateChildActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); UIChildNodeDefinitionForm uiChildNodeForm = uiForm.getChild(UIChildNodeDefinitionForm.class); String nodeName = event.getRequestContext().getRequestParameter(OBJECTID); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); NodeDefinitionValue nodeTypeValue = uiChildNodeForm.getChildNodeByName(nodeName, uiForm.addedChildDef_); ApplicationMessage message; String prefix = uiForm.getUIFormSelectBox(UIChildNodeDefinitionForm.NAMESPACE).getValue(); String childNodeName = uiForm.getUIStringInput(UIChildNodeDefinitionForm.CHILD_NAME).getValue(); if(childNodeName == null || childNodeName.trim().length() == 0) { uiForm.setTabRender(UINodeTypeForm.CHILDNODE_DEFINITION); uiApp.addMessage(new ApplicationMessage("UIChildNodeDefinitionForm.msg.child-name", null)); return; } for(int i = 0; i < childNodeName.length(); i ++){ char c = childNodeName.charAt(i); if(Character.isLetter(c) || Character.isDigit(c) || Character.isSpaceChar(c) || c=='_' || c=='-' || c=='.' || c==':' || c=='@' || c=='^' || c=='[' || c==']' || c==',' || childNodeName.equals("*")) { continue ; } uiApp.addMessage(new ApplicationMessage("UIChildNodeDefinitionForm.msg.child-invalid", null, ApplicationMessage.WARNING)); return; } if(prefix != null && prefix.length() > 0) { StringBuffer sb = new StringBuffer(); sb.append(prefix).append(":").append(childNodeName); childNodeName = sb.toString(); } if (nodeTypeValue == null) { nodeTypeValue = new NodeDefinitionValue(); } nodeTypeValue.setName(childNodeName); String defaultType = uiForm.getUIStringInput(UIChildNodeDefinitionForm.DEFAULT_PRIMARY_TYPE).getValue(); if(defaultType == null || defaultType.trim().length() == 0) { uiForm.setTabRender(UINodeTypeForm.CHILDNODE_DEFINITION); message = new ApplicationMessage("UIChildNodeDefinitionForm.msg.defaultPrimaryType", null); uiApp.addMessage(message); return; } nodeTypeValue.setDefaultNodeTypeName(defaultType); String isSameName = uiForm.getUIFormSelectBox(UIChildNodeDefinitionForm.SAME_NAME).getValue(); nodeTypeValue.setSameNameSiblings(Boolean.parseBoolean(isSameName)); String isMandatory = uiForm.getUIFormSelectBox(UIChildNodeDefinitionForm.MANDATORY).getValue(); nodeTypeValue.setMandatory(Boolean.parseBoolean(isMandatory)); String autoCreate = uiForm.getUIFormSelectBox(UIChildNodeDefinitionForm.AUTOCREATED).getValue(); nodeTypeValue.setAutoCreate(Boolean.parseBoolean(autoCreate)); String isProtected = uiForm.getUIFormSelectBox(UIChildNodeDefinitionForm.PROTECTED).getValue(); nodeTypeValue.setReadOnly(Boolean.parseBoolean(isProtected)); String parentVer = uiForm.getUIFormSelectBox(UIChildNodeDefinitionForm.PARENTVERSION).getValue(); nodeTypeValue.setOnVersion(Integer.parseInt(parentVer)); String requiredType = uiForm.getUIStringInput(UIChildNodeDefinitionForm.REQUIRED_PRIMARY_TYPE).getValue(); if(requiredType == null || requiredType.length() == 0) { uiForm.setTabRender(UINodeTypeForm.CHILDNODE_DEFINITION); message = new ApplicationMessage("UIChildNodeDefinitionForm.msg.requiredPrimaryType", null); uiApp.addMessage(message); return; } String[] types = requiredType.split(","); List<String> reqList = new ArrayList<String>(); for(int i = 0; i < types.length; i++) { reqList.add(types[i].trim()); } nodeTypeValue.setRequiredNodeTypeNames(reqList); uiForm.setChildValue(uiForm.addedChildDef_); uiChildNodeForm.refresh(); UIFormInputSetWithAction childTab = uiForm.getChildById(UINodeTypeForm.CHILDNODE_DEFINITION); childTab.setActions(new String[] {UINodeTypeForm.ADD_CHILD}, null); uiForm.setTabRender(UINodeTypeForm.NODETYPE_DEFINITION); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class AddChildActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); NodeDefinitionValue nodeTypeValue = new NodeDefinitionValue(); String prefix = uiForm.getUIFormSelectBox(NAMESPACE).getValue(); ApplicationMessage message; String childNodeName = uiForm.getUIStringInput(CHILD_NAME).getValue(); if(childNodeName == null || childNodeName.trim().length() == 0) { uiForm.setTabRender(UINodeTypeForm.CHILDNODE_DEFINITION); uiApp.addMessage(new ApplicationMessage("UIChildNodeDefinitionForm.msg.child-name", null)); return; } for(int i = 0; i < childNodeName.length(); i ++){ char c = childNodeName.charAt(i); if(Character.isLetter(c) || Character.isDigit(c) || Character.isSpaceChar(c) || c=='_' || c=='-' || c=='.' || c==':' || c=='@' || c=='^' || c=='[' || c==']' || c==',' || childNodeName.equals("*")) { continue ; } uiApp.addMessage(new ApplicationMessage( "UIChildNodeDefinitionForm.msg.child-invalid", null, ApplicationMessage.WARNING)); return; } if (prefix != null && prefix.length() > 0) { StringBuffer sb = new StringBuffer(); sb.append(prefix).append(":").append(childNodeName); childNodeName = sb.toString(); } nodeTypeValue.setName(childNodeName); String defaultType = uiForm.getUIStringInput(DEFAULT_PRIMARY_TYPE).getValue(); if(defaultType == null || defaultType.trim().length() == 0) { uiForm.setTabRender(UINodeTypeForm.CHILDNODE_DEFINITION); message = new ApplicationMessage("UIChildNodeDefinitionForm.msg.defaultPrimaryType", null); uiApp.addMessage(message); return; } nodeTypeValue.setDefaultNodeTypeName(defaultType); String isSameName = uiForm.getUIFormSelectBox(SAME_NAME).getValue(); nodeTypeValue.setSameNameSiblings(Boolean.parseBoolean(isSameName)); String madatory = uiForm.getUIFormSelectBox(MANDATORY).getValue(); nodeTypeValue.setMandatory(Boolean.parseBoolean(madatory)); String autoCreate = uiForm.getUIFormSelectBox(AUTOCREATED).getValue(); nodeTypeValue.setAutoCreate(Boolean.parseBoolean(autoCreate)); String isProtected = uiForm.getUIFormSelectBox(PROTECTED).getValue(); nodeTypeValue.setReadOnly(Boolean.parseBoolean(isProtected)); String parentVer = uiForm.getUIFormSelectBox(PARENTVERSION).getValue(); nodeTypeValue.setOnVersion(Integer.parseInt(parentVer)); String requiredType = uiForm.getUIStringInput(REQUIRED_PRIMARY_TYPE).getValue(); if(requiredType == null || requiredType.trim().length() == 0) { uiForm.setTabRender(UINodeTypeForm.CHILDNODE_DEFINITION); message = new ApplicationMessage("UIChildNodeDefinitionForm.msg.requiredPrimaryType", null); uiApp.addMessage(message); return; } String[] types = requiredType.split(","); List<String> reqList = new ArrayList<String>(); for(int i = 0; i < types.length; i++){ reqList.add(types[i].trim()); } nodeTypeValue.setRequiredNodeTypeNames(reqList); uiForm.addedChildDef_.add(nodeTypeValue); uiForm.setChildValue(uiForm.addedChildDef_); UIChildNodeDefinitionForm uiChildNodeForm = uiForm.getChild(UIChildNodeDefinitionForm.class); uiChildNodeForm.refresh(); uiForm.setTabRender(UINodeTypeForm.NODETYPE_DEFINITION); UIFormInputSetWithAction nodeTypeTab = uiForm.getChildById(UINodeTypeForm.NODETYPE_DEFINITION); nodeTypeTab.setIsView(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class AddDefaultTypeActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); UIFormInputSetWithAction defaultPrimaryTypeTab = new UINodeTypeOptionList(UINodeTypeForm.DEFAULT_PRIMARY_TYPE_TAB); uiForm.removeChildTabs(new String[] {UINodeTypeForm.SUPER_TYPE_TAB, UINodeTypeForm.REQUIRED_PRIMARY_TYPE_TAB}); if(defaultPrimaryTypeTab.isRendered()) { uiForm.removeChildById(UINodeTypeForm.DEFAULT_PRIMARY_TYPE_TAB); } String[] actionNames = {UINodeTypeForm.ADD_TYPE, UINodeTypeForm.ACTION_CANCEL_TAB}; String[] fieldNames = {DEFAULT_PRIMARY_TYPE, UINodeTypeForm.DEFAULT_PRIMARY_TYPE_TAB}; defaultPrimaryTypeTab.setActions(actionNames, fieldNames); uiForm.addUIComponentInput(defaultPrimaryTypeTab); uiForm.setTabRender(UINodeTypeForm.DEFAULT_PRIMARY_TYPE_TAB); UINodeTypeOptionList uiOptionList = uiForm.getChild(UINodeTypeOptionList.class); String defaultTypeValue = uiForm.getUIStringInput(DEFAULT_PRIMARY_TYPE).getValue(); uiOptionList.update(defaultTypeValue); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class AddRequiredTypeActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); UIFormInputSetWithAction requiredPrimaryTypeTab = new UINodeTypeOptionList(UINodeTypeForm.REQUIRED_PRIMARY_TYPE_TAB); uiForm.removeChildTabs(new String[] {UINodeTypeForm.SUPER_TYPE_TAB, UINodeTypeForm.DEFAULT_PRIMARY_TYPE_TAB}); if(requiredPrimaryTypeTab.isRendered()) { uiForm.removeChildById(UINodeTypeForm.REQUIRED_PRIMARY_TYPE_TAB); } String[] actionNames = {UINodeTypeForm.ADD_TYPE, UINodeTypeForm.ACTION_CANCEL_TAB}; String[] fieldNames = {REQUIRED_PRIMARY_TYPE, UINodeTypeForm.REQUIRED_PRIMARY_TYPE_TAB}; requiredPrimaryTypeTab.setActions(actionNames, fieldNames); uiForm.addUIComponentInput(requiredPrimaryTypeTab); uiForm.setTabRender(UINodeTypeForm.REQUIRED_PRIMARY_TYPE_TAB); UINodeTypeOptionList uiOptionList = uiForm.getChild(UINodeTypeOptionList.class); String requiredTypeValue = uiForm.getUIStringInput(REQUIRED_PRIMARY_TYPE).getValue(); uiOptionList.update(requiredTypeValue); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } static public class CancelChildActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm = event.getSource(); UIChildNodeDefinitionForm uiChildNodeForm = uiForm.getChild(UIChildNodeDefinitionForm.class); uiChildNodeForm.refresh(); UIFormInputSetWithAction childTab = uiForm.getChildById(UINodeTypeForm.CHILDNODE_DEFINITION); childTab.setActions(new String[] {UINodeTypeForm.ADD_CHILD}, null); uiForm.setTabRender(UINodeTypeForm.NODETYPE_DEFINITION); event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } }
26,623
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINodeTypeOptionList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/nodetype/UINodeTypeOptionList.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.admin.nodetype; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.jcr.nodetype.NodeType; import javax.jcr.nodetype.NodeTypeIterator; import javax.jcr.nodetype.NodeTypeManager; import org.apache.commons.lang3.StringUtils; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.jcr.RepositoryService; 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.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIFormInputInfo; import org.exoplatform.webui.form.UIFormInputSet; import org.exoplatform.webui.form.UIFormTableInputSet; import org.exoplatform.webui.form.input.UICheckBoxInput; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Sep 22, 2006 * 2:20:31 PM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "classpath:groovy/ecm/webui/form/UIFormInputSetWithAction.gtmpl", events = { @EventConfig(listeners = UINodeTypeOptionList.AddTypeActionListener.class) } ) public class UINodeTypeOptionList extends UIFormInputSetWithAction { final static String TABLE_NAME = "UINodeTypeOptionList"; final static String[] TABLE_COLUMNS = {"label", "input"}; public UINodeTypeOptionList(String name) throws Exception { super(name) ; setComponentConfig(getClass(), null) ; } public void processRender(WebuiRequestContext context) throws Exception { super.processRender(context) ; } private boolean getCheckedValue(String values, String name) { String[] selectNodes = values.split(",") ; for(int i = 0 ; i < selectNodes.length ; i ++ ) { if(selectNodes[i].equals(name)) return true ; } return false ; } public void update(String values) throws Exception { UIFormTableInputSet uiTableInputSet = createUIComponent(UIFormTableInputSet.class, null, null) ; NodeTypeManager ntManager = getApplicationComponent(RepositoryService.class) .getCurrentRepository().getNodeTypeManager() ; NodeTypeIterator nodeTypeIter = ntManager.getAllNodeTypes() ; List<NodeType> nodeTypeList = new ArrayList<NodeType>() ; while(nodeTypeIter.hasNext()) { NodeType nt = nodeTypeIter.nextNodeType() ; nodeTypeList.add(nt) ; } Collections.sort(nodeTypeList, new Utils.NodeTypeNameComparator()) ; UIFormInputSet uiInputSet ; uiTableInputSet.setName(TABLE_NAME); uiTableInputSet.setColumns(TABLE_COLUMNS); for(NodeType nt : nodeTypeList) { String ntName = nt.getName() ; uiInputSet = new UIFormInputSet(ntName) ; UIFormInputInfo uiInfo = new UIFormInputInfo("label", null, ntName); uiInputSet.addChild(uiInfo); UICheckBoxInput uiCheckbox = new UICheckBoxInput(ntName, ntName, null); if(values != null) { if(getCheckedValue(values, ntName)) uiCheckbox.setChecked(true) ; } else { uiCheckbox.setChecked(false); } uiInputSet.addChild(uiCheckbox); uiTableInputSet.addChild(uiInputSet); } addUIFormInput(uiTableInputSet) ; } private void setFieldValues(String fieldName, List<String> selectedNodes) throws Exception { StringBuffer strNodeList = null ; UINodeTypeForm uiNodeTypeForm = getParent() ; if(uiNodeTypeForm == null) return; if(selectedNodes != null && selectedNodes.size() > 0) { for (int i = 0; i < selectedNodes.size(); i++) { if (strNodeList == null) strNodeList = new StringBuffer(selectedNodes.get(i)); else strNodeList.append(",").append(selectedNodes.get(i)); } } if(strNodeList == null) uiNodeTypeForm.getUIStringInput(fieldName).setValue(StringUtils.EMPTY) ; else uiNodeTypeForm.getUIStringInput(fieldName).setValue(strNodeList.toString()) ; if(fieldName.equals(UINodeTypeForm.SUPER_TYPE)) { for(UIComponent uiComp : uiNodeTypeForm.getChildren()) { UIFormInputSetWithAction tab = uiNodeTypeForm.getChildById(uiComp.getId()) ; if(tab.getId().equals(UINodeTypeForm.NODETYPE_DEFINITION)) uiNodeTypeForm.setSelectedTab(tab.getId()) ; } uiNodeTypeForm.removeChildById(UINodeTypeForm.SUPER_TYPE_TAB) ; } else if(fieldName.equals(UIChildNodeDefinitionForm.REQUIRED_PRIMARY_TYPE)) { for(UIComponent uiComp : uiNodeTypeForm.getChildren()) { UIFormInputSetWithAction tab = uiNodeTypeForm.getChildById(uiComp.getId()) ; if(tab.getId().equals(UINodeTypeForm.CHILDNODE_DEFINITION)) { uiNodeTypeForm.setSelectedTab(tab.getId()) ; } } uiNodeTypeForm.removeChildById(UINodeTypeForm.REQUIRED_PRIMARY_TYPE_TAB) ; } else if(fieldName.equals(UIChildNodeDefinitionForm.DEFAULT_PRIMARY_TYPE)) { for(UIComponent uiComp : uiNodeTypeForm.getChildren()) { UIFormInputSetWithAction tab = uiNodeTypeForm.getChildById(uiComp.getId()) ; if(tab.getId().equals(UINodeTypeForm.CHILDNODE_DEFINITION)) { uiNodeTypeForm.setSelectedTab(tab.getId()) ; } } uiNodeTypeForm.removeChildById(UINodeTypeForm.DEFAULT_PRIMARY_TYPE_TAB) ; } } static public class AddTypeActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm= event.getSource() ; UINodeTypeOptionList uiOptionList = uiForm.getChild(UINodeTypeOptionList.class) ; UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class) ; String fieldName = event.getRequestContext().getRequestParameter(OBJECTID) ; List<String> selectedNodes = new ArrayList<String>() ; UINodeTypeManager uiManager = uiForm.getAncestorOfType(UINodeTypeManager.class) ; List<UICheckBoxInput> listCheckbox = new ArrayList<UICheckBoxInput>(); uiForm.findComponentOfType(listCheckbox, UICheckBoxInput.class); int count = 0 ; for(int i = 0; i < listCheckbox.size(); i ++) { if(listCheckbox.get(i).isChecked()) { selectedNodes.add(listCheckbox.get(i).getName()) ; count ++ ; } } if(fieldName.equals(UIChildNodeDefinitionForm.DEFAULT_PRIMARY_TYPE) && count > 1) { uiApp.addMessage(new ApplicationMessage("UINodeTypeForm.msg.values-error", null)) ; uiForm.setTabRender(UINodeTypeForm.DEFAULT_PRIMARY_TYPE_TAB) ; return ; } uiOptionList.setFieldValues(fieldName, selectedNodes) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class CancelTabActionListener extends EventListener<UINodeTypeForm> { public void execute(Event<UINodeTypeForm> event) throws Exception { UINodeTypeForm uiForm= event.getSource() ; String tabName = event.getRequestContext().getRequestParameter(OBJECTID) ; if(tabName.equals(UINodeTypeForm.SUPER_TYPE_TAB)) { uiForm.removeChildById(tabName) ; uiForm.setSelectedTab(UINodeTypeForm.NODETYPE_DEFINITION) ; } else if(tabName.equals(UINodeTypeForm.DEFAULT_PRIMARY_TYPE_TAB) || tabName.equals(UINodeTypeForm.REQUIRED_PRIMARY_TYPE_TAB)) { uiForm.removeChildById(tabName) ; uiForm.setSelectedTab(UINodeTypeForm.CHILDNODE_DEFINITION) ; } event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()) ; } } }
8,755
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINodeTypeManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/nodetype/UINodeTypeManager.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.admin.nodetype; import org.exoplatform.ecm.webui.nodetype.selector.UINodeTypeSearch; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; import org.exoplatform.webui.ext.manager.UIAbstractManager; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Sep 20, 2006 * 2:20:55 PM */ @ComponentConfig ( lifecycle = UIContainerLifecycle.class ) public class UINodeTypeManager extends UIAbstractManager { final static public String IMPORT_POPUP = "NodeTypeImportPopup" ; final static public String EXPORT_POPUP = "NodeTypeExportPopup" ; public UINodeTypeManager() throws Exception { addChild(UINodeTypeSearchForm.class, null, "NodeTypeSearchForm") ; addChild(UINodeTypeList.class, null, "ListNodeType") ; } public void refresh() throws Exception { update(); } public void update() throws Exception { UINodeTypeSearch uiNodeTypeSearch = getChild(UINodeTypeSearchForm.class).getChild(UINodeTypeSearch.class); uiNodeTypeSearch.init(); UINodeTypeList uiNodeTypeList = getChild(UINodeTypeList.class); uiNodeTypeList.refresh(uiNodeTypeList.getUIPageIterator().getCurrentPage()); } public void setExportPopup() throws Exception { removeChildById(EXPORT_POPUP) ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, EXPORT_POPUP); uiPopup.setWindowSize(500, 400); UINodeTypeExport uiExport = uiPopup.createUIComponent(UINodeTypeExport.class, null, null); uiExport.update() ; uiPopup.setUIComponent(uiExport) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public void setImportPopup() throws Exception { removeChildById(IMPORT_POPUP) ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, IMPORT_POPUP); uiPopup.setWindowSize(500, 400); UINodeTypeImportPopup uiImportPopup = uiPopup.createUIComponent(UINodeTypeImportPopup.class, null, null) ; uiPopup.setUIComponent(uiImportPopup) ; uiPopup.setShow(true) ; uiPopup.setShowMask(true); uiPopup.setResizable(true) ; } public void initPopup(boolean isView) throws Exception { String popupId = "NodeTypePopup" ; if(isView) popupId = "ViewNodeTypePopup" ; removeChildById("NodeTypePopup") ; removeChildById("ViewNodeTypePopup") ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, popupId) ; uiPopup.setShowMask(true); UINodeTypeForm uiForm = createUIComponent(UINodeTypeForm.class, null, null) ; uiForm.update(null, false) ; uiPopup.setWindowSize(660, 400) ; uiPopup.setUIComponent(uiForm) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } }
3,590
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UINodeTypeList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/nodetype/UINodeTypeList.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.admin.nodetype; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.Session; import javax.jcr.nodetype.NodeType; import javax.jcr.nodetype.NodeTypeIterator; import javax.jcr.nodetype.NodeTypeManager; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.core.UIPagingGridDecorator; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.core.ManageableRepository; 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.UIComponent; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.form.UIFormInputInfo; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Sep 20, 2006 * 3:28:26 PM */ @ComponentConfig( template = "app:/groovy/webui/component/admin/nodetype/UINodeTypeList.gtmpl", events = { @EventConfig(listeners = UINodeTypeList.ViewActionListener.class), @EventConfig(listeners = UINodeTypeList.EditActionListener.class), @EventConfig(listeners = UINodeTypeList.DeleteActionListener.class, confirm="UINodeTypeList.msg.confirm-delete"), @EventConfig(listeners = UINodeTypeList.AddActionListener.class), @EventConfig(listeners = UINodeTypeList.ImportActionListener.class), @EventConfig(listeners = UINodeTypeList.ExportActionListener.class) } ) public class UINodeTypeList extends UIPagingGridDecorator { final static public String DRAFTNODETYPE = "jcr:system/jcr:nodetypesDraft" ; final static public String[] ACTIONS = {"Add", "Import", "Export"} ; final static public String[] CANCEL = {"Cancel"} ; final static public String[] TAB_REMOVE = { UINodeTypeForm.SUPER_TYPE_TAB, UINodeTypeForm.DEFAULT_PRIMARY_TYPE_TAB, UINodeTypeForm.REQUIRED_PRIMARY_TYPE_TAB} ; public UINodeTypeList() throws Exception { getUIPageIterator().setId("UINodeTypeListIterator") ; } @SuppressWarnings("unchecked") public List getAllNodeTypes() throws Exception{ List nodeList = new ArrayList<NodeTypeBean>(); ManageableRepository mRepository = getApplicationComponent(RepositoryService.class).getCurrentRepository() ; NodeTypeManager ntManager = mRepository.getNodeTypeManager() ; NodeTypeIterator nodeTypeIter = ntManager.getAllNodeTypes() ; while(nodeTypeIter.hasNext()) { nodeList.add(new NodeTypeBean(nodeTypeIter.nextNodeType())) ; } Collections.sort(nodeList, new NodeTypeNameComparator()) ; Session session = mRepository.getSystemSession(mRepository.getConfiguration().getSystemWorkspaceName()) ; Node rootNode = session.getRootNode(); if(rootNode.hasNode(DRAFTNODETYPE)) { Node draftNode = rootNode.getNode(DRAFTNODETYPE) ; NodeIterator nodeIter = draftNode.getNodes() ; while(nodeIter.hasNext()) { nodeList.add(nodeIter.nextNode()) ; } } session.logout() ; return nodeList ; } public List getNodeTypeList() throws Exception { return NodeLocation.getNodeListByLocationList(getUIPageIterator().getCurrentPageData()); } public String[] getActions() { return ACTIONS ; } public void refresh(String name, int currentPage, List<NodeTypeBean> nodeType) throws Exception { ListAccess<Object> nodeTypeList = new ListAccessImpl<Object>(Object.class, NodeLocation.getLocationsByNodeList(nodeType)); LazyPageList<Object> pageList = new LazyPageList<Object>(nodeTypeList, getUIPageIterator().getItemsPerPage()); getUIPageIterator().setPageList(pageList); if (currentPage > getUIPageIterator().getAvailablePage()) getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage()); else getUIPageIterator().setCurrentPage(currentPage); } public void refresh(String name, int currentPage) throws Exception { ManageableRepository manaRepository = getApplicationComponent(RepositoryService.class).getCurrentRepository() ; Session session = manaRepository.getSystemSession(manaRepository.getConfiguration().getSystemWorkspaceName()) ; if(name != null) { Node rootNode = session.getRootNode(); if(rootNode.hasNode(DRAFTNODETYPE)) { Node draftNode = rootNode.getNode(DRAFTNODETYPE) ; if(draftNode.hasNode(name)) { Node deleteNode = draftNode.getNode(name) ; deleteNode.remove() ; draftNode.save() ; } if(!draftNode.hasNodes())draftNode.remove() ; session.save() ; } } else { session.refresh(true) ; } session.logout(); refresh(name, currentPage, getAllNodeTypes()); } static public class AddActionListener extends EventListener<UINodeTypeList> { public void execute(Event<UINodeTypeList> event) throws Exception { UINodeTypeList uiList = event.getSource() ; UINodeTypeManager uiManager = uiList.getParent() ; uiManager.initPopup(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class ImportActionListener extends EventListener<UINodeTypeList> { public void execute(Event<UINodeTypeList> event) throws Exception { UINodeTypeList uiList = event.getSource() ; UINodeTypeManager uiManager = uiList.getParent() ; uiManager.setImportPopup() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class ExportActionListener extends EventListener<UINodeTypeList> { public void execute(Event<UINodeTypeList> event) throws Exception { UINodeTypeList uiList = event.getSource() ; UINodeTypeManager uiManager = uiList.getParent() ; uiManager.setExportPopup() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class ViewActionListener extends EventListener<UINodeTypeList> { public void execute(Event<UINodeTypeList> event) throws Exception { UINodeTypeList uiList = event.getSource() ; String ntName = event.getRequestContext().getRequestParameter(OBJECTID) ; ManageableRepository manaRepository = uiList.getApplicationComponent(RepositoryService.class).getCurrentRepository() ; Session session = manaRepository.getSystemSession(manaRepository.getConfiguration().getSystemWorkspaceName()) ; NodeTypeManager ntManager = session.getWorkspace().getNodeTypeManager() ; NodeType nodeType = ntManager.getNodeType(ntName) ; UINodeTypeManager uiManager = uiList.getParent() ; uiManager.initPopup(true) ; UINodeTypeForm uiForm = uiManager.findFirstComponentOfType(UINodeTypeForm.class) ; uiForm.update(nodeType, true) ; for(UIComponent uiComp : uiForm.getChildren()) { UIFormInputSetWithAction tab = uiForm.getChildById(uiComp.getId()) ; for(UIComponent uiChild : tab.getChildren()) { if(!(uiChild instanceof UIFormInputInfo)) tab.setActionInfo(uiChild.getName(), null) ; } if(tab.getId().equals(UINodeTypeForm.NODETYPE_DEFINITION)) { tab.setRendered(true) ; tab.setActions(new String[] {"Close"}, null) ; } else { tab.setRendered(true) ; tab.setActions(null, null) ; } } uiForm.removeChildTabs(TAB_REMOVE) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class EditActionListener extends EventListener<UINodeTypeList> { public void execute(Event<UINodeTypeList> event) throws Exception { UINodeTypeList uiNodeList = event.getSource() ; ManageableRepository manaRepository = uiNodeList.getApplicationComponent(RepositoryService.class).getCurrentRepository() ; Session session = manaRepository.getSystemSession(manaRepository.getConfiguration().getSystemWorkspaceName()) ; String nodeName = event.getRequestContext().getRequestParameter(OBJECTID) ; Node draftNodeType = session.getRootNode().getNode(DRAFTNODETYPE + "/" + nodeName) ; UINodeTypeManager uiManager = uiNodeList.getParent() ; uiManager.initPopup(false) ; UINodeTypeForm uiForm = uiManager.findFirstComponentOfType(UINodeTypeForm.class) ; uiForm.refresh() ; uiForm.removeChildTabs(TAB_REMOVE) ; uiForm.updateEdit(draftNodeType, true) ; UIFormInputSetWithAction tab = uiForm.getChildById(UINodeTypeForm.NODETYPE_DEFINITION) ; String[] actionNames = {UINodeTypeForm.ACTION_SAVE, UINodeTypeForm.ACTION_SAVEDRAFT, UINodeTypeForm.ACTION_CANCEL} ; tab.setActions(actionNames, null) ; tab.setIsView(false) ; uiForm.setTabRender(UINodeTypeForm.NODETYPE_DEFINITION) ; session.logout() ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class DeleteActionListener extends EventListener<UINodeTypeList> { public void execute(Event<UINodeTypeList> event) throws Exception { UINodeTypeList uiNodeList = event.getSource() ; ManageableRepository manaRepository = uiNodeList.getApplicationComponent(RepositoryService.class).getCurrentRepository(); Session session = manaRepository.getSystemSession(manaRepository.getConfiguration().getSystemWorkspaceName()) ; String nodeName = event.getRequestContext().getRequestParameter(OBJECTID) ; Node rootNode = session.getRootNode(); if(rootNode.hasNode(DRAFTNODETYPE)) { Node draftNode = rootNode.getNode(DRAFTNODETYPE) ; Node deleteNode = draftNode.getNode(nodeName) ; deleteNode.remove() ; draftNode.save() ; if(!draftNode.hasNodes()) draftNode.remove() ; session.save() ; uiNodeList.refresh(null, uiNodeList.getUIPageIterator().getCurrentPage()); event.getRequestContext().addUIComponentToUpdateByAjax(uiNodeList.getParent()) ; } session.logout() ; } } public static class NodeTypeBean { private String nodeTypeName_; private boolean isMixin_; private boolean hasOrderableChildNodes_; public NodeTypeBean(NodeType nodeType) { this.nodeTypeName_ = nodeType.getName(); this.isMixin_ = nodeType.isMixin(); this.hasOrderableChildNodes_ = nodeType.hasOrderableChildNodes(); } public String getName() { return nodeTypeName_; } public void setName(String nodeTypeName) { nodeTypeName_ = nodeTypeName; } public boolean isMixin() { return isMixin_; } public void setMixin(boolean isMixin) { isMixin_ = isMixin; } public boolean hasOrderableChildNodes() { return hasOrderableChildNodes_; } public void setOrderableChildNodes(boolean value) { hasOrderableChildNodes_ = value; } } static public class NodeTypeNameComparator implements Comparator<NodeTypeBean> { public int compare(NodeTypeBean n1, NodeTypeBean n2) throws ClassCastException { String name1 = n1.getName(); String name2 = n2.getName(); return name1.compareToIgnoreCase(name2); } } public void refresh(int currentPage) throws Exception { refresh(null, currentPage); } }
12,668
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITagPermissionInputSet.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/folksonomy/UITagPermissionInputSet.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.admin.folksonomy; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.validator.MandatoryValidator; /** * Created by The eXo Platform SARL * Author : Nguyen Anh Vu * anhvurz90@gmail.com * Dec 14, 2009 * 4:46:20 PM */ @ComponentConfig(template = "classpath:groovy/ecm/webui/form/UIFormInputSetWithAction.gtmpl") public class UITagPermissionInputSet extends UIFormInputSetWithAction { final static public String FIELD_USERORGROUP = "userOrGroup"; public UITagPermissionInputSet(String name) throws Exception { super(name); setComponentConfig(getClass(), null) ; UIFormStringInput userGroup = new UIFormStringInput(FIELD_USERORGROUP, FIELD_USERORGROUP, null) ; userGroup.addValidator(MandatoryValidator.class) ; userGroup.setReadOnly(true); addUIFormInput(userGroup) ; setActionInfo(FIELD_USERORGROUP, new String[] {"SelectUser", "SelectMember", "AddAny"}); } }
1,824
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITagPermissionManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/folksonomy/UITagPermissionManager.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.admin.folksonomy; import org.exoplatform.ecm.webui.core.UIPermissionManagerBase; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; /** * Created by The eXo Platform SARL * Author : Nguyen Anh Vu * anhvurz90@gmail.com * Dec 11, 2009 * 4:55:20 PM */ @ComponentConfig( lifecycle = UIContainerLifecycle.class ) public class UITagPermissionManager extends UIPermissionManagerBase { public UITagPermissionManager() throws Exception { addChild(UITagPermissionInfo.class, null, null); addChild(UITagPermissionForm.class, null, null); } public void initPopupPermission(UIComponent uiSelector) throws Exception { UIPopupWindow uiPopup = getChildById(UITagPermissionForm.POPUP_SELECT); if(uiPopup == null) { uiPopup = addChild(UIPopupWindow.class, null, UITagPermissionForm.POPUP_SELECT); uiPopup.setWindowSize(560, 300); uiPopup.setShowMask(true); } else { uiPopup.setRendered(true); } uiPopup.setUIComponent(uiSelector); uiPopup.setShow(true); uiPopup.setResizable(true); } }
1,990
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITagPermissionInfo.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/folksonomy/UITagPermissionInfo.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.admin.folksonomy; import java.util.ArrayList; import java.util.List; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.services.cms.folksonomy.NewFolksonomyService; 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.UIGrid; import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Nguyen Anh Vu * anhvurz90@gmail.com * Dec 14, 2009 * 10:01:53 AM */ @ComponentConfig( lifecycle = UIContainerLifecycle.class, events = { @EventConfig (listeners = UITagPermissionInfo.DeleteActionListener.class, confirm = "UITagPermissionInfo.msg.confirm-delete-permission") } ) public class UITagPermissionInfo extends UIContainer { public static String[] PERMISSION_BEAN_FIELD = {"usersOrGroups"}; private static String[] PERMISSION_ACTION = {"Delete"}; public UITagPermissionInfo() throws Exception { UIGrid uiGrid = createUIComponent(UIGrid.class, null, "TagPermissionInfo"); addChild(uiGrid); updateGrid(); uiGrid.getUIPageIterator().setId("TagPermissionInfoIterator"); uiGrid.configure(PERMISSION_BEAN_FIELD[0], PERMISSION_BEAN_FIELD, PERMISSION_ACTION); } public void processRender(WebuiRequestContext context) throws Exception { updateGrid(); super.processRender(context); } public void updateGrid() throws Exception { List<TagPermissionData> tagPermissions = new ArrayList<TagPermissionData>(); NewFolksonomyService newFolksonomyService = getApplicationComponent(NewFolksonomyService.class); for (String usersOrGroups : newFolksonomyService.getTagPermissionList()) { tagPermissions.add(new TagPermissionData(usersOrGroups)); } UIGrid uiGrid = findFirstComponentOfType(UIGrid.class); int currentPage = uiGrid.getUIPageIterator().getCurrentPage(); ListAccess<TagPermissionData> tagPermList = new ListAccessImpl<TagPermissionData>(TagPermissionData.class, tagPermissions); LazyPageList<TagPermissionData> dataPageList = new LazyPageList<TagPermissionData>(tagPermList, 10); uiGrid.getUIPageIterator().setPageList(dataPageList); int total = uiGrid.getUIPageIterator().getAvailablePage(); uiGrid.getUIPageIterator().setCurrentPage(currentPage < total ? currentPage : total); } public static class DeleteActionListener extends EventListener<UITagPermissionInfo> { public void execute(Event<UITagPermissionInfo> event) throws Exception { UITagPermissionInfo uiInfo = event.getSource(); String name = event.getRequestContext().getRequestParameter(OBJECTID); NewFolksonomyService folksonomyService = uiInfo.getApplicationComponent(NewFolksonomyService.class); folksonomyService.removeTagPermission(name); event.getRequestContext().addUIComponentToUpdateByAjax(uiInfo) ; } } public static class TagPermissionData { private String usersOrGroups; public TagPermissionData(String usersOrGroups) { this.usersOrGroups = usersOrGroups; } public String getUsersOrGroups() { return usersOrGroups; } } }
4,332
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIFolksonomyManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/folksonomy/UIFolksonomyManager.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.admin.folksonomy; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.ext.manager.UIAbstractManager; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jan 11, 2007 * 2:22:08 PM */ @ComponentConfig(template = "system:/groovy/webui/core/UITabPane.gtmpl") public class UIFolksonomyManager extends UIAbstractManager { public UIFolksonomyManager() throws Exception { addChild(UITagManager.class, null, null); addChild(UITagPermissionManager.class, null, null).setRendered(false); } public void refresh() throws Exception { update(); } public void update() throws Exception { getChild(UITagManager.class).update(); } public void selectUITagPermissionManager() { getChild(UITagManager.class).setRendered(false); getChild(UITagPermissionManager.class).setRendered(true); } public void selectUITagManager() { getChild(UITagManager.class).setRendered(true); getChild(UITagPermissionManager.class).setRendered(false); } }
1,836
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITagManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/folksonomy/UITagManager.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.admin.folksonomy; import javax.jcr.Node; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.services.cms.folksonomy.NewFolksonomyService; 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 : Nguyen Anh Vu * anhvurz90@gmail.com * Dec 11, 2009 * 4:31:33 PM */ @ComponentConfig(lifecycle = UIContainerLifecycle.class) public class UITagManager extends UIContainer { public UITagManager() throws Exception { addChild(UITagStyleList.class, null, null); } public void refresh() throws Exception { update(); } public void update() throws Exception { getChild(UITagStyleList.class).refresh(1); } public void initTaggingFormPopup(Node selectedTagStyle) throws Exception { removeChildById("FolksonomyPopup") ; UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, "FolksonomyPopup") ; uiPopup.setShowMask(true); uiPopup.setWindowSize(600, 280) ; UITagStyleForm uiForm = createUIComponent(UITagStyleForm.class, null, null) ; uiForm.setTagStyle(selectedTagStyle) ; uiPopup.setUIComponent(uiForm) ; uiPopup.setRendered(true) ; uiPopup.setShow(true) ; uiPopup.setResizable(true) ; } public Node getSelectedTagStyle(String tagStyleName) throws Exception { NewFolksonomyService newFolksonomyService = getApplicationComponent(NewFolksonomyService.class) ; String repository = getAncestorOfType(UIECMAdminPortlet.class).getPreferenceRepository() ; String workspace = getAncestorOfType(UIECMAdminPortlet.class).getDMSSystemWorkspace(repository); for(Node tagStyle: newFolksonomyService.getAllTagStyle(workspace)) { if(tagStyle.getName().equals(tagStyleName)) return tagStyle ; } return null ; } }
2,725
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITagUserContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/folksonomy/UITagUserContainer.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.admin.folksonomy; 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 org.exoplatform.webui.organization.account.UIUserSelector; /** * Created by The eXo Platform SARL * Author : Nguyen Anh Vu * anhvurz90@gmail.com * Dec 14, 2009 * 5:00:55 PM */ @ComponentConfig( lifecycle = UIContainerLifecycle.class, events = {@EventConfig(listeners = UITagUserContainer.AddUserActionListener.class)} ) public class UITagUserContainer extends UIContainer implements UIPopupComponent { public UITagUserContainer() throws Exception { UIUserSelector uiUserSelector = getChild(UIUserSelector.class); if (uiUserSelector == null) { uiUserSelector = addChild(UIUserSelector.class, null, null); } uiUserSelector.setMulti(false); uiUserSelector.setShowSearchUser(true); uiUserSelector.setShowSearch(true); } public void activate() { } public void deActivate() { } static public class AddUserActionListener extends EventListener<UITagUserContainer> { public void execute(Event<UITagUserContainer> event) throws Exception { UITagUserContainer uiUserContainer = event.getSource(); UIUserSelector uiUserSelector = uiUserContainer.getChild(UIUserSelector.class); UITagPermissionManager uiParent = uiUserContainer.getAncestorOfType(UITagPermissionManager.class); UITagPermissionForm uiPermissionForm = uiParent.getChild(UITagPermissionForm.class); uiPermissionForm.doSelect(UITagPermissionInputSet.FIELD_USERORGROUP, uiUserSelector.getSelectedUsers()); UIPopupWindow uiPopup = uiParent.findComponentById("PopupUserSelector"); uiPopup.setShow(false); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); } } }
2,862
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITagStyleForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/folksonomy/UITagStyleForm.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.admin.folksonomy; import javax.jcr.ItemNotFoundException; import javax.jcr.Node; import org.apache.commons.lang3.StringUtils; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.services.cms.folksonomy.NewFolksonomyService; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; 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.UIPopupWindow; 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.UIFormStringInput; import org.exoplatform.webui.form.UIFormTextAreaInput; import org.exoplatform.webui.form.validator.MandatoryValidator; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jan 11, 2007 * 2:56:02 PM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UITagStyleForm.UpdateStyleActionListener.class), @EventConfig(listeners = UITagStyleForm.CancelActionListener.class, phase = Phase.DECODE) } ) public class UITagStyleForm extends UIForm { final static public String STYLE_NAME = "styleName" ; final static public String DOCUMENT_RANGE = "documentRange" ; final static public String STYLE_HTML = "styleHTML" ; private static final Log LOG = ExoLogger.getLogger(UITagStyleForm.class.getName()); private NodeLocation selectedTagStyle_ ; public UITagStyleForm() throws Exception { addUIFormInput(new UIFormStringInput(STYLE_NAME, STYLE_NAME, null).addValidator(MandatoryValidator.class)) ; addUIFormInput(new UIFormStringInput(DOCUMENT_RANGE, DOCUMENT_RANGE, null).addValidator(MandatoryValidator.class)) ; addUIFormInput(new UIFormTextAreaInput(STYLE_HTML, STYLE_HTML, null).addValidator(MandatoryValidator.class)) ; } public Node getTagStyle() { return NodeLocation.getNodeByLocation(selectedTagStyle_); } public void setTagStyle(Node selectedTagStyle) throws Exception { selectedTagStyle_ = NodeLocation.getNodeLocationByNode(selectedTagStyle); if (selectedTagStyle != null) { getUIStringInput(STYLE_NAME).setValue(selectedTagStyle.getName()) ; getUIStringInput(STYLE_NAME).setReadOnly(true); String range = selectedTagStyle.getProperty(UITagStyleList.RANGE_PROP).getValue().getString() ; getUIStringInput(DOCUMENT_RANGE).setValue(range) ; String htmlStyle = selectedTagStyle.getProperty(UITagStyleList.HTML_STYLE_PROP).getValue().getString() ; getUIFormTextAreaInput(STYLE_HTML).setValue(htmlStyle) ; } } private boolean validateRange(String range) { String[] vars = null ; try { vars = StringUtils.split(range,"..") ; } catch(Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } return false ; } if(vars == null || vars.length!= 2) return false ; String minRange = vars[0], maxRange = vars[1] ; if(!StringUtils.isNumeric(minRange)) return false ; try { int min = Integer.parseInt(vars[0]) ; if(min<0) return false ; if(!StringUtils.isNumeric(maxRange)) { if(!maxRange.equals("*")) return false ; } else { if(Integer.parseInt(maxRange)<=0) return false ; } } catch(Exception e) { return false ; } return true ; } static public class UpdateStyleActionListener extends EventListener<UITagStyleForm> { public void execute(Event<UITagStyleForm> event) throws Exception { UITagStyleForm uiForm = event.getSource() ; UITagManager uiManager = uiForm.getAncestorOfType(UITagManager.class) ; UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class) ; String repository = uiForm.getAncestorOfType(UIECMAdminPortlet.class).getPreferenceRepository() ; String workspace = uiForm.getAncestorOfType(UIECMAdminPortlet.class).getDMSSystemWorkspace(repository); String documentRange = uiForm.getUIStringInput(DOCUMENT_RANGE).getValue() ; String styleHTML = uiForm.getUIFormTextAreaInput(STYLE_HTML).getValue() ; if(!uiForm.validateRange(documentRange)) { uiApp.addMessage(new ApplicationMessage("UITagStyleForm.msg.range-validator", null)) ; return ; } try { // add new tag if (uiForm.getTagStyle() == null) { String tagStyleName = uiForm.getUIStringInput(STYLE_NAME).getValue().trim(); NewFolksonomyService newFolksonomyService = uiForm.getApplicationComponent(NewFolksonomyService.class) ; newFolksonomyService.addTagStyle(tagStyleName, "", "", workspace); for(Node tagStyle: newFolksonomyService.getAllTagStyle(workspace)) if(tagStyle.getName().equals(tagStyleName)) { uiForm.selectedTagStyle_ = NodeLocation.getNodeLocationByNode(tagStyle); break; } } uiForm.getTagStyle().setProperty(UITagStyleList.RANGE_PROP, documentRange) ; uiForm.getTagStyle().setProperty(UITagStyleList.HTML_STYLE_PROP, styleHTML) ; uiForm.getTagStyle().save() ; uiForm.getTagStyle().getSession().save() ; UITagStyleList uiTagList = uiManager.getChild(UITagStyleList.class) ; uiTagList.refresh(uiTagList.getUIPageIterator().getCurrentPage()); } catch (ItemNotFoundException ie) { String key = "UITagStyleForm.msg.item-not-existing" ; uiApp.addMessage(new ApplicationMessage(key, null, ApplicationMessage.WARNING)) ; return ; } catch(Exception e) { String key = "UITagStyleForm.msg.error-update" ; uiApp.addMessage(new ApplicationMessage(key, null, ApplicationMessage.WARNING)) ; return ; } UIPopupWindow uiPopup = uiManager.getChild(UIPopupWindow.class) ; uiPopup.setShow(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } static public class CancelActionListener extends EventListener<UITagStyleForm> { public void execute(Event<UITagStyleForm> event) throws Exception { UITagStyleForm uiForm = event.getSource() ; UITagManager uiManager = uiForm.getAncestorOfType(UITagManager.class) ; UIPopupWindow uiPopup = uiManager.getChild(UIPopupWindow.class) ; uiPopup.setShow(false) ; event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ; } } }
7,706
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITagStyleAddAction.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/folksonomy/UITagStyleAddAction.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.admin.folksonomy; 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 25, 2009 * 11:33:01 AM */ @ComponentConfig( template = "app:/groovy/webui/component/admin/folksonomy/UITagStyleAddAction.gtmpl" ) public class UITagStyleAddAction extends UIComponent { private static String[] ACTIONS = {"AddStyle"} ; public UITagStyleAddAction() { super(); } public String[] getActions() { return ACTIONS; } }
1,345
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITagStyleList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/folksonomy/UITagStyleList.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.admin.folksonomy; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet; import org.exoplatform.ecm.webui.core.UIPagingGrid; import org.exoplatform.services.cms.folksonomy.NewFolksonomyService; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import javax.jcr.Node; import java.util.ArrayList; import java.util.List; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Jan 11, 2007 * 2:55:47 PM */ @ComponentConfig(template = "system:/groovy/ecm/webui/UIGridWithButton.gtmpl", events = { @EventConfig(listeners = UITagStyleList.EditActionListener.class), @EventConfig(listeners = UITagStyleList.RemoveActionListener.class, confirm = "UIFolksonomyManager.msg.confirm-delete"), @EventConfig(listeners = UITagStyleList.AddStyleActionListener.class) }) public class UITagStyleList extends UIPagingGrid { final static String RANGE_PROP = "exo:styleRange" ; final static String HTML_STYLE_PROP = "exo:htmlStyle" ; private static String[] BEAN_FIELD = {"name", "documentRange", "tagHTML"} ; private static String[] ACTIONS = {"Edit", "Remove"} ; public UITagStyleList() throws Exception { getUIPageIterator().setId("TagStyleIterator") ; configure("name", BEAN_FIELD, ACTIONS) ; } public String[] getActions() { return new String[] {"AddStyle"} ; } public void refresh(int currentPage) throws Exception { List<TagStyleData> tagStyleList = new ArrayList<TagStyleData>() ; NewFolksonomyService newFolksonomyService = getApplicationComponent(NewFolksonomyService.class) ; String repository = getAncestorOfType(UIECMAdminPortlet.class).getPreferenceRepository() ; String workspace = getAncestorOfType(UIECMAdminPortlet.class).getDMSSystemWorkspace(repository); TagStyleData tagStyleData = null ; for (Node node : newFolksonomyService.getAllTagStyle(workspace)) { tagStyleData = new TagStyleData(node.getName(), getRangeOfStyle(node), getHtmlStyleOfStyle(node)); tagStyleList.add(tagStyleData); } ListAccess<TagStyleData> tagStyleListAccess = new ListAccessImpl<TagStyleData>(TagStyleData.class, tagStyleList); LazyPageList<TagStyleData> dataPageList = new LazyPageList<TagStyleData>(tagStyleListAccess, getUIPageIterator().getItemsPerPage()); getUIPageIterator().setPageList(dataPageList); getUIPageIterator().setTotalItems(tagStyleList.size()); if (currentPage > getUIPageIterator().getAvailablePage()) getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage()); else getUIPageIterator().setCurrentPage(currentPage); } public String getRangeOfStyle(Node tagStyle) throws Exception { return tagStyle.getProperty(RANGE_PROP).getValue().getString() ; } public String getHtmlStyleOfStyle(Node tagStyle) throws Exception { return tagStyle.getProperty(HTML_STYLE_PROP).getValue().getString() ; } static public class TagStyleData { private String tagName_ ; private String documentRange_ ; private String tagHTML_ ; public TagStyleData(String tagName, String documentRange, String tagHTML) { tagName_ = tagName ; documentRange_ = documentRange ; tagHTML_ = tagHTML ; } public String getName() { return tagName_ ; } public String getDocumentRange() { return documentRange_ ; } public String getTagHTML() { return tagHTML_ ; } } static public class EditActionListener extends EventListener<UITagStyleList> { public void execute(Event<UITagStyleList> event) throws Exception { UITagStyleList uiTagStyleList = event.getSource(); UITagManager uiManager = uiTagStyleList.getParent(); String selectedName = event.getRequestContext().getRequestParameter(OBJECTID); Node selectedTagStyle = uiManager.getSelectedTagStyle(selectedName); uiManager.initTaggingFormPopup(selectedTagStyle); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } static public class AddStyleActionListener extends EventListener<UITagStyleList> { public void execute(Event<UITagStyleList> event) throws Exception { UITagStyleList uiTagStyleList = event.getSource(); UITagManager uiManager = uiTagStyleList.getParent(); uiManager.initTaggingFormPopup(null); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } static public class RemoveActionListener extends EventListener<UITagStyleList> { public void execute(Event<UITagStyleList> event) throws Exception { UITagStyleList uiTagStyleList = event.getSource(); UITagManager uiManager = uiTagStyleList.getParent(); String selectedName = event.getRequestContext().getRequestParameter(OBJECTID); Node selectedTagStyle = uiManager.getSelectedTagStyle(selectedName); Node parentNode = selectedTagStyle.getParent(); selectedTagStyle.remove(); parentNode.getSession().save(); org.exoplatform.services.cms.impl.Utils.addEditedConfiguredData(selectedName, "TagStyle", "EditedConfiguredTagStyle", true); uiTagStyleList.refresh(uiTagStyleList.getUIPageIterator().getCurrentPage()); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } }
6,570
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UITagPermissionForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/folksonomy/UITagPermissionForm.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.admin.folksonomy; import javax.jcr.Node; import org.exoplatform.ecm.permission.info.UIPermissionInputSet; import org.exoplatform.ecm.webui.core.UIPermissionFormBase; import org.exoplatform.ecm.webui.core.UIPermissionManagerBase; import org.exoplatform.ecm.webui.selector.UIGroupMemberSelector; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.services.cms.folksonomy.NewFolksonomyService; 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.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.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.UIFormStringInput; /** * Created by The eXo Platform SARL * Author : Nguyen Anh Vu * anhvurz90@gmail.com * Dec 14, 2009 * 10:02:37 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/admin/tags/UITagPermissionForm.gtmpl", events = { @EventConfig(listeners = UITagPermissionForm.AddActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UITagPermissionForm.SelectMemberActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UITagPermissionForm.SelectUserActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UITagPermissionForm.AddAnyActionListener.class) } ) public class UITagPermissionForm extends UIPermissionFormBase implements UISelectable{ final static public String TAGS_PERMISSION = "permission"; final static public String POPUP_SELECT = "SelectUserOrGroup"; private static final Log LOG = ExoLogger.getLogger(UITagPermissionForm.class.getName()); public UITagPermissionForm() throws Exception { removeChildById(UIPermissionFormBase.PERMISSION); addChild(new UIPermissionInputSet(TAGS_PERMISSION, false)); UIPermissionInputSet uiPerInputset = getChildById(TAGS_PERMISSION); uiPerInputset.setButtonActions(new String[] {"Add"}); uiPerInputset.setPrimaryButtonAction("Add"); uiPerInputset.setActionInfo(UIPermissionInputSet.FIELD_USERORGROUP, new String[] {"SelectUser", "SelectMember", "AddAny"}); } static public class AddActionListener extends EventListener<UITagPermissionForm> { public void execute(Event<UITagPermissionForm> event) throws Exception { UITagPermissionForm uiForm = event.getSource(); UITagPermissionManager uiParent = uiForm.getParent(); UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class); String userOrGroup = uiForm.getChild(UIPermissionInputSet.class).getUIStringInput( UIPermissionInputSet.FIELD_USERORGROUP).getValue(); NewFolksonomyService newFolksonomyService = uiForm.getApplicationComponent(NewFolksonomyService.class); if (Utils.isNameEmpty(userOrGroup)) { uiApp.addMessage(new ApplicationMessage("UIPermissionForm.msg.userOrGroup-required", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); UIFolksonomyManager uiContainer = uiForm.getAncestorOfType(UIFolksonomyManager.class); if (uiContainer!=null) { uiContainer.selectUITagPermissionManager(); } return; } if (newFolksonomyService.getTagPermissionList().contains(userOrGroup)) { uiApp.addMessage(new ApplicationMessage("UITagPermissionForm.msg.userOrGroup-alreadyExists", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); UIFolksonomyManager uiContainer = uiForm.getAncestorOfType(UIFolksonomyManager.class); if (uiContainer!=null) { uiContainer.selectUITagPermissionManager(); } return; } newFolksonomyService.addTagPermission(userOrGroup); event.getRequestContext().addUIComponentToUpdateByAjax(uiParent); uiForm.getChild(UIPermissionInputSet.class).getChild(UIFormStringInput.class).setValue(""); } } static public class SelectMemberActionListener extends EventListener<UITagPermissionForm> { public void execute(Event<UITagPermissionForm> event) throws Exception { UITagPermissionForm uiForm = event.getSource(); UIGroupMemberSelector uiGroupMemberSelector = uiForm.createUIComponent(UIGroupMemberSelector.class, null, null); uiGroupMemberSelector.setSourceComponent(uiForm, new String[] { UIPermissionInputSet.FIELD_USERORGROUP }); uiForm.getAncestorOfType(UIPermissionManagerBase.class).initPopupPermission(uiGroupMemberSelector); UIPopupContainer popupContainer = uiForm.getAncestorOfType(UIPopupContainer.class); if (popupContainer != null) { event.getRequestContext().addUIComponentToUpdateByAjax(popupContainer); } else { event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } } static public class SelectUserActionListener extends EventListener<UITagPermissionForm> { public void execute(Event<UITagPermissionForm> event) throws Exception { UITagPermissionForm uiForm = event.getSource(); ((UIPermissionManagerBase)uiForm.getParent()).initUserSelector(); UIPopupContainer popupContainer = uiForm.getAncestorOfType(UIPopupContainer.class); if (popupContainer != null) { event.getRequestContext().addUIComponentToUpdateByAjax(popupContainer); } else { event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } } static public class AddAnyActionListener extends EventListener<UITagPermissionForm> { public void execute(Event<UITagPermissionForm> event) throws Exception { UITagPermissionForm uiForm = event.getSource(); UIPermissionInputSet uiInputSet = uiForm.getChildById(UITagPermissionForm.TAGS_PERMISSION); uiInputSet.getUIStringInput(UIPermissionInputSet.FIELD_USERORGROUP).setValue(IdentityConstants.ANY); UIPopupContainer popupContainer = uiForm.getAncestorOfType(UIPopupContainer.class); if (popupContainer != null) { event.getRequestContext().addUIComponentToUpdateByAjax(popupContainer); } else { event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()); } } } public void doSelect(String selectField, Object value) { try { getUIStringInput(selectField).setValue(value.toString()); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected error", e); } } } @Override public Node getCurrentNode() throws Exception { //Nothing to do with get current node in tags permissions form return null; } }
7,891
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UILockedNodePageList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/unlock/UILockedNodePageList.java
/* * Copyright (C) 2003-2012 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.exoplatform.ecm.webui.component.admin.unlock; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.Session; import javax.jcr.query.Query; import org.exoplatform.commons.exception.ExoMessageException; import org.exoplatform.commons.utils.PageList; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.core.ManageableRepository; import org.exoplatform.services.jcr.impl.core.query.QueryImpl; 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; /** * Created by The eXo Platform SAS * Author : eXoPlatform * exo@exoplatform.com * May 23, 2012 */ public class UILockedNodePageList extends PageList<NodeLocation> { private static final Log LOG = ExoLogger.getLogger(UILockedNodePageList.class); private static final int QUERY_SIZE = 200; private String query; private Map<String, Integer> workspaceNodeMap; private String[] workspaceNameList; private List<NodeLocation> buffer; public UILockedNodePageList(int pageSize) { super(pageSize); } public UILockedNodePageList(String query, int pageSize, int currentPage) { super(pageSize); this.query = query; workspaceNameList = getWorkSpaceNameList(); workspaceNodeMap = new HashMap<String, Integer>(); buffer = this.getData(0, Math.max(QUERY_SIZE, (currentPage + 10) * pageSize)); this.setAvailablePage(buffer.size()); } /** * gets list of workspace name in repository * @return */ private String[] getWorkSpaceNameList() { RepositoryService repoService = WCMCoreUtils.getService(RepositoryService.class); String[] ret = new String[]{}; try { ret = repoService.getCurrentRepository().getWorkspaceNames(); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error(e); } } return ret; } @Override protected void populateCurrentPage(int page) throws Exception { currentListPage_ = buffer.subList(getFrom(), getTo()); } @Override protected void checkAndSetPage(int page) throws Exception { if (page + 10 > availablePage_) { buffer.addAll(getData(buffer.size(), (page + 10) * getPageSize() - availablePage_ + QUERY_SIZE)); setAvailablePage(buffer.size()); } if (page < 1 || page > availablePage_) { Object[] args = {Integer.toString(page), Integer.toString(availablePage_)}; throw new ExoMessageException("PageList.page-out-of-range", args); } currentPage_ = page; } private List<NodeLocation> getData(int from, int count) { // int count = this.getTo() - this.getFrom();//number of node need to query // int delta = this.getFrom(); int delta = from; List<NodeLocation> ret = new ArrayList<NodeLocation>();//data will be filled to this list //iterate through all workspaces for (String workspace : workspaceNameList) { Integer lockedNodeCount = workspaceNodeMap.get(workspace); if (lockedNodeCount != null) { if (lockedNodeCount <= delta) {//(1.1) delta -= lockedNodeCount; } else if (delta < lockedNodeCount && lockedNodeCount <= delta + count) { //(1.2) ret.addAll(queryNodes(workspace, delta, lockedNodeCount - delta)); delta = 0; count -= (lockedNodeCount - delta); } else if (delta + count < lockedNodeCount) { ret = queryNodes(workspace, delta, count); break;//delta = 0; count = 0; } } else { //lockedNodeCount==null List<NodeLocation> queryNodeData = queryNodes(workspace, delta, count); if (queryNodeData.size() == 0) {//(2.1), as (1.1) : lockedNodeCount <= delta lockedNodeCount = queryNodes(workspace, 0, count).size(); delta -= lockedNodeCount; workspaceNodeMap.put(workspace, lockedNodeCount); } else if (0 < queryNodeData.size() && queryNodeData.size() < count) { //(2.2), as (1.2) : delta < lockedNodeCount && lockedNodeCount <= delta + count ret.addAll(queryNodeData); delta = 0; count -= queryNodeData.size(); } else if (queryNodeData.size() == count) {//(2.3), as (1.3) : delta + count < lockedNodeCount ret = queryNodeData; break;//delta = 0; count = 0; } } if (count == 0) { break; } } return ret; } /** * gets all nodes by this.query, in given workspace, from offset to (offset + limit) * @throws Exception */ private List<NodeLocation> queryNodes(String workspace, int offset, int limit) { List<NodeLocation> ret = new ArrayList<NodeLocation>(); try { ManageableRepository repo = WCMCoreUtils.getService(RepositoryService.class).getCurrentRepository(); Session session = WCMCoreUtils.getSystemSessionProvider().getSession(workspace, repo); Query query = session.getWorkspace().getQueryManager().createQuery(this.query, Query.SQL); ((QueryImpl)query).setOffset(offset); ((QueryImpl)query).setLimit(limit); for (NodeIterator iter = query.execute().getNodes(); iter.hasNext();) { Node node = iter.nextNode(); if (node.isLocked()) { ret.add(NodeLocation.getNodeLocationByNode(node)); } } } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error(e); } } return ret; } @Override public List getAll() throws Exception { return buffer; } }
6,477
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UILockHolderContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/unlock/UILockHolderContainer.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.admin.unlock; 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 : Hoang Van Hung * hunghvit@gmail.com * Dec 3, 2008 */ @ComponentConfig( lifecycle = UIContainerLifecycle.class ) public class UILockHolderContainer extends UIContainer { public UILockHolderContainer() throws Exception { addChild(UILockHolderList.class, null, null); addChild(UIPermissionSelector.class, null, null); } }
975
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UILockHolderList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/unlock/UILockHolderList.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.admin.unlock; import java.util.ArrayList; import java.util.List; 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.core.UIPagingGridDecorator; import org.exoplatform.ecm.utils.lock.LockUtil; import org.exoplatform.services.cms.lock.LockService; 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.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Dec 29, 2006 * 11:30:17 AM */ @ComponentConfig( template = "app:/groovy/webui/component/admin/unlock/UILockHolderList.gtmpl", events = { @EventConfig(listeners = UILockHolderList.DeleteLockActionListener.class) } ) public class UILockHolderList extends UIPagingGridDecorator { final static public String[] ACTIONS = {}; final static public String ST_EDIT = "EditUnLockForm"; public UILockHolderList() throws Exception { getUIPageIterator().setId("LockHolderListIterator"); } public String[] getActions() { return ACTIONS ; } public void refresh(int currentPage) throws Exception { ListAccess<String> groupsAndUsersForLockList = new ListAccessImpl<String>(String.class, getAllGroupsOrUsersForLock()); LazyPageList<String> pageList = new LazyPageList<String>(groupsAndUsersForLockList, getUIPageIterator().getItemsPerPage()); getUIPageIterator().setPageList(pageList); if (currentPage > getUIPageIterator().getAvailablePage()) getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage()); else getUIPageIterator().setCurrentPage(currentPage); } public List getGroupsOrUsersForLock() throws Exception { return getUIPageIterator().getCurrentPageData(); } public List<String> getAllGroupsOrUsersForLock() throws Exception { LockService lockService = getApplicationComponent(LockService.class); return lockService.getAllGroupsOrUsersForLock(); } static public class DeleteLockActionListener extends EventListener<UILockHolderList> { public void execute(Event<UILockHolderList> event) throws Exception { UILockHolderList uiLockHolderList = event.getSource(); UILockHolderContainer uiLockHolderContainer = uiLockHolderList.getAncestorOfType(UILockHolderContainer.class); String removedLockSetting = event.getRequestContext().getRequestParameter(OBJECTID); LockService lockService = uiLockHolderContainer.getApplicationComponent(LockService.class); if (!lockService.getPreSettingLockList().contains(removedLockSetting)) { lockService.removeGroupsOrUsersForLock(removedLockSetting); // Update lock cache List<String> ignoredList = new ArrayList<String>(); if (removedLockSetting.startsWith("*")) { String groupOfRemovedLockSetting = StringUtils.substringAfter(removedLockSetting, ":"); List<String> allLockSettings = lockService.getAllGroupsOrUsersForLock(); for (String lockSetting : allLockSettings) { if (groupOfRemovedLockSetting.equals(StringUtils.substringAfter(lockSetting, ":"))) { ignoredList.add(lockSetting); } } } LockUtil.removeLockCache(removedLockSetting, ignoredList); } else { Object[] args = {removedLockSetting}; UIApplication uiApp = uiLockHolderList.getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage("UILockHolderList.msg.can-not-delete-lock-holder", args, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiLockHolderContainer.getParent()); } UILockHolderList uiHolderList = uiLockHolderContainer.getChild(UILockHolderList.class); uiHolderList.refresh(uiHolderList.getUIPageIterator().getCurrentPage()); UIUnLockManager uiUnLockManager = uiLockHolderContainer.getParent(); uiUnLockManager.getChild(UILockNodeList.class).setRendered(false); uiLockHolderContainer.setRendered(true); event.getRequestContext().addUIComponentToUpdateByAjax(uiLockHolderContainer.getParent()); } } }
5,424
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UILockNodeList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/unlock/UILockNodeList.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.admin.unlock; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Set; import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.PathNotFoundException; import javax.jcr.Session; import javax.jcr.lock.LockException; import javax.jcr.query.Query; import javax.jcr.query.QueryManager; import javax.jcr.query.QueryResult; import javax.jcr.version.VersionException; import org.apache.commons.lang3.StringUtils; import org.exoplatform.commons.utils.PageList; import org.exoplatform.ecm.jcr.model.Preference; import org.exoplatform.ecm.utils.lock.LockUtil; import org.exoplatform.ecm.webui.comparator.NodeOwnerComparator; import org.exoplatform.ecm.webui.comparator.NodeTitleComparator; import org.exoplatform.ecm.webui.core.UIPagingGridDecorator; import org.exoplatform.ecm.webui.utils.JCRExceptionManager; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.portal.config.UserACL; import org.exoplatform.services.cms.lock.LockService; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.config.RepositoryEntry; import org.exoplatform.services.jcr.config.WorkspaceEntry; import org.exoplatform.services.jcr.core.ManageableRepository; import org.exoplatform.services.security.ConversationState; import org.exoplatform.services.security.MembershipEntry; 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.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.event.Event; import org.exoplatform.webui.event.EventListener; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Dec 29, 2006 * 11:30:17 AM */ @ComponentConfig( template = "app:/groovy/webui/component/admin/unlock/UILockNodeList.gtmpl", events = { @EventConfig(listeners = UILockNodeList.UnLockActionListener.class), @EventConfig(listeners = UILockNodeList.SortActionListener.class) } ) public class UILockNodeList extends UIPagingGridDecorator { final static public String[] ACTIONS = {}; final static public String ST_EDIT = "EditUnLockForm"; private Preference preferences_; private static final String LOCK_QUERY = "select * from mix:lockable where jcr:lockOwner IS NOT NULL " + "order by exo:dateCreated DESC"; private String typeSort_ = NodetypeConstant.SORT_BY_NODETYPE; private String sortOrder_ = Preference.BLUE_UP_ARROW; private String order_ = Preference.ASCENDING_ORDER; public static final String SORT_BY_NODENAME = "Alphabetic" ; public static final String SORT_BY_NODEOWNER= "Owner" ; public String getTypeSort() { return typeSort_; } public void setTypeSort(String typeSort) { typeSort_ = typeSort; } public String getSortOrder() { return sortOrder_; } public void setSortOrder(String sortOrder) { sortOrder_ = sortOrder; } public String getOrder() { return order_; } public void setOrder(String order) { order_ = order; } public void setPreferences(Preference preference) {this.preferences_ = preference; } public UILockNodeList() throws Exception { getUIPageIterator().setId("LockNodeListIterator"); } public String[] getActions() { return ACTIONS ; } public void refresh(int currentPage) throws Exception { if (!getUIPageIterator().isJustPaginated()) { PageList pageList = new UILockedNodePageList(LOCK_QUERY, getUIPageIterator().getItemsPerPage(), currentPage); getUIPageIterator().setPageList(pageList); } if (currentPage > getUIPageIterator().getAvailablePage()) getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage()); else getUIPageIterator().setCurrentPage(currentPage); getUIPageIterator().setJustPaginated(false); } public List getLockedNodeList() throws Exception { return sort(NodeLocation.getNodeListByLocationList(getUIPageIterator().getCurrentPageData())); } public List<Node> getAllLockedNodes() throws Exception { RepositoryService repositoryService = getApplicationComponent(RepositoryService.class); ManageableRepository manageRepository = repositoryService.getCurrentRepository(); RepositoryEntry repo = manageRepository.getConfiguration(); List<Node> listLockedNodes = new ArrayList<Node>(); QueryManager queryManager = null; Session session = null; String queryStatement = LOCK_QUERY; Query query = null; QueryResult queryResult = null; for(WorkspaceEntry ws : repo.getWorkspaceEntries()) { session = WCMCoreUtils.getSystemSessionProvider().getSession(ws.getName(), manageRepository); queryManager = session.getWorkspace().getQueryManager(); query = queryManager.createQuery(queryStatement, Query.SQL); queryResult = query.execute(); for(NodeIterator iter = queryResult.getNodes(); iter.hasNext();) { Node itemNode = iter.nextNode(); if (!Utils.isInTrash(itemNode) && itemNode.isLocked()) { listLockedNodes.add(itemNode); } } } return listLockedNodes; } private List<Node> sort(List<Node> childrenList) { if (SORT_BY_NODENAME.equals(this.getTypeSort())) Collections.sort(childrenList, new NodeTitleComparator(this.getOrder())) ; else if(SORT_BY_NODEOWNER.equals(this.getTypeSort())) Collections.sort(childrenList, new NodeOwnerComparator(this.getOrder())) ; return childrenList; } static public class SortActionListener extends EventListener<UILockNodeList> { public void execute(Event<UILockNodeList> event) throws Exception { UILockNodeList uicomp = event.getSource(); UIUnLockManager uiUnLockManager = event.getSource().getParent(); UIApplication uiApp = uiUnLockManager.getAncestorOfType(UIApplication.class); try { String sortParam = event.getRequestContext().getRequestParameter(OBJECTID) ; String[] array = sortParam.split(";"); String order = Preference.ASCENDING_ORDER.equals(array[0].trim()) || !array[1].trim().equals(uicomp.getTypeSort()) ? Preference.BLUE_DOWN_ARROW : Preference.BLUE_UP_ARROW; String prefOrder = Preference.ASCENDING_ORDER.equals(array[0].trim()) || !array[1].trim().equals(uicomp.getTypeSort())? Preference.ASCENDING_ORDER : Preference.DESCENDING_ORDER; uicomp.setSortOrder(order); uicomp.setTypeSort(array[1]); uicomp.setOrder(prefOrder); uiUnLockManager.refresh(); event.getRequestContext().addUIComponentToUpdateByAjax(uiUnLockManager); } catch (Exception e) { JCRExceptionManager.process(uiApp, e); return; } } } static public class UnLockActionListener extends EventListener<UILockNodeList> { private List<String> getCurrentUserMemberships() throws Exception { List<String> groupList = new ArrayList<String> (); Collection<MembershipEntry> memberships = ConversationState.getCurrent().getIdentity().getMemberships(); for(MembershipEntry entry: memberships){ groupList.add(entry.getMembershipType() + ":" + entry.getGroup()); } return groupList; } public void execute(Event<UILockNodeList> event) throws Exception { WebuiRequestContext rContext = event.getRequestContext(); UIUnLockManager uiUnLockManager = event.getSource().getParent(); UIApplication uiApp = uiUnLockManager.getAncestorOfType(UIApplication.class); String nodePath = rContext.getRequestParameter(OBJECTID); RepositoryService repositoryService = uiUnLockManager.getApplicationComponent(RepositoryService.class); ManageableRepository manageRepository = repositoryService.getCurrentRepository(); Session session = null; Node lockedNode = null; UserACL userACLService = WCMCoreUtils.getService(UserACL.class); String remoteUser = rContext.getRemoteUser(); boolean isAuthenticated = remoteUser.equals(userACLService.getSuperUser()); if (!isAuthenticated) { LockService lockService = WCMCoreUtils.getService(LockService.class); List<String> authorizedMemberships = lockService.getAllGroupsOrUsersForLock(); List<String> loginedUserMemberShips = getCurrentUserMemberships(); Set<String> loginedUserGroups = ConversationState.getCurrent().getIdentity().getGroups(); for (String authorizedMembership: authorizedMemberships) { if ((authorizedMembership.startsWith("*") && loginedUserGroups.contains(StringUtils.substringAfter(authorizedMembership, ":"))) || loginedUserMemberShips.contains(authorizedMembership)) { isAuthenticated=true; break; } } } RepositoryEntry repo = repositoryService.getCurrentRepository().getConfiguration(); for(WorkspaceEntry ws : repo.getWorkspaceEntries()) { if (isAuthenticated) { session = WCMCoreUtils.getSystemSessionProvider().getSession(ws.getName(), manageRepository); }else { session = WCMCoreUtils.getSystemSessionProvider().getSession(ws.getName(), manageRepository); } try { lockedNode = (Node) session.getItem(nodePath); if ((lockedNode != null) && !Utils.isInTrash(lockedNode)) break; } catch (PathNotFoundException e) { continue; } catch (AccessDeniedException accessDeniedException) { continue; } } if (lockedNode == null) { Object[] args = { nodePath }; ApplicationMessage msg = new ApplicationMessage("UILockNodeList.msg.access-denied-exception", args, ApplicationMessage.WARNING); msg.setArgsLocalized(false); uiApp.addMessage(msg); uiUnLockManager.refresh(); event.getRequestContext().addUIComponentToUpdateByAjax(uiUnLockManager); return; } if (isAuthenticated ) { session = WCMCoreUtils.getSystemSessionProvider() .getSession(lockedNode.getSession().getWorkspace().getName(), (ManageableRepository) lockedNode.getSession() .getRepository()); lockedNode = (Node)session.getItem(lockedNode.getPath()); } try { if(lockedNode.holdsLock()) { String lockToken = LockUtil.getLockToken(lockedNode); if(lockToken != null) { session.addLockToken(lockToken); } lockedNode.unlock(); lockedNode.removeMixin(Utils.MIX_LOCKABLE); lockedNode.getSession().save(); LockUtil.removeLock(lockedNode); } } catch(LockException le) { uiApp.addMessage(new ApplicationMessage("UILockNodeList.msg.can-not-unlock-node", null, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiUnLockManager); return; } catch(VersionException versionException) { Object[] args = {lockedNode.getName()}; uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.can-not-unlock-node-is-checked-in", args, ApplicationMessage.WARNING)); event.getRequestContext().addUIComponentToUpdateByAjax(uiUnLockManager); return; } catch (Exception e) { JCRExceptionManager.process(uiApp, e); } uiUnLockManager.refresh(); uiUnLockManager.getChild(UILockNodeList.class).setRendered(true); uiUnLockManager.getChild(UILockHolderContainer.class).setRendered(false); } } }
13,111
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIUnLockManager.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/unlock/UIUnLockManager.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.admin.unlock; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.core.UIPopupWindow; import org.exoplatform.webui.ext.manager.UIAbstractManager; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Dec 29, 2006 * 11:27:14 AM */ @ComponentConfig(template = "system:/groovy/webui/core/UITabPane.gtmpl") public class UIUnLockManager extends UIAbstractManager { public UIUnLockManager() throws Exception { addChild(UILockNodeList.class, null, null).setRendered(true); addChild(UILockHolderContainer.class, null, null).setRendered(false); } public void refresh() throws Exception { update(); } public void update() throws Exception{ UILockNodeList uiLockNodeList = getChild(UILockNodeList.class); uiLockNodeList.refresh(uiLockNodeList.getUIPageIterator().getCurrentPage()); UILockHolderContainer uiHolderContainer = getChild(UILockHolderContainer.class); if (uiHolderContainer != null) { UILockHolderList uiLockHolderList = uiHolderContainer.getChild(UILockHolderList.class); uiLockHolderList.refresh(uiLockHolderList.getUIPageIterator().getCurrentPage()); } } public void initFormPopup(String id) throws Exception { removeChildById(id); UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, id); uiPopup.setShowMask(true); uiPopup.setWindowSize(600, 500); UIUnLockForm uiForm = createUIComponent(UIUnLockForm.class, null, null); uiPopup.setUIComponent(uiForm); uiPopup.setRendered(true); uiPopup.setShow(true); uiPopup.setResizable(true); } public void initPermissionPopup(String membership) throws Exception { removeChildById("PermissionPopup"); UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, "PermissionPopup"); uiPopup.setShowMask(true); uiPopup.setWindowSize(560, 300); UIPermissionSelector uiECMPermission = createUIComponent(UIPermissionSelector.class, null, "GroupsOrUsersBrowse"); uiECMPermission.setSelectedMembership(true); if(membership != null && membership.indexOf(":/") > -1) { String[] arrMember = membership.split(":/"); uiECMPermission.setCurrentPermission("/" + arrMember[1]); } uiPopup.setUIComponent(uiECMPermission); UIUnLockForm uiForm = findFirstComponentOfType(UIUnLockForm.class); uiECMPermission.setSourceComponent(uiForm, new String[] {UIUnLockForm.GROUPS_OR_USERS}); uiPopup.setRendered(true); uiPopup.setShow(true); uiPopup.setResizable(true); } }
3,369
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIUnLockForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/unlock/UIUnLockForm.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.admin.unlock; import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.services.cms.lock.LockService; 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; /** * Created by The eXo Platform SARL * Author : Dang Van Minh * minh.dang@exoplatform.com * Dec 29, 2006 * 11:30:29 AM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIForm.gtmpl", events = { @EventConfig(listeners = UIUnLockForm.SaveActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIUnLockForm.CancelActionListener.class), @EventConfig(phase = Phase.DECODE, listeners = UIUnLockForm.AddPermissionActionListener.class) } ) public class UIUnLockForm extends UIForm implements UISelectable { final static public String GROUPS_OR_USERS = "groupsOrUsers"; final static public String[] ACTIONS = {"Save", "Cancel"}; public UIUnLockForm() throws Exception { UIFormInputSetWithAction uiInputAct = new UIFormInputSetWithAction("PermissionButton"); uiInputAct.addUIFormInput( new UIFormStringInput(GROUPS_OR_USERS, GROUPS_OR_USERS, null). setReadOnly(true).addValidator(MandatoryValidator.class)); uiInputAct.setActionInfo(GROUPS_OR_USERS, new String[] {"AddPermission"}); addUIComponentInput(uiInputAct); } public String[] getActions() { return ACTIONS ; } public void doSelect(String selectField, Object value) { getUIStringInput(selectField).setValue(value.toString()); UIUnLockManager uiManager = getAncestorOfType(UIUnLockManager.class); UIPopupWindow uiPopup = uiManager.getChildById("PermissionPopup"); uiPopup.setRendered(false); uiPopup.setShow(false); uiManager.getChild(UILockNodeList.class).setRendered(false); uiManager.getChild(UIUnLockForm.class).setRendered(true); } public void update()throws Exception { getUIStringInput(GROUPS_OR_USERS).setValue(""); } static public class CancelActionListener extends EventListener<UIUnLockForm> { public void execute(Event<UIUnLockForm> event) throws Exception { UIUnLockForm uiForm = event.getSource(); UIUnLockManager uiManager = uiForm.getAncestorOfType(UIUnLockManager.class); uiManager.removeChildById("PermissionPopup"); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } static public class SaveActionListener extends EventListener<UIUnLockForm> { public void execute(Event<UIUnLockForm> event) throws Exception { UIUnLockForm uiUnLockForm = event.getSource(); UIApplication uiApp = uiUnLockForm.getAncestorOfType(UIApplication.class); UIFormInputSetWithAction permField = uiUnLockForm.getChildById("PermissionButton"); String groupsOrUsers = permField.getUIStringInput(GROUPS_OR_USERS).getValue(); if((groupsOrUsers == null)||(groupsOrUsers.trim().length() == 0)) { uiApp.addMessage(new ApplicationMessage("UIUnLockForm.msg.permission-require", null, ApplicationMessage.WARNING)); return; } UIUnLockManager uiManager = uiUnLockForm.getAncestorOfType(UIUnLockManager.class); LockService lockService = uiUnLockForm.getApplicationComponent(LockService.class); lockService.addGroupsOrUsersForLock(groupsOrUsers); UILockNodeList uiLockList = uiManager.getChild(UILockNodeList.class); uiUnLockForm.update(); uiLockList.refresh(1); uiLockList.setRendered(true); uiManager.removeChildById("PermissionPopup"); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } static public class AddPermissionActionListener extends EventListener<UIUnLockForm> { public void execute(Event<UIUnLockForm> event) throws Exception { UIUnLockManager uiManager = event.getSource().getAncestorOfType(UIUnLockManager.class); String membership = event.getSource().getUIStringInput(GROUPS_OR_USERS).getValue(); uiManager.initPermissionPopup(membership); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } }
5,651
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UILockList.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/unlock/UILockList.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.admin.unlock; import java.util.List; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; import org.exoplatform.ecm.webui.core.UIPagingGridDecorator; import org.exoplatform.services.cms.lock.LockService; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; 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 * Dec 29, 2006 * 11:30:17 AM */ @ComponentConfig( template = "app:/groovy/webui/component/admin/unlock/UILockList.gtmpl", events = { @EventConfig(listeners = UILockList.DeleteLockActionListener.class) } ) public class UILockList extends UIPagingGridDecorator { final static public String[] ACTIONS = {}; final static public String ST_EDIT = "EditUnLockForm"; public UILockList() throws Exception { getUIPageIterator().setId("LockListIterator"); } public String[] getActions() { return ACTIONS; } public void refresh(int currentPage) throws Exception { ListAccess<String> groupsAndUsersForLockList = new ListAccessImpl<String>(String.class, getAllGroupsOrUsersForLock()); LazyPageList<String> pageList = new LazyPageList<String>(groupsAndUsersForLockList, getUIPageIterator().getItemsPerPage()); getUIPageIterator().setPageList(pageList); if (currentPage > getUIPageIterator().getAvailablePage()) getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage()); else getUIPageIterator().setCurrentPage(currentPage); } public List getGroupsOrUsersForLock() throws Exception { return getUIPageIterator().getCurrentPageData(); } public List<String> getAllGroupsOrUsersForLock() throws Exception { LockService lockService = getApplicationComponent(LockService.class); return lockService.getAllGroupsOrUsersForLock(); } static public class DeleteLockActionListener extends EventListener<UILockList> { public void execute(Event<UILockList> event) throws Exception { UIUnLockManager uiUnLockManager = event.getSource().getParent(); String settingLock = event.getRequestContext().getRequestParameter(OBJECTID); LockService lockService = uiUnLockManager.getApplicationComponent(LockService.class); lockService.removeGroupsOrUsersForLock(settingLock); UILockList uiLockList = uiUnLockManager.getChild(UILockList.class); uiLockList.refresh(uiLockList.getUIPageIterator().getCurrentPage()); event.getRequestContext().addUIComponentToUpdateByAjax(uiUnLockManager); } } }
3,680
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIUserContainer.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/unlock/UIUserContainer.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.admin.unlock; import org.exoplatform.services.cms.lock.LockService; 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.lifecycle.UIContainerLifecycle; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.organization.account.UIUserSelector; /** * Created by The eXo Platform SARL * Author : Hoang Van Hung * hunghvit@gmail.com * Dec 3, 2008 */ @ComponentConfig( lifecycle = UIContainerLifecycle.class, events = {@EventConfig(listeners = UIUserContainer.AddUserActionListener.class)} ) public class UIUserContainer extends UIContainer { public UIUserContainer() throws Exception { UIUserSelector uiUserSelector = getChild(UIUserSelector.class); if (uiUserSelector == null) { uiUserSelector = addChild(UIUserSelector.class, null, null); } uiUserSelector.setMulti(false); uiUserSelector.setShowSearchUser(true); uiUserSelector.setShowSearch(true); } static public class AddUserActionListener extends EventListener<UIUserContainer> { public void execute(Event<UIUserContainer> event) throws Exception { UIUserContainer uiUserContainer = event.getSource(); UIUserSelector uiUserSelector = uiUserContainer.getChild(UIUserSelector.class); LockService lockService = uiUserContainer.getApplicationComponent(LockService.class); lockService.addGroupsOrUsersForLock(uiUserSelector.getSelectedUsers()); UIUnLockManager uiUnLockManager = uiUserContainer.getParent(); uiUnLockManager.refresh(); } } }
2,121
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIPermissionSelector.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/unlock/UIPermissionSelector.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.admin.unlock; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.ecm.webui.selector.ComponentSelector; import org.exoplatform.ecm.webui.selector.UIAnyPermission; import org.exoplatform.ecm.utils.lock.LockUtil; import org.exoplatform.services.cms.lock.LockService; import org.exoplatform.services.organization.Group; import org.exoplatform.services.organization.OrganizationService; import org.exoplatform.services.organization.User; import org.exoplatform.services.wcm.utils.WCMCoreUtils; 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.UIBreadcumbs; import org.exoplatform.webui.core.UIComponent; import org.exoplatform.webui.core.UITree; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.organization.UIGroupMembershipSelector; /** * Created by The eXo Platform SARL Author : Dang Van Minh * minh.dang@exoplatform.com Nov 17, 2006 */ @ComponentConfigs( { @ComponentConfig( template = "classpath:groovy/ecm/webui/UIMemberSelector.gtmpl", events = { @EventConfig(listeners = UIPermissionSelector.ChangeNodeActionListener.class), @EventConfig(listeners = UIPermissionSelector.SelectMembershipActionListener.class), @EventConfig(listeners = UIPermissionSelector.SelectPathActionListener.class) }), @ComponentConfig( type = UITree.class, id = "UITreeGroupSelector", template = "system:/groovy/webui/core/UITree.gtmpl", events = @EventConfig(listeners = UITree.ChangeNodeActionListener.class)), @ComponentConfig( type = UIBreadcumbs.class, id = "BreadcumbGroupSelector", template = "system:/groovy/webui/core/UIBreadcumbs.gtmpl", events = @EventConfig(listeners = UIBreadcumbs.SelectPathActionListener.class)) } ) public class UIPermissionSelector extends UIGroupMembershipSelector implements ComponentSelector { /** The Constant defaultValue. */ final static public String defaultValue = "/admin"; /** The ui component. */ private UIComponent uiComponent; /** The return field name. */ private String returnFieldName = null; /** The is selected membership. */ private boolean isSelectedMembership = true; /** The is selected user. */ private boolean isSelectedUser; /** The is use popup. */ private boolean isUsePopup = true; /** * Instantiates a new uI permission selector. * * @throws Exception the exception */ public UIPermissionSelector() throws Exception { changeGroup(defaultValue); addChild(UIAnyPermission.class, null, null); } /** * Sets the current permission. * * @param per the new current permission * * @throws Exception the exception */ public void setCurrentPermission(String per) throws Exception { changeGroup(per); } /** * Gets the return component. * * @return the return component */ public UIComponent getSourceComponent() { return uiComponent; } /** * Gets the return field. * * @return the return field */ public String getReturnField() { return returnFieldName; } public void setIsUsePopup(boolean isUsePopup) { this.isUsePopup = isUsePopup; } public boolean isUsePopup() { return isUsePopup; } /* * (non-Javadoc) * @seeorg.exoplatform.ecm.webui.selector.ComponentSelector#setComponent(org. * exoplatform.webui.core.UIComponent, java.lang.String[]) */ public void setSourceComponent(UIComponent uicomponent, String[] initParams) { uiComponent = uicomponent; if (initParams == null || initParams.length == 0) return; for (int i = 0; i < initParams.length; i++) { if (initParams[i].indexOf("returnField") > -1) { String[] array = initParams[i].split("="); returnFieldName = array[1]; break; } returnFieldName = initParams[0]; } } /** * The listener interface for receiving selectMembershipAction events. The * class that is interested in processing a selectMembershipAction event * implements this interface, and the object created with that class is * registered with a component using the component's * <code>addSelectMembershipActionListener</code> method. When * the selectMembershipAction event occurs, that object's appropriate * method is invoked. */ static public class SelectMembershipActionListener extends EventListener<UIPermissionSelector> { /* (non-Javadoc) * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event) */ public void execute(Event<UIPermissionSelector> event) throws Exception { UIPermissionSelector uiPermissionSelector = event.getSource(); if (uiPermissionSelector.getCurrentGroup() == null) return; String groupId = uiPermissionSelector.getCurrentGroup().getId(); String permission = event.getRequestContext().getRequestParameter(OBJECTID); String value = ""; if(uiPermissionSelector.isSelectedUser()) { value = permission; } else { value = permission + ":" + groupId; } LockService lockService = uiPermissionSelector.getApplicationComponent(LockService.class); lockService.addGroupsOrUsersForLock(value); LockUtil.updateLockCache(value); UIUnLockManager uiUnLockManager = uiPermissionSelector.getAncestorOfType(UIUnLockManager.class); uiUnLockManager.refresh(); uiUnLockManager.getChild(UILockNodeList.class).setRendered(false); uiUnLockManager.getChild(UILockHolderContainer.class).setRendered(true); } } /** * The listener interface for receiving changeNodeAction events. The class * that is interested in processing a changeNodeAction event implements this * interface, and the object created with that class is registered with a * component using the component's * <code>addChangeNodeActionListener</code> method. When * the changeNodeAction event occurs, that object's appropriate * method is invoked. */ static public class ChangeNodeActionListener extends EventListener<UITree> { /* (non-Javadoc) * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event) */ public void execute(Event<UITree> event) throws Exception { UIPermissionSelector uiPermissionSelector = event.getSource().getParent(); String groupId = event.getRequestContext().getRequestParameter(OBJECTID); uiPermissionSelector.changeGroup(groupId); event.getRequestContext().addUIComponentToUpdateByAjax(uiPermissionSelector); } } /** * The listener interface for receiving selectPathAction events. The class * that is interested in processing a selectPathAction event implements this * interface, and the object created with that class is registered with a * component using the component's * <code>addSelectPathActionListener</code> method. When * the selectPathAction event occurs, that object's appropriate * method is invoked. */ static public class SelectPathActionListener extends EventListener<UIBreadcumbs> { /* (non-Javadoc) * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event) */ public void execute(Event<UIBreadcumbs> event) throws Exception { UIBreadcumbs uiBreadcumbs = event.getSource(); UIPermissionSelector uiPermissionSelector = uiBreadcumbs.getParent(); String objectId = event.getRequestContext().getRequestParameter(OBJECTID); uiBreadcumbs.setSelectPath(objectId); String selectGroupId = uiBreadcumbs.getSelectLocalPath().getId(); uiPermissionSelector.changeGroup(selectGroupId); event.getRequestContext().addUIComponentToUpdateByAjax(uiPermissionSelector); } } /** * Sets the selected user. * * @param bool the new selected user */ public void setSelectedUser(boolean bool) { isSelectedUser = bool; } /** * Checks if is selected user. * * @return true, if is selected user */ public boolean isSelectedUser() { return isSelectedUser; } /** * Sets the selected membership. * * @param bool the new selected membership */ public void setSelectedMembership(boolean bool) { isSelectedMembership = bool; } /** * Checks if is selected membership. * * @return true, if is selected membership */ public boolean isSelectedMembership() { return isSelectedMembership; } /** * Gets the users. * * @return the users * * @throws Exception the exception */ public List getUsers() throws Exception { List<User> children = new ArrayList<User>(); OrganizationService service = WCMCoreUtils.getService(OrganizationService.class); ListAccess<User> userPageList = service.getUserHandler().findUsersByGroupId(this.getCurrentGroup().getId()); for (User child : userPageList.load(0, userPageList.getSize())) { children.add(child); } return children; } /** * Check show/hide form to set any permission * @return */ public boolean isShowAnyPermission() { return false; } @SuppressWarnings("unchecked") public List<String> getListGroup() throws Exception { OrganizationService service = WCMCoreUtils.getService(OrganizationService.class); List<String> listGroup = new ArrayList<String>(); if(getCurrentGroup() == null) return null; Collection<Group> groups = service.getGroupHandler().findGroups(getCurrentGroup()); if(groups.size() > 0) { for (Object child : groups) { Group childGroup = (Group)child; listGroup.add(childGroup.getId()) ; } } return listGroup; } }
10,761
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z
UIDriveForm.java
/FileExtraction/Java_unseen/exoplatform_ecms/core/webui-administration/src/main/java/org/exoplatform/ecm/webui/component/admin/drives/UIDriveForm.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.admin.drives; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Set; import javax.jcr.Session; import org.exoplatform.ecm.webui.selector.UISelectable; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.services.cms.drives.DriveData; import org.exoplatform.services.cms.drives.ManageDriveService; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.jcr.RepositoryService; import org.exoplatform.services.jcr.config.WorkspaceEntry; import org.exoplatform.services.jcr.impl.core.WorkspaceInitializer; 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.UIComponent; 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.UIFormInputSet; import org.exoplatform.webui.form.UIFormSelectBox; import org.exoplatform.webui.form.UIFormStringInput; import org.exoplatform.webui.form.UIFormTabPane; /** * Created by The eXo Platform SARL * Author : Tran The Trong * trongtt@exoplatform.com * Sep 19, 2006 * 5:31:04 PM */ @ComponentConfig( lifecycle = UIFormLifecycle.class, template = "system:/groovy/webui/form/UIFormTabPane.gtmpl", events = { @EventConfig(listeners = UIDriveForm.SaveActionListener.class), @EventConfig(listeners = UIDriveForm.RefreshActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDriveForm.CancelActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDriveForm.AddPermissionActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDriveForm.RemovePermissionActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDriveForm.AddPathActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDriveForm.AddIconActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDriveForm.ChangeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDriveForm.ChooseNodeTypeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDriveForm.RemoveNodeTypeActionListener.class, phase = Phase.DECODE), @EventConfig(listeners = UIDriveForm.SelectTabActionListener.class, phase = Phase.DECODE) } ) public class UIDriveForm extends UIFormTabPane implements UISelectable { private boolean isAddNew_ = true; final static public String[] ACTIONS = {"Save", "Refresh", "Cancel"}; final static public String POPUP_DRIVEPERMISSION = "PopupDrivePermission"; final static public String POPUP_NODETYPE_SELECTOR = "PopupNodeTypeSelector"; private String membershipString = ""; private String nodeTypes = ""; final static public String ANY_PERMISSION = "*"; public UIDriveForm() throws Exception { super("UIDriveForm"); UIFormInputSet driveInputSet = new UIDriveInputSet("DriveInputSet"); UIFormSelectBox selectBox = driveInputSet.getChildById(UIDriveInputSet.FIELD_WORKSPACE); selectBox.setOnChange("Change"); addUIFormInput(driveInputSet); setSelectedTab(driveInputSet.getId()); UIFormInputSet viewInputSet = new UIViewsInputSet("ViewsInputSet"); addUIFormInput(viewInputSet); setActions(ACTIONS); } public String getLabel(ResourceBundle res, String id) { try { return res.getString("UIDriveForm.label." + id); } catch (MissingResourceException ex) { return id + " "; } } public void doSelect(String selectField, Object value) { UIFormStringInput uiStringInput = getUIStringInput(selectField); if (selectField.equals(UIDriveInputSet.FIELD_PERMISSION)){ String membership = value.toString(); String valuePermissions = uiStringInput.getValue(); List<String> permissionsList = new ArrayList<String>(); StringBuilder newsPermissions = new StringBuilder(); if(valuePermissions != null) { String[] permissionsArray = valuePermissions.split(","); permissionsList = Arrays.asList(permissionsArray); if (permissionsList.size() > 0) { for (String permission : permissionsList) { if(newsPermissions.length() > 0) newsPermissions.append(","); newsPermissions.append(permission.trim()); } } if(!permissionsList.contains(membership)) { if(newsPermissions.length() > 0) { newsPermissions.append(",").append(membership.trim()); } else { newsPermissions.append(membership.trim()); } } uiStringInput.setValue(newsPermissions.toString()); } else uiStringInput.setValue(value.toString()); } else if (selectField.equals(UIDriveInputSet.FIELD_HOMEPATH)){ uiStringInput.setValue(value.toString()); UIDriveInputSet driveInputSet = getChild(UIDriveInputSet.class); if (driveInputSet!=null) driveInputSet.updateFolderAllowed(value.toString()); } else { uiStringInput.setValue(value.toString()); } UIDriveManager uiContainer = getAncestorOfType(UIDriveManager.class) ; for(UIComponent uiChild : uiContainer.getChildren()) { if(uiChild.getId().equals(POPUP_DRIVEPERMISSION) || uiChild.getId().equals("JCRBrowser") || uiChild.getId().equals("JCRBrowserAssets") || uiChild.getId().equals(POPUP_NODETYPE_SELECTOR)) { UIPopupWindow uiPopup = uiContainer.getChildById(uiChild.getId()) ; uiPopup.setRendered(false) ; } } } public void refresh(String driveName) throws Exception { DriveData drive = null; if(driveName == null) { isAddNew_ = true; } else { isAddNew_ = false; setActions(new String[] {"Save", "Cancel"}); drive = getApplicationComponent(ManageDriveService.class).getDriveByName(driveName); } getChild(UIDriveInputSet.class).update(drive); getChild(UIViewsInputSet.class).update(drive); } public String getWorkspaceEntries(String selectedWorkspace) throws Exception { RepositoryService repositoryService = getApplicationComponent(RepositoryService.class); List<WorkspaceEntry> wsEntries = repositoryService.getCurrentRepository() .getConfiguration() .getWorkspaceEntries(); String wsInitRootNodeType = null; for(WorkspaceEntry wsEntry : wsEntries) { if(wsEntry.getName().equals(selectedWorkspace)) { wsInitRootNodeType = wsEntry.getInitializer().getParameterValue(WorkspaceInitializer.ROOT_NODETYPE_PARAMETER); break; } } return wsInitRootNodeType; } /* (non-Javadoc) * @see org.exoplatform.webui.form.UIForm#processRender(org.exoplatform.webui.application.WebuiRequestContext) */ @Override public void processRender(WebuiRequestContext context) throws Exception { context.getJavascriptManager().require("SHARED/jquery", "gj") .addScripts("gj(document).ready(function() { gj(\"*[rel='tooltip']\").tooltip();});"); super.processRender(context); } static public class SaveActionListener extends EventListener<UIDriveForm> { public void execute(Event<UIDriveForm> event) throws Exception { UIDriveForm uiDriveForm = event.getSource(); ManageDriveService dservice_ = uiDriveForm.getApplicationComponent(ManageDriveService.class); RepositoryService rservice = uiDriveForm.getApplicationComponent(RepositoryService.class); UIDriveInputSet driveInputSet = uiDriveForm.getChild(UIDriveInputSet.class); UIApplication uiApp = uiDriveForm.getAncestorOfType(UIApplication.class); String name = driveInputSet.getUIStringInput(UIDriveInputSet.FIELD_NAME).getValue().trim(); String workspace = driveInputSet.getUIFormSelectBox(UIDriveInputSet.FIELD_WORKSPACE).getValue(); String path = driveInputSet.getUIStringInput(UIDriveInputSet.FIELD_HOMEPATH).getValue(); if((path == null)||(path.trim().length() == 0)) path = "/"; // Only check path if Drive is not virtual drive if (!dservice_.isVitualDrive(name)) { Session session = null; try { session = rservice.getCurrentRepository().getSystemSession(workspace); String userId = Util.getPortalRequestContext().getRemoteUser(); String pathReal = org.exoplatform.services.cms.impl.Utils.getPersonalDrivePath(path, userId); session.getItem(pathReal); session.logout(); } catch(Exception e) { if(session!=null) { session.logout(); } uiApp.addMessage(new ApplicationMessage("UIDriveForm.msg.workspace-path-invalid", null, ApplicationMessage.WARNING)); return; } } boolean viewReferences = driveInputSet.getUICheckBoxInput(UIDriveInputSet.FIELD_VIEWPREFERENCESDOC).isChecked(); boolean viewSideBar = driveInputSet.getUICheckBoxInput(UIDriveInputSet.FIELD_VIEWSIDEBAR).isChecked(); boolean showHiddenNode = driveInputSet.getUICheckBoxInput(UIDriveInputSet.SHOW_HIDDEN_NODE).isChecked(); boolean viewNonDocument = driveInputSet.getUICheckBoxInput(UIDriveInputSet.FIELD_VIEWNONDOC).isChecked(); String[] allowCreateFolders = driveInputSet.getUIFormSelectBox(UIDriveInputSet.FIELD_ALLOW_CREATE_FOLDERS) .getSelectedValues(); if (allowCreateFolders == null || allowCreateFolders.length == 0 ) { allowCreateFolders = new String[] {}; } StringBuilder foldertypes = new StringBuilder(""); for (String allowCreateFolder : allowCreateFolders) { foldertypes.append(allowCreateFolder).append(","); } if (foldertypes.toString().endsWith(",")) foldertypes.deleteCharAt(foldertypes.length() -1 ); UIViewsInputSet viewsInputSet = uiDriveForm.getChild(UIViewsInputSet.class); String views = viewsInputSet.getViewsSelected(); String permissions = driveInputSet.getUIStringInput(UIDriveInputSet.FIELD_PERMISSION).getValue(); if (permissions.subSequence(permissions.length() - 1, permissions.length()).equals(",")) permissions = permissions.substring(0, permissions.length() - 1); String[] arrPermissions = permissions.split(","); for (String itemPermission : arrPermissions) { if (itemPermission != null && itemPermission.trim().equals("*")) { permissions = "*"; break; } } if(uiDriveForm.isAddNew_ && (dservice_.getDriveByName(name) != null)) { uiApp.addMessage(new ApplicationMessage("UIDriveForm.msg.drive-exists", null, ApplicationMessage.WARNING)); return; } String iconPath = driveInputSet.getUIStringInput(UIDriveInputSet.FIELD_WORKSPACEICON).getValue(); if(iconPath != null && iconPath.trim().length() > 0) { Session jcrSession = null; try { if(iconPath.indexOf(":/") > -1) { String[] paths = iconPath.split(":/"); jcrSession = rservice.getCurrentRepository().getSystemSession(paths[0]); jcrSession.getItem("/" + paths[1]); jcrSession.logout(); } } catch(Exception e) { if(jcrSession != null) { jcrSession.logout(); } uiApp.addMessage(new ApplicationMessage("UIDriveForm.msg.icon-not-found", null, ApplicationMessage.WARNING)); return; } } else { iconPath = ""; } String allowNodeTypesOnTree = driveInputSet.getUIStringInput(UIDriveInputSet.FIELD_ALLOW_NODETYPES_ON_TREE).getValue(); if ((allowNodeTypesOnTree==null) || (allowNodeTypesOnTree.length()==0)) allowNodeTypesOnTree = "*"; dservice_.addDrive(name, workspace, permissions, path, views, iconPath, viewReferences, viewNonDocument, viewSideBar, showHiddenNode, foldertypes.toString(), allowNodeTypesOnTree); UIDriveManager uiManager = uiDriveForm.getAncestorOfType(UIDriveManager.class); UIDriveList uiDriveList = uiManager.getChild(UIDriveList.class); uiDriveList.refresh(uiDriveList.getUIPageIterator().getCurrentPage()); uiDriveForm.refresh(null); UIDriveManager uiDriveManager = uiDriveForm.getAncestorOfType(UIDriveManager.class); uiDriveManager.removeChildById(UIDriveForm.POPUP_DRIVEPERMISSION); UIPopupWindow uiPopup = uiDriveManager.getChildById(UIDriveList.ST_ADD); if(uiPopup != null) { uiPopup.setShow(false); uiPopup.setRendered(false); } UIPopupWindow uiEditPopup = uiDriveManager.getChildById(UIDriveList.ST_EDIT); if(uiEditPopup != null) { uiEditPopup.setShow(false); uiEditPopup.setRendered(false); } event.getRequestContext().addUIComponentToUpdateByAjax(uiDriveManager); } } static public class CancelActionListener extends EventListener<UIDriveForm> { public void execute(Event<UIDriveForm> event) throws Exception { UIDriveForm uiDriveForm = event.getSource(); uiDriveForm.refresh(null); UIDriveManager uiDriveManager = uiDriveForm.getAncestorOfType(UIDriveManager.class); uiDriveManager.removeChildById(UIDriveForm.POPUP_DRIVEPERMISSION); UIPopupWindow uiPopup = uiDriveManager.getChildById(UIDriveList.ST_ADD); if(uiPopup != null) { uiPopup.setShow(false); uiPopup.setRendered(false); } UIPopupWindow uiEditPopup = uiDriveManager.getChildById(UIDriveList.ST_EDIT); if(uiEditPopup != null) { uiEditPopup.setShow(false); uiEditPopup.setRendered(false); } event.getRequestContext().addUIComponentToUpdateByAjax(uiDriveManager); } } static public class RefreshActionListener extends EventListener<UIDriveForm> { public void execute(Event<UIDriveForm> event) throws Exception { event.getSource().refresh(null); event.getRequestContext().addUIComponentToUpdateByAjax(event.getSource()); } } static public class AddPermissionActionListener extends EventListener<UIDriveForm> { public void execute(Event<UIDriveForm> event) throws Exception { UIDriveForm uiDriveForm = event.getSource(); UIDriveManager uiManager = uiDriveForm.getAncestorOfType(UIDriveManager.class); String membership = uiDriveForm.getUIStringInput(UIDriveInputSet.FIELD_PERMISSION).getValue(); uiDriveForm.membershipString = membership; uiDriveForm.getUIStringInput(UIDriveInputSet.FIELD_PERMISSION).setValue(uiDriveForm.membershipString); uiManager.initPopupPermission(uiDriveForm.membershipString); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } static public class RemovePermissionActionListener extends EventListener<UIDriveForm> { public void execute(Event<UIDriveForm> event) throws Exception { UIDriveForm uiDriveForm = event.getSource(); uiDriveForm.membershipString = ""; uiDriveForm.getUIStringInput(UIDriveInputSet.FIELD_PERMISSION).setValue(null); event.getRequestContext().addUIComponentToUpdateByAjax(uiDriveForm); } } static public class AddPathActionListener extends EventListener<UIDriveForm> { public void execute(Event<UIDriveForm> event) throws Exception { UIDriveForm uiDriveForm = event.getSource(); UIDriveManager uiManager = uiDriveForm.getAncestorOfType(UIDriveManager.class); UIDriveInputSet driveInputSet = uiDriveForm.getChild(UIDriveInputSet.class); String workspace = driveInputSet.getUIFormSelectBox(UIDriveInputSet.FIELD_WORKSPACE).getValue(); uiManager.initPopupJCRBrowser(workspace, true); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } static public class AddIconActionListener extends EventListener<UIDriveForm> { public void execute(Event<UIDriveForm> event) throws Exception { UIDriveForm uiDriveForm = event.getSource(); UIDriveManager uiManager = uiDriveForm.getAncestorOfType(UIDriveManager.class); UIDriveInputSet driveInputSet = uiDriveForm.getChild(UIDriveInputSet.class); String workspace = driveInputSet.getUIFormSelectBox(UIDriveInputSet.FIELD_WORKSPACE).getValue(); uiManager.initPopupJCRBrowserAssets(workspace); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } static public class ChangeActionListener extends EventListener<UIDriveForm> { public void execute(Event<UIDriveForm> event) throws Exception { UIDriveForm uiDriveForm = event.getSource(); String driverName = uiDriveForm.getUIStringInput(UIDriveInputSet.FIELD_NAME).getValue(); String selectedWorkspace = uiDriveForm.getUIStringInput(UIDriveInputSet.FIELD_WORKSPACE).getValue(); UIDriveInputSet driveInputSet = uiDriveForm.getChild(UIDriveInputSet.class); UIDriveManager uiManager = uiDriveForm.getAncestorOfType(UIDriveManager.class); ManageDriveService manageDriveService = uiDriveForm.getApplicationComponent(ManageDriveService.class); RepositoryService repositoryService = uiDriveForm.getApplicationComponent(RepositoryService.class); List<WorkspaceEntry> wsEntries = repositoryService.getCurrentRepository().getConfiguration().getWorkspaceEntries(); String wsInitRootNodeType = null; for(WorkspaceEntry wsEntry : wsEntries) { if(wsEntry.getName().equals(selectedWorkspace)) { wsInitRootNodeType = wsEntry.getInitializer().getParameterValue(WorkspaceInitializer.ROOT_NODETYPE_PARAMETER); } } TemplateService templateService = uiDriveForm.getApplicationComponent(TemplateService.class); Set<String> setFoldertypes = templateService.getAllowanceFolderType(); List<SelectItemOption<String>> foldertypeOptions = new ArrayList<SelectItemOption<String>>(); RequestContext context = RequestContext.getCurrentInstance(); ResourceBundle res = context.getApplicationResourceBundle(); String label = null; for(String folderType : setFoldertypes) { try { label = res.getString(driveInputSet.getId() + ".label." + folderType.replace(":", "_")); } catch(MissingResourceException mi) { label = folderType; } foldertypeOptions.add(new SelectItemOption<String>(label, folderType)); } List<SelectItemOption<String>> folderOptions = new ArrayList<SelectItemOption<String>>(); UIFormSelectBox uiInput = driveInputSet.<UIFormSelectBox>getUIInput(UIDriveInputSet.FIELD_ALLOW_CREATE_FOLDERS); if(wsInitRootNodeType != null && wsInitRootNodeType.equals(Utils.NT_FOLDER)) { folderOptions.add(new SelectItemOption<String>(UIDriveInputSet.FIELD_FOLDER_ONLY, Utils.NT_FOLDER)); } else { folderOptions.addAll(foldertypeOptions); } uiInput.setOptions(folderOptions); if(!uiDriveForm.isAddNew_) { DriveData drive = manageDriveService.getDriveByName(driverName); String defaultPath = drive.getHomePath(); if(!drive.getWorkspace().equals(selectedWorkspace)) defaultPath = "/"; uiDriveForm.getUIStringInput(UIDriveInputSet.FIELD_HOMEPATH).setValue(defaultPath); } event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } static public class ChooseNodeTypeActionListener extends EventListener<UIDriveForm> { public void execute(Event<UIDriveForm> event) throws Exception { UIDriveForm uiDriveForm = event.getSource(); UIDriveManager uiManager = uiDriveForm.getAncestorOfType(UIDriveManager.class); String nodeTypes = uiDriveForm.getUIStringInput(UIDriveInputSet.FIELD_ALLOW_NODETYPES_ON_TREE).getValue(); if (nodeTypes != null){ uiDriveForm.nodeTypes = nodeTypes; } else { uiDriveForm.nodeTypes = ""; } uiDriveForm.getUIStringInput( UIDriveInputSet.FIELD_ALLOW_NODETYPES_ON_TREE).setValue(uiDriveForm.nodeTypes); uiManager.initPopupNodeTypeSelector(uiDriveForm.nodeTypes); event.getRequestContext().addUIComponentToUpdateByAjax(uiManager); } } static public class RemoveNodeTypeActionListener extends EventListener<UIDriveForm> { public void execute(Event<UIDriveForm> event) throws Exception { UIDriveForm uiDriveForm = event.getSource(); uiDriveForm.nodeTypes = ""; uiDriveForm.getUIStringInput(UIDriveInputSet.FIELD_ALLOW_NODETYPES_ON_TREE).setValue(null); event.getRequestContext().addUIComponentToUpdateByAjax(uiDriveForm); } } static public class SelectTabActionListener extends EventListener<UIDriveForm> { public void execute(Event<UIDriveForm> event) throws Exception { WebuiRequestContext context = event.getRequestContext(); String renderTab = context.getRequestParameter(UIComponent.OBJECTID); if (renderTab == null) return; event.getSource().setSelectedTab(renderTab); event.getRequestContext().addUIComponentToUpdateByAjax(event.getSource()); } } }
22,764
Java
.java
exoplatform/ecms
25
59
13
2012-04-05T03:17:28Z
2024-05-09T08:26:32Z