Source Code Cross Referenced for JetspeedDesktopImpl.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » desktop » 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.desktop.impl 
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.desktop.impl;
0018:
0019:        import java.io.IOException;
0020:        import java.util.Iterator;
0021:        import java.util.ResourceBundle;
0022:        import java.util.Set;
0023:        import java.util.Random;
0024:
0025:        import javax.servlet.RequestDispatcher;
0026:        import javax.servlet.ServletContext;
0027:
0028:        import org.apache.commons.logging.Log;
0029:        import org.apache.commons.logging.LogFactory;
0030:        import org.apache.jetspeed.Jetspeed;
0031:        import org.apache.jetspeed.cache.CacheElement;
0032:        import org.apache.jetspeed.cache.JetspeedCache;
0033:        import org.apache.jetspeed.container.url.BasePortalURL;
0034:        import org.apache.jetspeed.decoration.DecorationFactory;
0035:        import org.apache.jetspeed.decoration.LayoutDecoration;
0036:        import org.apache.jetspeed.decoration.PortletDecoration;
0037:        import org.apache.jetspeed.decoration.Theme;
0038:        import org.apache.jetspeed.desktop.JetspeedDesktop;
0039:        import org.apache.jetspeed.desktop.JetspeedDesktopContext;
0040:        import org.apache.jetspeed.headerresource.HeaderResource;
0041:        import org.apache.jetspeed.headerresource.HeaderResourceFactory;
0042:        import org.apache.jetspeed.headerresource.HeaderResourceLib;
0043:        import org.apache.jetspeed.om.page.Page;
0044:        import org.apache.jetspeed.request.RequestContext;
0045:        import org.springframework.web.context.ServletContextAware;
0046:
0047:        /**
0048:         * Desktop Valve
0049:         *
0050:         * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
0051:         * @author <a href="mailto:smilek@apache.org">Steve Milek</a>
0052:         * @version $Id: JetspeedDesktopImpl.java $
0053:         */
0054:        public class JetspeedDesktopImpl implements  JetspeedDesktop,
0055:                ServletContextAware {
0056:            private static final Log log = LogFactory
0057:                    .getLog(JetspeedDesktopImpl.class);
0058:
0059:            private final static String EOL = "\r\n"; // html eol
0060:            private final static String DOJO_CONFIG_LAYOUT_DECORATION_PATH_VAR_NAME = HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME
0061:                    + ".layoutDecorationPath";
0062:            private final static String DOJO_CONFIG_LAYOUT_VAR_NAME = HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME
0063:                    + ".layoutName";
0064:            private final static String DOJO_CONFIG_PORTLET_DECORATIONS_PATH_VAR_NAME = HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME
0065:                    + ".portletDecorationsPath";
0066:            private final static String DOJO_CONFIG_PORTLET_DECORATIONS_ALLOWED_VAR_NAME = HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME
0067:                    + ".portletDecorationsAllowed";
0068:            private final static String DOJO_CONFIG_PORTLET_DECORATIONS_CONFIG_VAR_NAME = HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME
0069:                    + ".portletDecorationsProperties";
0070:            private final static String DOJO_CONFIG_ACTION_LABELS_NAME = HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME
0071:                    + ".desktopActionLabels";
0072:            private final static String DOJO_CONFIG_LOADING_IMGPROPS_NAME = HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME
0073:                    + ".loadingImgProps";
0074:            private final static String DOJO_CONFIG_PAGEEDITOR_LABELS_NAME = HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME
0075:                    + ".pageEditorLabels";
0076:            private final static String DOJO_CONFIG_PAGEEDITOR_DIALOG_LABELS_NAME = HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME
0077:                    + ".pageEditorDialogLabels";
0078:            private final static String DOJO_CONFIG_PAGEEDITOR_SETTINGS_NAME = HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME
0079:                    + ".pec";
0080:
0081:            private final static String[] DESKTOP_LOADING_PROPERTY_NAMES = new String[] {
0082:                    "dir", "animated", "stepprefix", "stepextension", "steps" };
0083:            private final static String[] DESKTOP_LOADING_OUTPUT_PROPERTY_NAMES = new String[] {
0084:                    "imgdir", "imganimated", "imgstepprefix",
0085:                    "imgstepextension", "imgsteps" };
0086:            private final static String[] DESKTOP_ACTION_RESOURCE_NAMES = new String[] {
0087:                    "menu", "tile", "untile", "heightexpand", "heightnormal",
0088:                    "restore", "removeportlet", "minimized", "maximized",
0089:                    "normal", "help", "edit", "view", "print", "config",
0090:                    "edit_defaults", "about", "addportlet", "editpage",
0091:                    "movetiled", "moveuntiled", "loadpage", "loadpageeditor",
0092:                    "loadportletrender", "loadportletaction",
0093:                    "loadportletupdate" };
0094:            private final static String[] DESKTOP_PAGEEDITOR_RESOURCE_NAMES = new String[] {
0095:                    "title", "changelayout", "changepagelayouttheme",
0096:                    "changepageportlettheme", "newpage", "deletepage",
0097:                    "addlayout", "addportlet", "columnsizes", "deletelayout",
0098:                    "movemode", "movemode_exit", "changeportlettheme" };
0099:            private final static String[] DESKTOP_PAGEEDITOR_DIALOG_RESOURCE_NAMES = new String[] {
0100:                    "columnsizes", "columnsizes_column1",
0101:                    "columnsizes_column2", "columnsizes_column3",
0102:                    "columnsizes_column4", "columnsizes_column5", "newpage",
0103:                    "newpage_name", "newpage_title", "newpage_titleshort",
0104:                    "deletepage", "deletelayout", "removeportlet", "ok",
0105:                    "cancel", "yes", "no" };
0106:
0107:            private final static String DESKTOP_LOADING_NAME_PREFIX = "desktop.loading.";
0108:            private final static String DESKTOP_ACTION_NAME_PREFIX = "desktop.action.";
0109:            private final static String DESKTOP_PAGEEDITOR_NAME_PREFIX = "desktop.pageeditor.";
0110:
0111:            private final static String DESKTOP_LOADING_IMG_NAME_PREFIX = DESKTOP_LOADING_NAME_PREFIX
0112:                    + "img.";
0113:            private final static String DESKTOP_ACTION_RESOURCE_NAME_PREFIX = DESKTOP_ACTION_NAME_PREFIX
0114:                    + "labels.";
0115:            private final static String DESKTOP_PAGEEDITOR_RESOURCE_NAME_PREFIX = DESKTOP_PAGEEDITOR_NAME_PREFIX
0116:                    + "labels.";
0117:            private final static String DESKTOP_PAGEEDITOR_DIALOG_RESOURCE_NAME_PREFIX = DESKTOP_PAGEEDITOR_NAME_PREFIX
0118:                    + "dialog.labels.";
0119:
0120:            private final static String DESKTOP_PAGEEDITOR_PAGE_LAYOUT_DECORATOR_EDITABLE = DESKTOP_PAGEEDITOR_NAME_PREFIX
0121:                    + "page.layout.decorator.editable";
0122:            private final static String DESKTOP_PAGEEDITOR_PAGE_LAYOUT_DECORATOR_EDITABLE_DEFAULT = "true";
0123:            private final static String DESKTOP_PAGEEDITOR_LAYOUT_NAME_EDITABLE = DESKTOP_PAGEEDITOR_NAME_PREFIX
0124:                    + "layout.name.editable";
0125:            private final static String DESKTOP_PAGEEDITOR_LAYOUT_NAME_EDITABLE_DEFAULT = "true";
0126:
0127:            private final static String DESKTOP_PAGEEDITOR_LAYOUT_COLUMNSIZE_EDITABLE = DESKTOP_PAGEEDITOR_NAME_PREFIX
0128:                    + "layout.columnsize.editable";
0129:            private final static String DESKTOP_PAGEEDITOR_LAYOUT_COLUMNSIZE_EDITABLE_DEFAULT = "true";
0130:
0131:            private final static String DESKTOP_PAGEEDITOR_PAGE_ADD_ENABLED = DESKTOP_PAGEEDITOR_NAME_PREFIX
0132:                    + "page.add.enabled";
0133:            private final static String DESKTOP_PAGEEDITOR_PAGE_ADD_ENABLED_DEFAULT = "true";
0134:            private final static String DESKTOP_PAGEEDITOR_PORTLET_ADD_ENABLED = DESKTOP_PAGEEDITOR_NAME_PREFIX
0135:                    + "portlet.add.enabled";
0136:            private final static String DESKTOP_PAGEEDITOR_PORTLET_ADD_ENABLED_DEFAULT = "true";
0137:            private final static String DESKTOP_PAGEEDITOR_PAGE_PORTLET_DECORATOR_EDITABLE = DESKTOP_PAGEEDITOR_NAME_PREFIX
0138:                    + "page.portlet.decorator.editable";
0139:            private final static String DESKTOP_PAGEEDITOR_PAGE_PORTLET_DECORATOR_EDITABLE_DEFAULT = "true";
0140:            private final static String DESKTOP_PAGEEDITOR_PORTLET_DECORATOR_EDITABLE = DESKTOP_PAGEEDITOR_NAME_PREFIX
0141:                    + "portlet.decorator.editable";
0142:            private final static String DESKTOP_PAGEEDITOR_PORTLET_DECORATOR_EDITABLE_DEFAULT = "true";
0143:
0144:            private final static String DESKTOP_PAGEEDITOR_MOVEMODE_ISDEFAULT = DESKTOP_PAGEEDITOR_NAME_PREFIX
0145:                    + "movemode.isdefault";
0146:            private final static String DESKTOP_PAGEEDITOR_MOVEMODE_ISDEFAULT_DEFAULT = "true";
0147:            private final static String DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_EDITABLE = DESKTOP_PAGEEDITOR_NAME_PREFIX
0148:                    + "layout.noactions.editable";
0149:            private final static String DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_EDITABLE_DEFAULT = "false";
0150:            private final static String DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_TOPLEVEL_MOVEABLE = DESKTOP_PAGEEDITOR_NAME_PREFIX
0151:                    + "layout.noactions.toplevel.moveable";
0152:            private final static String DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_TOPLEVEL_MOVEABLE_DEFAULT = "false";
0153:            private final static String DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_COLUMNSIZE_EDITABLE = DESKTOP_PAGEEDITOR_NAME_PREFIX
0154:                    + "layout.noactions.columnsize.editable";
0155:            private final static String DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_COLUMNSIZE_EDITABLE_DEFAULT = "false";
0156:
0157:            private final static String DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_EDITOR_ROLE = DESKTOP_PAGEEDITOR_NAME_PREFIX
0158:                    + "layout.noactions.editor.role";
0159:            private final static String DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_EDITOR_ROLE_DEFAULT = null;
0160:
0161:            private final static String DESKTOP_PAGEEDITOR_PAGE_LAYOUT_DEPTH_MAX = DESKTOP_PAGEEDITOR_NAME_PREFIX
0162:                    + "page.layout.depth.max";
0163:            private final static int DESKTOP_PAGEEDITOR_PAGE_LAYOUT_DEPTH_MAX_DEFAULT = 2; // allowed range is 0-15
0164:
0165:            private final static int DESKTOP_PAGEEDITOR_PAGE_LAYOUT_DEPTH_MAX_RESERVED = 0x000F; // max layout depth (0-15) is first 4 bits
0166:            private final static int DESKTOP_PAGEEDITOR_PAGE_LAYOUT_DECORATOR_EDITABLE_TRUE = 0x0010;
0167:            private final static int DESKTOP_PAGEEDITOR_LAYOUT_NAME_EDITABLE_TRUE = 0x0020;
0168:            private final static int DESKTOP_PAGEEDITOR_LAYOUT_COLUMNSIZE_EDITABLE_TRUE = 0x0040;
0169:            private final static int DESKTOP_PAGEEDITOR_PAGE_ADD_ENABLED_TRUE = 0x0080;
0170:            private final static int DESKTOP_PAGEEDITOR_PORTLET_ADD_ENABLED_TRUE = 0x0100;
0171:            private final static int DESKTOP_PAGEEDITOR_PAGE_PORTLET_DECORATOR_EDITABLE_TRUE = 0x0200;
0172:            private final static int DESKTOP_PAGEEDITOR_PORTLET_DECORATOR_EDITABLE_TRUE = 0x0400;
0173:            private final static int DESKTOP_PAGEEDITOR_MOVEMODE_ISDEFAULT_TRUE = 0x0800;
0174:            private final static int DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_EDITABLE_TRUE = 0x1000;
0175:            private final static int DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_TOPLEVEL_MOVEABLE_TRUE = 0x2000;
0176:            private final static int DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_COLUMNSIZE_EDITABLE_TRUE = 0x4000;
0177:            // algorithm used below and on client-size doesn't allow for further expansion (i.e. allows for expansion up to 0x4000)
0178:            //   (i.e. use of 0x8000 would break algorithm - because it would introduce the possibility of values close to 0xFFFF)
0179:            //   - if needed, add another variable for a fresh set of flags (and adjust the dependencies)
0180:
0181:            private DecorationFactory decorationFactory;
0182:
0183:            /** desktop pipeline servlet path */
0184:            private String desktopServletPath;
0185:
0186:            /** default extension for layout templates */
0187:            private String defaultLayoutTemplateExtension;
0188:
0189:            /** spring-fed servlet context property */
0190:            private ServletContext servletContext;
0191:
0192:            /** tool for directing output to html &lt;head&gt; */
0193:            private HeaderResourceFactory headerResourceFactory;
0194:
0195:            /** cache to minimize production of generated desktop configuration content **/
0196:            private JetspeedCache desktopContentCache;
0197:
0198:            /** base portal URL to override default URL server info from servlet */
0199:            private BasePortalURL baseUrlAccess = null;
0200:
0201:            public JetspeedDesktopImpl(DecorationFactory decorationFactory,
0202:                    HeaderResourceFactory headerResourceFactory,
0203:                    JetspeedCache desktopContentCache,
0204:                    String desktopServletPath,
0205:                    String defaultLayoutTemplateExtension) {
0206:                this (decorationFactory, headerResourceFactory,
0207:                        desktopContentCache, desktopServletPath,
0208:                        defaultLayoutTemplateExtension, null, null, null);
0209:            }
0210:
0211:            public JetspeedDesktopImpl(DecorationFactory decorationFactory,
0212:                    HeaderResourceFactory headerResourceFactory,
0213:                    JetspeedCache desktopContentCache,
0214:                    String desktopServletPath,
0215:                    String defaultLayoutTemplateExtension,
0216:                    String defaultDesktopLayoutDecoration,
0217:                    String defaultDesktopPortletDecoration) {
0218:                this (decorationFactory, headerResourceFactory,
0219:                        desktopContentCache, desktopServletPath,
0220:                        defaultLayoutTemplateExtension,
0221:                        defaultDesktopLayoutDecoration,
0222:                        defaultDesktopPortletDecoration, null);
0223:            }
0224:
0225:            public JetspeedDesktopImpl(DecorationFactory decorationFactory,
0226:                    HeaderResourceFactory headerResourceFactory,
0227:                    JetspeedCache desktopContentCache,
0228:                    String desktopServletPath,
0229:                    String defaultLayoutTemplateExtension,
0230:                    String defaultDesktopLayoutDecoration,
0231:                    String defaultDesktopPortletDecoration,
0232:                    BasePortalURL baseUrlAccess) {
0233:                this .decorationFactory = decorationFactory;
0234:                this .headerResourceFactory = headerResourceFactory;
0235:                this .desktopContentCache = desktopContentCache;
0236:
0237:                if (desktopServletPath != null
0238:                        && desktopServletPath.length() > 0) {
0239:                    if (desktopServletPath.charAt(0) != '/')
0240:                        desktopServletPath = "/" + desktopServletPath;
0241:                }
0242:                this .desktopServletPath = desktopServletPath;
0243:                if (this .desktopServletPath == null
0244:                        || this .desktopServletPath.length() == 0) {
0245:                    log
0246:                            .warn("JetspeedDesktopImpl initialization is incomplete due to undefined desktop servlet path.");
0247:                    this .desktopServletPath = null;
0248:                }
0249:
0250:                this .defaultLayoutTemplateExtension = defaultLayoutTemplateExtension;
0251:
0252:                // set default layout and portlet decorations only if they are not currently undefined
0253:                if (defaultDesktopLayoutDecoration != null
0254:                        && defaultDesktopLayoutDecoration.length() > 0) {
0255:                    String existingDefaultDesktopLayoutDecoration = decorationFactory
0256:                            .getDefaultDesktopLayoutDecoration();
0257:                    if (existingDefaultDesktopLayoutDecoration == null
0258:                            || existingDefaultDesktopLayoutDecoration.length() == 0) {
0259:                        decorationFactory
0260:                                .setDefaultDesktopLayoutDecoration(defaultDesktopLayoutDecoration);
0261:                    }
0262:                }
0263:                if (defaultDesktopPortletDecoration != null
0264:                        && defaultDesktopPortletDecoration.length() > 0) {
0265:                    String existingDefaultDesktopPortletDecoration = decorationFactory
0266:                            .getDefaultDesktopPortletDecoration();
0267:                    if (existingDefaultDesktopPortletDecoration == null
0268:                            || existingDefaultDesktopPortletDecoration.length() == 0) {
0269:                        decorationFactory
0270:                                .setDefaultDesktopPortletDecoration(defaultDesktopPortletDecoration);
0271:                    }
0272:                }
0273:
0274:                this .baseUrlAccess = baseUrlAccess;
0275:            }
0276:
0277:            public void render(RequestContext request) {
0278:                String layoutDecorationTemplatePath = null;
0279:                boolean layoutDecorationTemplatePathWasAssigned = false;
0280:                try {
0281:                    Page page = request.getPage();
0282:
0283:                    // enable desktop
0284:                    request.setAttribute(
0285:                            JetspeedDesktop.DESKTOP_ENABLED_REQUEST_ATTRIBUTE,
0286:                            Boolean.TRUE);
0287:
0288:                    // get decorations
0289:                    Theme theme = decorationFactory.getTheme(page, request);
0290:
0291:                    HeaderResource hr = getHeaderResourceFactory()
0292:                            .getHeaderResouce(request);
0293:                    JetspeedDesktopContext desktopContext = new JetspeedDesktopContextImpl(
0294:                            request, this .baseUrlAccess, theme, hr,
0295:                            defaultLayoutTemplateExtension);
0296:
0297:                    String layoutTemplateIdPropertyName = null;
0298:                    if ("true".equals(request.getRequest().getParameter(
0299:                            "jsprintmode")))
0300:                        layoutTemplateIdPropertyName = JetspeedDesktopContext.LAYOUT_PRINT_TEMPLATE_ID_PROP;
0301:
0302:                    layoutDecorationTemplatePath = desktopContext
0303:                            .getLayoutTemplatePath(layoutTemplateIdPropertyName);
0304:                    layoutDecorationTemplatePathWasAssigned = true;
0305:
0306:                    RequestDispatcher dispatcher = request.getRequest()
0307:                            .getRequestDispatcher(layoutDecorationTemplatePath);
0308:
0309:                    hr.dojoEnable();
0310:
0311:                    request.getRequest().setAttribute(
0312:                            JetspeedDesktopContext.DESKTOP_CONTEXT_ATTRIBUTE,
0313:                            desktopContext);
0314:                    request
0315:                            .getRequest()
0316:                            .setAttribute(
0317:                                    JetspeedDesktopContext.DESKTOP_REQUEST_CONTEXT_ATTRIBUTE,
0318:                                    request);
0319:                    request
0320:                            .getRequest()
0321:                            .setAttribute(
0322:                                    JetspeedDesktopContext.DESKTOP_COMPONENT_MANAGER_ATTRIBUTE,
0323:                                    Jetspeed.getComponentManager());
0324:
0325:                    String layoutDecorationName = desktopContext
0326:                            .getLayoutDecorationName();
0327:                    boolean inclStyleLayout = hr
0328:                            .isHeaderSectionIncluded(HeaderResource.HEADER_SECTION_DESKTOP_STYLE_LAYOUT);
0329:                    String dojoConfigContentCacheKey = DOJO_CONFIG_LAYOUT_VAR_NAME
0330:                            + "." + layoutDecorationName;
0331:                    String dojoConfigContent = getCachedContent(dojoConfigContentCacheKey);
0332:
0333:                    if (dojoConfigContent == null) {
0334:                        String portletDecorationsBasePath = decorationFactory
0335:                                .getPortletDecorationsBasePath();
0336:                        StringBuffer dojoConfigAddOn = new StringBuffer();
0337:                        dojoConfigAddOn.append("    ").append(
0338:                                DOJO_CONFIG_LAYOUT_DECORATION_PATH_VAR_NAME)
0339:                                .append(" = \"").append(
0340:                                        desktopContext.getLayoutBasePath())
0341:                                .append("\";").append(EOL);
0342:                        dojoConfigAddOn.append("    ").append(
0343:                                DOJO_CONFIG_LAYOUT_VAR_NAME).append(" = \"")
0344:                                .append(layoutDecorationName).append("\";")
0345:                                .append(EOL);
0346:                        dojoConfigAddOn.append("    ").append(
0347:                                DOJO_CONFIG_PORTLET_DECORATIONS_PATH_VAR_NAME)
0348:                                .append(" = \"").append(
0349:                                        portletDecorationsBasePath).append(
0350:                                        "\";").append(EOL);
0351:
0352:                        LayoutDecoration desktopLayoutDecoration = decorationFactory
0353:                                .getLayoutDecoration(layoutDecorationName,
0354:                                        request);
0355:                        if (desktopLayoutDecoration != null) {
0356:                            boolean atLeastOneFound = false;
0357:                            StringBuffer loadingPropsBuffer = new StringBuffer();
0358:                            loadingPropsBuffer.append("    ").append(
0359:                                    DOJO_CONFIG_LOADING_IMGPROPS_NAME).append(
0360:                                    " = { ");
0361:                            for (int i = 0; i < DESKTOP_LOADING_PROPERTY_NAMES.length; i++) {
0362:                                String propValue = desktopLayoutDecoration
0363:                                        .getProperty(DESKTOP_LOADING_IMG_NAME_PREFIX
0364:                                                + DESKTOP_LOADING_PROPERTY_NAMES[i]);
0365:                                if (propValue != null) {
0366:                                    if (atLeastOneFound) {
0367:                                        loadingPropsBuffer.append(", ");
0368:                                    } else {
0369:                                        atLeastOneFound = true;
0370:                                    }
0371:                                    String usePropertyName = DESKTOP_LOADING_PROPERTY_NAMES[i];
0372:                                    if (DESKTOP_LOADING_OUTPUT_PROPERTY_NAMES != null
0373:                                            && DESKTOP_LOADING_OUTPUT_PROPERTY_NAMES.length > i
0374:                                            && DESKTOP_LOADING_OUTPUT_PROPERTY_NAMES[i] != null)
0375:                                        usePropertyName = DESKTOP_LOADING_OUTPUT_PROPERTY_NAMES[i];
0376:
0377:                                    loadingPropsBuffer.append(usePropertyName)
0378:                                            .append(": ").append(propValue);
0379:                                }
0380:                            }
0381:                            loadingPropsBuffer.append(" };");
0382:                            if (atLeastOneFound)
0383:                                dojoConfigAddOn.append(
0384:                                        loadingPropsBuffer.toString()).append(
0385:                                        EOL);
0386:
0387:                            addPageEditorSettings(dojoConfigAddOn,
0388:                                    desktopLayoutDecoration);
0389:                        } else {
0390:                            log
0391:                                    .error("Failed to find desktop layout decoration "
0392:                                            + layoutDecorationName
0393:                                            + " - layout decoration properties cannot be added to content.");
0394:                        }
0395:
0396:                        Set desktopPortletDecorationsNames = decorationFactory
0397:                                .getDesktopPortletDecorations(request);
0398:                        String portletDecorationNamesContent = HeaderResourceLib
0399:                                .makeJSONStringArray(desktopPortletDecorationsNames);
0400:                        dojoConfigAddOn
0401:                                .append("    ")
0402:                                .append(
0403:                                        DOJO_CONFIG_PORTLET_DECORATIONS_ALLOWED_VAR_NAME)
0404:                                .append(" = ").append(
0405:                                        portletDecorationNamesContent).append(
0406:                                        ";");
0407:
0408:                        StringBuffer pDecsOut = new StringBuffer();
0409:                        Iterator desktopPortletDecorationsNamesIter = desktopPortletDecorationsNames
0410:                                .iterator();
0411:                        while (desktopPortletDecorationsNamesIter.hasNext()) {
0412:                            String desktopPortletDecorationName = (String) desktopPortletDecorationsNamesIter
0413:                                    .next();
0414:
0415:                            PortletDecoration desktopPortletDecoration = decorationFactory
0416:                                    .getPortletDecoration(
0417:                                            desktopPortletDecorationName,
0418:                                            request);
0419:
0420:                            StringBuffer pOut = new StringBuffer();
0421:
0422:                            String actionButtonOrderContent = desktopPortletDecoration
0423:                                    .getProperty(HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_BUTTON_ORDER);
0424:                            if (actionButtonOrderContent != null
0425:                                    && actionButtonOrderContent.length() > 0) {
0426:                                pOut
0427:                                        .append((pOut.length() > 0) ? ", " : "")
0428:                                        .append(
0429:                                                HeaderResource.DESKTOP_JSON_WINDOW_ACTION_BUTTON_ORDER)
0430:                                        .append(": ").append(
0431:                                                actionButtonOrderContent);
0432:                            }
0433:
0434:                            String actionNoImageContent = desktopPortletDecoration
0435:                                    .getProperty(HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_NOIMAGE);
0436:                            if (actionNoImageContent != null
0437:                                    && actionNoImageContent.length() > 0) {
0438:                                pOut
0439:                                        .append((pOut.length() > 0) ? ", " : "")
0440:                                        .append(
0441:                                                HeaderResource.DESKTOP_JSON_WINDOW_ACTION_NOIMAGE)
0442:                                        .append(": ").append(
0443:                                                actionNoImageContent);
0444:                            }
0445:
0446:                            String actionMenuOrderContent = desktopPortletDecoration
0447:                                    .getProperty(HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_MENU_ORDER);
0448:                            if (actionMenuOrderContent != null
0449:                                    && actionMenuOrderContent.length() > 0) {
0450:                                pOut
0451:                                        .append((pOut.length() > 0) ? ", " : "")
0452:                                        .append(
0453:                                                HeaderResource.DESKTOP_JSON_WINDOW_ACTION_MENU_ORDER)
0454:                                        .append(": ").append(
0455:                                                actionMenuOrderContent);
0456:                            }
0457:
0458:                            String windowActionButtonTooltip = desktopPortletDecoration
0459:                                    .getProperty(HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_BUTTON_TOOLTIP);
0460:                            if (windowActionButtonTooltip != null
0461:                                    && windowActionButtonTooltip.length() > 0) {
0462:                                pOut
0463:                                        .append((pOut.length() > 0) ? ", " : "")
0464:                                        .append(
0465:                                                HeaderResource.DESKTOP_JSON_WINDOW_ACTION_BUTTON_TOOLTIP)
0466:                                        .append(": ").append(
0467:                                                windowActionButtonTooltip);
0468:                            }
0469:
0470:                            String windowActionButtonMax = desktopPortletDecoration
0471:                                    .getProperty(HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_BUTTON_MAX);
0472:                            if (windowActionButtonMax != null
0473:                                    && windowActionButtonMax.length() > 0) {
0474:                                pOut
0475:                                        .append((pOut.length() > 0) ? ", " : "")
0476:                                        .append(
0477:                                                HeaderResource.DESKTOP_JSON_WINDOW_ACTION_BUTTON_MAX)
0478:                                        .append(": ").append(
0479:                                                windowActionButtonMax);
0480:                            }
0481:
0482:                            String iconEnabledContent = desktopPortletDecoration
0483:                                    .getProperty(HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ICON_ENABLED);
0484:                            if (iconEnabledContent != null
0485:                                    && iconEnabledContent.length() > 0) {
0486:                                pOut
0487:                                        .append((pOut.length() > 0) ? ", " : "")
0488:                                        .append(
0489:                                                HeaderResource.DESKTOP_JSON_WINDOW_ICON_ENABLED)
0490:                                        .append(": ")
0491:                                        .append(iconEnabledContent);
0492:                            }
0493:
0494:                            String iconPathContent = desktopPortletDecoration
0495:                                    .getProperty(HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ICON_PATH);
0496:                            if (iconPathContent != null
0497:                                    && iconPathContent.length() > 0) {
0498:                                pOut
0499:                                        .append((pOut.length() > 0) ? ", " : "")
0500:                                        .append(
0501:                                                HeaderResource.DESKTOP_JSON_WINDOW_ICON_PATH)
0502:                                        .append(": ").append(iconPathContent)
0503:                                        .append(";").append(EOL);
0504:                            }
0505:
0506:                            String titlebarEnabledContent = desktopPortletDecoration
0507:                                    .getProperty(HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_TITLEBAR_ENABLED);
0508:                            if (titlebarEnabledContent != null
0509:                                    && titlebarEnabledContent.length() > 0) {
0510:                                pOut
0511:                                        .append((pOut.length() > 0) ? ", " : "")
0512:                                        .append(
0513:                                                HeaderResource.DESKTOP_JSON_WINDOW_TITLEBAR_ENABLED)
0514:                                        .append(": ").append(
0515:                                                titlebarEnabledContent);
0516:                            }
0517:
0518:                            String resizebarEnabledContent = desktopPortletDecoration
0519:                                    .getProperty(HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_RESIZEBAR_ENABLED);
0520:                            if (resizebarEnabledContent != null
0521:                                    && resizebarEnabledContent.length() > 0) {
0522:                                pOut
0523:                                        .append((pOut.length() > 0) ? ", " : "")
0524:                                        .append(
0525:                                                HeaderResource.DESKTOP_JSON_WINDOW_RESIZEBAR_ENABLED)
0526:                                        .append(": ").append(
0527:                                                resizebarEnabledContent);
0528:                            }
0529:
0530:                            if (pOut.length() > 0) {
0531:                                if (pDecsOut.length() == 0) {
0532:                                    pDecsOut
0533:                                            .append(
0534:                                                    DOJO_CONFIG_PORTLET_DECORATIONS_CONFIG_VAR_NAME)
0535:                                            .append(" = { ");
0536:                                } else {
0537:                                    pDecsOut.append(", ");
0538:                                }
0539:                                pDecsOut.append("\"").append(
0540:                                        desktopPortletDecorationName).append(
0541:                                        "\": { ").append(pOut.toString())
0542:                                        .append(" }").append(EOL);
0543:                            }
0544:                        } // while ( desktopPortletDecorationsNamesIter.hasNext() )
0545:                        if (pDecsOut.length() > 0) {
0546:                            pDecsOut.append(" }");
0547:                            dojoConfigAddOn.append(EOL).append("    ").append(
0548:                                    pDecsOut.toString()).append(";");
0549:                        }
0550:
0551:                        dojoConfigContent = dojoConfigAddOn.toString();
0552:                        setCachedContent(dojoConfigContentCacheKey,
0553:                                dojoConfigContent);
0554:                    }
0555:
0556:                    if (dojoConfigContent != null) {
0557:                        hr.addHeaderSectionFragment(
0558:                                DOJO_CONFIG_LAYOUT_VAR_NAME,
0559:                                HeaderResource.HEADER_SECTION_DOJO_CONFIG,
0560:                                dojoConfigContent);
0561:                    }
0562:
0563:                    if (inclStyleLayout) {
0564:                        String contextPath = request.getRequest()
0565:                                .getContextPath();
0566:                        String styleLayoutContentCacheKey = (HeaderResource.HEADER_SECTION_DESKTOP_STYLE_LAYOUT
0567:                                + "." + layoutDecorationName + "." + contextPath);
0568:                        String styleLayoutContent = getCachedContent(styleLayoutContentCacheKey);
0569:                        if (styleLayoutContent == null) {
0570:                            String portletDecorationsBasePath = decorationFactory
0571:                                    .getPortletDecorationsBasePath();
0572:                            String portletDecorationsBaseRelative = portletDecorationsBasePath;
0573:                            if (portletDecorationsBaseRelative != null
0574:                                    && portletDecorationsBaseRelative.length() > 1
0575:                                    && portletDecorationsBaseRelative
0576:                                            .indexOf('/') == 0) {
0577:                                portletDecorationsBaseRelative = portletDecorationsBaseRelative
0578:                                        .substring(1);
0579:                            }
0580:                            StringBuffer desktopThemeStyleLink = new StringBuffer();
0581:
0582:                            int stylesheetCount = 0;
0583:                            Iterator stylesheetIter = theme.getStyleSheets()
0584:                                    .iterator();
0585:                            while (stylesheetIter.hasNext()) {
0586:                                String stylesheetHref = (String) stylesheetIter
0587:                                        .next();
0588:                                if (stylesheetHref != null
0589:                                        && stylesheetHref.length() > 0) {
0590:                                    if (!stylesheetHref
0591:                                            .startsWith(portletDecorationsBaseRelative)) { // exclude portlet decorations - in desktop these are loaded via javascript
0592:                                        if (stylesheetCount > 0) {
0593:                                            desktopThemeStyleLink.append(EOL);
0594:                                        }
0595:
0596:                                        desktopThemeStyleLink
0597:                                                .append("<link rel=\"stylesheet\" type=\"text/css\" media=\"screen, projection\" href=\"");
0598:                                        //desktopThemeStyleLink.append( desktopContext.getPortalResourceUrl( stylesheetHref ) ).append( "\"/>" );
0599:                                        desktopThemeStyleLink.append(
0600:                                                contextPath + "/"
0601:                                                        + stylesheetHref)
0602:                                                .append("\"/>");
0603:
0604:                                        stylesheetCount++;
0605:                                    }
0606:                                }
0607:                            }
0608:                            styleLayoutContent = desktopThemeStyleLink
0609:                                    .toString();
0610:                            setCachedContent(styleLayoutContentCacheKey,
0611:                                    styleLayoutContent);
0612:                        }
0613:                        if (styleLayoutContent != null
0614:                                && styleLayoutContent.length() > 0) {
0615:                            hr
0616:                                    .setHeaderSectionType(
0617:                                            HeaderResource.HEADER_SECTION_DESKTOP_STYLE_LAYOUT,
0618:                                            HeaderResource.HEADER_TYPE_LINK_TAG);
0619:                            hr
0620:                                    .addHeaderSectionFragment(
0621:                                            "desktop.style.layout",
0622:                                            HeaderResource.HEADER_SECTION_DESKTOP_STYLE_LAYOUT,
0623:                                            styleLayoutContent);
0624:                        }
0625:                    }
0626:
0627:                    String layoutDecorationLocaleSuffix = "."
0628:                            + layoutDecorationName + "."
0629:                            + request.getLocale().toString();
0630:                    String desktopActionLabelsCacheKey = DOJO_CONFIG_ACTION_LABELS_NAME
0631:                            + layoutDecorationLocaleSuffix;
0632:                    String pageEditorLabelsCacheKey = DOJO_CONFIG_PAGEEDITOR_LABELS_NAME
0633:                            + layoutDecorationLocaleSuffix;
0634:                    String pageEditorDialogLabelsCacheKey = DOJO_CONFIG_PAGEEDITOR_DIALOG_LABELS_NAME
0635:                            + layoutDecorationLocaleSuffix;
0636:
0637:                    String desktopActionLabelsContent = getCachedContent(desktopActionLabelsCacheKey);
0638:                    String pageEditorLabelsContent = getCachedContent(pageEditorLabelsCacheKey);
0639:                    String pageEditorDialogLabelsContent = getCachedContent(pageEditorDialogLabelsCacheKey);
0640:                    if (desktopActionLabelsContent == null
0641:                            || pageEditorLabelsContent == null
0642:                            || pageEditorDialogLabelsContent == null) {
0643:                        ResourceBundle messages = desktopContext
0644:                                .getLayoutResourceBundle(request.getLocale());
0645:                        if (desktopActionLabelsContent == null) {
0646:                            desktopActionLabelsContent = getResourcesAsJavascriptObject(
0647:                                    DESKTOP_ACTION_RESOURCE_NAME_PREFIX,
0648:                                    DESKTOP_ACTION_RESOURCE_NAMES, messages,
0649:                                    DOJO_CONFIG_ACTION_LABELS_NAME, "    ",
0650:                                    true);
0651:                            setCachedContent(desktopActionLabelsCacheKey,
0652:                                    desktopActionLabelsContent);
0653:                        }
0654:                        if (pageEditorLabelsContent == null) {
0655:                            pageEditorLabelsContent = getResourcesAsJavascriptObject(
0656:                                    DESKTOP_PAGEEDITOR_RESOURCE_NAME_PREFIX,
0657:                                    DESKTOP_PAGEEDITOR_RESOURCE_NAMES,
0658:                                    messages,
0659:                                    DOJO_CONFIG_PAGEEDITOR_LABELS_NAME, "    ",
0660:                                    true);
0661:                            setCachedContent(pageEditorLabelsCacheKey,
0662:                                    pageEditorLabelsContent);
0663:                        }
0664:                        if (pageEditorDialogLabelsContent == null) {
0665:                            pageEditorDialogLabelsContent = getResourcesAsJavascriptObject(
0666:                                    DESKTOP_PAGEEDITOR_DIALOG_RESOURCE_NAME_PREFIX,
0667:                                    DESKTOP_PAGEEDITOR_DIALOG_RESOURCE_NAMES,
0668:                                    messages,
0669:                                    DOJO_CONFIG_PAGEEDITOR_DIALOG_LABELS_NAME,
0670:                                    "    ", true);
0671:                            setCachedContent(pageEditorDialogLabelsCacheKey,
0672:                                    pageEditorDialogLabelsContent);
0673:                        }
0674:                    }
0675:                    if (desktopActionLabelsContent != null
0676:                            && desktopActionLabelsContent.length() > 0) {
0677:                        hr.addHeaderSectionFragment(
0678:                                DOJO_CONFIG_ACTION_LABELS_NAME,
0679:                                HeaderResource.HEADER_SECTION_DOJO_CONFIG,
0680:                                desktopActionLabelsContent);
0681:                    }
0682:                    if (pageEditorLabelsContent != null
0683:                            && pageEditorLabelsContent.length() > 0) {
0684:                        hr.addHeaderSectionFragment(
0685:                                DOJO_CONFIG_PAGEEDITOR_LABELS_NAME,
0686:                                HeaderResource.HEADER_SECTION_DOJO_CONFIG,
0687:                                pageEditorLabelsContent);
0688:                    }
0689:                    if (pageEditorDialogLabelsContent != null
0690:                            && pageEditorDialogLabelsContent.length() > 0) {
0691:                        hr.addHeaderSectionFragment(
0692:                                DOJO_CONFIG_PAGEEDITOR_DIALOG_LABELS_NAME,
0693:                                HeaderResource.HEADER_SECTION_DOJO_CONFIG,
0694:                                pageEditorDialogLabelsContent);
0695:                    }
0696:
0697:                    dispatcher.include(request.getRequest(), request
0698:                            .getResponse());
0699:                } catch (Exception e) {
0700:                    try {
0701:                        if (layoutDecorationTemplatePathWasAssigned) {
0702:                            layoutDecorationTemplatePath = (layoutDecorationTemplatePath == null
0703:                                    || layoutDecorationTemplatePath.length() == 0 ? "null"
0704:                                    : layoutDecorationTemplatePath);
0705:                            log.error(
0706:                                    "Failed to include desktop layout decoration at path "
0707:                                            + layoutDecorationTemplatePath, e);
0708:                            request.getResponse().getWriter().println(
0709:                                    "Desktop layout decoration "
0710:                                            + layoutDecorationTemplatePath
0711:                                            + " is not available");
0712:                        } else {
0713:                            log
0714:                                    .error(
0715:                                            "Failed to initialize for inclusion of desktop layout decoration",
0716:                                            e);
0717:                            request
0718:                                    .getResponse()
0719:                                    .getWriter()
0720:                                    .println(
0721:                                            "Failed to initialize for inclusion of desktop layout decoration");
0722:                        }
0723:                    } catch (IOException ioe) {
0724:                        log
0725:                                .error(
0726:                                        "Failed to write desktop layout decoration exception information to servlet output writer",
0727:                                        ioe);
0728:                    }
0729:                }
0730:            }
0731:
0732:            private void addPageEditorSettings(StringBuffer dojoConfigAddOn,
0733:                    LayoutDecoration desktopLayoutDecoration) {
0734:                int[] pageEditorConfigFlags = new int[] { 0 };
0735:                String propValue;
0736:
0737:                propValue = desktopLayoutDecoration
0738:                        .getProperty(DESKTOP_PAGEEDITOR_PAGE_LAYOUT_DECORATOR_EDITABLE);
0739:                processBooleanFlagProperty(
0740:                        pageEditorConfigFlags,
0741:                        propValue,
0742:                        DESKTOP_PAGEEDITOR_PAGE_LAYOUT_DECORATOR_EDITABLE_DEFAULT,
0743:                        DESKTOP_PAGEEDITOR_PAGE_LAYOUT_DECORATOR_EDITABLE_TRUE);
0744:
0745:                propValue = desktopLayoutDecoration
0746:                        .getProperty(DESKTOP_PAGEEDITOR_LAYOUT_NAME_EDITABLE);
0747:                processBooleanFlagProperty(pageEditorConfigFlags, propValue,
0748:                        DESKTOP_PAGEEDITOR_LAYOUT_NAME_EDITABLE_DEFAULT,
0749:                        DESKTOP_PAGEEDITOR_LAYOUT_NAME_EDITABLE_TRUE);
0750:
0751:                propValue = desktopLayoutDecoration
0752:                        .getProperty(DESKTOP_PAGEEDITOR_LAYOUT_COLUMNSIZE_EDITABLE);
0753:                processBooleanFlagProperty(pageEditorConfigFlags, propValue,
0754:                        DESKTOP_PAGEEDITOR_LAYOUT_COLUMNSIZE_EDITABLE_DEFAULT,
0755:                        DESKTOP_PAGEEDITOR_LAYOUT_COLUMNSIZE_EDITABLE_TRUE);
0756:
0757:                propValue = desktopLayoutDecoration
0758:                        .getProperty(DESKTOP_PAGEEDITOR_PAGE_ADD_ENABLED);
0759:                processBooleanFlagProperty(pageEditorConfigFlags, propValue,
0760:                        DESKTOP_PAGEEDITOR_PAGE_ADD_ENABLED_DEFAULT,
0761:                        DESKTOP_PAGEEDITOR_PAGE_ADD_ENABLED_TRUE);
0762:
0763:                propValue = desktopLayoutDecoration
0764:                        .getProperty(DESKTOP_PAGEEDITOR_PORTLET_ADD_ENABLED);
0765:                processBooleanFlagProperty(pageEditorConfigFlags, propValue,
0766:                        DESKTOP_PAGEEDITOR_PORTLET_ADD_ENABLED_DEFAULT,
0767:                        DESKTOP_PAGEEDITOR_PORTLET_ADD_ENABLED_TRUE);
0768:
0769:                propValue = desktopLayoutDecoration
0770:                        .getProperty(DESKTOP_PAGEEDITOR_PAGE_PORTLET_DECORATOR_EDITABLE);
0771:                processBooleanFlagProperty(
0772:                        pageEditorConfigFlags,
0773:                        propValue,
0774:                        DESKTOP_PAGEEDITOR_PAGE_PORTLET_DECORATOR_EDITABLE_DEFAULT,
0775:                        DESKTOP_PAGEEDITOR_PAGE_PORTLET_DECORATOR_EDITABLE_TRUE);
0776:
0777:                propValue = desktopLayoutDecoration
0778:                        .getProperty(DESKTOP_PAGEEDITOR_PORTLET_DECORATOR_EDITABLE);
0779:                processBooleanFlagProperty(pageEditorConfigFlags, propValue,
0780:                        DESKTOP_PAGEEDITOR_PORTLET_DECORATOR_EDITABLE_DEFAULT,
0781:                        DESKTOP_PAGEEDITOR_PORTLET_DECORATOR_EDITABLE_TRUE);
0782:
0783:                propValue = desktopLayoutDecoration
0784:                        .getProperty(DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_EDITABLE);
0785:                processBooleanFlagProperty(pageEditorConfigFlags, propValue,
0786:                        DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_EDITABLE_DEFAULT,
0787:                        DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_EDITABLE_TRUE);
0788:
0789:                propValue = desktopLayoutDecoration
0790:                        .getProperty(DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_TOPLEVEL_MOVEABLE);
0791:                processBooleanFlagProperty(
0792:                        pageEditorConfigFlags,
0793:                        propValue,
0794:                        DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_TOPLEVEL_MOVEABLE_DEFAULT,
0795:                        DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_TOPLEVEL_MOVEABLE_TRUE);
0796:
0797:                propValue = desktopLayoutDecoration
0798:                        .getProperty(DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_COLUMNSIZE_EDITABLE);
0799:                processBooleanFlagProperty(
0800:                        pageEditorConfigFlags,
0801:                        propValue,
0802:                        DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_COLUMNSIZE_EDITABLE_DEFAULT,
0803:                        DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_COLUMNSIZE_EDITABLE_TRUE);
0804:
0805:                propValue = desktopLayoutDecoration
0806:                        .getProperty(DESKTOP_PAGEEDITOR_MOVEMODE_ISDEFAULT);
0807:                processBooleanFlagProperty(pageEditorConfigFlags, propValue,
0808:                        DESKTOP_PAGEEDITOR_MOVEMODE_ISDEFAULT_DEFAULT,
0809:                        DESKTOP_PAGEEDITOR_MOVEMODE_ISDEFAULT_TRUE);
0810:
0811:                propValue = desktopLayoutDecoration
0812:                        .getProperty(DESKTOP_PAGEEDITOR_PAGE_LAYOUT_DEPTH_MAX);
0813:                Integer maxLayoutNestingObj = null;
0814:                try {
0815:                    maxLayoutNestingObj = new Integer(propValue);
0816:                } catch (NumberFormatException ex) {
0817:                    maxLayoutNestingObj = new Integer(
0818:                            DESKTOP_PAGEEDITOR_PAGE_LAYOUT_DEPTH_MAX_DEFAULT);
0819:                }
0820:                int maxLayoutNesting = maxLayoutNestingObj.intValue();
0821:                if (maxLayoutNesting < 0)
0822:                    maxLayoutNesting = 0;
0823:                if (maxLayoutNesting > DESKTOP_PAGEEDITOR_PAGE_LAYOUT_DEPTH_MAX_RESERVED)
0824:                    maxLayoutNesting = DESKTOP_PAGEEDITOR_PAGE_LAYOUT_DEPTH_MAX_RESERVED;
0825:                pageEditorConfigFlags[0] += maxLayoutNesting;
0826:
0827:                String allowEditNoactionsRole = desktopLayoutDecoration
0828:                        .getProperty(DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_EDITOR_ROLE);
0829:                if (allowEditNoactionsRole == null)
0830:                    allowEditNoactionsRole = DESKTOP_PAGEEDITOR_LAYOUT_NOACTIONS_EDITOR_ROLE_DEFAULT;
0831:                if (allowEditNoactionsRole == null)
0832:                    allowEditNoactionsRole = "";
0833:                char[] allowEditNoactionsRoleChars = allowEditNoactionsRole
0834:                        .toCharArray();
0835:                int allowEditNoactionsRoleCharsLen = ((allowEditNoactionsRoleChars == null) ? 0
0836:                        : allowEditNoactionsRoleChars.length);
0837:                Random rnd = new Random();
0838:                int extrasCount = (allowEditNoactionsRoleCharsLen > 0 ? getRandom(
0839:                        rnd, 2, 5)
0840:                        : getRandom(rnd, 5, 8));
0841:                int hexLen = 1 + extrasCount + allowEditNoactionsRoleCharsLen;
0842:                int addedExtras = 0;
0843:                int nextRoleChar = 0;
0844:                StringBuffer pageEditorSettings = new StringBuffer();
0845:                for (int i = 0; i < hexLen; i++) { // here we "mix-up" (obfuscate) the way this information is provided to the client-side
0846:                    //    this is done to avoid obvious display of certain strings in content, like "manager" or "admin"
0847:                    int rndVal = getRandom(rnd, 0x1000, 0xFFFD);
0848:                    boolean isRndValEven = ((rndVal % 2) == 0);
0849:                    int rndValTens = (int) Math.floor(rndVal / 10);
0850:                    int rndValTensEven = (((rndValTens % 2) == 1) ? Math.max(
0851:                            rndValTens - 1, 2) : rndValTens);
0852:                    int valToHex;
0853:                    if (i == 0) {
0854:                        valToHex = pageEditorConfigFlags[0];
0855:                    } else if (addedExtras < extrasCount
0856:                            && (((i % 2) == 1) || nextRoleChar >= allowEditNoactionsRoleCharsLen)) {
0857:                        if (!isRndValEven)
0858:                            rndVal++;
0859:                        valToHex = getRandom(rnd, 0x0A00, 0xDFFF);
0860:                        if ((valToHex % 2) == 1)
0861:                            valToHex = valToHex + 1;
0862:                        pageEditorSettings.append(", ");
0863:                        addedExtras++;
0864:                    } else {
0865:                        //log.info( "char '" + allowEditNoactionsRoleChars[nextRoleChar] + "' numericval=" + (int)allowEditNoactionsRoleChars[nextRoleChar] + " hex=" + Integer.toHexString( (int)allowEditNoactionsRoleChars[nextRoleChar] ) + " hexLshift4=" + Integer.toHexString( (int)allowEditNoactionsRoleChars[nextRoleChar] << 4 ) + " hexLshift4+1=" + Integer.toHexString( ((int)allowEditNoactionsRoleChars[nextRoleChar] << 4 ) | 0x0001 ) );
0866:                        valToHex = (((int) allowEditNoactionsRoleChars[nextRoleChar] << 4) | 0x0001);
0867:                        pageEditorSettings.append(", ");
0868:                        nextRoleChar++;
0869:                    }
0870:                    String rndValHex = Integer.toHexString(0x10000 | rndVal)
0871:                            .substring(1);
0872:
0873:                    String realValHex = Integer.toHexString(
0874:                            0x10000 | (valToHex + rndValTensEven)).substring(1);
0875:                    if (isRndValEven && i > 0)
0876:                        pageEditorSettings.append("0x").append(realValHex)
0877:                                .append(rndValHex);
0878:                    else
0879:                        pageEditorSettings.append("0x").append(rndValHex)
0880:                                .append(realValHex);
0881:                }
0882:                dojoConfigAddOn.append("    ").append(
0883:                        DOJO_CONFIG_PAGEEDITOR_SETTINGS_NAME).append(" = [ ")
0884:                        .append(pageEditorSettings.toString()).append(" ];")
0885:                        .append(EOL);
0886:            }
0887:
0888:            private int getRandom(Random rnd, int minValueInclusive,
0889:                    int maxValueExclusive) {
0890:                if (minValueInclusive > maxValueExclusive)
0891:                    throw new IllegalArgumentException("minValueInclusive ("
0892:                            + minValueInclusive
0893:                            + ") cannot be greater than maxValueExclusive ("
0894:                            + maxValueExclusive + ")");
0895:
0896:                int diff = (int) (maxValueExclusive - minValueInclusive);
0897:                if (diff == 0)
0898:                    return minValueInclusive;
0899:
0900:                double sample = rnd.nextDouble();
0901:                int result = (int) (sample * diff + minValueInclusive);
0902:                result = ((result != maxValueExclusive) ? result : (result - 1));
0903:                return result;
0904:            }
0905:
0906:            private void processBooleanFlagProperty(int[] flags,
0907:                    Object propVal, Object propValDefault, int propIsTrueBit) {
0908:                String boolStr = ((propVal == null) ? ((propValDefault == null) ? (String) null
0909:                        : propValDefault.toString())
0910:                        : propVal.toString());
0911:                if (boolStr != null && boolStr.toLowerCase().equals("true"))
0912:                    flags[0] |= propIsTrueBit;
0913:            }
0914:
0915:            private String getCachedContent(String cacheKey) {
0916:                CacheElement cachedElement = desktopContentCache.get(cacheKey);
0917:                if (cachedElement != null)
0918:                    return (String) cachedElement.getContent();
0919:                return null;
0920:            }
0921:
0922:            private void setCachedContent(String cacheKey, String content) {
0923:                CacheElement cachedElement = desktopContentCache.createElement(
0924:                        cacheKey, content);
0925:                cachedElement.setTimeToIdleSeconds(desktopContentCache
0926:                        .getTimeToIdleSeconds());
0927:                cachedElement.setTimeToLiveSeconds(desktopContentCache
0928:                        .getTimeToLiveSeconds());
0929:                desktopContentCache.put(cachedElement);
0930:            }
0931:
0932:            private String getResourcesAsJavascriptObject(
0933:                    String resourceNamePrefix, String[] resourceNames,
0934:                    ResourceBundle messages, String varName, String indent,
0935:                    boolean ifEmptyReturnEmptyString) {
0936:                StringBuffer jsObjBuffer = new StringBuffer();
0937:                boolean atLeastOneFound = false;
0938:                if (indent != null)
0939:                    jsObjBuffer.append(indent);
0940:                if (varName != null)
0941:                    jsObjBuffer.append(varName).append(" = ");
0942:                jsObjBuffer.append("{ ");
0943:                for (int i = 0; i < resourceNames.length; i++) {
0944:                    String resourceValue = null;
0945:                    try {
0946:                        resourceValue = messages.getString(resourceNamePrefix
0947:                                + resourceNames[i]);
0948:                    } catch (java.util.MissingResourceException ex) {
0949:                    }
0950:                    if (resourceValue != null) {
0951:                        if (atLeastOneFound) {
0952:                            jsObjBuffer.append(", ");
0953:                        } else {
0954:                            atLeastOneFound = true;
0955:                        }
0956:                        jsObjBuffer.append(resourceNames[i]).append(": \"")
0957:                                .append(resourceValue).append("\"");
0958:                    }
0959:                }
0960:                jsObjBuffer.append(" };");
0961:                if (!atLeastOneFound && ifEmptyReturnEmptyString)
0962:                    return "";
0963:                return jsObjBuffer.toString();
0964:            }
0965:
0966:            public boolean isDesktopEnabled(RequestContext requestContext) {
0967:                return this .decorationFactory.isDesktopEnabled(requestContext);
0968:            }
0969:
0970:            public ServletContext getServletContext() {
0971:                return servletContext;
0972:            }
0973:
0974:            public void setServletContext(ServletContext servletContext) {
0975:                this .servletContext = servletContext;
0976:            }
0977:
0978:            public HeaderResourceFactory getHeaderResourceFactory() {
0979:                return this .headerResourceFactory;
0980:            }
0981:
0982:            // get portal urls - each of these methods is copied from HeaderResourceImpl.java
0983:
0984:            /**
0985:             * Desktop servlet path ( e.g. /desktop )
0986:             * 
0987:             * @return portal base url
0988:             */
0989:            public String getDesktopServletPath() {
0990:                return this .desktopServletPath;
0991:            }
0992:
0993:            /**
0994:             * Portal base url ( e.g. http://localhost:8080/jetspeed )
0995:             * 
0996:             * @return portal base url
0997:             */
0998:            public String getPortalBaseUrl(RequestContext context) {
0999:                return HeaderResourceLib.getPortalBaseUrl(context,
1000:                        this .baseUrlAccess);
1001:            }
1002:
1003:            /**
1004:             * Portal base url ( e.g. http://localhost:8080/jetspeed )
1005:             * 
1006:             * @return portal base url
1007:             */
1008:            public String getPortalBaseUrl(RequestContext context,
1009:                    boolean encode) {
1010:                String baseurl = getPortalBaseUrl(context);
1011:                if (!encode) {
1012:                    return baseurl;
1013:                } else {
1014:                    return context.getResponse().encodeURL(baseurl);
1015:                }
1016:            }
1017:
1018:            /**
1019:             * Portal base url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/javascript/dojo/ )
1020:             * 
1021:             * @return portal base url with relativePath argument appended
1022:             */
1023:            public String getPortalResourceUrl(RequestContext context,
1024:                    String relativePath) {
1025:                return getPortalResourceUrl(context, relativePath, false);
1026:            }
1027:
1028:            /**
1029:             * Portal base url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/javascript/dojo/ )
1030:             * 
1031:             * @return portal base url with relativePath argument appended
1032:             */
1033:            public String getPortalResourceUrl(RequestContext context,
1034:                    String relativePath, boolean encode) {
1035:                return HeaderResourceLib.getPortalResourceUrl(relativePath,
1036:                        getPortalBaseUrl(context), encode, context);
1037:            }
1038:
1039:            /**
1040:             * Portal base servlet url ( e.g. http://localhost:8080/jetspeed/desktop/ )
1041:             * 
1042:             * @return portal base servlet url
1043:             */
1044:            public String getPortalUrl(RequestContext context) {
1045:                return HeaderResourceLib.getPortalUrl(
1046:                        getPortalBaseUrl(context), context,
1047:                        getDesktopServletPath());
1048:            }
1049:
1050:            /**
1051:             * Portal base servlet url ( e.g. http://localhost:8080/jetspeed/desktop/ )
1052:             * 
1053:             * @return portal base servlet url
1054:             */
1055:            public String getPortalUrl(RequestContext context, boolean encode) {
1056:                return getPortalUrl(context, null, encode);
1057:            }
1058:
1059:            /**
1060:             * Portal base servlet url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/desktop/default-page.psml )
1061:             * 
1062:             * @return portal base servlet url with relativePath argument appended
1063:             */
1064:            public String getPortalUrl(RequestContext context,
1065:                    String relativePath) {
1066:                return getPortalUrl(context, relativePath, false);
1067:            }
1068:
1069:            /**
1070:             * Portal base servlet url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/desktop/default-page.psml )
1071:             * 
1072:             * @return portal base servlet url with relativePath argument appended
1073:             */
1074:            public String getPortalUrl(RequestContext context,
1075:                    String relativePath, boolean encode) {
1076:                return HeaderResourceLib.getPortalResourceUrl(relativePath,
1077:                        getPortalUrl(context), encode, context);
1078:            }
1079:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.