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


0001:        /*
0002:         * Licensed to the Apache Software Foundation (ASF) under one or more
0003:         * contributor license agreements.  See the NOTICE file distributed with
0004:         * this work for additional information regarding copyright ownership.
0005:         * The ASF licenses this file to You under the Apache License, Version 2.0
0006:         * (the "License"); you may not use this file except in compliance with
0007:         * the License.  You may obtain a copy of the License at
0008:         * 
0009:         *      http://www.apache.org/licenses/LICENSE-2.0
0010:         * 
0011:         * Unless required by applicable law or agreed to in writing, software
0012:         * distributed under the License is distributed on an "AS IS" BASIS,
0013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         * See the License for the specific language governing permissions and
0015:         * limitations under the License.
0016:         */
0017:        package org.apache.jetspeed.portlets.layout;
0018:
0019:        import java.io.IOException;
0020:        import java.io.UnsupportedEncodingException;
0021:        import java.net.URLEncoder;
0022:        import java.util.ArrayList;
0023:        import java.util.Iterator;
0024:        import java.util.List;
0025:        import java.util.StringTokenizer;
0026:
0027:        import javax.portlet.ActionRequest;
0028:        import javax.portlet.ActionResponse;
0029:        import javax.portlet.PortletConfig;
0030:        import javax.portlet.PortletException;
0031:        import javax.portlet.PortletMode;
0032:        import javax.portlet.RenderRequest;
0033:        import javax.portlet.RenderResponse;
0034:
0035:        import org.apache.commons.logging.Log;
0036:        import org.apache.commons.logging.LogFactory;
0037:        import org.apache.jetspeed.CommonPortletServices;
0038:        import org.apache.jetspeed.PortalReservedParameters;
0039:        import org.apache.jetspeed.cache.JetspeedContentCache;
0040:        import org.apache.jetspeed.decoration.DecorationFactory;
0041:        import org.apache.jetspeed.decoration.PageEditAccess;
0042:        import org.apache.jetspeed.desktop.JetspeedDesktop;
0043:        import org.apache.jetspeed.om.folder.Folder;
0044:        import org.apache.jetspeed.om.page.ContentFragment;
0045:        import org.apache.jetspeed.om.page.ContentPage;
0046:        import org.apache.jetspeed.om.page.Fragment;
0047:        import org.apache.jetspeed.om.page.Page;
0048:        import org.apache.jetspeed.page.FolderNotUpdatedException;
0049:        import org.apache.jetspeed.page.document.NodeException;
0050:        import org.apache.jetspeed.request.RequestContext;
0051:        import org.apache.pluto.om.window.PortletWindow;
0052:
0053:        /**
0054:         */
0055:        public class MultiColumnPortlet extends LayoutPortlet {
0056:            /** Commons logging */
0057:            protected final static Log log = LogFactory
0058:                    .getLog(MultiColumnPortlet.class);
0059:
0060:            protected final static String PARAM_NUM_COLUMN = "columns";
0061:            protected final static int DEFAULT_NUM_COLUMN = 2;
0062:            protected final static String PARAM_COLUMN_SIZES = "sizes";
0063:            protected final static String DEFAULT_ONE_COLUMN_SIZES = "100%";
0064:            protected final static String DEFAULT_TWO_COLUMN_SIZES = "50%,50%";
0065:            protected final static String DEFAULT_THREE_COLUMN_SIZES = "34%,33%,33%";
0066:
0067:            private int numColumns = 0;
0068:            private String columnSizes = null;
0069:            private String portletName = null;
0070:            private String layoutType;
0071:            private String editorType = null;
0072:            protected DecorationFactory decorators;
0073:            protected JetspeedDesktop desktop;
0074:            protected JetspeedContentCache decoratorCache;
0075:
0076:            public void init(PortletConfig config) throws PortletException {
0077:                super .init(config);
0078:                this .portletName = config.getPortletName();
0079:                this .layoutType = config.getInitParameter("layoutType");
0080:                this .editorType = config.getInitParameter("editorType");
0081:                if (this .layoutType == null) {
0082:                    throw new PortletException("Layout type not specified for "
0083:                            + this .portletName);
0084:                }
0085:                this .numColumns = Integer.parseInt(config
0086:                        .getInitParameter(PARAM_NUM_COLUMN));
0087:                if (this .numColumns < 1) {
0088:                    this .numColumns = 1;
0089:                }
0090:                this .columnSizes = config.getInitParameter(PARAM_COLUMN_SIZES);
0091:                if ((this .columnSizes == null)
0092:                        || (this .columnSizes.trim().length() == 0)) {
0093:                    switch (this .numColumns) {
0094:                    case 1:
0095:                        this .columnSizes = DEFAULT_ONE_COLUMN_SIZES;
0096:                        break;
0097:                    case 2:
0098:                        this .columnSizes = DEFAULT_TWO_COLUMN_SIZES;
0099:                        break;
0100:                    case 3:
0101:                        this .columnSizes = DEFAULT_THREE_COLUMN_SIZES;
0102:                        break;
0103:                    default:
0104:                        this .columnSizes = null;
0105:                        break;
0106:                    }
0107:                }
0108:                if (this .columnSizes == null) {
0109:                    throw new PortletException(
0110:                            "Column sizes cannot be defaulted for "
0111:                                    + this .numColumns
0112:                                    + " columns and are not specified for "
0113:                                    + this .portletName);
0114:                }
0115:
0116:                this .decorators = (DecorationFactory) getPortletContext()
0117:                        .getAttribute(
0118:                                CommonPortletServices.CPS_DECORATION_FACTORY);
0119:                if (null == this .decorators) {
0120:                    throw new PortletException(
0121:                            "Failed to find the Decoration Factory on portlet initialization");
0122:                }
0123:
0124:                this .desktop = (JetspeedDesktop) getPortletContext()
0125:                        .getAttribute(CommonPortletServices.CPS_DESKTOP);
0126:
0127:                this .decoratorCache = (JetspeedContentCache) getPortletContext()
0128:                        .getAttribute(CommonPortletServices.CPS_DECORATOR_CACHE);
0129:            }
0130:
0131:            public void doView(RenderRequest request, RenderResponse response)
0132:                    throws PortletException, IOException {
0133:                RequestContext context = getRequestContext(request);
0134:
0135:                ContentPage requestPage = context.getPage();
0136:                PageEditAccess pageEditAccess = (PageEditAccess) context
0137:                        .getAttribute(PortalReservedParameters.PAGE_EDIT_ACCESS_ATTRIBUTE);
0138:                if (requestPage == null) {
0139:                    // Targetting this portlet REQUIRES that the ProfilerValve has been invoked!
0140:                    throw new PortletException(
0141:                            "Current request page not available.");
0142:                }
0143:                if (pageEditAccess == null) {
0144:                    // Targetting this portlet REQUIRES that the ProfilerValve has been invoked!
0145:                    throw new PortletException(
0146:                            "Current PageEditAccess not available.");
0147:                }
0148:
0149:                Boolean editing = (pageEditAccess.isEditing()
0150:                        && PortletMode.VIEW.equals(request.getPortletMode()) && request
0151:                        .isPortletModeAllowed(PortletMode.EDIT)) ? Boolean.TRUE
0152:                        : Boolean.FALSE;
0153:
0154:                PortletWindow window = context.getPortalURL()
0155:                        .getNavigationalState().getMaximizedWindow();
0156:                if (window != null) {
0157:                    super .doView(request, response);
0158:                    return;
0159:                }
0160:
0161:                // get fragment column sizes
0162:                Fragment f = getFragment(request, false);
0163:                String fragmentColumnSizes = columnSizes;
0164:                String fragmentColumnSizesProperty = f
0165:                        .getProperty(Fragment.SIZES_PROPERTY_NAME);
0166:                if (fragmentColumnSizesProperty != null) {
0167:                    fragmentColumnSizes = fragmentColumnSizesProperty;
0168:                }
0169:                String[] fragmentColumnSizesArray = fragmentColumnSizes
0170:                        .split("\\,");
0171:                List fragmentColumnSizesList = new ArrayList(
0172:                        fragmentColumnSizesArray.length);
0173:                for (int i = 0; (i < fragmentColumnSizesArray.length); i++) {
0174:                    fragmentColumnSizesList.add(fragmentColumnSizesArray[i]);
0175:                }
0176:
0177:                // construct layout object
0178:                ColumnLayout layout;
0179:                try {
0180:                    layout = new ColumnLayout(numColumns, layoutType, f
0181:                            .getFragments(), fragmentColumnSizesArray);
0182:                    layout
0183:                            .addLayoutEventListener(new PageManagerLayoutEventListener(
0184:                                    pageManager, context.getPage(), layoutType));
0185:                } catch (LayoutEventException e1) {
0186:                    throw new PortletException("Failed to build ColumnLayout "
0187:                            + e1.getMessage(), e1);
0188:                }
0189:
0190:                // invoke the JSP associated with this portlet
0191:                request.setAttribute("columnLayout", layout);
0192:                request
0193:                        .setAttribute("numberOfColumns",
0194:                                new Integer(numColumns));
0195:                request.setAttribute("decorationFactory", this .decorators);
0196:                request.setAttribute("columnSizes", fragmentColumnSizesList);
0197:                request.setAttribute("editing", editing);
0198:                request.setAttribute("fragmentNestingLevel", new Integer(
0199:                        getFragmentNestingLevel(requestPage, f.getId())));
0200:                super .doView(request, response);
0201:                request.removeAttribute("decorationFactory");
0202:                request.removeAttribute("columnLayout");
0203:                request.removeAttribute("numberOfColumns");
0204:                request.removeAttribute("columnSizes");
0205:                request.removeAttribute("editing");
0206:                request.removeAttribute(("fragmentNestingLevel"));
0207:            }
0208:
0209:            public void processAction(ActionRequest request,
0210:                    ActionResponse response) throws PortletException,
0211:                    IOException {
0212:                RequestContext requestContext = (RequestContext) request
0213:                        .getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
0214:
0215:                ContentPage requestPage = requestContext.getPage();
0216:                PageEditAccess pageEditAccess = (PageEditAccess) requestContext
0217:                        .getAttribute(PortalReservedParameters.PAGE_EDIT_ACCESS_ATTRIBUTE);
0218:                if (requestPage == null || pageEditAccess == null) {
0219:                    // Targetting this portlet with an ActionRequest REQUIRES that the ProfilerValve has been invoked!
0220:                    throw new PortletException(
0221:                            "Current request page or PageEditAccess not available.");
0222:                }
0223:
0224:                decoratorCache.invalidate(requestContext);
0225:
0226:                String pageMode = request.getParameter("pageMode");
0227:                if (pageMode != null) {
0228:                    if ("view".equals(pageMode)) {
0229:                        pageEditAccess.setEditing(false);
0230:                    } else if ("edit".equals(pageMode)
0231:                            && pageEditAccess.isEditAllowed()) {
0232:                        if (this .editorType != null
0233:                                && this .editorType.equals("desktop")) {
0234:                            String redirectUrl = this .desktop.getPortalUrl(
0235:                                    requestContext, requestContext.getPath());
0236:                            redirectUrl += "?editPage=true&portal=true";
0237:                            response.sendRedirect(redirectUrl);
0238:                        } else {
0239:                            pageEditAccess.setEditing(true);
0240:                        }
0241:                    }
0242:                    return;
0243:                }
0244:
0245:                if (pageEditAccess.isEditAllowed()
0246:                        && request.isPortletModeAllowed(PortletMode.EDIT)) {
0247:                    String layout = null;
0248:
0249:                    boolean addLayout = request.getParameter("jsAddLayout") != null;
0250:                    if (addLayout
0251:                            || request.getParameter("jsChangeLayout") != null) {
0252:                        layout = request.getParameter("layout");
0253:                        if (layout != null && layout.length() > 0) {
0254:                            PortletWindow window = requestContext
0255:                                    .getActionWindow();
0256:                            ContentFragment targetFragment = requestPage
0257:                                    .getContentFragmentById(window.getId()
0258:                                            .toString());
0259:
0260:                            if (targetFragment == null) {
0261:                                // ignore no longer consistent page definition
0262:                                return;
0263:                            }
0264:
0265:                            if (addLayout) {
0266:                                try {
0267:                                    Fragment fragment = pageManager
0268:                                            .newFragment();
0269:                                    fragment.setType(Fragment.LAYOUT);
0270:                                    fragment.setName(layout);
0271:                                    targetFragment.getFragments().add(fragment);
0272:                                    pageManager.updatePage(requestPage);
0273:                                    clearLayoutAttributes(request);
0274:                                } catch (Exception e) {
0275:                                    throw new PortletException(
0276:                                            "failed to add portlet " + layout
0277:                                                    + " to page: "
0278:                                                    + requestPage + ": "
0279:                                                    + e.getMessage(), e);
0280:                                }
0281:                            } else if (!layout.equals(targetFragment.getName())) {
0282:                                try {
0283:                                    // layout portlet change
0284:                                    targetFragment.setName(layout);
0285:                                    pageManager.updatePage(requestPage);
0286:                                    entityAccess
0287:                                            .updatePortletEntity(window
0288:                                                    .getPortletEntity(),
0289:                                                    targetFragment);
0290:                                    entityAccess.storePortletEntity(window
0291:                                            .getPortletEntity());
0292:                                    windowAccess.createPortletWindow(window
0293:                                            .getPortletEntity(), targetFragment
0294:                                            .getId());
0295:                                    clearLayoutAttributes(request);
0296:                                    return;
0297:                                } catch (Exception e) {
0298:                                    throw new PortletException(
0299:                                            "Unable to update page: "
0300:                                                    + e.getMessage(), e);
0301:                                }
0302:                            }
0303:                        }
0304:                        return;
0305:                    }
0306:
0307:                    if (request.getParameter("jsSubmitPage") != null) {
0308:                        String jsPageName = request.getParameter("jsPageName");
0309:                        String jsPageTitle = request
0310:                                .getParameter("jsPageTitle");
0311:                        String jsPageShortTitle = request
0312:                                .getParameter("jsPageShortTitle");
0313:                        if (jsPageName != null
0314:                                && jsPageName.length() > 0
0315:                                && jsPageName.indexOf(Folder.PATH_SEPARATOR) == -1) {
0316:                            try {
0317:                                Folder parent = (Folder) requestPage
0318:                                        .getParent();
0319:                                if (parent != null) {
0320:                                    String path = parent.getPath();
0321:                                    if (path.endsWith(Folder.PATH_SEPARATOR)) {
0322:                                        path = path
0323:                                                + getEscapedName(jsPageName);
0324:                                    } else {
0325:                                        path = path + Folder.PATH_SEPARATOR
0326:                                                + getEscapedName(jsPageName);
0327:                                    }
0328:                                    Page page = pageManager.newPage(path);
0329:                                    if (layout == null || layout.length() == 0) {
0330:                                        layout = requestPage.getRootFragment()
0331:                                                .getName();
0332:                                    }
0333:                                    page.getRootFragment().setName(layout);
0334:                                    page
0335:                                            .setDefaultDecorator(
0336:                                                    requestPage
0337:                                                            .getDefaultDecorator(Fragment.LAYOUT),
0338:                                                    Fragment.LAYOUT);
0339:                                    page
0340:                                            .setDefaultDecorator(
0341:                                                    requestPage
0342:                                                            .getDefaultDecorator(Fragment.PORTLET),
0343:                                                    Fragment.PORTLET);
0344:                                    page
0345:                                            .setTitle(jsPageTitle != null
0346:                                                    && !jsPageTitle.equals("") ? jsPageTitle
0347:                                                    : jsPageName);
0348:                                    page
0349:                                            .setShortTitle(jsPageShortTitle != null
0350:                                                    && !jsPageShortTitle
0351:                                                            .equals("") ? jsPageShortTitle
0352:                                                    : jsPageName);
0353:                                    pageManager.updatePage(page);
0354:                                    clearLayoutAttributes(request);
0355:                                    List orderList = parent.getDocumentOrder();
0356:                                    if (orderList != null) {
0357:                                        String name = page.getName();
0358:                                        if (orderList.indexOf(name) < 0) {
0359:                                            orderList.add(name);
0360:                                            parent.setDocumentOrder(orderList);
0361:                                            pageManager.updateFolder(parent);
0362:                                        }
0363:                                    }
0364:                                }
0365:                            } catch (Exception e) {
0366:                                throw new PortletException(
0367:                                        "Unable to access page for editing: "
0368:                                                + e.getMessage(), e);
0369:                            }
0370:                        }
0371:                        return;
0372:                    }
0373:
0374:                    if (request.getParameter("jsChangePageName") != null) {
0375:                        String jsPageTitle = request
0376:                                .getParameter("jsPageTitle");
0377:                        String jsPageShortTitle = request
0378:                                .getParameter("jsPageShortTitle");
0379:                        try {
0380:                            if (jsPageTitle != null && !jsPageTitle.equals("")) {
0381:                                requestPage.setTitle(jsPageTitle);
0382:                            }
0383:                            if (jsPageShortTitle != null
0384:                                    && !jsPageShortTitle.equals("")) {
0385:                                requestPage.setShortTitle(jsPageShortTitle);
0386:                            }
0387:                            pageManager.updatePage(requestPage);
0388:                        } catch (Exception e) {
0389:                            throw new PortletException(
0390:                                    "Unable to access page for editing: "
0391:                                            + e.getMessage(), e);
0392:                        }
0393:                        return;
0394:                    }
0395:
0396:                    if (request.getParameter("jsDeletePage") != null) {
0397:                        try {
0398:                            Folder parent = (Folder) requestPage.getParent();
0399:                            if (parent != null) {
0400:                                List orderList = parent.getDocumentOrder();
0401:                                if (orderList != null) {
0402:                                    String name = requestPage.getName();
0403:                                    if (orderList.indexOf(name) > -1) {
0404:                                        orderList.remove(name);
0405:                                        parent.setDocumentOrder(orderList);
0406:                                        pageManager.updateFolder(parent);
0407:                                    }
0408:                                }
0409:                            }
0410:
0411:                            pageManager.removePage(requestPage);
0412:                        } catch (Exception e) {
0413:                            throw new PortletException(
0414:                                    "Unable to access page for removing: "
0415:                                            + e.getMessage(), e);
0416:                        }
0417:                        return;
0418:                    }
0419:
0420:                    if (request.getParameter("jsMovePageLeft") != null) {
0421:                        try {
0422:                            Folder parent = (Folder) requestPage.getParent();
0423:                            if (parent != null) {
0424:                                List orderList = parent.getDocumentOrder();
0425:                                String name = requestPage.getName();
0426:                                if (orderList != null) {
0427:                                    int index = orderList.indexOf(name);
0428:                                    if (index > -1) {
0429:                                        String type = requestPage.getType();
0430:                                        int i = index - 1;
0431:                                        while (i >= 0) {
0432:                                            String value = (String) orderList
0433:                                                    .get(i);
0434:                                            if (value.endsWith(type)) {
0435:                                                orderList.remove(index);
0436:                                                orderList.add(i, name);
0437:                                                parent
0438:                                                        .setDocumentOrder(orderList);
0439:                                                pageManager
0440:                                                        .updateFolder(parent);
0441:                                                break;
0442:                                            }
0443:                                            i--;
0444:                                        }
0445:                                    } else {
0446:                                        orderList.add(name);
0447:                                        parent.setDocumentOrder(orderList);
0448:                                        pageManager.updateFolder(parent);
0449:                                    }
0450:                                } else {
0451:                                    orderList = new ArrayList(4);
0452:                                    orderList.add(name);
0453:                                    parent.setDocumentOrder(orderList);
0454:                                    pageManager.updateFolder(parent);
0455:                                }
0456:                            }
0457:                        } catch (Exception e) {
0458:                            throw new PortletException(
0459:                                    "Unable to access page for changing the document order: "
0460:                                            + e.getMessage(), e);
0461:                        }
0462:                        return;
0463:                    }
0464:
0465:                    if (request.getParameter("jsMovePageRight") != null) {
0466:                        try {
0467:                            Folder parent = (Folder) requestPage.getParent();
0468:                            if (parent != null) {
0469:                                List orderList = parent.getDocumentOrder();
0470:                                String name = requestPage.getName();
0471:                                if (orderList != null) {
0472:                                    int index = orderList.indexOf(name);
0473:                                    if (index > -1) {
0474:                                        String type = requestPage.getType();
0475:                                        int i = index + 1;
0476:                                        while (i < orderList.size()) {
0477:                                            String value = (String) orderList
0478:                                                    .get(i);
0479:                                            if (value.endsWith(type)) {
0480:                                                orderList.remove(index);
0481:                                                orderList.add(i, name);
0482:                                                parent
0483:                                                        .setDocumentOrder(orderList);
0484:                                                pageManager
0485:                                                        .updateFolder(parent);
0486:                                                break;
0487:                                            }
0488:                                            i++;
0489:                                        }
0490:                                    } else {
0491:                                        orderList.add(name);
0492:                                        parent.setDocumentOrder(orderList);
0493:                                        pageManager.updateFolder(parent);
0494:                                    }
0495:                                } else {
0496:                                    orderList = new ArrayList(4);
0497:                                    orderList.add(name);
0498:                                    parent.setDocumentOrder(orderList);
0499:                                    pageManager.updateFolder(parent);
0500:                                }
0501:                            }
0502:                        } catch (Exception e) {
0503:                            throw new PortletException(
0504:                                    "Unable to access page for changing the document order: "
0505:                                            + e.getMessage(), e);
0506:                        }
0507:                        return;
0508:                    }
0509:
0510:                    if (request.getParameter("jsSubmitFolder") != null) {
0511:                        String jsFolderName = request
0512:                                .getParameter("jsFolderName");
0513:                        String jsFolderTitle = request
0514:                                .getParameter("jsFolderTitle");
0515:                        String jsFolderShortTitle = request
0516:                                .getParameter("jsFolderShortTitle");
0517:                        if (jsFolderName != null
0518:                                && jsFolderName.length() > 0
0519:                                && jsFolderName.indexOf(Folder.PATH_SEPARATOR) == -1) {
0520:                            try {
0521:                                Folder parent = (Folder) requestPage
0522:                                        .getParent();
0523:                                if (parent != null) {
0524:                                    String path = parent.getPath();
0525:                                    if (path.endsWith(Folder.PATH_SEPARATOR)) {
0526:                                        path = path
0527:                                                + getEscapedName(jsFolderName);
0528:                                    } else {
0529:                                        path = path + Folder.PATH_SEPARATOR
0530:                                                + getEscapedName(jsFolderName);
0531:                                    }
0532:                                    Folder folder = pageManager.newFolder(path);
0533:                                    if (layout == null || layout.length() == 0) {
0534:                                        layout = requestPage.getRootFragment()
0535:                                                .getName();
0536:                                    }
0537:                                    folder
0538:                                            .setDefaultDecorator(
0539:                                                    requestPage
0540:                                                            .getDefaultDecorator(Fragment.LAYOUT),
0541:                                                    Fragment.LAYOUT);
0542:                                    folder
0543:                                            .setDefaultDecorator(
0544:                                                    requestPage
0545:                                                            .getDefaultDecorator(Fragment.PORTLET),
0546:                                                    Fragment.PORTLET);
0547:                                    folder
0548:                                            .setTitle(jsFolderTitle != null
0549:                                                    && !jsFolderTitle
0550:                                                            .equals("") ? jsFolderTitle
0551:                                                    : jsFolderName);
0552:                                    folder
0553:                                            .setShortTitle(jsFolderShortTitle != null
0554:                                                    && !jsFolderShortTitle
0555:                                                            .equals("") ? jsFolderShortTitle
0556:                                                    : jsFolderName);
0557:                                    pageManager.updateFolder(folder);
0558:
0559:                                    List orderList = parent.getDocumentOrder();
0560:                                    if (orderList != null) {
0561:                                        String name = folder.getName();
0562:                                        if (orderList.indexOf(name) < 0) {
0563:                                            orderList.add(name);
0564:                                            parent.setDocumentOrder(orderList);
0565:                                            pageManager.updateFolder(parent);
0566:                                        }
0567:                                    }
0568:
0569:                                    // add default page
0570:                                    path = folder.getPath();
0571:                                    if (path.endsWith(Folder.PATH_SEPARATOR)) {
0572:                                        path = path
0573:                                                + getEscapedName("default-page");
0574:                                    } else {
0575:                                        path = path
0576:                                                + Folder.PATH_SEPARATOR
0577:                                                + getEscapedName("default-page");
0578:                                    }
0579:                                    Page page = pageManager.newPage(path);
0580:                                    if (layout == null || layout.length() == 0) {
0581:                                        layout = requestPage.getRootFragment()
0582:                                                .getName();
0583:                                    }
0584:                                    page.getRootFragment().setName(layout);
0585:                                    page
0586:                                            .setDefaultDecorator(
0587:                                                    requestPage
0588:                                                            .getDefaultDecorator(Fragment.LAYOUT),
0589:                                                    Fragment.LAYOUT);
0590:                                    page
0591:                                            .setDefaultDecorator(
0592:                                                    requestPage
0593:                                                            .getDefaultDecorator(Fragment.PORTLET),
0594:                                                    Fragment.PORTLET);
0595:                                    page.setTitle(jsFolderName);
0596:                                    pageManager.updatePage(page);
0597:
0598:                                    orderList = folder.getDocumentOrder();
0599:                                    if (orderList != null) {
0600:                                        String name = page.getName();
0601:                                        if (orderList.indexOf(name) < 0) {
0602:                                            orderList.add(name);
0603:                                            folder.setDocumentOrder(orderList);
0604:                                            pageManager.updateFolder(folder);
0605:                                        }
0606:                                    }
0607:                                }
0608:                            } catch (Exception e) {
0609:                                throw new PortletException(
0610:                                        "Unable to access folder for editing: "
0611:                                                + e.getMessage(), e);
0612:                            }
0613:                        }
0614:                        return;
0615:                    }
0616:
0617:                    if (request.getParameter("jsChangeFolderName") != null) {
0618:                        String jsFolderTitle = request
0619:                                .getParameter("jsFolderTitle");
0620:                        String jsFolderShortTitle = request
0621:                                .getParameter("jsFolderShortTitle");
0622:                        try {
0623:                            Folder parent = (Folder) requestPage.getParent();
0624:                            if (parent != null) {
0625:                                if (jsFolderTitle != null
0626:                                        && !jsFolderTitle.equals("")) {
0627:                                    parent.setTitle(jsFolderTitle);
0628:                                }
0629:                                if (jsFolderShortTitle != null
0630:                                        && !jsFolderShortTitle.equals("")) {
0631:                                    parent.setShortTitle(jsFolderShortTitle);
0632:                                }
0633:                                pageManager.updateFolder(parent);
0634:                            }
0635:
0636:                        } catch (Exception e) {
0637:                            throw new PortletException(
0638:                                    "Unable to access folder for editing: "
0639:                                            + e.getMessage(), e);
0640:                        }
0641:                        return;
0642:                    }
0643:
0644:                    if (request.getParameter("jsDeleteFolder") != null) {
0645:                        try {
0646:                            Folder targetFolder = (Folder) requestPage
0647:                                    .getParent();
0648:                            Folder parent = (Folder) targetFolder.getParent();
0649:                            if (parent != null) {
0650:                                List orderList = parent.getDocumentOrder();
0651:                                if (orderList != null) {
0652:                                    String name = targetFolder.getName();
0653:                                    if (orderList.indexOf(name) > -1) {
0654:                                        orderList.remove(name);
0655:                                        parent.setDocumentOrder(orderList);
0656:                                        pageManager.updateFolder(parent);
0657:                                    }
0658:                                }
0659:
0660:                                // do not remove if the folder is root.
0661:                                pageManager.removeFolder(targetFolder);
0662:                            }
0663:                        } catch (Exception e) {
0664:                            throw new PortletException(
0665:                                    "Unable to access folder for removing: "
0666:                                            + e.getMessage(), e);
0667:                        }
0668:                        return;
0669:                    }
0670:
0671:                    if (request.getParameter("jsMoveFolderLeft") != null) {
0672:                        try {
0673:                            Folder targetFolder = (Folder) requestPage
0674:                                    .getParent();
0675:                            Folder parent = (Folder) targetFolder.getParent();
0676:                            if (parent != null) {
0677:                                List orderList = parent.getDocumentOrder();
0678:                                String name = targetFolder.getName();
0679:                                if (orderList != null) {
0680:                                    int index = orderList.indexOf(name);
0681:                                    if (index > -1) {
0682:                                        int i = index - 1;
0683:                                        while (i >= 0) {
0684:                                            String value = (String) orderList
0685:                                                    .get(i);
0686:                                            if (!value.endsWith(".psml")
0687:                                                    && !value.endsWith(".link")) {
0688:                                                orderList.remove(index);
0689:                                                orderList.add(i, name);
0690:                                                parent
0691:                                                        .setDocumentOrder(orderList);
0692:                                                pageManager
0693:                                                        .updateFolder(parent);
0694:                                                break;
0695:                                            }
0696:                                            i--;
0697:                                        }
0698:                                    } else {
0699:                                        orderList.add(name);
0700:                                        parent.setDocumentOrder(orderList);
0701:                                        pageManager.updateFolder(parent);
0702:                                    }
0703:                                } else {
0704:                                    orderList = new ArrayList(4);
0705:                                    orderList.add(name);
0706:                                    parent.setDocumentOrder(orderList);
0707:                                    pageManager.updateFolder(parent);
0708:                                }
0709:                            }
0710:                        } catch (Exception e) {
0711:                            throw new PortletException(
0712:                                    "Unable to access folder for changing the document order: "
0713:                                            + e.getMessage(), e);
0714:                        }
0715:                        return;
0716:                    }
0717:
0718:                    if (request.getParameter("jsMoveFolderRight") != null) {
0719:                        try {
0720:                            Folder targetFolder = (Folder) requestPage
0721:                                    .getParent();
0722:                            Folder parent = (Folder) targetFolder.getParent();
0723:                            if (parent != null) {
0724:                                List orderList = parent.getDocumentOrder();
0725:                                String name = targetFolder.getName();
0726:                                if (orderList != null) {
0727:                                    int index = orderList.indexOf(name);
0728:                                    if (index > -1) {
0729:                                        int i = index + 1;
0730:                                        while (i < orderList.size()) {
0731:                                            String value = (String) orderList
0732:                                                    .get(i);
0733:                                            if (!value.endsWith(".psml")
0734:                                                    && !value.endsWith(".link")) {
0735:                                                orderList.remove(index);
0736:                                                orderList.add(i, name);
0737:                                                parent
0738:                                                        .setDocumentOrder(orderList);
0739:                                                pageManager
0740:                                                        .updateFolder(parent);
0741:                                                break;
0742:                                            }
0743:                                            i++;
0744:                                        }
0745:                                    } else {
0746:                                        orderList.add(name);
0747:                                        parent.setDocumentOrder(orderList);
0748:                                        pageManager.updateFolder(parent);
0749:                                    }
0750:                                } else {
0751:                                    orderList = new ArrayList(4);
0752:                                    orderList.add(name);
0753:                                    parent.setDocumentOrder(orderList);
0754:                                    pageManager.updateFolder(parent);
0755:                                }
0756:                            }
0757:                        } catch (Exception e) {
0758:                            throw new PortletException(
0759:                                    "Unable to access folder for changing the document order: "
0760:                                            + e.getMessage(), e);
0761:                        }
0762:                        return;
0763:                    }
0764:
0765:                    String theme = request.getParameter("theme");
0766:                    if (theme != null
0767:                            && theme.length() > 0
0768:                            && !theme.equals(requestPage
0769:                                    .getDefaultDecorator(Fragment.LAYOUT))) {
0770:                        requestPage.setDefaultDecorator(theme, Fragment.LAYOUT);
0771:                        try {
0772:                            pageManager.updatePage(requestPage);
0773:                        } catch (Exception e) {
0774:                            throw new PortletException(
0775:                                    "Unable to update page: " + e.getMessage(),
0776:                                    e);
0777:                        }
0778:                        return;
0779:                    }
0780:
0781:                    String fragmentId = request.getParameter("fragment");
0782:                    if (fragmentId != null && fragmentId.length() > 0) {
0783:                        String move = request.getParameter("move");
0784:                        if (move != null && move.length() > 0) {
0785:                            int moveCode = Integer.parseInt(move);
0786:                            PortletWindow window = requestContext
0787:                                    .getActionWindow();
0788:                            Fragment currentFragment = requestPage
0789:                                    .getFragmentById(window.getId().toString());
0790:                            Fragment fragmentToMove = requestPage
0791:                                    .getFragmentById(fragmentId);
0792:
0793:                            if (currentFragment == null
0794:                                    || fragmentToMove == null) {
0795:                                // ignore no longer consistent page definition
0796:                                return;
0797:                            }
0798:
0799:                            ColumnLayout columnLayout;
0800:                            try {
0801:                                columnLayout = new ColumnLayout(numColumns,
0802:                                        layoutType, currentFragment
0803:                                                .getFragments(), null);
0804:                                columnLayout
0805:                                        .addLayoutEventListener(new PageManagerLayoutEventListener(
0806:                                                pageManager, requestPage,
0807:                                                layoutType));
0808:                            } catch (LayoutEventException e1) {
0809:                                throw new PortletException(
0810:                                        "Failed to build ColumnLayout "
0811:                                                + e1.getMessage(), e1);
0812:                            }
0813:
0814:                            try {
0815:                                switch (moveCode) {
0816:                                case LayoutEvent.MOVED_UP:
0817:                                    columnLayout.moveUp(fragmentToMove);
0818:                                    break;
0819:                                case LayoutEvent.MOVED_DOWN:
0820:                                    columnLayout.moveDown(fragmentToMove);
0821:                                    break;
0822:                                case LayoutEvent.MOVED_RIGHT:
0823:                                    columnLayout.moveRight(fragmentToMove);
0824:                                    break;
0825:                                case LayoutEvent.MOVED_LEFT:
0826:                                    columnLayout.moveLeft(fragmentToMove);
0827:                                    break;
0828:                                default:
0829:                                    throw new PortletException(
0830:                                            "Invalid movement code " + moveCode);
0831:                                }
0832:
0833:                            } catch (SecurityException se) {
0834:                                // ignore page security constraint violations, only
0835:                                // permitted users can edit managed pages; page
0836:                                // update will remain transient
0837:                                log
0838:                                        .info(
0839:                                                "Unable to update page "
0840:                                                        + requestPage.getId()
0841:                                                        + " layout due to security permission/constraint.",
0842:                                                se);
0843:                            } catch (Exception e) {
0844:                                if (e instanceof  PortletException) {
0845:                                    throw (PortletException) e;
0846:                                } else {
0847:                                    throw new PortletException(
0848:                                            "Unable to process layout for page "
0849:                                                    + requestPage.getId()
0850:                                                    + " layout: "
0851:                                                    + e.toString(), e);
0852:                                }
0853:                            }
0854:                            return;
0855:                        }
0856:
0857:                        String remove = request.getParameter("remove");
0858:                        if (remove != null && remove.length() > 0) {
0859:                            Page page = null;
0860:                            try {
0861:                                // TODO: for now retrieve the real Page instead of ContentPage
0862:                                //       because removing fragments isn't working through the ContentFragment wrapping
0863:                                page = pageManager.getPage(requestPage
0864:                                        .getPath());
0865:                            } catch (Exception e) {
0866:                                throw new PortletException(
0867:                                        "Unable to retrieve page "
0868:                                                + requestPage.getId(), e);
0869:                            }
0870:
0871:                            PortletWindow window = requestContext
0872:                                    .getActionWindow();
0873:                            Fragment currentFragment = page
0874:                                    .getFragmentById(window.getId().toString());
0875:
0876:                            if (currentFragment == null) {
0877:                                // ignore no longer consistent page definition
0878:                                return;
0879:                            }
0880:
0881:                            removeFragment(page, currentFragment, fragmentId);
0882:                            return;
0883:                        }
0884:
0885:                        String decorator = request.getParameter("decorator");
0886:                        if (decorator != null) {
0887:                            Fragment fragment = requestPage
0888:                                    .getFragmentById(fragmentId);
0889:
0890:                            if (fragment == null) {
0891:                                // ignore no longer consistent page definition
0892:                                return;
0893:                            }
0894:
0895:                            if (decorator.trim().length() == 0)
0896:                                fragment.setDecorator(null);
0897:                            else
0898:                                fragment.setDecorator(decorator);
0899:                            try {
0900:                                pageManager.updatePage(requestPage);
0901:                            } catch (Exception e) {
0902:                                throw new PortletException(
0903:                                        "Unable to update page for fragment decorator: "
0904:                                                + e.getMessage(), e);
0905:                            }
0906:                            return;
0907:                        }
0908:                    }
0909:                    // change style for all pages in user folder 
0910:                    String jsChangeUserPagesTheme = request
0911:                            .getParameter("jsChangeUserPagesTheme");
0912:                    if (jsChangeUserPagesTheme != null) {
0913:                        String user_pages_theme = request
0914:                                .getParameter("user_pages_theme");
0915:                        try {
0916:                            Folder f = pageManager.getUserFolder(request
0917:                                    .getRemoteUser());
0918:                            applyStyle(f, user_pages_theme, Fragment.LAYOUT);
0919:                        } catch (Exception e) {
0920:                            throw new PortletException(
0921:                                    "Unable to update folder for defUserLayoutDeco decorator: "
0922:                                            + e.getMessage(), e);
0923:                        }
0924:                        return;
0925:                    }
0926:                    String jsChangeUserPortletsDeco = request
0927:                            .getParameter("jsChangeUserPortletsDeco");
0928:                    if (jsChangeUserPortletsDeco != null) {
0929:                        String user_portlets_deco = request
0930:                                .getParameter("user_portlets_deco");
0931:                        try {
0932:                            Folder f = pageManager.getUserFolder(request
0933:                                    .getRemoteUser());
0934:                            applyStyle(f, user_portlets_deco, Fragment.PORTLET);
0935:                        } catch (Exception e) {
0936:                            throw new PortletException(
0937:                                    "Unable to update folder for defUserPortletDeco decorator: "
0938:                                            + e.getMessage(), e);
0939:                        }
0940:                        return;
0941:                    }
0942:
0943:                    String jsChangeThemeAll = request
0944:                            .getParameter("jsChangeThemeAll");
0945:                    if (jsChangeThemeAll != null) {
0946:                        String decorators = request.getParameter("decorators");
0947:                        Iterator fragmentsIter = requestPage.getRootFragment()
0948:                                .getFragments().iterator();
0949:                        while (fragmentsIter.hasNext()) {
0950:                            Fragment fragment = (Fragment) fragmentsIter.next();
0951:                            if (fragment == null) {
0952:                                // ignore no longer consistent page definition
0953:                                return;
0954:                            }
0955:
0956:                            if (decorators.trim().length() == 0)
0957:                                fragment.setDecorator(null);
0958:                            else
0959:                                fragment.setDecorator(decorators);
0960:                        }
0961:                        try {
0962:                            pageManager.updatePage(requestPage);
0963:                        } catch (Exception e) {
0964:                            throw new PortletException(
0965:                                    "Unable to update page for fragment decorator: "
0966:                                            + e.getMessage(), e);
0967:                        }
0968:                        return;
0969:                    }
0970:
0971:                    String portlets = request.getParameter("portlets");
0972:                    if (portlets != null && portlets.length() > 0) {
0973:                        PortletWindow window = requestContext.getActionWindow();
0974:                        Fragment targetFragment = requestPage
0975:                                .getFragmentById(window.getId().toString());
0976:
0977:                        if (targetFragment == null) {
0978:                            // ignore no longer consistent page definition
0979:                            return;
0980:                        }
0981:
0982:                        StringTokenizer tokenizer = new StringTokenizer(
0983:                                portlets, ",");
0984:                        while (tokenizer.hasMoreTokens()) {
0985:                            String portlet = tokenizer.nextToken();
0986:                            if (portlet.startsWith("box_")) {
0987:                                portlet = portlet.substring("box_".length());
0988:                                addPortletToPage(requestPage, targetFragment,
0989:                                        portlet);
0990:                            }
0991:                        }
0992:                        return;
0993:                    }
0994:                }
0995:            }
0996:
0997:            protected void clearLayoutAttributes(ActionRequest request) {
0998:                request.getPortletSession().removeAttribute(
0999:                        PortalReservedParameters.PAGE_LAYOUT_VIEW);
1000:                request.getPortletSession().removeAttribute(
1001:                        PortalReservedParameters.PAGE_LAYOUT_SOLO);
1002:                request.getPortletSession().removeAttribute(
1003:                        PortalReservedParameters.PAGE_LAYOUT_MAX);
1004:                request.getPortletSession().removeAttribute(
1005:                        PortalReservedParameters.PAGE_LAYOUT_HELP);
1006:            }
1007:
1008:            protected int getFragmentNestingLevel(Page page, String fragmentId) {
1009:                Fragment root = page.getRootFragment();
1010:                if (root.getId().equals(fragmentId)) {
1011:                    return 0;
1012:                } else {
1013:                    return getFragmentNestingLevel(root, 1, fragmentId);
1014:                }
1015:            }
1016:
1017:            protected int getFragmentNestingLevel(Fragment parent, int level,
1018:                    String fragmentId) {
1019:                Iterator iter = parent.getFragments().iterator();
1020:                Fragment child;
1021:                int childLevel;
1022:                while (iter.hasNext()) {
1023:                    child = (Fragment) iter.next();
1024:                    if (child.getId().equals(fragmentId)) {
1025:                        return level;
1026:                    } else {
1027:                        childLevel = getFragmentNestingLevel(child, level + 1,
1028:                                fragmentId);
1029:                        if (childLevel != -1) {
1030:                            return childLevel;
1031:                        }
1032:                    }
1033:                }
1034:                return -1;
1035:            }
1036:
1037:            protected String getEscapedName(String pageName) {
1038:                try {
1039:                    return URLEncoder.encode(pageName, "UTF-8").replace('%',
1040:                            '_');
1041:                } catch (UnsupportedEncodingException e) {
1042:                    log.warn("Unsupported Encoding Exception.", e);
1043:                    return pageName;
1044:                }
1045:            }
1046:
1047:            private void applyStyle(Folder f, String theme, String theme_type)
1048:                    throws FolderNotUpdatedException, NodeException {
1049:                f.setDefaultDecorator(theme, theme_type);
1050:                pageManager.updateFolder(f);
1051:                Iterator pagesIter = f.getPages().iterator();
1052:                while (pagesIter.hasNext()) {
1053:                    Page pp = (Page) pagesIter.next();
1054:                    pp.setDefaultDecorator(theme, theme_type);
1055:                    pageManager.updatePage(pp);
1056:                }
1057:                Iterator userFoldersIter = pageManager.getFolders(f).iterator();
1058:                while (userFoldersIter.hasNext()) {
1059:                    Folder ff = (Folder) userFoldersIter.next();
1060:                    applyStyle(ff, theme, theme_type);
1061:                }
1062:            }
1063:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.