Source Code Cross Referenced for AddPresentationController.java in  » ERP-CRM-Financial » sakai » org » theospi » portfolio » presentation » control » 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 » ERP CRM Financial » sakai » org.theospi.portfolio.presentation.control 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**********************************************************************************
0002:         * $URL:https://source.sakaiproject.org/svn/osp/trunk/presentation/tool/src/java/org/theospi/portfolio/presentation/control/AddPresentationController.java $
0003:         * $Id:AddPresentationController.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
0004:         ***********************************************************************************
0005:         *
0006:         * Copyright (c) 2005, 2006, 2007 The Sakai Foundation.
0007:         *
0008:         * Licensed under the Educational Community License, Version 1.0 (the "License");
0009:         * you may not use this file except in compliance with the License.
0010:         * You may obtain a copy of the License at
0011:         *
0012:         *      http://www.opensource.org/licenses/ecl1.php
0013:         *
0014:         * Unless required by applicable law or agreed to in writing, software
0015:         * distributed under the License is distributed on an "AS IS" BASIS,
0016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017:         * See the License for the specific language governing permissions and
0018:         * limitations under the License.
0019:         *
0020:         **********************************************************************************/package org.theospi.portfolio.presentation.control;
0021:
0022:        import java.text.SimpleDateFormat;
0023:        import java.util.*;
0024:
0025:        import javax.servlet.http.HttpServletRequest;
0026:        import javax.servlet.http.HttpServletResponse;
0027:        import javax.servlet.http.HttpSession;
0028:
0029:        import org.apache.commons.logging.Log;
0030:        import org.apache.commons.logging.LogFactory;
0031:        import org.sakaiproject.component.api.ServerConfigurationService;
0032:        import org.sakaiproject.content.api.ContentCollection;
0033:        import org.sakaiproject.content.api.ContentCollectionEdit;
0034:        import org.sakaiproject.content.api.ContentHostingService;
0035:        import org.sakaiproject.content.api.ResourceEditingHelper;
0036:        import org.sakaiproject.entity.api.ResourceProperties;
0037:        import org.sakaiproject.exception.IdUnusedException;
0038:        import org.sakaiproject.exception.IdUsedException;
0039:        import org.sakaiproject.exception.PermissionException;
0040:        import org.sakaiproject.exception.TypeException;
0041:        import org.sakaiproject.metaobj.security.AuthenticationManager;
0042:        import org.sakaiproject.metaobj.shared.FormHelper;
0043:        import org.sakaiproject.metaobj.shared.mgt.AgentManager;
0044:        import org.sakaiproject.metaobj.shared.mgt.HomeFactory;
0045:        import org.sakaiproject.metaobj.shared.mgt.IdManager;
0046:        import org.sakaiproject.metaobj.shared.model.Agent;
0047:        import org.sakaiproject.metaobj.shared.model.Id;
0048:        import org.sakaiproject.metaobj.utils.Config;
0049:        import org.sakaiproject.metaobj.utils.mvc.impl.servlet.ServletRequestBeanDataBinder;
0050:        import org.sakaiproject.metaobj.utils.mvc.intf.ListScroll;
0051:        import org.sakaiproject.metaobj.utils.mvc.intf.ListScrollIndexer;
0052:        import org.sakaiproject.metaobj.utils.mvc.intf.TypedPropertyEditor;
0053:        import org.sakaiproject.metaobj.utils.xml.SchemaFactory;
0054:        import org.sakaiproject.metaobj.utils.xml.SchemaNode;
0055:        import org.sakaiproject.metaobj.worksite.mgt.WorksiteManager;
0056:        import org.sakaiproject.site.cover.SiteService;
0057:        import org.sakaiproject.tool.api.Placement;
0058:        import org.sakaiproject.tool.api.ToolSession;
0059:        import org.sakaiproject.tool.api.Tool;
0060:        import org.sakaiproject.tool.cover.SessionManager;
0061:        import org.sakaiproject.tool.cover.ToolManager;
0062:        import org.sakaiproject.user.api.User;
0063:        import org.sakaiproject.user.cover.UserDirectoryService;
0064:        import org.springframework.beans.propertyeditors.CustomDateEditor;
0065:        import org.springframework.validation.BindException;
0066:        import org.springframework.validation.Errors;
0067:        import org.springframework.web.bind.ServletRequestDataBinder;
0068:        import org.springframework.web.servlet.ModelAndView;
0069:        import org.springframework.web.servlet.mvc.AbstractWizardFormController;
0070:        import org.springframework.web.util.WebUtils;
0071:        import org.theospi.portfolio.presentation.PresentationFunctionConstants;
0072:        import org.theospi.portfolio.presentation.PresentationManager;
0073:        import org.theospi.portfolio.presentation.intf.FreeFormHelper;
0074:        import org.theospi.portfolio.presentation.model.Presentation;
0075:        import org.theospi.portfolio.presentation.model.PresentationItem;
0076:        import org.theospi.portfolio.presentation.model.PresentationItemDefinition;
0077:        import org.theospi.portfolio.presentation.model.PresentationTemplate;
0078:        import org.theospi.portfolio.security.AudienceSelectionHelper;
0079:        import org.theospi.portfolio.security.AuthorizationFacade;
0080:        import org.theospi.portfolio.shared.model.Node;
0081:
0082:        public class AddPresentationController extends
0083:                AbstractWizardFormController {
0084:            public static final String PARAM_FINISH_AND_NOTIFY = "_finish_notify";
0085:            public static final String PARAM_RESET_FORM = "resetForm";
0086:
0087:            final public static int ADD_PAGE = 0;
0088:            final public static int INITIAL_PAGE = 1;
0089:            final public static int PROPERTY_PAGE = 2;
0090:            final public static int PRESENTATION_ITEMS = 3;
0091:            final public static int PRESETATION_FREE_FORM_PAGES = 4;
0092:            final public static int PRESENTATION_AUTHORIZATIONS = 5;
0093:            final public static int PRESENTATION_NOTIFICATIONS = 6;
0094:
0095:            final public static String SESSION_PAGE_PROP_ENTRY = "portfolio.pageProp.entry";
0096:            final public static String SESSION_PAGE_PROP_DIRECTION = "portfolio.pageProp.direction";
0097:            final public static int PAGE_DIRECTION_FORWARD = 1;
0098:            final public static int PAGE_DIRECTION_BACKWARD = -1;
0099:
0100:            private IdManager idManager;
0101:            private List customTypedEditors = new ArrayList();
0102:            private AgentManager agentManager;
0103:            private PresentationManager presentationManager;
0104:            private AuthenticationManager authManager;
0105:            private HomeFactory homeFactory;
0106:            protected final Log logger = LogFactory.getLog(getClass());
0107:            private AuthorizationFacade authzManager = null;
0108:            private Config ospConfig;
0109:            private WorksiteManager worksiteManager;
0110:            private ListScrollIndexer listScrollIndexer;
0111:            private ServerConfigurationService serverConfigurationService;
0112:            private ContentHostingService contentHosting = null;
0113:            private int initialPage = 0;
0114:
0115:            public Object formBackingObject(HttpServletRequest request)
0116:                    throws Exception {
0117:                Presentation presentation = new Presentation();
0118:                presentation.setTemplate(new PresentationTemplate());
0119:
0120:                presentation.setToolId(ToolManager.getCurrentPlacement()
0121:                        .getId());
0122:
0123:                // this is an edit, load model
0124:                if (request.getParameter("id") != null) {
0125:                    int page = parseTarget(request.getParameter("target"));
0126:                    setInitialPage(page);
0127:                    Id id = getIdManager().getId(request.getParameter("id"));
0128:                    presentation = getPresentationManager().getPresentation(id);
0129:                    getAuthzManager().checkPermission(
0130:                            PresentationFunctionConstants.EDIT_PRESENTATION,
0131:                            presentation.getId());
0132:                } else {
0133:                    setInitialPage(0);
0134:                    getAuthzManager().checkPermission(
0135:                            PresentationFunctionConstants.CREATE_PRESENTATION,
0136:                            getIdManager().getId(
0137:                                    ToolManager.getCurrentPlacement().getId()));
0138:                    presentation.setId(getIdManager().createId());
0139:                    presentation.setNewObject(true);
0140:                    presentation.setSiteId(ToolManager.getCurrentPlacement()
0141:                            .getContext());
0142:                }
0143:
0144:                if (request.getParameter("templateId") != null) {
0145:                    presentation
0146:                            .setTemplate(getPresentationManager()
0147:                                    .getPresentationTemplate(
0148:                                            getIdManager()
0149:                                                    .getId(
0150:                                                            request
0151:                                                                    .getParameter("templateId"))));
0152:
0153:                    presentation.setName(presentation.getTemplate().getName());
0154:                    presentation.setDescription(presentation.getTemplate()
0155:                            .getDescription());
0156:                }
0157:
0158:                return presentation;
0159:            }
0160:
0161:            /**
0162:             * 
0163:             * @param target The target parameter from the request string - Like "_target3"
0164:             * @return The number at the end of the "_target".  If it happens to be 
0165:             * something else, an exception is caught and 1 is returned 
0166:             */
0167:            protected int parseTarget(String target) {
0168:                try {
0169:                    if (target.startsWith(PARAM_TARGET)) {
0170:                        String retTar = target.substring(PARAM_TARGET.length(),
0171:                                target.length());
0172:                        return Integer.parseInt(retTar);
0173:                    }
0174:                } catch (Exception e) {
0175:                    //In case something goes wrong, just return 1
0176:                    return 1;
0177:                }
0178:                return 1;
0179:            }
0180:
0181:            protected String getFormSessionAttributeName() {
0182:                return getCommandName();
0183:            }
0184:
0185:            protected void onBindAndValidate(HttpServletRequest request,
0186:                    Object command, BindException errors, int page)
0187:                    throws Exception {
0188:                Presentation presentation = (Presentation) command;
0189:                if (page == INITIAL_PAGE
0190:                        && request.getParameter("isDefault") == null) {
0191:                    presentation.setIsDefault(false);
0192:                }
0193:            }
0194:
0195:            protected void initBinder(HttpServletRequest request,
0196:                    ServletRequestDataBinder binder) {
0197:                SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
0198:                dateFormat.setLenient(false);
0199:                binder.registerCustomEditor(Date.class, null,
0200:                        new CustomDateEditor(dateFormat, true));
0201:
0202:                for (Iterator i = getCustomTypedEditors().iterator(); i
0203:                        .hasNext();) {
0204:                    TypedPropertyEditor editor = (TypedPropertyEditor) i.next();
0205:                    binder.registerCustomEditor(editor.getType(), editor);
0206:                }
0207:            }
0208:
0209:            protected ServletRequestDataBinder createBinder(
0210:                    HttpServletRequest request, Object command)
0211:                    throws Exception {
0212:                ServletRequestDataBinder binder = null;
0213:                binder = new ServletRequestBeanDataBinder(command,
0214:                        getCommandName());
0215:                initBinder(request, binder);
0216:
0217:                return binder;
0218:            }
0219:
0220:            /**
0221:             * loads a schema from a file id in the repository.  Puts
0222:             * the technical metadata for the schema file in the model
0223:             *
0224:             * @param xsdId - id of the xsd file in the repository
0225:             * @return schema
0226:             */
0227:            protected SchemaNode loadSchema(Id xsdId, Map model) {
0228:                //RepositoryNode rNode = (RepositoryNode) getRepositoryManager().getNode(xsdId);
0229:                Node rNode = (Node) getPresentationManager().getNode(xsdId);
0230:                model.put("propertyFileMetadata", rNode.getTechnicalMetadata());
0231:                SchemaFactory schemaFactory = SchemaFactory.getInstance();
0232:                return schemaFactory.getSchema(rNode.getInputStream());
0233:            }
0234:
0235:            protected Map referenceData(HttpServletRequest request, int page)
0236:                    throws Exception {
0237:                Map model = new HashMap();
0238:                Presentation presentation = (Presentation) request.getSession()
0239:                        .getAttribute(getCommandName());
0240:
0241:                if (presentation.getName() != null && page == 0) {
0242:                    page++;
0243:                }
0244:                String baseUrl = this .getServerConfigurationService()
0245:                        .getServerUrl();
0246:                model.put("baseUrl", baseUrl);
0247:                model.put("currentPage", getCurrentPageNumber(presentation,
0248:                        page));
0249:                model.put("totalPages", getTotalPages(presentation, page));
0250:                model.put("allowGuests", Config.getInstance().getProperties()
0251:                        .getProperty("allowGuests"));
0252:
0253:                if ("true".equals(request.getParameter("preview")))
0254:                    model.put("preview", true);
0255:
0256:                if (page == ADD_PAGE) {
0257:                    Agent agent = getAuthManager().getAgent();
0258:                    model.put("templates", getPresentationManager()
0259:                            .findTemplatesByOwner(
0260:                                    agent,
0261:                                    ToolManager.getCurrentPlacement()
0262:                                            .getContext()));
0263:                    model.put("publishedTemplates", getPresentationManager()
0264:                            .findPublishedTemplates(
0265:                                    ToolManager.getCurrentPlacement()
0266:                                            .getContext()));
0267:                    model.put("globalPublishedTemplates",
0268:                            getPresentationManager().findGlobalTemplates());
0269:                    return model;
0270:                }
0271:                if (page == PROPERTY_PAGE) {
0272:                    PresentationTemplate template = getPresentationManager()
0273:                            .getPresentationTemplate(
0274:                                    presentation.getTemplate().getId());
0275:                    presentation.setTemplate(template);
0276:
0277:                    String formTypeId = template.getPropertyFormType()
0278:                            .getValue();
0279:                    HttpSession session = request.getSession();
0280:
0281:                    session.setAttribute(ResourceEditingHelper.CREATE_TYPE,
0282:                            ResourceEditingHelper.CREATE_TYPE_FORM);
0283:
0284:                    Node propFormNode = getPresentationManager().getNode(
0285:                            presentation.getPropertyForm());
0286:
0287:                    if (template.getPropertyFormType() != null) {
0288:                        String nodeId = propFormNode == null ? null
0289:                                : propFormNode.getResource().getId();
0290:                        setupSessionInfoForPropertyForm(session, presentation
0291:                                .getName(), formTypeId, nodeId);
0292:                    }
0293:                }
0294:                if (page == PRESETATION_FREE_FORM_PAGES) {
0295:                    if (presentation.getPages() == null) {
0296:                        presentation.setPages(getPresentationManager()
0297:                                .getPresentationPagesByPresentation(
0298:                                        presentation.getId()));
0299:                    }
0300:
0301:                    if (presentation.getPages().size() == 0) {
0302:                        presentation.setPages(new ArrayList());
0303:                    }
0304:                }
0305:                if (page == PRESENTATION_ITEMS) {
0306:                    Map artifacts = new HashMap();
0307:                    Map artifactCache = new HashMap();
0308:                    Agent agent = getAuthManager().getAgent();
0309:
0310:                    PresentationTemplate template = getPresentationManager()
0311:                            .getPresentationTemplate(
0312:                                    presentation.getTemplate().getId());
0313:                    presentation.setTemplate(template);
0314:
0315:                    model.put("types", template.getSortedItems());
0316:                    for (Iterator i = template.getSortedItems().iterator(); i
0317:                            .hasNext();) {
0318:                        PresentationItemDefinition itemDef = (PresentationItemDefinition) i
0319:                                .next();
0320:
0321:                        if (artifactCache.containsKey(itemDef.getType())
0322:                                && !itemDef.getHasMimeTypes()) {
0323:                            artifacts.put(itemDef.getId().getValue(),
0324:                                    artifactCache.get(itemDef.getType()));
0325:                        } else {
0326:                            Collection itemArtifacts = getPresentationManager()
0327:                                    .loadArtifactsForItemDef(itemDef, agent);
0328:
0329:                            if (!itemDef.getHasMimeTypes()) {
0330:                                // cache only full list
0331:                                artifactCache.put(itemDef.getType(),
0332:                                        itemArtifacts);
0333:                            }
0334:                            artifacts.put(itemDef.getId().getValue(),
0335:                                    itemArtifacts);
0336:                        }
0337:                    }
0338:                    model.put("artifacts", artifacts);
0339:                    Collection items = new ArrayList();
0340:                    for (Iterator i = presentation.getPresentationItems()
0341:                            .iterator(); i.hasNext();) {
0342:                        PresentationItem item = (PresentationItem) i.next();
0343:                        items.add(item.getDefinition().getId().getValue() + "."
0344:                                + item.getArtifactId());
0345:                    }
0346:                    model.put("items", items);
0347:                    return model;
0348:                }
0349:                if (page == PRESENTATION_AUTHORIZATIONS) {
0350:
0351:                    setAudienceSelectionVariables(request.getSession(),
0352:                            presentation);
0353:                }
0354:
0355:                return model;
0356:            }
0357:
0358:            protected void setupSessionInfoForPropertyForm(HttpSession session,
0359:                    String presentationTitle, String formTypeId,
0360:                    String currentFormId) {
0361:
0362:                if (currentFormId == null) {
0363:                    session
0364:                            .removeAttribute(ResourceEditingHelper.ATTACHMENT_ID);
0365:                    session.setAttribute(ResourceEditingHelper.CREATE_TYPE,
0366:                            ResourceEditingHelper.CREATE_TYPE_FORM);
0367:                    session.setAttribute(ResourceEditingHelper.CREATE_SUB_TYPE,
0368:                            formTypeId);
0369:
0370:                    ResourceBundle myResources = ResourceBundle
0371:                            .getBundle(PresentationManager.PRESENTATION_MESSAGE_BUNDLE);
0372:
0373:                    String propFormText = myResources.getString("propertyForm");
0374:
0375:                    try {
0376:                        String folderBase = getUserCollection().getId();
0377:
0378:                        Placement placement = ToolManager.getCurrentPlacement();
0379:                        String currentSite = placement.getContext();
0380:
0381:                        String rootDisplayName = myResources
0382:                                .getString(PresentationManager.PORTFOLIO_INTERACTION_FOLDER_DISPNAME);
0383:                        String rootDescription = myResources
0384:                                .getString(PresentationManager.PORTFOLIO_INTERACTION_FOLDER_DESC);
0385:
0386:                        String folderPath = createFolder(folderBase,
0387:                                "portfolio-interaction", rootDisplayName,
0388:                                rootDescription);
0389:                        folderPath = createFolder(folderPath, currentSite,
0390:                                SiteService.getSiteDisplay(currentSite), null);
0391:
0392:                        String dispName = myResources
0393:                                .getString(PresentationManager.PRESENTATION_PROPERTIES_FOLDER_DISPNAME);
0394:                        String desc = myResources
0395:                                .getString(PresentationManager.PRESENTATION_PROPERTIES_FOLDER_DESC);
0396:
0397:                        folderPath = createFolder(
0398:                                folderPath,
0399:                                PresentationManager.PRESENTATION_PROPERTIES_FOLDER,
0400:                                dispName, desc);
0401:
0402:                        session.setAttribute(FormHelper.PARENT_ID_TAG,
0403:                                folderPath);
0404:                    } catch (TypeException e) {
0405:                        throw new RuntimeException(
0406:                                "Failed to redirect to helper", e);
0407:                    } catch (IdUnusedException e) {
0408:                        throw new RuntimeException(
0409:                                "Failed to redirect to helper", e);
0410:                    } catch (PermissionException e) {
0411:                        throw new RuntimeException(
0412:                                "Failed to redirect to helper", e);
0413:                    }
0414:
0415:                    //CWM OSP-UI-09 - for auto naming
0416:                    session
0417:                            .setAttribute(FormHelper.NEW_FORM_DISPLAY_NAME_TAG,
0418:                                    getFormDisplayName(presentationTitle,
0419:                                            propFormText));
0420:                } else {
0421:                    //session.put(ResourceEditingHelper.ATTACHMENT_ID, request.get("current_form_id"));
0422:                    session.removeAttribute(ResourceEditingHelper.CREATE_TYPE);
0423:                    session
0424:                            .removeAttribute(ResourceEditingHelper.CREATE_SUB_TYPE);
0425:                    session
0426:                            .removeAttribute(ResourceEditingHelper.CREATE_PARENT);
0427:                    session.setAttribute(ResourceEditingHelper.CREATE_TYPE,
0428:                            ResourceEditingHelper.CREATE_TYPE_FORM);
0429:                    session.setAttribute(ResourceEditingHelper.ATTACHMENT_ID,
0430:                            currentFormId);
0431:                }
0432:            }
0433:
0434:            protected String getFormDisplayName(String objectTitle,
0435:                    String formTypeName) {
0436:                return objectTitle + "-" + formTypeName;
0437:            }
0438:
0439:            protected String createFolder(String base, String append,
0440:                    String appendDisplay, String appendDescription) {
0441:                //String folder = "/user/" + 
0442:                //SessionManager.getCurrentSessionUserId() + 
0443:                //PresentationManager.PRESENTATION_PROPERTIES_FOLDER_PATH;
0444:                String folder = base + append + "/";
0445:
0446:                try {
0447:                    ContentCollectionEdit propFolder = getContentHosting()
0448:                            .addCollection(folder);
0449:                    propFolder.getPropertiesEdit()
0450:                            .addProperty(ResourceProperties.PROP_DISPLAY_NAME,
0451:                                    appendDisplay);
0452:                    propFolder.getPropertiesEdit().addProperty(
0453:                            ResourceProperties.PROP_DESCRIPTION,
0454:                            appendDescription);
0455:                    getContentHosting().commitCollection(propFolder);
0456:                    return propFolder.getId();
0457:                } catch (IdUsedException e) {
0458:                    // ignore... it is already there.
0459:                } catch (Exception e) {
0460:                    throw new RuntimeException(e);
0461:                }
0462:                return folder;
0463:            }
0464:
0465:            protected ContentCollection getUserCollection()
0466:                    throws TypeException, IdUnusedException,
0467:                    PermissionException {
0468:                User user = UserDirectoryService.getCurrentUser();
0469:                String userId = user.getId();
0470:                String wsId = SiteService.getUserSiteId(userId);
0471:                String wsCollectionId = getContentHosting().getSiteCollection(
0472:                        wsId);
0473:                ContentCollection collection = getContentHosting()
0474:                        .getCollection(wsCollectionId);
0475:                return collection;
0476:            }
0477:
0478:            protected Integer getTotalPages(Presentation presentation, int page) {
0479:                if (presentation.getTemplate().getPropertyPage() == null) {
0480:                    return new Integer(4);
0481:                } else {
0482:                    return new Integer(5);
0483:                }
0484:            }
0485:
0486:            protected Integer getCurrentPageNumber(Presentation presentation,
0487:                    int page) {
0488:                boolean hasProperties = getTotalPages(presentation, page)
0489:                        .intValue() == 4;
0490:                if (page == ADD_PAGE) {
0491:                    return new Integer(1);
0492:                } else if (page == INITIAL_PAGE) {
0493:                    return new Integer(2);
0494:                } else if (page == PROPERTY_PAGE) {
0495:                    return new Integer(3);
0496:                } else if (page == PRESENTATION_ITEMS
0497:                        || page == PRESETATION_FREE_FORM_PAGES) {
0498:                    return new Integer(hasProperties ? 4 : 3);
0499:                } else if (page == PRESENTATION_AUTHORIZATIONS) {
0500:                    return new Integer(hasProperties ? 5 : 4);
0501:                } else {
0502:                    return new Integer(0);
0503:                }
0504:            }
0505:
0506:            protected int getTargetPage(HttpServletRequest request,
0507:                    Object command, Errors errors, int currentPage) {
0508:                if (logger.isDebugEnabled()) {
0509:                    logger.debug("getTargetPage()");
0510:                }
0511:
0512:                if (errors.getErrorCount() > 0) {
0513:                    return currentPage;
0514:                }
0515:
0516:                Presentation presentation = ((Presentation) command);
0517:                int target = super .getTargetPage(request, command, errors,
0518:                        currentPage);
0519:
0520:                if (target == PROPERTY_PAGE
0521:                        && presentation.getPresentationType().equals(
0522:                                Presentation.FREEFORM_TYPE)) {
0523:                    return PRESETATION_FREE_FORM_PAGES;
0524:                }
0525:
0526:                if (target == PRESETATION_FREE_FORM_PAGES) {
0527:                    if (presentation.getPresentationType().equals(
0528:                            Presentation.FREEFORM_TYPE)) {
0529:                        ToolSession session = SessionManager
0530:                                .getCurrentToolSession();
0531:                        String action = (String) session
0532:                                .getAttribute(FreeFormHelper.FREE_FORM_ACTION);
0533:                        if (action != null) {
0534:                            if (action.equals(FreeFormHelper.ACTION_BACK)) {
0535:                                session
0536:                                        .removeAttribute(FreeFormHelper.FREE_FORM_ACTION);
0537:                                target -= hasProperties(presentation) ? 2 : 3;
0538:                            } else if (action
0539:                                    .equals(FreeFormHelper.ACTION_CONTINUE)) {
0540:                                session
0541:                                        .removeAttribute(FreeFormHelper.FREE_FORM_ACTION);
0542:                                target++;
0543:                            }
0544:                        }
0545:                    } else {
0546:                        // skip free form
0547:                        if (target > currentPage)
0548:                            return target + 1;
0549:                        if (target < currentPage)
0550:                            return target - 1;
0551:                    }
0552:                }
0553:
0554:                if (target == PROPERTY_PAGE) {
0555:                    HttpSession session = request.getSession();
0556:                    boolean hasProperties = hasProperties(presentation);
0557:
0558:                    if (!hasProperties && currentPage == INITIAL_PAGE
0559:                            && target > currentPage)
0560:                        return target + 1;
0561:                    if (!hasProperties && currentPage == PRESENTATION_ITEMS
0562:                            && target < currentPage)
0563:                        return target - 1;
0564:                    if (hasProperties
0565:                            && FormHelper.RETURN_ACTION_SAVE
0566:                                    .equals((String) session
0567:                                            .getAttribute(FormHelper.RETURN_ACTION_TAG))
0568:                            && session
0569:                                    .getAttribute(FormHelper.RETURN_REFERENCE_TAG) != null) {
0570:                        String artifactId = (String) session
0571:                                .getAttribute(FormHelper.RETURN_REFERENCE_TAG);
0572:
0573:                        Node node = getPresentationManager().getNode(
0574:                                getIdManager().getId(artifactId));
0575:                        presentation.setPropertyForm(node.getId());
0576:
0577:                        session
0578:                                .removeAttribute(FormHelper.RETURN_REFERENCE_TAG);
0579:                        session.removeAttribute(FormHelper.RETURN_ACTION_TAG);
0580:                        session.removeAttribute(SESSION_PAGE_PROP_ENTRY);
0581:                        return getDirection(session, target, false);
0582:                    }
0583:
0584:                    if (hasProperties
0585:                            && (FormHelper.RETURN_ACTION_CANCEL
0586:                                    .equals((String) session
0587:                                            .getAttribute(FormHelper.RETURN_ACTION_TAG)) || session
0588:                                    .getAttribute(SESSION_PAGE_PROP_ENTRY) != null)) {
0589:                        session.removeAttribute(FormHelper.RETURN_ACTION_TAG);
0590:                        session.removeAttribute(SESSION_PAGE_PROP_ENTRY);
0591:                        return getDirection(session, target, true);
0592:                    }
0593:
0594:                    //I think if we get here, we just want to go to the prop page...
0595:                    session.setAttribute(SESSION_PAGE_PROP_ENTRY, "true");
0596:                    if (currentPage < target) {
0597:                        session.setAttribute(SESSION_PAGE_PROP_DIRECTION,
0598:                                new Integer(PAGE_DIRECTION_FORWARD));
0599:                    } else if (currentPage > target) {
0600:                        session.setAttribute(SESSION_PAGE_PROP_DIRECTION,
0601:                                new Integer(PAGE_DIRECTION_BACKWARD));
0602:                    }
0603:                }
0604:
0605:                return target;
0606:            }
0607:
0608:            protected int getDirection(HttpSession session, int target,
0609:                    boolean cancelSwitch) {
0610:                int cancelSwitcher = cancelSwitch ? -1 : 1;
0611:                int direction = PAGE_DIRECTION_FORWARD;
0612:                try {
0613:                    direction = ((Integer) session
0614:                            .getAttribute(SESSION_PAGE_PROP_DIRECTION))
0615:                            .intValue();
0616:                } catch (Exception e) {
0617:                    logger.warn("Couldn't get direction.  Moving to target: "
0618:                            + (target + (direction * cancelSwitcher)));
0619:                    //return target + (direction * cancelSwitcher);
0620:                }
0621:                session.removeAttribute(SESSION_PAGE_PROP_DIRECTION);
0622:                return target + (direction * cancelSwitcher);
0623:            }
0624:
0625:            protected boolean hasProperties(Presentation presentation) {
0626:                Id templateId = presentation.getTemplate().getId();
0627:                Id propId = presentationManager.getPresentationTemplate(
0628:                        templateId).getPropertyFormType();
0629:                boolean hasProperties = propId != null;
0630:                return hasProperties;
0631:            }
0632:
0633:            protected boolean isFormSubmission(HttpServletRequest request) {
0634:
0635:                Presentation pres = (Presentation) request.getSession()
0636:                        .getAttribute(getCommandName());
0637:
0638:                if (pres == null) {
0639:                    return false;
0640:                }
0641:
0642:                if (isFinish(request) || isNext(request)
0643:                        || WebUtils.hasSubmitParameter(request, PARAM_CANCEL)) {
0644:                    return true;
0645:                }
0646:                /*
0647:                 if (request.getParameter(PARAM_RESET_FORM) != null &&
0648:                 (pres.getId() != null || request.getParameter("id") != null ||
0649:                 request.getParameter("templateId") != null)) {
0650:                 return false;
0651:                 }
0652:                 */
0653:                if (request.getParameter(PARAM_RESET_FORM) != null) {
0654:                    return false;
0655:                }
0656:
0657:                return true;
0658:            }
0659:
0660:            protected boolean isNext(HttpServletRequest request) {
0661:                //      String direction = request.getParameter("direction");
0662:                //      return ("next".equals(direction) || "previous".equals(direction));
0663:                //         return true;
0664:                Enumeration enumer = request.getParameterNames();
0665:                while (enumer.hasMoreElements()) {
0666:
0667:                    String param = (String) enumer.nextElement();
0668:                    if (param.startsWith(PARAM_TARGET)) {
0669:                        return true;
0670:                    }
0671:                }
0672:
0673:                return false;
0674:            }
0675:
0676:            protected boolean isFinish(HttpServletRequest request) {
0677:                ToolSession session = SessionManager.getCurrentToolSession();
0678:                String action = (String) session
0679:                        .getAttribute(FreeFormHelper.FREE_FORM_ACTION);
0680:
0681:                if (action != null) {
0682:                    if (action.equals(FreeFormHelper.ACTION_SAVE)) {
0683:                        return true;
0684:                    }
0685:                }
0686:
0687:                return WebUtils.hasSubmitParameter(request, PARAM_FINISH)
0688:                        || WebUtils.hasSubmitParameter(request,
0689:                                PARAM_FINISH_AND_NOTIFY);
0690:
0691:            }
0692:
0693:            protected boolean isCancelRequest(HttpServletRequest request) {
0694:                ToolSession session = SessionManager.getCurrentToolSession();
0695:                String action = (String) session
0696:                        .getAttribute(FreeFormHelper.FREE_FORM_ACTION);
0697:                if (action != null) {
0698:                    if (action.equals(FreeFormHelper.ACTION_CANCEL)) {
0699:                        return true;
0700:                    }
0701:                }
0702:
0703:                //This is if the form helper was a cancel...
0704:                if (FormHelper.RETURN_ACTION_CANCEL.equals((String) session
0705:                        .getAttribute(FormHelper.RETURN_ACTION_TAG))) {
0706:                    session.removeAttribute(FormHelper.RETURN_ACTION_TAG);
0707:                    session.removeAttribute(SESSION_PAGE_PROP_ENTRY);
0708:                    return true;
0709:                }
0710:
0711:                return super .isCancelRequest(request);
0712:            }
0713:
0714:            protected void validatePage(Object model, Errors errors, int page) {
0715:                PresentationValidator validator = (PresentationValidator) getValidator();
0716:                switch (page) {
0717:                case ADD_PAGE:
0718:                    validator.validatePresentationInitialPage(model, errors);
0719:                    break;
0720:                case INITIAL_PAGE:
0721:                    validator.validatePresentationFirstPage(model, errors);
0722:                    break;
0723:                case PROPERTY_PAGE:
0724:                    Presentation presentation = (Presentation) model;
0725:                    if (presentation.getProperties() != null) {
0726:                        SchemaNode schemaNode = presentation.getProperties()
0727:                                .getCurrentSchema();
0728:                        if (schemaNode == null) {
0729:                            schemaNode = loadSchema(
0730:                                    presentation.getTemplate()
0731:                                            .getPropertyPage(), new HashMap())
0732:                                    .getChild(
0733:                                            presentation.getTemplate()
0734:                                                    .getDocumentRoot());
0735:                            presentation.getProperties().setCurrentSchema(
0736:                                    schemaNode);
0737:                        }
0738:                        validator.validatePresentationProperties(presentation,
0739:                                errors);
0740:                    }
0741:                    break;
0742:                case PRESENTATION_ITEMS:
0743:                    validator.validatePresentationSecondPage(model, errors);
0744:                    break;
0745:                case PRESENTATION_AUTHORIZATIONS:
0746:                    validator.validatePresentationThirdPage(model, errors);
0747:                    break;
0748:                }
0749:            }
0750:
0751:            protected ModelAndView processFinish(
0752:                    HttpServletRequest httpServletRequest,
0753:                    HttpServletResponse httpServletResponse, Object o,
0754:                    BindException e) throws Exception {
0755:                ToolSession session = SessionManager.getCurrentToolSession();
0756:                session.removeAttribute(FreeFormHelper.FREE_FORM_ACTION);
0757:                Presentation presentation = (Presentation) o;
0758:                Agent agent = getAuthManager().getAgent();
0759:                String isPublic = (String) session
0760:                        .getAttribute(AudienceSelectionHelper.AUDIENCE_PUBLIC_FLAG);
0761:                if (isPublic != null && !isPublic.equals("")) {
0762:                    presentation.setIsPublic(isPublic.equals("true") ? true
0763:                            : false);
0764:                }
0765:                List viewers = (List) session
0766:                        .getAttribute("PRESENTATION_VIEWERS");
0767:                if (viewers != null) {
0768:                    presentation.setViewers(viewers);
0769:                    session.removeAttribute("PRESENTATION_VIEWERS");
0770:                }
0771:
0772:                //don't do this for an edit
0773:                if (presentation.getId() == null) {
0774:                    presentation.setOwner(agent);
0775:                }
0776:
0777:                if (presentation.getTemplate().getPropertyPage() == null) {
0778:                    presentation.setProperties(null);
0779:                }
0780:                presentation.setToolId(ToolManager.getCurrentPlacement()
0781:                        .getId());
0782:                getPresentationManager().storePresentation(presentation);
0783:
0784:                httpServletRequest.getSession().removeAttribute(
0785:                        getCommandName());
0786:                if (WebUtils.hasSubmitParameter(httpServletRequest,
0787:                        PARAM_FINISH_AND_NOTIFY)) {
0788:                    Map params = new HashMap();
0789:                    params.put("presentationId", presentation.getId()
0790:                            .getValue());
0791:                    return new ModelAndView("notifyViewersRedirect", params);
0792:                }
0793:
0794:                Map model = new Hashtable();
0795:
0796:                model.put("isMaintainer", isMaintainer());
0797:                model.put("newPresentationId", presentation.getId());
0798:
0799:                List presentations = new ArrayList(getPresentationManager()
0800:                        .findPresentationsByViewer(getAuthManager().getAgent(),
0801:                                ToolManager.getCurrentPlacement().getId()));
0802:
0803:                Map request = new Hashtable();
0804:                request.put(ListScroll.ENSURE_VISIBLE_TAG, ""
0805:                        + getPresentationIndex(presentations, presentation));
0806:
0807:                model.put("presentations", getListScrollIndexer().indexList(
0808:                        request, model, presentations));
0809:                model.put("osp_agent", getAuthManager().getAgent());
0810:
0811:                return new ModelAndView("listPresentationRedirect", model);
0812:
0813:            }
0814:
0815:            protected int getPresentationIndex(List presentations,
0816:                    Presentation presentation) {
0817:                if (presentation.getId() == null) {
0818:                    return 0;
0819:                }
0820:
0821:                for (int i = 0; i < presentations.size(); i++) {
0822:                    Presentation current = (Presentation) presentations.get(i);
0823:                    if (current.getId().equals(presentation.getId())) {
0824:                        return i;
0825:                    }
0826:                }
0827:                return 0;
0828:            }
0829:
0830:            protected ModelAndView processCancel(
0831:                    HttpServletRequest httpServletRequest,
0832:                    HttpServletResponse httpServletResponse, Object o,
0833:                    BindException e) throws Exception {
0834:                ToolSession session = SessionManager.getCurrentToolSession();
0835:                session.removeAttribute(FreeFormHelper.FREE_FORM_ACTION);
0836:                Presentation presentation = (Presentation) o;
0837:
0838:                Map model = new Hashtable();
0839:
0840:                model.put("isMaintainer", isMaintainer());
0841:
0842:                List presentations = new ArrayList(getPresentationManager()
0843:                        .findPresentationsByViewer(getAuthManager().getAgent(),
0844:                                ToolManager.getCurrentPlacement().getId()));
0845:
0846:                Map request = new Hashtable();
0847:                request.put(ListScroll.ENSURE_VISIBLE_TAG, ""
0848:                        + getPresentationIndex(presentations, presentation));
0849:
0850:                model.put("presentations", getListScrollIndexer().indexList(
0851:                        request, model, presentations));
0852:                model.put("osp_agent", getAuthManager().getAgent());
0853:
0854:                return new ModelAndView("listPresentationRedirect", model);
0855:            }
0856:
0857:            protected void setAudienceSelectionVariables(HttpSession session,
0858:                    Presentation pres) {
0859:                String baseUrl = this .getServerConfigurationService()
0860:                        .getServerUrl();
0861:                String url = baseUrl
0862:                        + "/osp-presentation-tool/viewPresentation.osp?id="
0863:                        + pres.getId().getValue();
0864:                url += "&"
0865:                        + Tool.PLACEMENT_ID
0866:                        + "="
0867:                        + SessionManager.getCurrentToolSession()
0868:                                .getPlacementId();
0869:
0870:                ResourceBundle myResources = ResourceBundle
0871:                        .getBundle(PresentationManager.PRESENTATION_MESSAGE_BUNDLE);
0872:                session.setAttribute(AudienceSelectionHelper.AUDIENCE_FUNCTION,
0873:                        "osp.presentation.view");
0874:
0875:                String id = pres.getId() != null ? pres.getId().getValue()
0876:                        : pres.getNewId().getValue();
0877:                session.setAttribute(
0878:                        AudienceSelectionHelper.AUDIENCE_PORTFOLIO_WIZARD,
0879:                        "true");
0880:                session.setAttribute(
0881:                        AudienceSelectionHelper.AUDIENCE_QUALIFIER, id);
0882:                session.setAttribute(
0883:                        AudienceSelectionHelper.AUDIENCE_GLOBAL_TITLE, pres
0884:                                .isNewObject() ? myResources
0885:                                .getString("title_addPortfolio") : myResources
0886:                                .getString("title_editPresentation1"));
0887:                session
0888:                        .setAttribute(
0889:                                AudienceSelectionHelper.AUDIENCE_INSTRUCTIONS,
0890:                                myResources
0891:                                        .getString("instructions_addViewersToPresentation"));
0892:                session.setAttribute(
0893:                        AudienceSelectionHelper.AUDIENCE_GROUP_TITLE,
0894:                        myResources.getString("instructions_publishToGroup"));
0895:
0896:                session.setAttribute(
0897:                        AudienceSelectionHelper.AUDIENCE_INDIVIDUAL_TITLE,
0898:                        myResources
0899:                                .getString("instructions_publishToIndividual"));
0900:
0901:                session.setAttribute(
0902:                        AudienceSelectionHelper.AUDIENCE_PUBLIC_FLAG, pres
0903:                                .getIsPublic() ? "true" : "false");
0904:                session
0905:                        .setAttribute(
0906:                                AudienceSelectionHelper.AUDIENCE_PUBLIC_TITLE,
0907:                                myResources
0908:                                        .getString("instructions_publishToInternet"));
0909:                session.setAttribute(
0910:                        AudienceSelectionHelper.AUDIENCE_SELECTED_TITLE,
0911:                        myResources.getString("instructions_selectedAudience"));
0912:                session
0913:                        .setAttribute(
0914:                                AudienceSelectionHelper.AUDIENCE_FILTER_INSTRUCTIONS,
0915:                                myResources
0916:                                        .getString("instructions_selectFilterUserList"));
0917:                session.setAttribute(
0918:                        AudienceSelectionHelper.AUDIENCE_GUEST_EMAIL, "true");
0919:                session.setAttribute(
0920:                        AudienceSelectionHelper.AUDIENCE_WORKSITE_LIMITED,
0921:                        "false");
0922:                session.setAttribute(
0923:                        AudienceSelectionHelper.AUDIENCE_PUBLIC_INSTRUCTIONS,
0924:                        myResources.getString("publish_message"));
0925:                session.setAttribute(
0926:                        AudienceSelectionHelper.AUDIENCE_PUBLIC_URL, url);
0927:
0928:                session.setAttribute(
0929:                        AudienceSelectionHelper.AUDIENCE_CANCEL_TARGET,
0930:                        PARAM_CANCEL);
0931:                session.setAttribute(
0932:                        AudienceSelectionHelper.AUDIENCE_SAVE_NOTIFY_TARGET,
0933:                        PARAM_FINISH_AND_NOTIFY);
0934:                session.setAttribute(
0935:                        AudienceSelectionHelper.AUDIENCE_SAVE_TARGET,
0936:                        PARAM_FINISH);
0937:                session.setAttribute(
0938:                        AudienceSelectionHelper.AUDIENCE_BACK_TARGET,
0939:                        PARAM_TARGET
0940:                                + (pres.getPresentationType().equals(
0941:                                        Presentation.FREEFORM_TYPE) ? 2 : 3));
0942:                session.setAttribute(
0943:                        AudienceSelectionHelper.AUDIENCE_BROWSE_INDIVIDUAL,
0944:                        myResources.getString("audience_browse_individual"));
0945:            }
0946:
0947:            /**
0948:             *
0949:             * @return true is current agent is a maintainer in the current site
0950:             */
0951:            protected Boolean isMaintainer() {
0952:                return new Boolean(getAuthzManager()
0953:                        .isAuthorized(
0954:                                WorksiteManager.WORKSITE_MAINTAIN,
0955:                                getIdManager().getId(
0956:                                        ToolManager.getCurrentPlacement()
0957:                                                .getContext())));
0958:            }
0959:
0960:            public PresentationManager getPresentationManager() {
0961:                return presentationManager;
0962:            }
0963:
0964:            public void setPresentationManager(
0965:                    PresentationManager presentationManager) {
0966:                this .presentationManager = presentationManager;
0967:            }
0968:
0969:            public AuthenticationManager getAuthManager() {
0970:                return authManager;
0971:            }
0972:
0973:            public void setAuthManager(AuthenticationManager authManager) {
0974:                this .authManager = authManager;
0975:            }
0976:
0977:            public AgentManager getAgentManager() {
0978:                return agentManager;
0979:            }
0980:
0981:            public void setAgentManager(AgentManager agentManager) {
0982:                this .agentManager = agentManager;
0983:            }
0984:
0985:            public HomeFactory getHomeFactory() {
0986:                return homeFactory;
0987:            }
0988:
0989:            public void setHomeFactory(HomeFactory homeFactory) {
0990:                this .homeFactory = homeFactory;
0991:            }
0992:
0993:            public List getCustomTypedEditors() {
0994:                return customTypedEditors;
0995:            }
0996:
0997:            public void setCustomTypedEditors(List customTypedEditors) {
0998:                this .customTypedEditors = customTypedEditors;
0999:            }
1000:
1001:            public IdManager getIdManager() {
1002:                return idManager;
1003:            }
1004:
1005:            public void setIdManager(IdManager idManager) {
1006:                this .idManager = idManager;
1007:            }
1008:
1009:            public AuthorizationFacade getAuthzManager() {
1010:                return authzManager;
1011:            }
1012:
1013:            public void setAuthzManager(AuthorizationFacade authzManager) {
1014:                this .authzManager = authzManager;
1015:            }
1016:
1017:            public Config getOspConfig() {
1018:                return ospConfig;
1019:            }
1020:
1021:            public void setOspConfig(Config ospConfig) {
1022:                this .ospConfig = ospConfig;
1023:            }
1024:
1025:            public WorksiteManager getWorksiteManager() {
1026:                return worksiteManager;
1027:            }
1028:
1029:            public void setWorksiteManager(WorksiteManager worksiteManager) {
1030:                this .worksiteManager = worksiteManager;
1031:            }
1032:
1033:            public ListScrollIndexer getListScrollIndexer() {
1034:                return listScrollIndexer;
1035:            }
1036:
1037:            public void setListScrollIndexer(ListScrollIndexer listScrollIndexer) {
1038:                this .listScrollIndexer = listScrollIndexer;
1039:            }
1040:
1041:            public ServerConfigurationService getServerConfigurationService() {
1042:                return serverConfigurationService;
1043:            }
1044:
1045:            public void setServerConfigurationService(
1046:                    ServerConfigurationService serverConfigurationService) {
1047:                this .serverConfigurationService = serverConfigurationService;
1048:            }
1049:
1050:            protected int getInitialPage(HttpServletRequest request) {
1051:                return initialPage;
1052:            }
1053:
1054:            private void setInitialPage(int page) {
1055:                initialPage = page;
1056:            }
1057:
1058:            /**
1059:             * @return the contentHosting
1060:             */
1061:            public ContentHostingService getContentHosting() {
1062:                return contentHosting;
1063:            }
1064:
1065:            /**
1066:             * @param contentHosting the contentHosting to set
1067:             */
1068:            public void setContentHosting(ContentHostingService contentHosting) {
1069:                this.contentHosting = contentHosting;
1070:            }
1071:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.