Source Code Cross Referenced for UpdatePageAction.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » layout » impl » 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 » Portal » jetspeed 2.1.3 » org.apache.jetspeed.layout.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.jetspeed.layout.impl;
018:
019:        import java.util.HashMap;
020:        import java.util.Map;
021:
022:        import org.apache.commons.logging.Log;
023:        import org.apache.commons.logging.LogFactory;
024:        import org.apache.jetspeed.JetspeedActions;
025:        import org.apache.jetspeed.ajax.AJAXException;
026:        import org.apache.jetspeed.ajax.AjaxAction;
027:        import org.apache.jetspeed.ajax.AjaxBuilder;
028:        import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
029:        import org.apache.jetspeed.components.portletentity.PortletEntityNotStoredException;
030:        import org.apache.jetspeed.container.window.FailedToRetrievePortletWindow;
031:        import org.apache.jetspeed.container.window.PortletWindowAccessor;
032:        import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
033:        import org.apache.jetspeed.om.folder.Folder;
034:        import org.apache.jetspeed.om.page.ContentFragment;
035:        import org.apache.jetspeed.om.page.ContentFragmentImpl;
036:        import org.apache.jetspeed.om.page.Fragment;
037:        import org.apache.jetspeed.om.page.Page;
038:        import org.apache.jetspeed.page.PageManager;
039:        import org.apache.jetspeed.page.document.Node;
040:        import org.apache.jetspeed.request.RequestContext;
041:        import org.apache.pluto.om.window.PortletWindow;
042:
043:        /**
044:         * Update Page action -- updates various parts of the PSML page
045:         * 
046:         * AJAX Parameters: 
047:         *    action = updatepage
048:         *    General methods:
049:         *    method = add | remove 
050:         *    Info methods:
051:         *    | info 
052:         *    Meta methods:
053:         *    | add-meta | update-meta | remove-meta
054:         *    Security methods:
055:         *    | add-secref | remove-secref
056:         *    Fragment methods:
057:         *    | update-fragment | add-fragment | remove-fragment
058:         *    
059:         *    update-fragment params: id, layout(name), sizes, layoutid (add)
060:         *    
061:         * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
062:         * @version $Id: $
063:         */
064:        public class UpdatePageAction extends BaseSiteUpdateAction implements 
065:                AjaxAction, AjaxBuilder, Constants {
066:            protected Log log = LogFactory.getLog(UpdatePageAction.class);
067:            protected PortletWindowAccessor windowAccess;
068:            protected PortletEntityAccessComponent entityAccess;
069:
070:            public UpdatePageAction(String template, String errorTemplate,
071:                    PageManager pm, PortletWindowAccessor windowAccess,
072:                    PortletEntityAccessComponent entityAccess,
073:                    PortletActionSecurityBehavior securityBehavior)
074:
075:            {
076:                super (template, errorTemplate, pm, securityBehavior);
077:                this .windowAccess = windowAccess;
078:                this .entityAccess = entityAccess;
079:            }
080:
081:            public boolean run(RequestContext requestContext, Map resultMap)
082:                    throws AJAXException {
083:                boolean success = true;
084:                String status = "success";
085:                try {
086:                    resultMap.put(ACTION, "updatepage");
087:                    // Get the necessary parameters off of the request
088:                    String method = getActionParameter(requestContext, "method");
089:                    if (method == null) {
090:                        throw new RuntimeException("Method not provided");
091:                    }
092:                    resultMap.put("method", method);
093:                    if (false == checkAccess(requestContext,
094:                            JetspeedActions.EDIT)) {
095:                        success = false;
096:                        resultMap
097:                                .put(REASON,
098:                                        "Insufficient access to administer portal permissions");
099:                        return success;
100:                    }
101:                    int count = 0;
102:                    Page page = null;
103:                    String path = getActionParameter(requestContext, "path");
104:                    if (path == null) {
105:                        page = requestContext.getPage();
106:                    } else {
107:                        if (!method.equals("add")) {
108:                            page = pageManager.getPage(path);
109:                        } else {
110:                            if (pageManager.pageExists(path)) {
111:                                success = false;
112:                                resultMap.put(REASON,
113:                                        "Can't create: Page already exists: "
114:                                                + path);
115:                                return success;
116:                            }
117:                        }
118:                    }
119:                    if (method.equals("info")) {
120:                        count = updateInformation(requestContext, resultMap,
121:                                page, path);
122:                    } else if (method.equals("add-meta")) {
123:                        count = insertMetadata(requestContext, resultMap, page);
124:                    } else if (method.equals("update-meta")) {
125:                        count = updateMetadata(requestContext, resultMap, page);
126:                    } else if (method.equals("remove-meta")) {
127:                        count = removeMetadata(requestContext, resultMap, page);
128:                    } else if (method.equals("add-secref")) {
129:                        count = insertSecurityReference(requestContext,
130:                                resultMap, page);
131:                    } else if (method.equals("update-secref")) {
132:                        count = updateSecurityReference(requestContext,
133:                                resultMap, page);
134:                    } else if (method.equals("remove-secref")) {
135:                        count = removeSecurityReference(requestContext,
136:                                resultMap, page);
137:                    } else if (method.equals("remove-secdef")) {
138:                        count = removeSecurityDef(requestContext, resultMap,
139:                                page);
140:                    } else if (method.equals("add")) {
141:                        page = pageManager.newPage(path);
142:                        page
143:                                .setTitle(getActionParameter(requestContext,
144:                                        TITLE));
145:                        String s = getActionParameter(requestContext,
146:                                SHORT_TITLE);
147:                        if (!isBlank(s))
148:                            page.setShortTitle(s);
149:                        page.getRootFragment().setName(
150:                                getActionParameter(requestContext,
151:                                        DEFAULT_LAYOUT));
152:                        count++;
153:                    } else if (method.equals("copy")) {
154:                        String destination = getActionParameter(requestContext,
155:                                "destination");
156:                        String name = getActionParameter(requestContext,
157:                                RESOURCE_NAME);
158:                        destination = destination + Folder.PATH_SEPARATOR
159:                                + name;
160:                        Page newPage = pageManager.copyPage(page, destination);
161:                        pageManager.updatePage(newPage);
162:                    } else if (method.equals("move")) {
163:                        String destination = getActionParameter(requestContext,
164:                                "destination");
165:                        String name = getActionParameter(requestContext,
166:                                RESOURCE_NAME);
167:                        destination = destination + Folder.PATH_SEPARATOR
168:                                + name;
169:                        Page newPage = pageManager.copyPage(page, destination);
170:                        pageManager.updatePage(newPage);
171:                        pageManager.removePage(page);
172:                    } else if (method.equals("remove")) {
173:                        pageManager.removePage(page);
174:                    } else if (method.equals("update-fragment")) {
175:                        String fragmentId = getActionParameter(requestContext,
176:                                PORTLETID);
177:                        String layout = getActionParameter(requestContext,
178:                                LAYOUT);
179:                        if (isBlank(fragmentId) || isBlank(layout)) {
180:                            resultMap.put(REASON,
181:                                    "Missing parameter to update fragment");
182:                            return false;
183:                        }
184:                        count = updateFragment(requestContext, resultMap, page,
185:                                fragmentId, layout);
186:                    } else if (method.equals("add-fragment")) {
187:                        String parentId = getActionParameter(requestContext,
188:                                LAYOUTID);
189:                        String layout = getActionParameter(requestContext,
190:                                LAYOUT);
191:                        if (isBlank(parentId) || isBlank(layout)) {
192:                            resultMap.put(REASON,
193:                                    "Missing parameter to add fragment");
194:                            return false;
195:                        }
196:                        count = addFragment(requestContext, resultMap, page,
197:                                parentId, layout);
198:                    } else if (method.equals("remove-fragment")) {
199:                        String fragmentId = getActionParameter(requestContext,
200:                                PORTLETID);
201:                        if (isBlank(fragmentId)) {
202:                            resultMap.put(REASON,
203:                                    "Missing parameter to remove fragment");
204:                            return false;
205:                        }
206:                        count = removeFragment(requestContext, resultMap, page,
207:                                fragmentId);
208:                    } else if (method.equals("update-portlet-decorator")) {
209:                        String fragmentId = getActionParameter(requestContext,
210:                                PORTLETID);
211:                        String portletDecorator = getActionParameter(
212:                                requestContext, "portlet-decorator");
213:                        if (isBlank(fragmentId) || isBlank(portletDecorator)) {
214:                            resultMap
215:                                    .put(REASON,
216:                                            "Missing parameter to update portlet decorator");
217:                            return false;
218:                        }
219:                        count = updatePortletDecorator(requestContext,
220:                                resultMap, page, fragmentId, portletDecorator);
221:                    } else {
222:                        success = false;
223:                        resultMap.put(REASON,
224:                                "Unsupported Site Update method: " + method);
225:                        return success;
226:                    }
227:                    if (count > 0) {
228:                        pageManager.updatePage(page);
229:                    }
230:                    resultMap.put("count", Integer.toString(count));
231:                    resultMap.put(STATUS, status);
232:                } catch (Exception e) {
233:                    log.error("exception administering Site update", e);
234:                    resultMap.put(REASON, e.toString());
235:                    success = false;
236:                }
237:                return success;
238:            }
239:
240:            protected int updatePortletDecorator(RequestContext requestContext,
241:                    Map resultMap, Page page, String fragmentId,
242:                    String portletDecorator)
243:                    throws PortletEntityNotStoredException,
244:                    FailedToRetrievePortletWindow {
245:                int count = 0;
246:                Fragment fragment = page.getFragmentById(fragmentId);
247:                if (fragment != null) {
248:                    fragment.setDecorator(portletDecorator);
249:                    count++;
250:                }
251:                return count;
252:            }
253:
254:            protected int updateFragment(RequestContext requestContext,
255:                    Map resultMap, Page page, String fragmentId, String layout)
256:                    throws PortletEntityNotStoredException,
257:                    FailedToRetrievePortletWindow {
258:                int count = 0;
259:                String sizes = getActionParameter(requestContext, SIZES);
260:                Fragment fragment = page.getFragmentById(fragmentId);
261:                if (fragment != null) {
262:                    if (!layout.equals(fragment.getName())) {
263:                        fragment.setName(layout);
264:                        ContentFragment contentFragment = new ContentFragmentImpl(
265:                                fragment, new HashMap());
266:                        PortletWindow window = windowAccess
267:                                .getPortletWindow(contentFragment);
268:                        if (window != null) {
269:                            entityAccess.updatePortletEntity(window
270:                                    .getPortletEntity(), contentFragment);
271:                            entityAccess.storePortletEntity(window
272:                                    .getPortletEntity());
273:                            windowAccess.createPortletWindow(window
274:                                    .getPortletEntity(), contentFragment
275:                                    .getId());
276:                            count++;
277:                            if (isBlank(sizes)) {
278:                                fragment.setLayoutSizes(null);
279:                            } else {
280:                                fragment.setLayoutSizes(sizes);
281:                            }
282:                            count++;
283:                        }
284:                    } else {
285:                        if (!isBlank(sizes)) {
286:                            fragment.setLayoutSizes(sizes);
287:                            count++;
288:                        }
289:                    }
290:                }
291:                return count;
292:            }
293:
294:            protected int addFragment(RequestContext requestContext,
295:                    Map resultMap, Page page, String parentFragmentId,
296:                    String layout) {
297:                int count = 0;
298:                String sizes = getActionParameter(requestContext, SIZES);
299:                Fragment fragment = page.getFragmentById(parentFragmentId);
300:                if (fragment != null) {
301:                    Fragment newFragment = pageManager.newFragment();
302:                    newFragment.setType(Fragment.LAYOUT);
303:                    newFragment.setName(layout);
304:                    fragment.getFragments().add(newFragment);
305:                    resultMap.put(PORTLETID, newFragment.getId());
306:                    count++;
307:                    if (!isBlank(sizes)) {
308:                        newFragment.setLayoutSizes(sizes);
309:                        count++;
310:                    }
311:                }
312:                return count;
313:            }
314:
315:            protected int removeFragment(RequestContext requestContext,
316:                    Map resultMap, Page page, String fragmentId) {
317:                int count = 0;
318:                Fragment fragment = page.getFragmentById(fragmentId);
319:                if (fragment != null) {
320:                    page.removeFragmentById(fragment.getId());
321:                    count++;
322:                }
323:                return count;
324:            }
325:
326:            protected int updateInformation(RequestContext requestContext,
327:                    Map resultMap, Node node, String path) throws AJAXException {
328:                int count = 0;
329:                try {
330:                    Page page = (Page) node;
331:                    String title = getActionParameter(requestContext, "title");
332:                    if (title != null
333:                            && isFieldModified(title, page.getTitle()))
334:                        page.setTitle(title);
335:                    String shortTitle = getActionParameter(requestContext,
336:                            "short-title");
337:                    if (shortTitle != null
338:                            && isFieldModified(shortTitle, page.getShortTitle()))
339:                        page.setShortTitle(shortTitle);
340:                    String layoutDecorator = getActionParameter(requestContext,
341:                            "layout-decorator");
342:                    if (layoutDecorator != null
343:                            && isFieldModified(layoutDecorator, page
344:                                    .getDefaultDecorator(Fragment.LAYOUT))) {
345:                        if (isBlank(layoutDecorator))
346:                            layoutDecorator = null;
347:                        page.setDefaultDecorator(layoutDecorator,
348:                                Fragment.LAYOUT);
349:                    }
350:                    String portletDecorator = getActionParameter(
351:                            requestContext, "portlet-decorator");
352:                    if (portletDecorator != null
353:                            && isFieldModified(portletDecorator, page
354:                                    .getDefaultDecorator(Fragment.PORTLET))) {
355:                        if (isBlank(portletDecorator))
356:                            portletDecorator = null;
357:                        page.setDefaultDecorator(portletDecorator,
358:                                Fragment.PORTLET);
359:                    }
360:                    String theme = getActionParameter(requestContext, "theme");
361:                    if (theme != null && isFieldModified(theme, page.getSkin())) {
362:                        if (isBlank(theme))
363:                            theme = null;
364:                        page.setSkin(theme);
365:                    }
366:                    String hidden = getActionParameter(requestContext, "hidden");
367:                    if (hidden != null
368:                            && isBooleanModified(hidden, page.isHidden()))
369:                        page.setHidden(!page.isHidden());
370:                    count++;
371:                } catch (Exception e) {
372:                    throw new AJAXException(e);
373:                }
374:                return count;
375:            }
376:
377:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.