Source Code Cross Referenced for ContentTreeEditor.java in  » J2EE » fleXive » com » flexive » war » javascript » tree » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » fleXive » com.flexive.war.javascript.tree 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***************************************************************
002:         *  This file is part of the [fleXive](R) project.
003:         *
004:         *  Copyright (c) 1999-2007
005:         *  UCS - unique computing solutions gmbh (http://www.ucs.at)
006:         *  All rights reserved
007:         *
008:         *  The [fleXive](R) project is free software; you can redistribute
009:         *  it and/or modify it under the terms of the GNU General Public
010:         *  License as published by the Free Software Foundation;
011:         *  either version 2 of the License, or (at your option) any
012:         *  later version.
013:         *
014:         *  The GNU General Public License can be found at
015:         *  http://www.gnu.org/copyleft/gpl.html.
016:         *  A copy is found in the textfile GPL.txt and important notices to the
017:         *  license from the author are found in LICENSE.txt distributed with
018:         *  these libraries.
019:         *
020:         *  This library is distributed in the hope that it will be useful,
021:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
022:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023:         *  GNU General Public License for more details.
024:         *
025:         *  For further information about UCS - unique computing solutions gmbh,
026:         *  please see the company website: http://www.ucs.at
027:         *
028:         *  For further information about [fleXive](R), please see the
029:         *  project website: http://www.flexive.org
030:         *
031:         *
032:         *  This copyright notice MUST APPEAR in all copies of the file!
033:         ***************************************************************/package com.flexive.war.javascript.tree;
034:
035:        import com.flexive.shared.EJBLookup;
036:        import com.flexive.shared.FxContext;
037:        import com.flexive.shared.content.FxPK;
038:        import com.flexive.shared.interfaces.TreeEngine;
039:        import com.flexive.shared.tree.FxTreeMode;
040:        import static com.flexive.shared.tree.FxTreeMode.Edit;
041:        import static com.flexive.shared.tree.FxTreeMode.Live;
042:        import com.flexive.shared.tree.FxTreeNode;
043:        import com.flexive.shared.tree.FxTreeNodeEdit;
044:        import com.flexive.war.JsonWriter;
045:        import org.apache.commons.lang.StringUtils;
046:        import org.apache.commons.logging.Log;
047:        import org.apache.commons.logging.LogFactory;
048:
049:        import java.io.IOException;
050:        import java.io.Serializable;
051:        import java.io.StringWriter;
052:
053:        /**
054:         * Content tree edit actions invoked via JSON/RPC.
055:         *
056:         * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
057:         * @version $Rev: 1 $
058:         */
059:        public class ContentTreeEditor implements  Serializable {
060:            private static final long serialVersionUID = -6518286246610051456L;
061:            private static final Log LOG = LogFactory
062:                    .getLog(ContentTreeEditor.class);
063:
064:            /**
065:             * Update the tree node's label.
066:             *
067:             * @param nodeId   the node id
068:             * @param label    the new label
069:             * @param liveTree true if the live tree should be rendered, false for the edit tree
070:             * @param pathMode true if node labels should be paths instead of content captions
071:             * @return nothing
072:             * @throws java.io.IOException if the response could not be created
073:             */
074:            public String saveLabel(long nodeId, String label,
075:                    boolean liveTree, boolean pathMode) throws IOException {
076:
077:                // Rename the node
078:                try {
079:                    if (label.endsWith("<br>")) {
080:                        label = label.substring(0, label.length() - 4);
081:                    }
082:                    final FxTreeNodeEdit node = EJBLookup.getTreeEngine()
083:                            .getNode(liveTree ? Live : Edit, nodeId)
084:                            .asEditable();
085:                    if (pathMode) {
086:                        node.setName(label);
087:                    } else {
088:                        node.getLabel().setTranslation(
089:                                FxContext.get().getTicket().getLanguage(),
090:                                label);
091:                    }
092:                    EJBLookup.getTreeEngine().save(node);
093:                    //            EJBLookup.getTreeInterface().renameNode(nodeId,false,label,null);
094:                } catch (Exception e) {
095:                    LOG.error("Failed to save label: " + e.getMessage(), e);
096:                }
097:
098:                String title = StringUtils.defaultString(label).trim();
099:                try {
100:                    // add subnode count
101:                    final FxTreeNode node = EJBLookup.getTreeEngine().getNode(
102:                            Edit, nodeId);
103:                    int totalChildren = node.getTotalChildCount();
104:                    if (totalChildren > 0) {
105:                        title += " [" + totalChildren + "]";
106:                    }
107:
108:                    // add dirty flag
109:                    if (node.isDirty()) {
110:                        title = "<span class=\"dirty\">" + title + "</span>";
111:                    }
112:                } catch (Exception e) {
113:                    LOG.error("Failed to save label: " + e.getMessage(), e);
114:                }
115:
116:                // response: [{title: 'new title'}]
117:                StringWriter out = new StringWriter();
118:                new JsonWriter(out).startArray().startMap().writeAttribute(
119:                        "title", title).closeMap().closeArray()
120:                        .finishResponse();
121:                return out.toString();
122:            }
123:
124:            /**
125:             * Move the given node to the new parent at position <code>index</code>
126:             *
127:             * @param nodeId      the tree node to be moved
128:             * @param newParentId the the parent node
129:             * @param index       the new position
130:             * @return nothing
131:             * @throws Exception if an error occured
132:             */
133:            public String move(long nodeId, long newParentId, int index,
134:                    boolean live) throws Exception {
135:                try {
136:                    EJBLookup.getTreeEngine().move(live ? Live : Edit, nodeId,
137:                            newParentId, index);
138:                } catch (Exception e) {
139:                    LOG.error("Failed to move node: " + e, e);
140:                    throw e;
141:                }
142:                return "[]";
143:            }
144:
145:            /**
146:             * Remove a tree node and (depending on the removeContent parameter) the attached
147:             * content instance.
148:             *
149:             * @param nodeId         the tree node ID
150:             * @param removeContent  if true, the attached content instance will also be removed
151:             * @param live           if the tree is in live mode
152:             * @param deleteChildren if the node children should also be deleted
153:             * @return nothing
154:             * @throws Exception if an error occured
155:             */
156:            public String remove(long nodeId, boolean removeContent,
157:                    boolean live, boolean deleteChildren) throws Exception {
158:                try {
159:                    FxTreeNode node = EJBLookup.getTreeEngine().getNode(
160:                            live ? Live : Edit, nodeId);
161:                    EJBLookup.getTreeEngine().remove(node, removeContent,
162:                            deleteChildren);
163:                } catch (Exception e) {
164:                    LOG.error("Failed to delete node: " + e, e);
165:                    throw e;
166:                }
167:                return "[]";
168:            }
169:
170:            public String addReferences(long nodeId, long[] referenceIds)
171:                    throws Exception {
172:                try {
173:                    TreeEngine tree = EJBLookup.getTreeEngine();
174:                    for (long referenceId : referenceIds) {
175:                        tree.save(FxTreeNodeEdit.createNew(
176:                                String.valueOf(referenceId)).setParentNodeId(
177:                                nodeId).setReference(new FxPK(referenceId)));
178:                        //                tree.createNode(nodeId, String.valueOf(referenceId), referenceId);
179:                    }
180:                } catch (Exception e) {
181:                    LOG.error("Failed to add nodes: " + e.getMessage(), e);
182:                    throw e;
183:                }
184:                return "[]";
185:            }
186:
187:            public String createFolder(long parentNodeId, String folderName)
188:                    throws Exception {
189:                try {
190:                    EJBLookup.getTreeEngine().save(
191:                            FxTreeNodeEdit.createNew(folderName)
192:                                    .setParentNodeId(parentNodeId));
193:                } catch (Exception e) {
194:                    LOG.error(
195:                            "Failed to create tree folder: " + e.getMessage(),
196:                            e);
197:                    throw e;
198:                }
199:                return "[]";
200:            }
201:
202:            public String activate(long nodeId, boolean includeChildren)
203:                    throws Exception {
204:                try {
205:                    EJBLookup.getTreeEngine().activate(FxTreeMode.Edit, nodeId,
206:                            includeChildren);
207:                } catch (Exception e) {
208:                    LOG.error("Failed to activate node: " + e.getMessage(), e);
209:                    throw e;
210:                }
211:                return "[]";
212:            }
213:
214:            public String copy(long nodeId, long newParentId, int index,
215:                    boolean live) throws Exception {
216:                try {
217:                    EJBLookup.getTreeEngine().copy(live ? Live : Edit, nodeId,
218:                            newParentId, index);
219:                } catch (Exception e) {
220:                    LOG.error("Failed to copy node: " + e.getMessage(), e);
221:                    throw e;
222:                }
223:                return "[]";
224:            }
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.