Source Code Cross Referenced for SyllabusTool.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » tool » syllabus » 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.sakaiproject.tool.syllabus 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**********************************************************************************
0002:         * $URL: https://source.sakaiproject.org/svn/syllabus/tags/sakai_2-4-1/syllabus-app/src/java/org/sakaiproject/tool/syllabus/SyllabusTool.java $
0003:         * $Id: SyllabusTool.java 21393 2007-02-12 18:16:16Z josrodri@iupui.edu $
0004:         ***********************************************************************************
0005:         *
0006:         * Copyright (c) 2003, 2004, 2005, 2006 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.sakaiproject.tool.syllabus;
0021:
0022:        import java.io.InputStream;
0023:        import java.util.ArrayList;
0024:        import java.util.Iterator;
0025:        import java.util.List;
0026:        import java.util.Map;
0027:        import java.util.Set;
0028:        import java.util.logging.Logger;
0029:
0030:        import javax.faces.component.UIComponent;
0031:        import javax.faces.context.ExternalContext;
0032:        import javax.faces.context.FacesContext;
0033:        import javax.faces.event.PhaseId;
0034:        import javax.faces.event.ValueChangeEvent;
0035:
0036:        import org.apache.commons.fileupload.FileItem;
0037:        import org.sakaiproject.api.app.syllabus.SyllabusAttachment;
0038:        import org.sakaiproject.api.app.syllabus.SyllabusData;
0039:        import org.sakaiproject.api.app.syllabus.SyllabusItem;
0040:        import org.sakaiproject.api.app.syllabus.SyllabusManager;
0041:        import org.sakaiproject.api.app.syllabus.SyllabusService;
0042:        import org.sakaiproject.component.cover.ServerConfigurationService;
0043:        import org.sakaiproject.content.api.ContentResource;
0044:        import org.sakaiproject.content.api.FilePickerHelper;
0045:        import org.sakaiproject.content.cover.ContentHostingService;
0046:        import org.sakaiproject.entity.api.Entity;
0047:        import org.sakaiproject.entity.api.Reference;
0048:        import org.sakaiproject.entity.api.ResourcePropertiesEdit;
0049:        import org.sakaiproject.entity.cover.EntityManager;
0050:        import org.sakaiproject.exception.PermissionException;
0051:        import org.sakaiproject.site.cover.SiteService;
0052:        import org.sakaiproject.tool.api.Placement;
0053:        import org.sakaiproject.tool.api.ToolSession;
0054:        import org.sakaiproject.tool.cover.SessionManager;
0055:        import org.sakaiproject.tool.cover.ToolManager;
0056:        import org.sakaiproject.user.cover.UserDirectoryService;
0057:        import org.sakaiproject.util.FormattedText;
0058:        import org.apache.commons.logging.Log;
0059:        import org.apache.commons.logging.LogFactory;
0060:
0061:        import com.sun.faces.util.MessageFactory;
0062:
0063:        //sakai2 - no need to import org.sakaiproject.jsf.ToolBean here as sakai does.
0064:
0065:        /**
0066:         * @author cwen TODO To change the template for this generated type comment go to Window - Preferences -
0067:         *         Java - Code Style - Code Templates
0068:         */
0069:        //sakai2 - doesn't implement ToolBean as sakai does.
0070:        public class SyllabusTool {
0071:            public class DecoratedSyllabusEntry {
0072:                protected SyllabusData in_entry = null;
0073:
0074:                protected boolean selected = false;
0075:
0076:                protected boolean justCreated = false;
0077:
0078:                protected ArrayList attachmentList = new ArrayList();
0079:
0080:                public DecoratedSyllabusEntry(SyllabusData en) {
0081:                    in_entry = en;
0082:                }
0083:
0084:                public SyllabusData getEntry() {
0085:                    return in_entry;
0086:                }
0087:
0088:                public boolean isJustCreated() {
0089:                    return justCreated;
0090:                }
0091:
0092:                public boolean isSelected() {
0093:                    return selected;
0094:                }
0095:
0096:                public void setSelected(boolean b) {
0097:                    selected = b;
0098:                }
0099:
0100:                public void setJustCreated(boolean b) {
0101:                    justCreated = b;
0102:                }
0103:
0104:                public String processListRead() {
0105:                    //logger.info(this + ".processListRead() in SyllabusTool.");
0106:
0107:                    attachments.clear();
0108:
0109:                    SyllabusData sd = syllabusManager.getSyllabusData(in_entry
0110:                            .getSyllabusId().toString());
0111:                    Set tempAttach = syllabusManager
0112:                            .getSyllabusAttachmentsForSyllabusData(sd);
0113:
0114:                    Iterator iter = tempAttach.iterator();
0115:                    while (iter.hasNext()) {
0116:                        oldAttachments.add((SyllabusAttachment) iter.next());
0117:                    }
0118:
0119:                    allAttachments.clear();
0120:                    for (int i = 0; i < oldAttachments.size(); i++) {
0121:                        allAttachments.add((SyllabusAttachment) oldAttachments
0122:                                .get(i));
0123:                    }
0124:
0125:                    syllabusService.readSyllabus(sd);
0126:
0127:                    entry = this ;
0128:
0129:                    entries.clear();
0130:
0131:                    return "read";
0132:                }
0133:
0134:                public String processDownMove() {
0135:                    downOnePlace(this .getEntry());
0136:                    return "main_edit";
0137:                }
0138:
0139:                public String processUpMove() {
0140:                    upOnePlace(this .getEntry());
0141:                    return "main_edit";
0142:                }
0143:
0144:                public ArrayList getAttachmentList() {
0145:                    Set tempList = syllabusManager
0146:                            .getSyllabusAttachmentsForSyllabusData(in_entry);
0147:
0148:                    Iterator iter = tempList.iterator();
0149:                    while (iter.hasNext()) {
0150:                        SyllabusAttachment sa = (SyllabusAttachment) iter
0151:                                .next();
0152:                        attachmentList.add(sa);
0153:                    }
0154:
0155:                    return attachmentList;
0156:                }
0157:
0158:                public void setAttachmentList(ArrayList attachmentList) {
0159:                    this .attachmentList = attachmentList;
0160:                }
0161:            }
0162:
0163:            protected SyllabusManager syllabusManager;
0164:
0165:            protected SyllabusItem syllabusItem;
0166:
0167:            protected ArrayList entries;
0168:
0169:            protected String userId;
0170:
0171:            protected DecoratedSyllabusEntry entry = null;
0172:
0173:            protected Log logger = LogFactory.getLog(SyllabusTool.class);
0174:
0175:            protected String filename = null;
0176:
0177:            protected String siteId = null;
0178:
0179:            protected String editAble = null;
0180:
0181:            protected String title = null;
0182:
0183:            private boolean displayNoEntryMsg = false;
0184:
0185:            private boolean displayTitleErroMsg = false;
0186:
0187:            private boolean displayEvilTagMsg = false;
0188:
0189:            private String evilTagMsg = null;
0190:
0191:            private SyllabusService syllabusService;
0192:
0193:            private ArrayList attachments = new ArrayList();
0194:
0195:            private boolean attachCaneled = false;
0196:
0197:            private String removeAttachId = null;
0198:
0199:            private ArrayList oldAttachments = new ArrayList();
0200:
0201:            private ArrayList allAttachments = new ArrayList();
0202:
0203:            private ArrayList prepareRemoveAttach = new ArrayList();
0204:
0205:            private List filePickerList;
0206:
0207:            private String currentRediredUrl = null;
0208:
0209:            public SyllabusTool() {
0210:            }
0211:
0212:            public boolean getdisplayNoEntryMsg() {
0213:                return this .displayNoEntryMsg;
0214:            }
0215:
0216:            public ArrayList getEntries() throws PermissionException {
0217:                if (userId == null)
0218:                    userId = UserDirectoryService.getCurrentUser().getId();
0219:                //sakai2 - use Placement to get context instead of getting currentSitePageId from PortalService in sakai.
0220:                Placement placement = ToolManager.getCurrentPlacement();
0221:                String currentSiteId = placement.getContext();
0222:
0223:                if ((entries == null)
0224:                        || (entries.isEmpty())
0225:                        || ((currentSiteId != null) && (!currentSiteId
0226:                                .equals(siteId)))) {
0227:                    //logger.info(this + ".getEntries() in SyllabusTool");
0228:
0229:                    siteId = currentSiteId;
0230:                    try {
0231:                        if (entries == null)
0232:                            entries = new ArrayList();
0233:                        else
0234:                            entries.clear();
0235:
0236:                        syllabusItem = getSyllabusItem();
0237:
0238:                        Set tempEntries = syllabusManager
0239:                                .getSyllabiForSyllabusItem(syllabusItem);
0240:
0241:                        if (tempEntries != null) {
0242:                            Iterator iter = tempEntries.iterator();
0243:                            while (iter.hasNext()) {
0244:                                SyllabusData en = (SyllabusData) iter.next();
0245:                                if (this .checkAccess()) {
0246:                                    DecoratedSyllabusEntry den = new DecoratedSyllabusEntry(
0247:                                            en);
0248:                                    entries.add(den);
0249:                                } else {
0250:                                    if (en.getStatus().equals("Posted")) {
0251:                                        DecoratedSyllabusEntry den = new DecoratedSyllabusEntry(
0252:                                                en);
0253:                                        entries.add(den);
0254:                                    }
0255:                                }
0256:                            }
0257:                        }
0258:                    } catch (Exception e) {
0259:                        logger
0260:                                .info(this  + ".getEntries() in SyllabusTool "
0261:                                        + e);
0262:                        FacesContext.getCurrentInstance().addMessage(
0263:                                null,
0264:                                MessageFactory.getMessage(FacesContext
0265:                                        .getCurrentInstance(),
0266:                                        "error_permission", (new Object[] { e
0267:                                                .toString() })));
0268:                    }
0269:                } else {
0270:                    try {
0271:                        siteId = currentSiteId;
0272:                        if ((userId != null) && (siteId != null)) {
0273:                            syllabusItem = syllabusManager
0274:                                    .getSyllabusItemByContextId(siteId);
0275:                        }
0276:
0277:                        boolean getFromDbAgain = true;
0278:                        for (int i = 0; i < entries.size(); i++) {
0279:                            DecoratedSyllabusEntry this DecEn = (DecoratedSyllabusEntry) entries
0280:                                    .get(i);
0281:                            if (this DecEn.isSelected()) {
0282:                                getFromDbAgain = false;
0283:                                break;
0284:                            }
0285:                        }
0286:
0287:                        if (getFromDbAgain) {
0288:                            entries.clear();
0289:                            Set tempEntries = syllabusManager
0290:                                    .getSyllabiForSyllabusItem(syllabusItem);
0291:
0292:                            if (tempEntries != null) {
0293:                                Iterator iter = tempEntries.iterator();
0294:                                while (iter.hasNext()) {
0295:                                    SyllabusData en = (SyllabusData) iter
0296:                                            .next();
0297:                                    if (this .checkAccess()) {
0298:                                        DecoratedSyllabusEntry den = new DecoratedSyllabusEntry(
0299:                                                en);
0300:                                        entries.add(den);
0301:                                    } else {
0302:                                        if (en.getStatus().equals("Posted")) {
0303:                                            DecoratedSyllabusEntry den = new DecoratedSyllabusEntry(
0304:                                                    en);
0305:                                            entries.add(den);
0306:                                        }
0307:                                    }
0308:                                }
0309:                            }
0310:                        }
0311:                    } catch (Exception e) {
0312:                        logger
0313:                                .info(this 
0314:                                        + ".getEntries() in SyllabusTool for redirection"
0315:                                        + e);
0316:                        FacesContext.getCurrentInstance().addMessage(
0317:                                null,
0318:                                MessageFactory.getMessage(FacesContext
0319:                                        .getCurrentInstance(),
0320:                                        "error_permission", (new Object[] { e
0321:                                                .toString() })));
0322:                    }
0323:                }
0324:                if (entries == null || entries.isEmpty()) {
0325:                    this .displayNoEntryMsg = true;
0326:                } else {
0327:                    this .displayNoEntryMsg = false;
0328:                }
0329:                return entries;
0330:            }
0331:
0332:            public DecoratedSyllabusEntry getEntry() {
0333:                return entry;
0334:            }
0335:
0336:            public ArrayList getSelectedEntries() {
0337:                ArrayList rv = new ArrayList();
0338:
0339:                if ((entry != null) && (entry.isSelected())) {
0340:                    rv.add(entry);
0341:                } else {
0342:                    for (int i = 0; i < entries.size(); i++) {
0343:                        DecoratedSyllabusEntry den = (DecoratedSyllabusEntry) entries
0344:                                .get(i);
0345:                        if (den.isSelected()) {
0346:                            rv.add(den);
0347:                        }
0348:                    }
0349:                }
0350:                return rv;
0351:            }
0352:
0353:            public SyllabusManager getSyllabusManager() {
0354:                return syllabusManager;
0355:            }
0356:
0357:            public void setSyllabusManager(SyllabusManager syllabusManager) {
0358:                this .syllabusManager = syllabusManager;
0359:            }
0360:
0361:            public SyllabusItem getSyllabusItem() throws PermissionException {
0362:                //sakai2 - use Placement to get context instead of getting currentSitePageId from PortalService in sakai.
0363:                Placement placement = ToolManager.getCurrentPlacement();
0364:                String currentSiteId = placement.getContext();
0365:                String currentUserId = UserDirectoryService.getCurrentUser()
0366:                        .getId();
0367:                try {
0368:                    if ((syllabusItem != null)
0369:                            && (syllabusItem.getContextId()
0370:                                    .equals(currentSiteId))
0371:                            && (syllabusItem.getUserId().equals(currentUserId))) {
0372:                        return syllabusItem;
0373:                    }
0374:
0375:                    syllabusItem = syllabusManager
0376:                            .getSyllabusItemByContextId(currentSiteId);
0377:
0378:                    if (syllabusItem == null) {
0379:                        if (!this .checkAccess()) {
0380:                            throw new PermissionException(
0381:                                    "syllabus_access_athz", "", currentUserId);
0382:                        } else {
0383:                            syllabusItem = syllabusManager.createSyllabusItem(
0384:                                    currentUserId, currentSiteId, null);
0385:                        }
0386:                    }
0387:                } catch (Exception e) {
0388:                    logger.info(this  + ".getSyllabusItem() in SyllabusTool "
0389:                            + e);
0390:                    FacesContext.getCurrentInstance().addMessage(
0391:                            null,
0392:                            MessageFactory.getMessage(FacesContext
0393:                                    .getCurrentInstance(), "error_permission",
0394:                                    (new Object[] { e.toString() })));
0395:                }
0396:                return syllabusItem;
0397:            }
0398:
0399:            public void setSyllabusItem(SyllabusItem syllabusItem) {
0400:                this .syllabusItem = syllabusItem;
0401:            }
0402:
0403:            public void setLogger(Log logger) {
0404:                this .logger = logger;
0405:            }
0406:
0407:            public String getFilename() {
0408:                //logger.info(this + ".getFilename() in SyllabusTool");
0409:                return filename;
0410:            }
0411:
0412:            public void setFilename(String filename) {
0413:                //logger.info(this + ".setFilename() in SyllabusTool");
0414:                this .filename = filename;
0415:            }
0416:
0417:            public String getUserId() {
0418:                return userId;
0419:            }
0420:
0421:            public void setUserId(String userId) {
0422:                this .userId = userId;
0423:            }
0424:
0425:            public String getSiteId() {
0426:                return siteId;
0427:            }
0428:
0429:            public void setSiteId(String siteId) {
0430:                this .siteId = siteId;
0431:            }
0432:
0433:            //testing the access to control the "create/edit"
0434:            //button showing up or not on main page.
0435:            public String getEditAble() {
0436:                if (checkAccess()) {
0437:                    editAble = "true";
0438:                } else {
0439:                    editAble = null;
0440:                }
0441:                return editAble;
0442:            }
0443:
0444:            public void setEditAble(String editAble) {
0445:                this .editAble = editAble;
0446:            }
0447:
0448:            public void setDisplayTitleErroMsg(boolean displayTitleErroMsg) {
0449:                this .displayTitleErroMsg = displayTitleErroMsg;
0450:            }
0451:
0452:            public boolean getDisplayTitleErroMsg() {
0453:                return displayTitleErroMsg;
0454:            }
0455:
0456:            /* testing fileUpload
0457:             * public FileUpload getFileUpload() { return fileUpload; } public void setFileUpload(FileUpload
0458:             * fileUpload) { this.fileUpload = fileUpload; }
0459:             */
0460:
0461:            public boolean getDisplayEvilTagMsg() {
0462:                return displayEvilTagMsg;
0463:            }
0464:
0465:            public void setDisplayEvilTagMsg(boolean displayEvilTagMsg) {
0466:                this .displayEvilTagMsg = displayEvilTagMsg;
0467:            }
0468:
0469:            public String getEvilTagMsg() {
0470:                return evilTagMsg;
0471:            }
0472:
0473:            public void setEvilTagMsg(String evilTagMsg) {
0474:                this .evilTagMsg = evilTagMsg;
0475:            }
0476:
0477:            public String processDeleteCancel() {
0478:                //logger.info(this + ".processDeleteCancel() in SyllabusTool.");
0479:
0480:                entries.clear();
0481:                entry = null;
0482:
0483:                return "main_edit";
0484:            }
0485:
0486:            public String processDelete()
0487:                    throws org.sakaiproject.exception.PermissionException {
0488:                //logger.info(this + ".processDelete() in SyllabusTool");
0489:
0490:                ArrayList selected = getSelectedEntries();
0491:                try {
0492:                    if (!this .checkAccess()) {
0493:                        return "permission_error";
0494:                    } else {
0495:                        Set dataSet = syllabusManager
0496:                                .getSyllabiForSyllabusItem(syllabusItem);
0497:                        for (int i = 0; i < selected.size(); i++) {
0498:                            DecoratedSyllabusEntry den = (DecoratedSyllabusEntry) selected
0499:                                    .get(i);
0500:
0501:                            //          if(den.getEntry().getStatus().equalsIgnoreCase("Posted"))
0502:                            //          {
0503:                            syllabusService
0504:                                    .deletePostedSyllabus(den.getEntry());
0505:                            //          }
0506:
0507:                            //Set syllabusAttachments = den.getEntry().getAttachments();
0508:                            Set syllabusAttachments = syllabusManager
0509:                                    .getSyllabusAttachmentsForSyllabusData(den
0510:                                            .getEntry());
0511:                            //den.getEntry().getAttachments();
0512:                            Iterator iter = syllabusAttachments.iterator();
0513:                            while (iter.hasNext()) {
0514:                                SyllabusAttachment attach = (SyllabusAttachment) iter
0515:                                        .next();
0516:                                String id = attach.getAttachmentId();
0517:
0518:                                syllabusManager
0519:                                        .removeSyllabusAttachSyllabusData(den
0520:                                                .getEntry(), attach);
0521:                                if (id.toLowerCase().startsWith("/attachment"))
0522:                                    ContentHostingService.removeResource(id);
0523:                            }
0524:                            syllabusManager.removeSyllabusFromSyllabusItem(
0525:                                    syllabusItem, den.getEntry());
0526:                        }
0527:                    }
0528:                    Placement currentPlacement = ToolManager
0529:                            .getCurrentPlacement();
0530:                    syllabusItem = syllabusManager
0531:                            .getSyllabusItemByContextId(currentPlacement
0532:                                    .getContext());
0533:
0534:                    entries.clear();
0535:                    entry = null;
0536:
0537:                    return "main_edit";
0538:                } catch (Exception e) {
0539:                    logger.info(this  + ".processDelete: " + e);
0540:                    FacesContext.getCurrentInstance().addMessage(
0541:                            null,
0542:                            MessageFactory.getMessage(FacesContext
0543:                                    .getCurrentInstance(), "error_permission",
0544:                                    (new Object[] { e.toString() })));
0545:                }
0546:
0547:                entries.clear();
0548:                entry = null;
0549:
0550:                return null;
0551:            }
0552:
0553:            public String processEditCancel() {
0554:                //logger.info(this + ".processEditCancel() in SyllabusTool ");
0555:
0556:                try {
0557:                    if (entry != null) {
0558:                        for (int i = 0; i < attachments.size(); i++) {
0559:                            String id = ((SyllabusAttachment) attachments
0560:                                    .get(i)).getAttachmentId();
0561:                            syllabusManager
0562:                                    .removeSyllabusAttachmentObject((SyllabusAttachment) attachments
0563:                                            .get(i));
0564:                            if (id.toLowerCase().startsWith("/attachment"))
0565:                                ContentHostingService.removeResource(id);
0566:                        }
0567:                        syllabusManager.removeSyllabusDataObject(entry
0568:                                .getEntry());
0569:                    }
0570:                } catch (Exception e) {
0571:                    logger.error(this  + ".processEditCancel - " + e);
0572:                    e.printStackTrace();
0573:                }
0574:                displayTitleErroMsg = false;
0575:                displayEvilTagMsg = false;
0576:                entries.clear();
0577:                entry = null;
0578:                attachments.clear();
0579:
0580:                return "main_edit";
0581:            }
0582:
0583:            public String processEditSave() throws PermissionException {
0584:                //logger.info(this + ".processEditSave() in SyllabusTool");
0585:
0586:                try {
0587:                    displayTitleErroMsg = false;
0588:                    displayEvilTagMsg = false;
0589:                    if (!this .checkAccess()) {
0590:                        return "permission_error";
0591:                    } else {
0592:                        if (entry.getEntry().getTitle() == null) {
0593:                            displayTitleErroMsg = true;
0594:                            return "edit";
0595:                        } else if (entry.getEntry().getTitle().trim()
0596:                                .equals("")) {
0597:                            displayTitleErroMsg = true;
0598:                            return "edit";
0599:                        }
0600:                        if (entry.getEntry().getAsset() != null) {
0601:                            StringBuffer alertMsg = new StringBuffer();
0602:                            String errorMsg = null;
0603:                            try {
0604:                                errorMsg = FormattedText.processFormattedText(
0605:                                        entry.getEntry().getAsset(), alertMsg);
0606:                                if (alertMsg.length() > 0) {
0607:                                    evilTagMsg = alertMsg.toString();
0608:                                    displayEvilTagMsg = true;
0609:                                    return "edit";
0610:                                }
0611:                            } catch (Exception e) {
0612:                                logger.warn(this  + " " + errorMsg, e);
0613:                            }
0614:                        }
0615:                        if (entry.justCreated == true) {
0616:                            syllabusManager.addSyllabusToSyllabusItem(
0617:                                    syllabusItem, getEntry().getEntry());
0618:                            for (int i = 0; i < attachments.size(); i++) {
0619:                                syllabusManager
0620:                                        .addSyllabusAttachToSyllabusData(
0621:                                                getEntry().getEntry(),
0622:                                                (SyllabusAttachment) attachments
0623:                                                        .get(i));
0624:                            }
0625:                            syllabusService.draftNewSyllabus(getEntry()
0626:                                    .getEntry());
0627:                        }
0628:                    }
0629:
0630:                    entries.clear();
0631:                    entry = null;
0632:                    attachments.clear();
0633:
0634:                    return "main_edit";
0635:                } catch (Exception e) {
0636:                    logger
0637:                            .info(this  + ".processEditSave in SyllabusTool: "
0638:                                    + e);
0639:                    FacesContext.getCurrentInstance().addMessage(
0640:                            null,
0641:                            MessageFactory.getMessage(FacesContext
0642:                                    .getCurrentInstance(), "error_permission",
0643:                                    (new Object[] { e.toString() })));
0644:                }
0645:
0646:                return null;
0647:            }
0648:
0649:            public String processEditPost() throws PermissionException {
0650:                //logger.info(this + ".processEditPost() in SyllabusTool");
0651:
0652:                try {
0653:                    displayTitleErroMsg = false;
0654:                    displayEvilTagMsg = false;
0655:                    if (!this .checkAccess()) {
0656:                        return "permission_error";
0657:                    } else {
0658:                        if (entry.getEntry().getTitle() == null) {
0659:                            displayTitleErroMsg = true;
0660:                            return "edit";
0661:                        } else if (entry.getEntry().getTitle().trim()
0662:                                .equals("")) {
0663:                            displayTitleErroMsg = true;
0664:                            return "edit";
0665:                        }
0666:                        if (entry.getEntry().getAsset() != null) {
0667:                            StringBuffer alertMsg = new StringBuffer();
0668:                            String errorMsg = null;
0669:                            try {
0670:                                errorMsg = FormattedText.processFormattedText(
0671:                                        entry.getEntry().getAsset(), alertMsg);
0672:                                if (alertMsg.length() > 0) {
0673:                                    evilTagMsg = alertMsg.toString();
0674:                                    displayEvilTagMsg = true;
0675:                                    return "edit";
0676:                                }
0677:                            } catch (Exception e) {
0678:                                logger.warn(this  + " " + errorMsg, e);
0679:                            }
0680:                        }
0681:                        if (entry.justCreated == true) {
0682:                            getEntry().getEntry().setStatus("Posted");
0683:                            syllabusManager.addSyllabusToSyllabusItem(
0684:                                    syllabusItem, getEntry().getEntry());
0685:                            //syllabusManager.saveSyllabusItem(syllabusItem);
0686:                            for (int i = 0; i < attachments.size(); i++) {
0687:                                syllabusManager
0688:                                        .addSyllabusAttachToSyllabusData(
0689:                                                getEntry().getEntry(),
0690:                                                (SyllabusAttachment) attachments
0691:                                                        .get(i));
0692:                            }
0693:
0694:                            syllabusService.postNewSyllabus(getEntry()
0695:                                    .getEntry());
0696:
0697:                            entries.clear();
0698:                            entry = null;
0699:                            attachments.clear();
0700:
0701:                            return "main_edit";
0702:                        }
0703:                    }
0704:                } catch (Exception e) {
0705:                    logger
0706:                            .info(this  + ".processEditPost in SyllabusTool: "
0707:                                    + e);
0708:                    e.printStackTrace();
0709:                    FacesContext.getCurrentInstance().addMessage(
0710:                            null,
0711:                            MessageFactory.getMessage(FacesContext
0712:                                    .getCurrentInstance(), "error_permission",
0713:                                    (new Object[] { e.toString() })));
0714:                }
0715:
0716:                return null;
0717:            }
0718:
0719:            public String processListDelete() throws PermissionException {
0720:                //logger.info(this + ".processListDelete() in SyllabusTool");
0721:
0722:                try {
0723:                    if (!this .checkAccess()) {
0724:                        return "permission_error";
0725:                    } else {
0726:                        ArrayList selected = getSelectedEntries();
0727:                        if (selected.isEmpty()) {
0728:                            FacesContext.getCurrentInstance().addMessage(
0729:                                    null,
0730:                                    MessageFactory.getMessage(FacesContext
0731:                                            .getCurrentInstance(),
0732:                                            "error_delete_select", null));
0733:
0734:                            return null;
0735:                        }
0736:                        return "delete_confirm";
0737:                    }
0738:                } catch (Exception e) {
0739:                    logger.info(this  + ".processListDelete in SyllabusTool: "
0740:                            + e);
0741:                    FacesContext.getCurrentInstance().addMessage(
0742:                            null,
0743:                            MessageFactory.getMessage(FacesContext
0744:                                    .getCurrentInstance(), "error_permission",
0745:                                    (new Object[] { e.toString() })));
0746:                }
0747:
0748:                return null;
0749:            }
0750:
0751:            public String processListNew() throws PermissionException {
0752:                //logger.info(this + ".processListNew() in SyllabusTool");
0753:
0754:                try {
0755:                    if (!this .checkAccess()) {
0756:                        return "permission_error";
0757:                    } else {
0758:                        int initPosition = syllabusManager
0759:                                .findLargestSyllabusPosition(syllabusItem)
0760:                                .intValue() + 1;
0761:                        SyllabusData en = syllabusManager
0762:                                .createSyllabusDataObject(null, new Integer(
0763:                                        initPosition), null, null, "Draft",
0764:                                        "none");
0765:                        en.setView("no");
0766:
0767:                        entry = new DecoratedSyllabusEntry(en);
0768:                        entry.setJustCreated(true);
0769:
0770:                        entries.clear();
0771:
0772:                        return "edit";
0773:                    }
0774:                } catch (Exception e) {
0775:                    logger.info(this  + ".processListNew in SyllabusTool: " + e);
0776:                    FacesContext.getCurrentInstance().addMessage(
0777:                            null,
0778:                            MessageFactory.getMessage(FacesContext
0779:                                    .getCurrentInstance(), "error_permission",
0780:                                    (new Object[] { e.toString() })));
0781:
0782:                    return null;
0783:                }
0784:            }
0785:
0786:            public String processReadCancel() {
0787:                //logger.info(this + ".processReadCancel() in SyllabusTool");
0788:
0789:                try {
0790:                    for (int i = 0; i < attachments.size(); i++) {
0791:                        String id = ((SyllabusAttachment) attachments.get(i))
0792:                                .getAttachmentId();
0793:                        syllabusManager
0794:                                .removeSyllabusAttachmentObject((SyllabusAttachment) attachments
0795:                                        .get(i));
0796:                        if (id.toLowerCase().startsWith("/attachment"))
0797:                            ContentHostingService.removeResource(id);
0798:                    }
0799:                } catch (Exception e) {
0800:                    logger.error(this  + ".processReadCancel - " + e);
0801:                    e.printStackTrace();
0802:                }
0803:
0804:                displayTitleErroMsg = false;
0805:                displayEvilTagMsg = false;
0806:                entries.clear();
0807:                entry = null;
0808:                attachments.clear();
0809:                oldAttachments.clear();
0810:
0811:                return "main_edit";
0812:            }
0813:
0814:            public String processReadSave() throws PermissionException {
0815:                //logger.info(this + ".processReadSave() in SyllabusTool");
0816:
0817:                try {
0818:                    displayTitleErroMsg = false;
0819:                    displayEvilTagMsg = false;
0820:                    if (!this .checkAccess()) {
0821:                        return "permission_error";
0822:                    } else {
0823:                        if (entry.getEntry().getTitle() == null) {
0824:                            displayTitleErroMsg = true;
0825:
0826:                            return "read";
0827:                        } else if (entry.getEntry().getTitle().trim()
0828:                                .equals("")) {
0829:                            displayTitleErroMsg = true;
0830:                            return "read";
0831:                        }
0832:                        if (entry.getEntry().getAsset() != null) {
0833:                            StringBuffer alertMsg = new StringBuffer();
0834:                            String errorMsg = null;
0835:                            try {
0836:                                errorMsg = FormattedText.processFormattedText(
0837:                                        entry.getEntry().getAsset(), alertMsg);
0838:                                if (alertMsg.length() > 0) {
0839:                                    evilTagMsg = alertMsg.toString();
0840:                                    displayEvilTagMsg = true;
0841:                                    return "edit";
0842:                                }
0843:                            } catch (Exception e) {
0844:                                logger.warn(this  + " " + errorMsg, e);
0845:                            }
0846:                        }
0847:                        if (entry.justCreated == false) {
0848:                            getEntry().getEntry().setStatus("Draft");
0849:                            syllabusManager.saveSyllabus(getEntry().getEntry());
0850:
0851:                            for (int i = 0; i < attachments.size(); i++) {
0852:                                syllabusManager
0853:                                        .addSyllabusAttachToSyllabusData(
0854:                                                getEntry().getEntry(),
0855:                                                (SyllabusAttachment) attachments
0856:                                                        .get(i));
0857:                            }
0858:
0859:                            syllabusService.draftChangeSyllabus(getEntry()
0860:                                    .getEntry());
0861:                        }
0862:                    }
0863:
0864:                    entries.clear();
0865:                    entry = null;
0866:                    attachments.clear();
0867:                    oldAttachments.clear();
0868:
0869:                    return "main_edit";
0870:                } catch (Exception e) {
0871:                    logger
0872:                            .info(this  + ".processReadSave in SyllabusTool: "
0873:                                    + e);
0874:                    FacesContext.getCurrentInstance().addMessage(
0875:                            null,
0876:                            MessageFactory.getMessage(FacesContext
0877:                                    .getCurrentInstance(), "error_permission",
0878:                                    (new Object[] { e.toString() })));
0879:                }
0880:
0881:                return null;
0882:            }
0883:
0884:            public String processReadPost() throws PermissionException {
0885:                //logger.info(this + ".processReadPost() in SyllabusTool");
0886:
0887:                try {
0888:                    displayTitleErroMsg = false;
0889:                    displayEvilTagMsg = false;
0890:                    if (!this .checkAccess()) {
0891:                        return "permission_error";
0892:                    } else {
0893:                        if (entry.getEntry().getTitle() == null) {
0894:                            displayTitleErroMsg = true;
0895:                            return "read";
0896:                        } else if (entry.getEntry().getTitle().trim()
0897:                                .equals("")) {
0898:                            displayTitleErroMsg = true;
0899:                            return "read";
0900:                        }
0901:                        if (entry.getEntry().getAsset() != null) {
0902:                            StringBuffer alertMsg = new StringBuffer();
0903:                            String errorMsg = null;
0904:                            try {
0905:                                errorMsg = FormattedText.processFormattedText(
0906:                                        entry.getEntry().getAsset(), alertMsg);
0907:                                if (alertMsg.length() > 0) {
0908:                                    evilTagMsg = alertMsg.toString();
0909:                                    displayEvilTagMsg = true;
0910:                                    return "edit";
0911:                                }
0912:                            } catch (Exception e) {
0913:                                logger.warn(this  + " " + errorMsg, e);
0914:                            }
0915:                        }
0916:                        if (entry.justCreated == false) {
0917:                            getEntry().getEntry().setStatus("Posted");
0918:                            syllabusManager.saveSyllabus(getEntry().getEntry());
0919:
0920:                            syllabusService.postChangeSyllabus(getEntry()
0921:                                    .getEntry());
0922:
0923:                            for (int i = 0; i < attachments.size(); i++) {
0924:                                syllabusManager
0925:                                        .addSyllabusAttachToSyllabusData(
0926:                                                getEntry().getEntry(),
0927:                                                (SyllabusAttachment) attachments
0928:                                                        .get(i));
0929:                            }
0930:
0931:                            entries.clear();
0932:                            entry = null;
0933:                            attachments.clear();
0934:                            oldAttachments.clear();
0935:
0936:                            return "main_edit";
0937:                        }
0938:                    }
0939:                } catch (Exception e) {
0940:                    logger
0941:                            .info(this  + ".processReadPost in SyllabusTool: "
0942:                                    + e);
0943:                    FacesContext.getCurrentInstance().addMessage(
0944:                            null,
0945:                            MessageFactory.getMessage(FacesContext
0946:                                    .getCurrentInstance(), "error_permission",
0947:                                    (new Object[] { e.toString() })));
0948:                }
0949:
0950:                return null;
0951:            }
0952:
0953:            public void downOnePlace(SyllabusData en) {
0954:                //logger.info(this + ".downOnePlace() in SyllabusTool");
0955:
0956:                SyllabusData swapData = null;
0957:                Iterator iter = syllabusManager.getSyllabiForSyllabusItem(
0958:                        syllabusItem).iterator();
0959:                while (iter.hasNext()) {
0960:                    SyllabusData data = (SyllabusData) iter.next();
0961:                    if (en.equals(data)) {
0962:                        if (iter.hasNext())
0963:                            swapData = (SyllabusData) iter.next();
0964:                        break;
0965:                    }
0966:                }
0967:
0968:                if (swapData != null)
0969:                    syllabusManager.swapSyllabusDataPositions(syllabusItem, en,
0970:                            swapData);
0971:
0972:                entries.clear();
0973:                entry = null;
0974:            }
0975:
0976:            public void upOnePlace(SyllabusData en) {
0977:                //logger.info(this + ".upOnePlace() in SyllabusTool");
0978:
0979:                SyllabusData swapData = null;
0980:                Iterator iter = syllabusManager.getSyllabiForSyllabusItem(
0981:                        syllabusItem).iterator();
0982:                while (iter.hasNext()) {
0983:                    SyllabusData data = (SyllabusData) iter.next();
0984:                    if (en.equals(data)) {
0985:                        break;
0986:                    } else {
0987:                        swapData = data;
0988:                    }
0989:                }
0990:
0991:                if (swapData != null)
0992:                    syllabusManager.swapSyllabusDataPositions(syllabusItem, en,
0993:                            swapData);
0994:
0995:                entries.clear();
0996:                entry = null;
0997:            }
0998:
0999:            public String processEditPreview() {
1000:                displayTitleErroMsg = false;
1001:                displayEvilTagMsg = false;
1002:                if (entry.getEntry().getTitle() == null) {
1003:                    displayTitleErroMsg = true;
1004:                    return "edit";
1005:                }
1006:                if (entry.getEntry().getTitle().trim().equals("")) {
1007:                    displayTitleErroMsg = true;
1008:                    return "edit";
1009:                }
1010:                if (entry.getEntry().getAsset() != null) {
1011:                    StringBuffer alertMsg = new StringBuffer();
1012:                    String errorMsg = null;
1013:                    try {
1014:                        errorMsg = FormattedText.processFormattedText(entry
1015:                                .getEntry().getAsset(), alertMsg);
1016:                        if (alertMsg.length() > 0) {
1017:                            evilTagMsg = alertMsg.toString();
1018:                            displayEvilTagMsg = true;
1019:                            return "edit";
1020:                        }
1021:                    } catch (Exception e) {
1022:                        logger.warn(this  + " " + errorMsg, e);
1023:                    }
1024:                }
1025:                return "preview";
1026:
1027:            }
1028:
1029:            public String processEditPreviewBack() {
1030:                return "edit";
1031:            }
1032:
1033:            public String processReadPreview() {
1034:                displayTitleErroMsg = false;
1035:                displayEvilTagMsg = false;
1036:                if (entry.getEntry().getTitle() == null) {
1037:                    displayTitleErroMsg = true;
1038:                    return "read";
1039:                }
1040:                if (entry.getEntry().getTitle().trim().equals("")) {
1041:                    displayTitleErroMsg = true;
1042:                    return "read";
1043:                }
1044:                if (entry.getEntry().getAsset() != null) {
1045:                    StringBuffer alertMsg = new StringBuffer();
1046:                    String errorMsg = null;
1047:                    try {
1048:                        errorMsg = FormattedText.processFormattedText(entry
1049:                                .getEntry().getAsset(), alertMsg);
1050:                        if (alertMsg.length() > 0) {
1051:                            evilTagMsg = alertMsg.toString();
1052:                            displayEvilTagMsg = true;
1053:                            return "edit";
1054:                        }
1055:                    } catch (Exception e) {
1056:                        logger.warn(this  + " " + errorMsg, e);
1057:                    }
1058:                }
1059:                return "read_preview";
1060:
1061:            }
1062:
1063:            public String processReadPreviewBack() {
1064:                return "read";
1065:            }
1066:
1067:            public String processEditUpload() {
1068:                //TODO let the filter work and upload...
1069:                /*
1070:                 * try { FacesContext fc = FacesContext.getCurrentInstance(); ExternalContext exFc =
1071:                 * fc.getExternalContext(); HttpServletRequest currentRequest = (HttpServletRequest)
1072:                 * exFc.getRequest(); String[] fileNames ={filename}; org.apache.commons.fileupload.FileUploadBase
1073:                 * fu = new org.apache.commons.fileupload.DiskFileUpload(); HttpServletRequest req =
1074:                 * HttpServletRequestFactory.createValidHttpServletRequest(fileNames); java.util.List itemList =
1075:                 * fu.parseRequest(req); } catch(Exception e) { e.printStackTrace(); }
1076:                 */
1077:
1078:                filename = null;
1079:                return "edit";
1080:            }
1081:
1082:            public String processReadUpload() {
1083:                //TODO let the filter work and upload...
1084:                filename = null;
1085:                return "read";
1086:            }
1087:
1088:            public String processRedirect() throws PermissionException {
1089:                try {
1090:                    if (!this .checkAccess()) {
1091:                        return "permission_error";
1092:                    } else {
1093:                        currentRediredUrl = syllabusItem.getRedirectURL();
1094:
1095:                        return "edit_redirect";
1096:                    }
1097:                } catch (Exception e) {
1098:                    logger
1099:                            .info(this  + ".processRedirect in SyllabusTool: "
1100:                                    + e);
1101:                    FacesContext.getCurrentInstance().addMessage(
1102:                            null,
1103:                            MessageFactory.getMessage(FacesContext
1104:                                    .getCurrentInstance(), "error_permission",
1105:                                    (new Object[] { e.toString() })));
1106:                }
1107:                return null;
1108:            }
1109:
1110:            public String processEditCancelRedirect() {
1111:                //logger.info(this + ".processEditCancelRedirect() in SyllabusTool ");
1112:
1113:                entries.clear();
1114:                entry = null;
1115:
1116:                return "main_edit";
1117:            }
1118:
1119:            public String processEditSaveRedirect() throws PermissionException {
1120:                //logger.info(this + ".processEditSaveRedirect() in SyllabusTool");
1121:
1122:                try {
1123:                    if (!this .checkAccess()) {
1124:                        return "permission_error";
1125:                    } else {
1126:                        currentRediredUrl = currentRediredUrl.replaceAll("\"",
1127:                                "");
1128:                        syllabusItem.setRedirectURL(currentRediredUrl);
1129:                        syllabusManager.saveSyllabusItem(syllabusItem);
1130:
1131:                        entries.clear();
1132:                        entry = null;
1133:                    }
1134:
1135:                    return "main_edit";
1136:                } catch (Exception e) {
1137:                    logger.info(this 
1138:                            + ".processEditSaveRedirect in SyllabusTool: " + e);
1139:                    FacesContext.getCurrentInstance().addMessage(
1140:                            null,
1141:                            MessageFactory.getMessage(FacesContext
1142:                                    .getCurrentInstance(), "error_permission",
1143:                                    (new Object[] { e.toString() })));
1144:                }
1145:
1146:                return null;
1147:            }
1148:
1149:            public String processCreateAndEdit() {
1150:                //logger.info(this + ".processCreateAndEdit() in SyllabusTool");
1151:
1152:                try {
1153:                    if (!this .checkAccess()) {
1154:                        return "permission_error";
1155:                    } else {
1156:                        //      syllabusManager.saveSyllabusItem(syllabusItem);
1157:
1158:                        entries.clear();
1159:                        entry = null;
1160:                        attachments.clear();
1161:                        oldAttachments.clear();
1162:                    }
1163:
1164:                    return "main_edit";
1165:                } catch (Exception e) {
1166:                    logger.info(this 
1167:                            + ".processCreateAndEdit() in SyllabusTool: " + e);
1168:                    FacesContext.getCurrentInstance().addMessage(
1169:                            null,
1170:                            MessageFactory.getMessage(FacesContext
1171:                                    .getCurrentInstance(), "error_permission",
1172:                                    (new Object[] { e.toString() })));
1173:                }
1174:                return null;
1175:            }
1176:
1177:            public String processStudentView() {
1178:                return "main";
1179:            }
1180:
1181:            public boolean checkAccess() {
1182:                //sakai2 - use Placement to get context instead of getting currentSitePageId from PortalService in sakai.
1183:                Placement placement = ToolManager.getCurrentPlacement();
1184:                String currentSiteId = placement.getContext();
1185:                boolean allowOrNot = SiteService.allowUpdateSite(currentSiteId);
1186:                return SiteService.allowUpdateSite(currentSiteId);
1187:            }
1188:
1189:            public String getTitle() {
1190:                ////return SiteService.findTool(PortalService.getCurrentToolId()).getTitle();
1191:                Placement placement = ToolManager.getCurrentPlacement();
1192:                return SiteService.findTool(placement.getToolId()).getTitle();
1193:
1194:            }
1195:
1196:            /*test send email.  private void sendNotification()
1197:             {
1198:             String realmName = "/site/" + siteId;
1199:             try
1200:             {
1201:             AuthzGroup siteRealm = AuthzGroupService.getRealm(realmName);
1202:             Set users = siteRealm.getUsers();
1203:            
1204:             if(entry.getEntry().getEmailNotification().equalsIgnoreCase("high"))
1205:             {
1206:             Iterator userIter = users.iterator();
1207:             String userId;
1208:             User thisUser;
1209:             while(userIter.hasNext())
1210:             {
1211:             userId = (String) userIter.next();
1212:             thisUser = UserDirectoryService.getUser(userId);
1213:             if(thisUser.getEmail() != null)
1214:             {
1215:             if(!thisUser.getEmail().equalsIgnoreCase(""))
1216:             {
1217:             EmailService.send("cwen@iupui.edu", thisUser.getEmail(), entry.getEntry().getTitle(), 
1218:             entry.getEntry().getAsset(), null, null, null);
1219:             }
1220:             }
1221:             }
1222:             }
1223:             else if(this.entry.in_entry.getEmailNotification().equalsIgnoreCase("low"))
1224:             {
1225:             }
1226:             else
1227:             {
1228:             }
1229:             }
1230:             catch(Exception e)
1231:             {
1232:             logger.info(this + ".sendNotification() in SyllabusTool.");
1233:             e.printStackTrace();
1234:             }
1235:             //for test    EmailService.send("cwen@iupui.edu", "cwen@iupui.edu", entry.getEntry().getTitle(), 
1236:             //for test        entry.getEntry().getAsset(), null, null, null);
1237:             }*/
1238:
1239:            public SyllabusService getSyllabusService() {
1240:                return syllabusService;
1241:            }
1242:
1243:            public void setSyllabusService(SyllabusService syllabusService) {
1244:                this .syllabusService = syllabusService;
1245:            }
1246:
1247:            public String processAddAttRead() {
1248:                if (entry.getEntry().getTitle() == null) {
1249:                    displayTitleErroMsg = true;
1250:                    return "edit";
1251:                } else if (entry.getEntry().getTitle().trim().equals("")) {
1252:                    displayTitleErroMsg = true;
1253:                    return "edit";
1254:                } else {
1255:                    displayTitleErroMsg = false;
1256:                    return "add_attach";
1257:                }
1258:            }
1259:
1260:            public String processUpload(ValueChangeEvent event) {
1261:                if (attachCaneled == false) {
1262:                    UIComponent component = event.getComponent();
1263:                    Object newValue = event.getNewValue();
1264:                    Object oldValue = event.getOldValue();
1265:                    PhaseId phaseId = event.getPhaseId();
1266:                    Object source = event.getSource();
1267:
1268:                    if (newValue instanceof  String)
1269:                        return "";
1270:                    if (newValue == null)
1271:                        return "";
1272:
1273:                    try {
1274:                        FileItem item = (FileItem) event.getNewValue();
1275:                        String fileName = item.getName();
1276:                        byte[] fileContents = item.get();
1277:
1278:                        ResourcePropertiesEdit props = ContentHostingService
1279:                                .newResourceProperties();
1280:
1281:                        String tempS = fileName;
1282:                        //logger.info(tempS);
1283:                        int lastSlash = tempS.lastIndexOf("/") > tempS
1284:                                .lastIndexOf("\\") ? tempS.lastIndexOf("/")
1285:                                : tempS.lastIndexOf("\\");
1286:                        if (lastSlash > 0)
1287:                            fileName = tempS.substring(lastSlash + 1);
1288:
1289:                        ContentResource this Attach = ContentHostingService
1290:                                .addAttachmentResource(fileName, item
1291:                                        .getContentType(), fileContents, props);
1292:
1293:                        SyllabusAttachment attachObj = syllabusManager
1294:                                .createSyllabusAttachmentObject(this Attach
1295:                                        .getId(), fileName);
1296:                        ////////revise        syllabusManager.addSyllabusAttachToSyllabusData(getEntry().getEntry(), attachObj);
1297:                        attachments.add(attachObj);
1298:
1299:                        String ss = this Attach.getUrl();
1300:                        String fileWithWholePath = this Attach.getUrl();
1301:
1302:                        ContentResource getAttach = ContentHostingService
1303:                                .getResource(this Attach.getId());
1304:
1305:                        String s = ss;
1306:
1307:                        if (entry.justCreated != true) {
1308:                            allAttachments.add(attachObj);
1309:                        }
1310:                    } catch (Exception e) {
1311:                        logger.error(this  + ".processUpload() in SyllabusTool "
1312:                                + e);
1313:                        e.printStackTrace();
1314:                    }
1315:                    if (entry.justCreated == true) {
1316:                        return "edit";
1317:                    } else {
1318:                        return "read";
1319:                    }
1320:                }
1321:                return null;
1322:            }
1323:
1324:            public String processUploadConfirm() {
1325:                //attachCaneled = false;
1326:                if (this .entry.justCreated == true)
1327:                    return "edit";
1328:                else {
1329:                    return "read";
1330:                }
1331:            }
1332:
1333:            public String processUploadCancel() {
1334:                //attachCaneled = true;
1335:                if (this .entry.justCreated == true)
1336:                    return "edit";
1337:                else
1338:                    return "read";
1339:            }
1340:
1341:            public ArrayList getAttachments() {
1342:                ToolSession session = SessionManager.getCurrentToolSession();
1343:                if (session.getAttribute(FilePickerHelper.FILE_PICKER_CANCEL) == null
1344:                        && session
1345:                                .getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS) != null) {
1346:                    List refs = (List) session
1347:                            .getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS);
1348:                    Reference ref = null;
1349:
1350:                    for (int i = 0; i < refs.size(); i++) {
1351:                        ref = (Reference) refs.get(i);
1352:                        SyllabusAttachment this Attach = syllabusManager
1353:                                .createSyllabusAttachmentObject(
1354:                                        ref.getId(),
1355:                                        ref
1356:                                                .getProperties()
1357:                                                .getProperty(
1358:                                                        ref
1359:                                                                .getProperties()
1360:                                                                .getNamePropDisplayName()));
1361:
1362:                        attachments.add(this Attach);
1363:
1364:                        if (entry.justCreated != true) {
1365:                            allAttachments.add(this Attach);
1366:                        }
1367:                    }
1368:                }
1369:                session
1370:                        .removeAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS);
1371:                session.removeAttribute(FilePickerHelper.FILE_PICKER_CANCEL);
1372:                if (filePickerList != null)
1373:                    filePickerList.clear();
1374:
1375:                return attachments;
1376:            }
1377:
1378:            public void setAttachments(ArrayList attachments) {
1379:                this .attachments = attachments;
1380:            }
1381:
1382:            public boolean getAttachCaneled() {
1383:                return attachCaneled;
1384:            }
1385:
1386:            public void setAttachCaneled(boolean attachCaneled) {
1387:                this .attachCaneled = attachCaneled;
1388:            }
1389:
1390:            public String processDeleteAttach() {
1391:                ExternalContext context = FacesContext.getCurrentInstance()
1392:                        .getExternalContext();
1393:                String attachId = null;
1394:
1395:                Map paramMap = context.getRequestParameterMap();
1396:                Iterator itr = paramMap.keySet().iterator();
1397:                while (itr.hasNext()) {
1398:                    Object key = itr.next();
1399:                    if (key instanceof  String) {
1400:                        String name = (String) key;
1401:                        int pos = name.lastIndexOf("syllabus_current_attach");
1402:
1403:                        if (pos >= 0
1404:                                && name.length() == pos
1405:                                        + "syllabus_current_attach".length()) {
1406:                            attachId = (String) paramMap.get(key);
1407:                            break;
1408:                        }
1409:                    }
1410:                }
1411:
1412:                removeAttachId = attachId;
1413:
1414:                if ((removeAttachId != null) && (!removeAttachId.equals("")))
1415:                    return "remove_attach_confirm";
1416:                else
1417:                    return null;
1418:            }
1419:
1420:            public String processRemoveAttach() {
1421:                if (entry.justCreated == true) {
1422:                    try {
1423:                        SyllabusAttachment sa = syllabusManager
1424:                                .getSyllabusAttachment(removeAttachId);
1425:                        String id = sa.getAttachmentId();
1426:
1427:                        for (int i = 0; i < attachments.size(); i++) {
1428:                            SyllabusAttachment this Attach = (SyllabusAttachment) attachments
1429:                                    .get(i);
1430:                            if (((Long) this Attach.getSyllabusAttachId())
1431:                                    .toString().equals(removeAttachId)) {
1432:                                attachments.remove(i);
1433:                                break;
1434:                            }
1435:                        }
1436:
1437:                        ContentResource cr = ContentHostingService
1438:                                .getResource(id);
1439:                        syllabusManager.removeSyllabusAttachmentObject(sa);
1440:                        if (id.toLowerCase().startsWith("/attachment"))
1441:                            ContentHostingService.removeResource(id);
1442:                    } catch (Exception e) {
1443:                        logger.error(this  + ".processRemoveAttach() - " + e);
1444:                        e.printStackTrace();
1445:                    }
1446:
1447:                    removeAttachId = null;
1448:                    prepareRemoveAttach.clear();
1449:                    return "edit";
1450:                } else {
1451:                    try {
1452:                        SyllabusAttachment sa = syllabusManager
1453:                                .getSyllabusAttachment(removeAttachId);
1454:                        String id = sa.getAttachmentId();
1455:                        boolean deleted = false;
1456:
1457:                        for (int i = 0; i < attachments.size(); i++) {
1458:                            SyllabusAttachment this Attach = (SyllabusAttachment) attachments
1459:                                    .get(i);
1460:                            if (((Long) this Attach.getSyllabusAttachId())
1461:                                    .toString().equals(removeAttachId)) {
1462:                                attachments.remove(i);
1463:                                deleted = true;
1464:                                break;
1465:                            }
1466:                        }
1467:                        if (deleted == false) {
1468:                            for (int i = 0; i < oldAttachments.size(); i++) {
1469:                                SyllabusAttachment this Attach = (SyllabusAttachment) oldAttachments
1470:                                        .get(i);
1471:                                if (((Long) this Attach.getSyllabusAttachId())
1472:                                        .toString().equals(removeAttachId)) {
1473:                                    oldAttachments.remove(i);
1474:                                    break;
1475:                                }
1476:                            }
1477:                        }
1478:
1479:                        ContentResource cr = ContentHostingService
1480:                                .getResource(id);
1481:                        syllabusManager.removeSyllabusAttachmentObject(sa);
1482:                        if (id.toLowerCase().startsWith("/attachment"))
1483:                            ContentHostingService.removeResource(id);
1484:
1485:                        allAttachments.clear();
1486:                        for (int i = 0; i < attachments.size(); i++) {
1487:                            allAttachments.add((SyllabusAttachment) attachments
1488:                                    .get(i));
1489:                        }
1490:                        for (int i = 0; i < oldAttachments.size(); i++) {
1491:                            allAttachments
1492:                                    .add((SyllabusAttachment) oldAttachments
1493:                                            .get(i));
1494:                        }
1495:
1496:                    } catch (Exception e) {
1497:                        logger.error(this  + ".processRemoveAttach() - " + e);
1498:                        e.printStackTrace();
1499:                    }
1500:
1501:                    removeAttachId = null;
1502:                    prepareRemoveAttach.clear();
1503:                    return "read";
1504:                }
1505:            }
1506:
1507:            public String processRemoveAttachCancel() {
1508:                removeAttachId = null;
1509:                prepareRemoveAttach.clear();
1510:                if (entry.justCreated == true) {
1511:                    return "edit";
1512:                } else {
1513:                    return "read";
1514:                }
1515:            }
1516:
1517:            public String getRemoveAttachId() {
1518:                return removeAttachId;
1519:            }
1520:
1521:            public final void setRemoveAttachId(String removeAttachId) {
1522:                this .removeAttachId = removeAttachId;
1523:            }
1524:
1525:            public final ArrayList getOldAttachments() {
1526:                return oldAttachments;
1527:            }
1528:
1529:            public final void setOldAttachments(ArrayList oldAttachments) {
1530:                this .oldAttachments = oldAttachments;
1531:            }
1532:
1533:            public String processAddAttWithOldItem() {
1534:                if (entry.getEntry().getTitle() == null) {
1535:                    displayTitleErroMsg = true;
1536:                    return "read";
1537:                } else if (entry.getEntry().getTitle().trim().equals("")) {
1538:                    displayTitleErroMsg = true;
1539:                    return "read";
1540:                } else {
1541:                    displayTitleErroMsg = false;
1542:                    return "add_attach";
1543:                }
1544:            }
1545:
1546:            public final ArrayList getAllAttachments() {
1547:                ToolSession session = SessionManager.getCurrentToolSession();
1548:                if (session.getAttribute(FilePickerHelper.FILE_PICKER_CANCEL) == null
1549:                        && session
1550:                                .getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS) != null) {
1551:                    List refs = (List) session
1552:                            .getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS);
1553:                    Reference ref = null;
1554:
1555:                    for (int i = 0; i < refs.size(); i++) {
1556:                        ref = (Reference) refs.get(i);
1557:                        SyllabusAttachment this Attach = syllabusManager
1558:                                .createSyllabusAttachmentObject(
1559:                                        ref.getId(),
1560:                                        ref
1561:                                                .getProperties()
1562:                                                .getProperty(
1563:                                                        ref
1564:                                                                .getProperties()
1565:                                                                .getNamePropDisplayName()));
1566:
1567:                        attachments.add(this Attach);
1568:
1569:                        if (entry.justCreated != true) {
1570:                            allAttachments.add(this Attach);
1571:                        }
1572:                    }
1573:                }
1574:                session
1575:                        .removeAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS);
1576:                session.removeAttribute(FilePickerHelper.FILE_PICKER_CANCEL);
1577:                if (filePickerList != null)
1578:                    filePickerList.clear();
1579:
1580:                return allAttachments;
1581:            }
1582:
1583:            public final void setAllAttachments(ArrayList allAttachments) {
1584:                this .allAttachments = allAttachments;
1585:            }
1586:
1587:            public ArrayList getPrepareRemoveAttach() {
1588:                if ((removeAttachId != null) && (!removeAttachId.equals(""))) {
1589:                    prepareRemoveAttach.add(syllabusManager
1590:                            .getSyllabusAttachment(removeAttachId));
1591:                }
1592:
1593:                return prepareRemoveAttach;
1594:            }
1595:
1596:            public final void setPrepareRemoveAttach(
1597:                    ArrayList prepareRemoveAttach) {
1598:                this .prepareRemoveAttach = prepareRemoveAttach;
1599:            }
1600:
1601:            public String processAddAttachRedirect() {
1602:                try {
1603:                    filePickerList = EntityManager.newReferenceList();
1604:                    ToolSession currentToolSession = SessionManager
1605:                            .getCurrentToolSession();
1606:                    currentToolSession.setAttribute(
1607:                            FilePickerHelper.FILE_PICKER_ATTACHMENTS,
1608:                            filePickerList);
1609:                    ExternalContext context = FacesContext.getCurrentInstance()
1610:                            .getExternalContext();
1611:                    context.redirect("sakai.filepicker.helper/tool");
1612:                    return null;
1613:                } catch (Exception e) {
1614:                    logger.error(this  + ".processAddAttachRedirect - " + e);
1615:                    e.printStackTrace();
1616:                    return null;
1617:                }
1618:            }
1619:
1620:            public String getCurrentRediredUrl() {
1621:                return currentRediredUrl;
1622:            }
1623:
1624:            public void setCurrentRediredUrl(String currentRediredUrl) {
1625:                this .currentRediredUrl = currentRediredUrl;
1626:            }
1627:
1628:            /**
1629:             * @return
1630:             * 	String url if using an external url or
1631:             * 	'#' so current page appears in new window
1632:             */
1633:            public String getPrintFriendlyUrl() {
1634:                return ServerConfigurationService.getToolUrl()
1635:                        + Entity.SEPARATOR
1636:                        + ToolManager.getCurrentPlacement().getId()
1637:                        + Entity.SEPARATOR + "printFriendly";
1638:            }
1639:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.