001: package org.contineo.web.document;
002:
003: import org.apache.commons.logging.Log;
004: import org.apache.commons.logging.LogFactory;
005:
006: import org.contineo.core.security.Menu;
007: import org.contineo.core.security.dao.MenuDAO;
008:
009: import org.contineo.util.Context;
010:
011: import org.contineo.web.SessionManagement;
012: import org.contineo.web.i18n.Messages;
013: import org.contineo.web.navigation.PageContentBean;
014:
015: /**
016: * Base form for directory editing
017: *
018: * @author Marco Meschieri
019: * @version $Id: DirectoryEditForm.java,v 1.2 2006/09/03 16:24:37 marco Exp $
020: * @since 3.0
021: */
022: public class DirectoryEditForm {
023: protected static Log log = LogFactory
024: .getLog(DirectoryEditForm.class);
025: private String folderName;
026: private Directory directory;
027: private String[] menuGroup;
028: private DocumentNavigation documentNavigation;
029:
030: public Directory getDirectory() {
031: return directory;
032: }
033:
034: public void setDirectory(Directory directory) {
035: this .directory = directory;
036: this .folderName = directory.getMenu().getMenuText();
037: }
038:
039: public String[] getMenuGroup() {
040: return menuGroup;
041: }
042:
043: public void setMenuGroup(String[] menuGroup) {
044: this .menuGroup = menuGroup;
045: }
046:
047: public String getFolderName() {
048: return folderName;
049: }
050:
051: public void setFolderName(String folderName) {
052: this .folderName = folderName;
053: }
054:
055: public String update() {
056: if (SessionManagement.isValid()) {
057: MenuDAO dao = (MenuDAO) Context.getInstance().getBean(
058: MenuDAO.class);
059:
060: try {
061: directory.setDisplayText(folderName);
062: directory.getMenu().setMenuText(folderName);
063: dao.store(directory.getMenu());
064:
065: documentNavigation
066: .setSelectedPanel(new PageContentBean(
067: "documents"));
068: } catch (Exception e) {
069: log.error(e.getMessage(), e);
070: Messages
071: .addLocalizedError("errors.action.savefolder.notstored");
072: }
073:
074: return null;
075: } else {
076: return "login";
077: }
078: }
079:
080: public String insert() {
081: int menuparent = documentNavigation.getSelectedDir()
082: .getMenuId();
083:
084: if (SessionManagement.isValid()) {
085: MenuDAO dao = (MenuDAO) Context.getInstance().getBean(
086: MenuDAO.class);
087:
088: try {
089: Menu menu = new Menu();
090: menu.setMenuText(getFolderName());
091: menu.setMenuParent(menuparent);
092: menu.setMenuSort(1);
093: menu.setMenuIcon("folder.png");
094: menu.setMenuPath(menu.getMenuPath() + "/"
095: + menu.getMenuId());
096: menu.setMenuType(Menu.MENUTYPE_DIRECTORY);
097: menu.setMenuHier(menu.getMenuHier());
098: menu.setMenuRef("");
099:
100: // by default add read and write privileges to admin group
101: boolean hasAdmin = false;
102:
103: for (int i = 0; i < menuGroup.length; i++) {
104: if (menuGroup[i].equals("admin")) {
105: hasAdmin = true;
106:
107: break;
108: }
109: }
110:
111: if (!hasAdmin) {
112: String[] menuGroupAdmin = new String[menuGroup.length + 1];
113: menuGroupAdmin[0] = "admin";
114:
115: for (int i = 0; i < menuGroup.length; i++) {
116: menuGroupAdmin[i + 1] = menuGroup[i];
117: }
118:
119: menu.setMenuGroup(menuGroupAdmin);
120: } else {
121: menu.setMenuGroup(menuGroup);
122: }
123:
124: boolean stored = dao.store(menu);
125:
126: if (!stored) {
127: Messages
128: .addLocalizedError("errors.action.savefolder.notstored");
129: } else {
130: Messages.addLocalizedInfo("msg.action.savefolder");
131: }
132:
133: documentNavigation.addNewDir(menu, null);
134: documentNavigation
135: .setSelectedPanel(new PageContentBean(
136: "documents"));
137: } catch (Exception e) {
138: log.error(e.getMessage(), e);
139: Messages
140: .addLocalizedError("errors.action.savefolder.notstored");
141: }
142:
143: return null;
144: } else {
145: return "login";
146: }
147: }
148:
149: public void setDocumentNavigation(
150: DocumentNavigation documentNavigation) {
151: this.documentNavigation = documentNavigation;
152: }
153: }
|