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


0001:        /**********************************************************************************
0002:         * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/DiscussionForumServiceImpl.java $
0003:         * $Id: DiscussionForumServiceImpl.java 9227 2006-05-15 15:02:42Z cwen@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.component.app.messageforums;
0021:
0022:        import java.util.Collection;
0023:        import java.util.Iterator;
0024:        import java.util.List;
0025:        import java.util.Map;
0026:        import java.util.Set;
0027:        import java.util.Stack;
0028:        import java.util.Vector;
0029:        import java.util.HashSet;
0030:        import java.util.ArrayList;
0031:
0032:        import org.apache.commons.logging.Log;
0033:        import org.apache.commons.logging.LogFactory;
0034:        import org.apache.commons.codec.binary.Base64;
0035:        import org.sakaiproject.api.app.messageforums.Area;
0036:        import org.sakaiproject.api.app.messageforums.Attachment;
0037:        import org.sakaiproject.api.app.messageforums.DiscussionTopic;
0038:        import org.sakaiproject.api.app.messageforums.AreaManager;
0039:        import org.sakaiproject.api.app.messageforums.DiscussionForumService;
0040:        import org.sakaiproject.api.app.messageforums.DiscussionForum;
0041:        import org.sakaiproject.api.app.messageforums.MessageForumsForumManager;
0042:        import org.sakaiproject.api.app.messageforums.MessageForumsMessageManager;
0043:        import org.sakaiproject.api.app.messageforums.MessageForumsTypeManager;
0044:        import org.sakaiproject.api.app.messageforums.PermissionLevel;
0045:        import org.sakaiproject.api.app.messageforums.PermissionsMask;
0046:        import org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager;
0047:        import org.sakaiproject.api.app.messageforums.DBMembershipItem;
0048:        import org.sakaiproject.api.app.messageforums.PermissionLevelManager;
0049:        import org.sakaiproject.authz.api.AuthzGroup;
0050:        import org.sakaiproject.authz.cover.AuthzGroupService;
0051:        import org.sakaiproject.authz.api.GroupNotDefinedException;
0052:        import org.sakaiproject.authz.api.Role;
0053:        import org.sakaiproject.entity.api.Entity;
0054:        import org.sakaiproject.entity.api.EntityTransferrer;
0055:        import org.sakaiproject.entity.api.HttpAccess;
0056:        import org.sakaiproject.entity.api.Reference;
0057:        import org.sakaiproject.entity.api.ResourceProperties;
0058:        import org.sakaiproject.entity.cover.EntityManager;
0059:        import org.sakaiproject.exception.IdUnusedException;
0060:        import org.sakaiproject.component.cover.ComponentManager;
0061:        import org.sakaiproject.component.cover.ServerConfigurationService;
0062:        import org.sakaiproject.content.cover.ContentHostingService;
0063:        import org.sakaiproject.content.api.ContentResource;
0064:        import org.sakaiproject.service.gradebook.shared.GradebookService;
0065:        import org.sakaiproject.site.api.Group;
0066:        import org.sakaiproject.site.api.Site;
0067:        import org.sakaiproject.site.cover.SiteService;
0068:        import org.sakaiproject.tool.cover.ToolManager;
0069:        import org.sakaiproject.util.Validator;
0070:        import org.w3c.dom.DOMException;
0071:        import org.w3c.dom.Document;
0072:        import org.w3c.dom.Element;
0073:        import org.w3c.dom.Node;
0074:        import org.w3c.dom.NodeList;
0075:
0076:        public class DiscussionForumServiceImpl implements 
0077:                DiscussionForumService, EntityTransferrer {
0078:            private static final String MESSAGEFORUM = "messageforum";
0079:            private static final String DISCUSSION_FORUM = "discussion_forum";
0080:            private static final String DISCUSSION_TOPIC = "discussion_topic";
0081:            private static final String DISCUSSION_FORUM_TITLE = "category";
0082:            private static final String DISCUSSION_FORUM_DESC = "body";
0083:            private static final String DISCUSSION_FORUM_SHORT_DESC = "summary";
0084:            private static final String TOPIC_TITLE = "subject";
0085:            private static final String DRAFT = "draft";
0086:            private static final String LOCKED = "locked";
0087:            private static final String MODERATED = "moderated";
0088:            private static final String PROPERTIES = "properties";
0089:            private static final String PROPERTY = "property";
0090:            private static final String TOPIC_SHORT_DESC = "Classic:bboardForums_description";
0091:            private static final String TOPIC_LONG_DESC = "Classic:bboardForums_content";
0092:            private static final String NAME = "name";
0093:            private static final String ENCODE = "enc";
0094:            private static final String BASE64 = "BASE64";
0095:            private static final String VALUE = "value";
0096:            private static final String ATTACHMENT = "attachment";
0097:            private static final String ATTACH_ID = "relative-url";
0098:            private static final String PERMISSIONS = "permissions";
0099:            private static final String PERMISSION = "permission";
0100:            private static final String PERMISSION_TYPE = "permission_type";
0101:            private static final String PERMISSION_NAME = "permission_name";
0102:            private static final String PERMISSION_LEVEL_NAME = "permission_level_name";
0103:            private static final String CUSTOM_PERMISSIONS = "permission_levels";
0104:
0105:            private static final String ARCHIVE_VERSION = "2.4"; // in case new features are added in future exports
0106:            private static final String VERSION_ATTR = "version";
0107:
0108:            private MessageForumsForumManager forumManager;
0109:            private AreaManager areaManager;
0110:            private MessageForumsMessageManager messageManager;
0111:            private MessageForumsTypeManager typeManager;
0112:            private DiscussionForumManager dfManager;
0113:            private PermissionLevelManager permissionManager;
0114:
0115:            private static final Log LOG = LogFactory
0116:                    .getLog(DiscussionForumService.class);
0117:
0118:            public void init() throws Exception {
0119:                LOG.info("init()");
0120:                EntityManager.registerEntityProducer(this , REFERENCE_ROOT);
0121:            }
0122:
0123:            public String archive(String siteId, Document doc, Stack stack,
0124:                    String archivePath, List attachments) {
0125:                Base64 base64Encoder = new Base64();
0126:                StringBuffer results = new StringBuffer();
0127:
0128:                try {
0129:                    int forumCount = 0;
0130:                    results.append("archiving " + getLabel() + " context "
0131:                            + Entity.SEPARATOR + siteId + Entity.SEPARATOR
0132:                            + SiteService.MAIN_CONTAINER + ".\n");
0133:                    // start with an element with our very own (service) name
0134:                    Element element = doc
0135:                            .createElement(DiscussionForumService.class
0136:                                    .getName());
0137:                    element.setAttribute(VERSION_ATTR, ARCHIVE_VERSION);
0138:                    ((Element) stack.peek()).appendChild(element);
0139:                    stack.push(element);
0140:
0141:                    if (siteId != null && siteId.trim().length() > 0) {
0142:                        Area dfArea = areaManager.getAreaByContextIdAndTypeId(
0143:                                siteId, typeManager.getDiscussionForumType());
0144:
0145:                        if (dfArea != null) {
0146:                            Element dfElement = doc.createElement(MESSAGEFORUM);
0147:
0148:                            //List forums = dfManager.getDiscussionForumsByContextId(siteId);
0149:                            List forums = dfManager
0150:                                    .getDiscussionForumsWithTopicsMembershipNoAttachments(siteId);
0151:
0152:                            if (forums != null && !forums.isEmpty()) {
0153:                                Iterator forumsIter = forums.iterator();
0154:                                while (forumsIter.hasNext()) {
0155:                                    DiscussionForum forum = (DiscussionForum) forumsIter
0156:                                            .next();
0157:
0158:                                    if (forum != null) {
0159:                                        forumCount++;
0160:                                        Element df_data = doc
0161:                                                .createElement(DISCUSSION_FORUM);
0162:                                        df_data.setAttribute(
0163:                                                DISCUSSION_FORUM_TITLE, forum
0164:                                                        .getTitle());
0165:                                        df_data.setAttribute(DRAFT, forum
0166:                                                .getDraft().toString());
0167:                                        df_data.setAttribute(LOCKED, forum
0168:                                                .getLocked().toString());
0169:                                        df_data.setAttribute(MODERATED, forum
0170:                                                .getModerated().toString());
0171:
0172:                                        try {
0173:                                            String encoded = new String(
0174:                                                    base64Encoder
0175:                                                            .encode(forum
0176:                                                                    .getExtendedDescription()
0177:                                                                    .getBytes()));
0178:                                            df_data.setAttribute(
0179:                                                    DISCUSSION_FORUM_DESC,
0180:                                                    encoded);
0181:                                        } catch (Exception e) {
0182:                                            //LOG.warn("Encode DF Extended Desc - " + e);
0183:                                            df_data.setAttribute(
0184:                                                    DISCUSSION_FORUM_DESC, "");
0185:                                        }
0186:
0187:                                        try {
0188:                                            String encoded = new String(
0189:                                                    base64Encoder
0190:                                                            .encode(forum
0191:                                                                    .getShortDescription()
0192:                                                                    .getBytes()));
0193:                                            df_data
0194:                                                    .setAttribute(
0195:                                                            DISCUSSION_FORUM_SHORT_DESC,
0196:                                                            encoded);
0197:                                        } catch (Exception e) {
0198:                                            //LOG.warn("Encode DF Short Desc - " + e);
0199:                                            df_data
0200:                                                    .setAttribute(
0201:                                                            DISCUSSION_FORUM_SHORT_DESC,
0202:                                                            "");
0203:                                        }
0204:
0205:                                        List atts = forumManager.getForumById(
0206:                                                true, forum.getId())
0207:                                                .getAttachments();
0208:                                        for (int i = 0; i < atts.size(); i++) {
0209:                                            Element forum_attachment = doc
0210:                                                    .createElement(ATTACHMENT);
0211:                                            String attachId = ((Attachment) atts
0212:                                                    .get(i)).getAttachmentId();
0213:
0214:                                            forum_attachment.setAttribute(
0215:                                                    ATTACH_ID, attachId);
0216:                                            df_data
0217:                                                    .appendChild(forum_attachment);
0218:                                        }
0219:
0220:                                        Set forumMembershipItems = forum
0221:                                                .getMembershipItemSet();
0222:                                        if (forumMembershipItems != null
0223:                                                && forumMembershipItems.size() > 0) {
0224:                                            Element forum_permissions = doc
0225:                                                    .createElement(PERMISSIONS);
0226:                                            Iterator membershipIter = forumMembershipItems
0227:                                                    .iterator();
0228:                                            while (membershipIter.hasNext()) {
0229:                                                DBMembershipItem membershipItem = (DBMembershipItem) membershipIter
0230:                                                        .next();
0231:                                                Element permission = doc
0232:                                                        .createElement(PERMISSION);
0233:                                                permission.setAttribute(
0234:                                                        PERMISSION_TYPE,
0235:                                                        membershipItem
0236:                                                                .getType()
0237:                                                                .toString());
0238:                                                permission.setAttribute(
0239:                                                        PERMISSION_NAME,
0240:                                                        membershipItem
0241:                                                                .getName());
0242:                                                permission
0243:                                                        .setAttribute(
0244:                                                                PERMISSION_LEVEL_NAME,
0245:                                                                membershipItem
0246:                                                                        .getPermissionLevelName());
0247:
0248:                                                if (PermissionLevelManager.PERMISSION_LEVEL_NAME_CUSTOM
0249:                                                        .equals(membershipItem
0250:                                                                .getPermissionLevelName())) {
0251:                                                    List customPerms = permissionManager
0252:                                                            .getCustomPermissions();
0253:                                                    if (customPerms != null
0254:                                                            && customPerms
0255:                                                                    .size() > 0) {
0256:                                                        Element customPermissions = doc
0257:                                                                .createElement(CUSTOM_PERMISSIONS);
0258:                                                        for (int i = 0; i < customPerms
0259:                                                                .size(); i++) {
0260:                                                            String name = (String) customPerms
0261:                                                                    .get(i);
0262:                                                            String hasPermission = permissionManager
0263:                                                                    .getCustomPermissionByName(
0264:                                                                            name,
0265:                                                                            membershipItem
0266:                                                                                    .getPermissionLevel())
0267:                                                                    .toString();
0268:                                                            customPermissions
0269:                                                                    .setAttribute(
0270:                                                                            name,
0271:                                                                            hasPermission);
0272:                                                        }
0273:                                                        permission
0274:                                                                .appendChild(customPermissions);
0275:                                                    }
0276:                                                }
0277:
0278:                                                forum_permissions
0279:                                                        .appendChild(permission);
0280:                                            }
0281:                                            df_data
0282:                                                    .appendChild(forum_permissions);
0283:                                        }
0284:
0285:                                        List topicList = dfManager
0286:                                                .getTopicsByIdWithMessagesMembershipAndAttachments(forum
0287:                                                        .getId());
0288:                                        if (topicList != null
0289:                                                && topicList.size() > 0) {
0290:                                            Iterator topicIter = topicList
0291:                                                    .iterator();
0292:                                            while (topicIter.hasNext()) {
0293:                                                DiscussionTopic topic = (DiscussionTopic) topicIter
0294:                                                        .next();
0295:                                                Element topic_data = doc
0296:                                                        .createElement(DISCUSSION_TOPIC);
0297:                                                topic_data.setAttribute(
0298:                                                        TOPIC_TITLE, topic
0299:                                                                .getTitle());
0300:                                                topic_data.setAttribute(DRAFT,
0301:                                                        topic.getDraft()
0302:                                                                .toString());
0303:                                                topic_data.setAttribute(LOCKED,
0304:                                                        topic.getLocked()
0305:                                                                .toString());
0306:                                                topic_data.setAttribute(
0307:                                                        MODERATED, topic
0308:                                                                .getModerated()
0309:                                                                .toString());
0310:
0311:                                                Element topic_properties = doc
0312:                                                        .createElement(PROPERTIES);
0313:                                                Element topic_short_desc = doc
0314:                                                        .createElement(PROPERTY);
0315:
0316:                                                try {
0317:                                                    String encoded = new String(
0318:                                                            base64Encoder
0319:                                                                    .encode(topic
0320:                                                                            .getShortDescription()
0321:                                                                            .getBytes()));
0322:                                                    topic_short_desc
0323:                                                            .setAttribute(NAME,
0324:                                                                    TOPIC_SHORT_DESC);
0325:                                                    topic_short_desc
0326:                                                            .setAttribute(
0327:                                                                    ENCODE,
0328:                                                                    BASE64);
0329:                                                    topic_short_desc
0330:                                                            .setAttribute(
0331:                                                                    VALUE,
0332:                                                                    encoded);
0333:                                                } catch (Exception e) {
0334:                                                    //LOG.warn("Encode Topic Short Desc - " + e);
0335:                                                    topic_short_desc
0336:                                                            .setAttribute(NAME,
0337:                                                                    TOPIC_SHORT_DESC);
0338:                                                    topic_short_desc
0339:                                                            .setAttribute(
0340:                                                                    ENCODE,
0341:                                                                    BASE64);
0342:                                                    topic_short_desc
0343:                                                            .setAttribute(
0344:                                                                    VALUE, "");
0345:                                                }
0346:
0347:                                                topic_properties
0348:                                                        .appendChild(topic_short_desc);
0349:
0350:                                                Element topic_long_desc = doc
0351:                                                        .createElement(PROPERTY);
0352:
0353:                                                try {
0354:                                                    String encoded = new String(
0355:                                                            base64Encoder
0356:                                                                    .encode(topic
0357:                                                                            .getExtendedDescription()
0358:                                                                            .getBytes()));
0359:                                                    topic_long_desc
0360:                                                            .setAttribute(NAME,
0361:                                                                    TOPIC_LONG_DESC);
0362:                                                    topic_long_desc
0363:                                                            .setAttribute(
0364:                                                                    ENCODE,
0365:                                                                    BASE64);
0366:                                                    topic_long_desc
0367:                                                            .setAttribute(
0368:                                                                    VALUE,
0369:                                                                    encoded);
0370:                                                } catch (Exception e) {
0371:                                                    //LOG.warn("Encode Topic Ext Desc - " + e);
0372:                                                    topic_long_desc
0373:                                                            .setAttribute(NAME,
0374:                                                                    TOPIC_LONG_DESC);
0375:                                                    topic_long_desc
0376:                                                            .setAttribute(
0377:                                                                    ENCODE,
0378:                                                                    BASE64);
0379:                                                    topic_long_desc
0380:                                                            .setAttribute(
0381:                                                                    VALUE, "");
0382:                                                }
0383:
0384:                                                topic_properties
0385:                                                        .appendChild(topic_long_desc);
0386:
0387:                                                topic_data
0388:                                                        .appendChild(topic_properties);
0389:
0390:                                                // permissions
0391:                                                Set topicMembershipItems = topic
0392:                                                        .getMembershipItemSet();
0393:                                                if (topicMembershipItems != null
0394:                                                        && topicMembershipItems
0395:                                                                .size() > 0) {
0396:                                                    Element topic_permissions = doc
0397:                                                            .createElement(PERMISSIONS);
0398:                                                    Iterator topicMembershipIter = topicMembershipItems
0399:                                                            .iterator();
0400:                                                    while (topicMembershipIter
0401:                                                            .hasNext()) {
0402:                                                        DBMembershipItem membershipItem = (DBMembershipItem) topicMembershipIter
0403:                                                                .next();
0404:                                                        Element permission = doc
0405:                                                                .createElement(PERMISSION);
0406:                                                        permission
0407:                                                                .setAttribute(
0408:                                                                        PERMISSION_TYPE,
0409:                                                                        membershipItem
0410:                                                                                .getType()
0411:                                                                                .toString());
0412:                                                        permission
0413:                                                                .setAttribute(
0414:                                                                        PERMISSION_NAME,
0415:                                                                        membershipItem
0416:                                                                                .getName());
0417:                                                        permission
0418:                                                                .setAttribute(
0419:                                                                        PERMISSION_LEVEL_NAME,
0420:                                                                        membershipItem
0421:                                                                                .getPermissionLevelName());
0422:                                                        topic_permissions
0423:                                                                .appendChild(permission);
0424:
0425:                                                        if (PermissionLevelManager.PERMISSION_LEVEL_NAME_CUSTOM
0426:                                                                .equals(membershipItem
0427:                                                                        .getPermissionLevelName())) {
0428:                                                            List customPerms = permissionManager
0429:                                                                    .getCustomPermissions();
0430:                                                            if (customPerms != null
0431:                                                                    && customPerms
0432:                                                                            .size() > 0) {
0433:                                                                Element customPermissions = doc
0434:                                                                        .createElement(CUSTOM_PERMISSIONS);
0435:                                                                for (int i = 0; i < customPerms
0436:                                                                        .size(); i++) {
0437:                                                                    String name = (String) customPerms
0438:                                                                            .get(i);
0439:                                                                    String hasPermission = permissionManager
0440:                                                                            .getCustomPermissionByName(
0441:                                                                                    name,
0442:                                                                                    membershipItem
0443:                                                                                            .getPermissionLevel())
0444:                                                                            .toString();
0445:                                                                    customPermissions
0446:                                                                            .setAttribute(
0447:                                                                                    name,
0448:                                                                                    hasPermission);
0449:                                                                }
0450:                                                                permission
0451:                                                                        .appendChild(customPermissions);
0452:                                                            }
0453:                                                        }
0454:                                                    }
0455:                                                    topic_data
0456:                                                            .appendChild(topic_permissions);
0457:                                                }
0458:
0459:                                                List topicAtts = forumManager
0460:                                                        .getTopicByIdWithAttachments(
0461:                                                                topic.getId())
0462:                                                        .getAttachments();
0463:                                                for (int j = 0; j < topicAtts
0464:                                                        .size(); j++) {
0465:                                                    Element topic_attachment = doc
0466:                                                            .createElement(ATTACHMENT);
0467:                                                    String attachId = ((Attachment) topicAtts
0468:                                                            .get(j))
0469:                                                            .getAttachmentId();
0470:
0471:                                                    topic_attachment
0472:                                                            .setAttribute(
0473:                                                                    ATTACH_ID,
0474:                                                                    attachId);
0475:                                                    topic_data
0476:                                                            .appendChild(topic_attachment);
0477:                                                }
0478:
0479:                                                df_data.appendChild(topic_data);
0480:                                            }
0481:                                        }
0482:
0483:                                        dfElement.appendChild(df_data);
0484:                                    }
0485:                                }
0486:                            }
0487:                            results
0488:                                    .append("archiving "
0489:                                            + getLabel()
0490:                                            + ": ("
0491:                                            + forumCount
0492:                                            + ") messageforum DF items archived successfully.\n");
0493:
0494:                            ((Element) stack.peek()).appendChild(dfElement);
0495:                            stack.push(dfElement);
0496:                        } else {
0497:                            results.append("archiving " + getLabel()
0498:                                    + ": empty messageforum DF archived.\n");
0499:                        }
0500:
0501:                    }
0502:                    stack.pop();
0503:
0504:                } catch (DOMException e) {
0505:                    LOG.error(e.getMessage(), e);
0506:                }
0507:                return results.toString();
0508:            }
0509:
0510:            public Entity getEntity(Reference ref) {
0511:                // TODO Auto-generated method stub
0512:                return null;
0513:            }
0514:
0515:            public Collection getEntityAuthzGroups(Reference ref, String userId) {
0516:                // TODO Auto-generated method stub
0517:                return null;
0518:            }
0519:
0520:            public String getEntityDescription(Reference ref) {
0521:                // TODO Auto-generated method stub
0522:                return null;
0523:            }
0524:
0525:            public ResourceProperties getEntityResourceProperties(Reference ref) {
0526:                // TODO Auto-generated method stub
0527:                return null;
0528:            }
0529:
0530:            public String getEntityUrl(Reference ref) {
0531:                // TODO Auto-generated method stub
0532:                return null;
0533:            }
0534:
0535:            public HttpAccess getHttpAccess() {
0536:                // TODO Auto-generated method stub
0537:                return null;
0538:            }
0539:
0540:            public String getLabel() {
0541:                return "messageforum";
0542:            }
0543:
0544:            public String[] myToolIds() {
0545:                String[] toolIds = { "sakai.messagecenter", "sakai.forums" };
0546:                return toolIds;
0547:            }
0548:
0549:            public void transferCopyEntities(String fromContext,
0550:                    String toContext, List ids) {
0551:                try {
0552:                    LOG.debug("transfer copy mc items by transferCopyEntities");
0553:
0554:                    //List fromDfList = dfManager.getDiscussionForumsByContextId(fromContext);
0555:                    List fromDfList = dfManager
0556:                            .getDiscussionForumsWithTopicsMembershipNoAttachments(fromContext);
0557:
0558:                    if (fromDfList != null && !fromDfList.isEmpty()) {
0559:                        for (int currForum = 0; currForum < fromDfList.size(); currForum++) {
0560:                            DiscussionForum fromForum = (DiscussionForum) fromDfList
0561:                                    .get(currForum);
0562:                            Long fromForumId = fromForum.getId();
0563:
0564:                            DiscussionForum newForum = forumManager
0565:                                    .createDiscussionForum();
0566:                            newForum.setTitle(fromForum.getTitle());
0567:
0568:                            if (fromForum.getShortDescription() != null
0569:                                    && fromForum.getShortDescription().length() > 0)
0570:                                newForum.setShortDescription(fromForum
0571:                                        .getShortDescription());
0572:
0573:                            if (fromForum.getExtendedDescription() != null
0574:                                    && fromForum.getExtendedDescription()
0575:                                            .length() > 0)
0576:                                newForum.setExtendedDescription(fromForum
0577:                                        .getExtendedDescription());
0578:
0579:                            newForum.setDraft(fromForum.getDraft());
0580:                            newForum.setLocked(fromForum.getLocked());
0581:                            newForum.setModerated(fromForum.getModerated());
0582:
0583:                            // get permissions for "from" site
0584:                            Set membershipItemSet = fromForum
0585:                                    .getMembershipItemSet();
0586:                            List allowedPermNames = this 
0587:                                    .getSiteRolesAndGroups(toContext);
0588:
0589:                            if (membershipItemSet != null
0590:                                    && !membershipItemSet.isEmpty()
0591:                                    && allowedPermNames != null
0592:                                    && !allowedPermNames.isEmpty()) {
0593:                                Iterator membershipIter = membershipItemSet
0594:                                        .iterator();
0595:                                while (membershipIter.hasNext()) {
0596:                                    DBMembershipItem oldItem = (DBMembershipItem) membershipIter
0597:                                            .next();
0598:                                    if (allowedPermNames.contains(oldItem
0599:                                            .getName())) {
0600:
0601:                                        DBMembershipItem newItem = getMembershipItemCopy(oldItem);
0602:                                        if (newItem != null) {
0603:                                            permissionManager
0604:                                                    .saveDBMembershipItem(newItem);
0605:                                            newForum.addMembershipItem(newItem);
0606:                                        }
0607:                                    }
0608:                                }
0609:                            }
0610:
0611:                            // get/add the forum's attachments
0612:                            List fromAttach = forumManager.getForumById(true,
0613:                                    fromForumId).getAttachments();
0614:                            if (fromAttach != null && !fromAttach.isEmpty()) {
0615:                                for (int currAttach = 0; currAttach < fromAttach
0616:                                        .size(); currAttach++) {
0617:                                    Attachment this Attach = (Attachment) fromAttach
0618:                                            .get(currAttach);
0619:                                    Attachment newAttachment = copyAttachment(this Attach
0620:                                            .getAttachmentId());
0621:                                    if (newForum != null
0622:                                            && newAttachment != null)
0623:                                        newForum.addAttachment(newAttachment);
0624:                                }
0625:                            }
0626:
0627:                            // get/add the gradebook assignment associated with the forum settings
0628:                            GradebookService gradebookService = (org.sakaiproject.service.gradebook.shared.GradebookService) ComponentManager
0629:                                    .get("org.sakaiproject.service.gradebook.GradebookService");
0630:                            String gradebookUid = ToolManager
0631:                                    .getCurrentPlacement().getContext();
0632:
0633:                            if (gradebookService
0634:                                    .isGradebookDefined(gradebookUid)) {
0635:                                String fromAssignmentTitle = fromForum
0636:                                        .getDefaultAssignName();
0637:                                if (gradebookService.isAssignmentDefined(
0638:                                        gradebookUid, fromAssignmentTitle)) {
0639:                                    newForum
0640:                                            .setDefaultAssignName(fromAssignmentTitle);
0641:                                }
0642:                            }
0643:
0644:                            // save the forum
0645:                            Area area = areaManager.getDiscusionArea();
0646:                            newForum.setArea(area);
0647:
0648:                            if ("false"
0649:                                    .equalsIgnoreCase(ServerConfigurationService
0650:                                            .getString("import.importAsDraft"))) {
0651:                                forumManager.saveDiscussionForum(newForum,
0652:                                        newForum.getDraft().booleanValue());
0653:                            } else {
0654:                                newForum.setDraft(new Boolean("true"));
0655:                                forumManager
0656:                                        .saveDiscussionForum(newForum, true);
0657:                            }
0658:
0659:                            // get/add the topics
0660:                            List topicList = dfManager
0661:                                    .getTopicsByIdWithMessagesMembershipAndAttachments(fromForumId);
0662:                            if (topicList != null && !topicList.isEmpty()) {
0663:                                for (int currTopic = 0; currTopic < topicList
0664:                                        .size(); currTopic++) {
0665:                                    DiscussionTopic fromTopic = (DiscussionTopic) topicList
0666:                                            .get(currTopic);
0667:                                    Long fromTopicId = fromTopic.getId();
0668:
0669:                                    DiscussionTopic newTopic = forumManager
0670:                                            .createDiscussionForumTopic(newForum);
0671:
0672:                                    newTopic.setTitle(fromTopic.getTitle());
0673:                                    if (fromTopic.getShortDescription() != null
0674:                                            && fromTopic.getShortDescription()
0675:                                                    .length() > 0)
0676:                                        newTopic.setShortDescription(fromTopic
0677:                                                .getShortDescription());
0678:                                    if (fromTopic.getExtendedDescription() != null
0679:                                            && fromTopic
0680:                                                    .getExtendedDescription()
0681:                                                    .length() > 0)
0682:                                        newTopic
0683:                                                .setExtendedDescription(fromTopic
0684:                                                        .getExtendedDescription());
0685:                                    newTopic.setLocked(fromTopic.getLocked());
0686:                                    newTopic.setDraft(fromTopic.getDraft());
0687:                                    newTopic.setModerated(fromTopic
0688:                                            .getModerated());
0689:
0690:                                    // Get/set the topic's permissions
0691:                                    Set topicMembershipItemSet = fromTopic
0692:                                            .getMembershipItemSet();
0693:
0694:                                    if (topicMembershipItemSet != null
0695:                                            && !topicMembershipItemSet
0696:                                                    .isEmpty()
0697:                                            && allowedPermNames != null
0698:                                            && !allowedPermNames.isEmpty()) {
0699:                                        Iterator membershipIter = topicMembershipItemSet
0700:                                                .iterator();
0701:                                        while (membershipIter.hasNext()) {
0702:                                            DBMembershipItem oldItem = (DBMembershipItem) membershipIter
0703:                                                    .next();
0704:                                            if (allowedPermNames
0705:                                                    .contains(oldItem.getName())) {
0706:                                                DBMembershipItem newItem = getMembershipItemCopy(oldItem);
0707:                                                if (newItem != null) {
0708:                                                    permissionManager
0709:                                                            .saveDBMembershipItem(newItem);
0710:                                                    newTopic
0711:                                                            .addMembershipItem(newItem);
0712:                                                }
0713:                                            }
0714:                                        }
0715:                                    }
0716:                                    // Add the attachments
0717:                                    List fromTopicAttach = forumManager
0718:                                            .getTopicByIdWithAttachments(
0719:                                                    fromTopicId)
0720:                                            .getAttachments();
0721:                                    if (fromTopicAttach != null
0722:                                            && !fromTopicAttach.isEmpty()) {
0723:                                        for (int topicAttach = 0; topicAttach < fromTopicAttach
0724:                                                .size(); topicAttach++) {
0725:                                            Attachment this Attach = (Attachment) fromTopicAttach
0726:                                                    .get(topicAttach);
0727:                                            Attachment newAttachment = copyAttachment(this Attach
0728:                                                    .getAttachmentId());
0729:                                            if (newTopic != null
0730:                                                    && newAttachment != null)
0731:                                                newTopic
0732:                                                        .addAttachment(newAttachment);
0733:                                        }
0734:                                    }
0735:
0736:                                    // get/add the gradebook assignment associated with the topic	
0737:                                    if (gradebookService
0738:                                            .isGradebookDefined(gradebookUid)) {
0739:                                        String fromAssignmentTitle = fromTopic
0740:                                                .getDefaultAssignName();
0741:                                        if (gradebookService
0742:                                                .isAssignmentDefined(
0743:                                                        gradebookUid,
0744:                                                        fromAssignmentTitle)) {
0745:                                            newTopic
0746:                                                    .setDefaultAssignName(fromAssignmentTitle);
0747:                                        }
0748:                                    }
0749:
0750:                                    forumManager.saveDiscussionForumTopic(
0751:                                            newTopic, newForum.getDraft()
0752:                                                    .booleanValue());
0753:                                }
0754:                            }
0755:                        }
0756:                    }
0757:                }
0758:
0759:                catch (Exception e) {
0760:                    e.printStackTrace();
0761:                    LOG.error(e.getMessage(), e);
0762:                }
0763:            }
0764:
0765:            public String merge(String siteId, Element root,
0766:                    String archivePath, String fromSiteId, Map attachmentNames,
0767:                    Map userIdTrans, Set userListAllowImport) {
0768:                Base64 base64Encoder = new Base64();
0769:                StringBuffer results = new StringBuffer();
0770:                if (siteId != null && siteId.trim().length() > 0) {
0771:                    try {
0772:                        NodeList allChildrenNodes = root.getChildNodes();
0773:                        int length = allChildrenNodes.getLength();
0774:                        for (int i = 0; i < length; i++) {
0775:                            Node siteNode = allChildrenNodes.item(i);
0776:                            if (siteNode.getNodeType() == Node.ELEMENT_NODE) {
0777:                                Element siteElement = (Element) siteNode;
0778:                                if (siteElement.getTagName().equals(
0779:                                        MESSAGEFORUM)) {
0780:                                    NodeList allForumNodes = siteElement
0781:                                            .getChildNodes();
0782:                                    int lengthForum = allForumNodes.getLength();
0783:                                    for (int j = 0; j < lengthForum; j++) {
0784:                                        Node child1 = allForumNodes.item(j);
0785:                                        if (child1.getNodeType() == Node.ELEMENT_NODE) {
0786:                                            Element forumElement = (Element) child1;
0787:                                            if (forumElement.getTagName()
0788:                                                    .equals(DISCUSSION_FORUM)) {
0789:                                                DiscussionForum dfForum = forumManager
0790:                                                        .createDiscussionForum();
0791:
0792:                                                String forumTitle = forumElement
0793:                                                        .getAttribute(DISCUSSION_FORUM_TITLE);
0794:                                                dfForum.setTitle(forumTitle);
0795:
0796:                                                String forumDraft = forumElement
0797:                                                        .getAttribute(DRAFT);
0798:                                                if (forumDraft != null
0799:                                                        && forumDraft.length() > 0)
0800:                                                    dfForum
0801:                                                            .setDraft(new Boolean(
0802:                                                                    forumDraft));
0803:
0804:                                                String forumLocked = forumElement
0805:                                                        .getAttribute(LOCKED);
0806:                                                if (forumLocked != null
0807:                                                        && forumLocked.length() > 0)
0808:                                                    dfForum
0809:                                                            .setLocked(new Boolean(
0810:                                                                    forumLocked));
0811:
0812:                                                String forumModerated = forumElement
0813:                                                        .getAttribute(MODERATED);
0814:                                                if (forumModerated != null
0815:                                                        && forumModerated
0816:                                                                .length() > 0) {
0817:                                                    dfForum
0818:                                                            .setModerated(new Boolean(
0819:                                                                    forumModerated));
0820:                                                } else {
0821:                                                    dfForum
0822:                                                            .setModerated(Boolean.FALSE);
0823:                                                }
0824:
0825:                                                String forumDesc = forumElement
0826:                                                        .getAttribute(DISCUSSION_FORUM_DESC);
0827:                                                String trimBody = null;
0828:                                                if (forumDesc != null
0829:                                                        && forumDesc.length() > 0) {
0830:                                                    trimBody = trimToNull(forumDesc);
0831:                                                    if (trimBody != null
0832:                                                            && trimBody
0833:                                                                    .length() > 0) {
0834:                                                        byte[] decoded = base64Encoder
0835:                                                                .decode(trimBody
0836:                                                                        .getBytes());
0837:                                                        trimBody = new String(
0838:                                                                decoded,
0839:                                                                "UTF-8");
0840:                                                    }
0841:                                                }
0842:                                                if (trimBody != null) {
0843:                                                    dfForum
0844:                                                            .setExtendedDescription(trimBody);
0845:                                                }
0846:
0847:                                                String forumShortDesc = forumElement
0848:                                                        .getAttribute(DISCUSSION_FORUM_SHORT_DESC);
0849:                                                String trimSummary = null;
0850:                                                if (forumShortDesc != null
0851:                                                        && forumShortDesc
0852:                                                                .length() > 0) {
0853:                                                    trimSummary = trimToNull(forumShortDesc);
0854:                                                    if (trimSummary != null
0855:                                                            && trimSummary
0856:                                                                    .length() > 0) {
0857:                                                        byte[] decoded = base64Encoder
0858:                                                                .decode(trimSummary
0859:                                                                        .getBytes());
0860:                                                        trimSummary = new String(
0861:                                                                decoded,
0862:                                                                "UTF-8");
0863:                                                    }
0864:                                                }
0865:                                                if (trimSummary != null) {
0866:                                                    dfForum
0867:                                                            .setShortDescription(trimSummary);
0868:                                                }
0869:
0870:                                                NodeList forumDetailNodes = forumElement
0871:                                                        .getChildNodes();
0872:                                                boolean hasTopic = false;
0873:                                                for (int k = 0; k < forumDetailNodes
0874:                                                        .getLength(); k++) {
0875:                                                    Node forumChild = forumDetailNodes
0876:                                                            .item(k);
0877:                                                    if (forumChild
0878:                                                            .getNodeType() == Node.ELEMENT_NODE) {
0879:                                                        Element forumChildElement = (Element) forumChild;
0880:
0881:                                                        if (forumChildElement
0882:                                                                .getTagName()
0883:                                                                .equals(
0884:                                                                        ATTACHMENT)) {
0885:                                                            String oldAttachId = forumChildElement
0886:                                                                    .getAttribute(ATTACH_ID);
0887:                                                            if (oldAttachId != null
0888:                                                                    && oldAttachId
0889:                                                                            .trim()
0890:                                                                            .length() > 0) {
0891:                                                                String oldUrl = oldAttachId;
0892:                                                                if (oldUrl
0893:                                                                        .startsWith("/content/attachment/")) {
0894:                                                                    String newUrl = (String) attachmentNames
0895:                                                                            .get(oldUrl);
0896:                                                                    if (newUrl != null) {
0897:                                                                        oldAttachId = Validator
0898:                                                                                .escapeQuestionMark(newUrl);
0899:                                                                    }
0900:                                                                } else if (oldUrl
0901:                                                                        .startsWith("/content/group/"
0902:                                                                                + fromSiteId
0903:                                                                                + "/")) {
0904:                                                                    String newUrl = "/content/group/"
0905:                                                                            + siteId
0906:                                                                            + oldUrl
0907:                                                                                    .substring(15 + fromSiteId
0908:                                                                                            .length());
0909:                                                                    oldAttachId = Validator
0910:                                                                            .escapeQuestionMark(newUrl);
0911:                                                                }
0912:                                                                Attachment newAttachment = copyAttachment(oldAttachId);
0913:                                                                if (newAttachment != null)
0914:                                                                    dfForum
0915:                                                                            .addAttachment(newAttachment);
0916:                                                            }
0917:                                                        }
0918:                                                        // PERMISSIONS
0919:                                                        else if (forumChildElement
0920:                                                                .getTagName()
0921:                                                                .equals(
0922:                                                                        PERMISSIONS)) {
0923:                                                            Set membershipItemSet = getMembershipItemSetFromPermissionElement(
0924:                                                                    forumChildElement,
0925:                                                                    siteId);
0926:                                                            if (membershipItemSet != null
0927:                                                                    && membershipItemSet
0928:                                                                            .size() > 0) {
0929:                                                                Iterator membershipIter = membershipItemSet
0930:                                                                        .iterator();
0931:                                                                while (membershipIter
0932:                                                                        .hasNext()) {
0933:                                                                    DBMembershipItem oldItem = (DBMembershipItem) membershipIter
0934:                                                                            .next();
0935:
0936:                                                                    DBMembershipItem newItem = getMembershipItemCopy(oldItem);
0937:                                                                    if (newItem != null) {
0938:                                                                        permissionManager
0939:                                                                                .saveDBMembershipItem(newItem);
0940:                                                                        dfForum
0941:                                                                                .addMembershipItem(newItem);
0942:                                                                    }
0943:
0944:                                                                }
0945:                                                            }
0946:                                                        }
0947:
0948:                                                        else if (forumChildElement
0949:                                                                .getTagName()
0950:                                                                .equals(
0951:                                                                        DISCUSSION_TOPIC)) {
0952:                                                            DiscussionTopic dfTopic = forumManager
0953:                                                                    .createDiscussionForumTopic(dfForum);
0954:
0955:                                                            String topicTitle = forumChildElement
0956:                                                                    .getAttribute(TOPIC_TITLE);
0957:                                                            dfTopic
0958:                                                                    .setTitle(topicTitle);
0959:
0960:                                                            String topicDraft = forumChildElement
0961:                                                                    .getAttribute(DRAFT);
0962:                                                            if (topicDraft != null
0963:                                                                    && topicDraft
0964:                                                                            .length() > 0)
0965:                                                                dfTopic
0966:                                                                        .setDraft(new Boolean(
0967:                                                                                topicDraft));
0968:
0969:                                                            String topicLocked = forumChildElement
0970:                                                                    .getAttribute(LOCKED);
0971:                                                            if (topicLocked != null
0972:                                                                    && topicLocked
0973:                                                                            .length() > 0)
0974:                                                                dfTopic
0975:                                                                        .setLocked(new Boolean(
0976:                                                                                topicLocked));
0977:
0978:                                                            String topicModerated = forumChildElement
0979:                                                                    .getAttribute(MODERATED);
0980:                                                            if (topicModerated != null
0981:                                                                    && topicModerated
0982:                                                                            .length() > 0)
0983:                                                                dfTopic
0984:                                                                        .setModerated(new Boolean(
0985:                                                                                topicModerated));
0986:                                                            else
0987:                                                                dfTopic
0988:                                                                        .setModerated(Boolean.FALSE);
0989:
0990:                                                            NodeList topicPropertiesNodes = forumChildElement
0991:                                                                    .getChildNodes();
0992:                                                            for (int m = 0; m < topicPropertiesNodes
0993:                                                                    .getLength(); m++) {
0994:                                                                Node propertiesNode = topicPropertiesNodes
0995:                                                                        .item(m);
0996:                                                                if (propertiesNode
0997:                                                                        .getNodeType() == Node.ELEMENT_NODE) {
0998:                                                                    Element propertiesElement = (Element) propertiesNode;
0999:                                                                    if (propertiesElement
1000:                                                                            .getTagName()
1001:                                                                            .equals(
1002:                                                                                    PROPERTIES)) {
1003:                                                                        NodeList propertyList = propertiesElement
1004:                                                                                .getChildNodes();
1005:                                                                        for (int n = 0; n < propertyList
1006:                                                                                .getLength(); n++) {
1007:                                                                            Node propertyNode = propertyList
1008:                                                                                    .item(n);
1009:                                                                            if (propertyNode
1010:                                                                                    .getNodeType() == Node.ELEMENT_NODE) {
1011:                                                                                Element propertyElement = (Element) propertyNode;
1012:                                                                                if (propertyElement
1013:                                                                                        .getTagName()
1014:                                                                                        .equals(
1015:                                                                                                PROPERTY)) {
1016:                                                                                    if (TOPIC_SHORT_DESC
1017:                                                                                            .equals(propertyElement
1018:                                                                                                    .getAttribute(NAME))) {
1019:                                                                                        if (BASE64
1020:                                                                                                .equals(propertyElement
1021:                                                                                                        .getAttribute(ENCODE))) {
1022:                                                                                            String topicDesc = propertyElement
1023:                                                                                                    .getAttribute(VALUE);
1024:                                                                                            String trimDesc = null;
1025:                                                                                            if (topicDesc != null
1026:                                                                                                    && topicDesc
1027:                                                                                                            .length() > 0) {
1028:                                                                                                trimDesc = trimToNull(topicDesc);
1029:                                                                                                if (trimDesc != null
1030:                                                                                                        && trimDesc
1031:                                                                                                                .length() > 0) {
1032:                                                                                                    byte[] decoded = base64Encoder
1033:                                                                                                            .decode(trimDesc
1034:                                                                                                                    .getBytes());
1035:                                                                                                    trimDesc = new String(
1036:                                                                                                            decoded,
1037:                                                                                                            "UTF-8");
1038:                                                                                                }
1039:                                                                                            }
1040:                                                                                            if (trimDesc != null) {
1041:                                                                                                dfTopic
1042:                                                                                                        .setShortDescription(trimDesc);
1043:                                                                                            }
1044:                                                                                        } else
1045:                                                                                            dfTopic
1046:                                                                                                    .setShortDescription(propertyElement
1047:                                                                                                            .getAttribute(VALUE));
1048:                                                                                    }
1049:                                                                                    if (TOPIC_LONG_DESC
1050:                                                                                            .equals(propertyElement
1051:                                                                                                    .getAttribute(NAME))) {
1052:
1053:                                                                                        if (BASE64
1054:                                                                                                .equals(propertyElement
1055:                                                                                                        .getAttribute(ENCODE))) {
1056:                                                                                            String topicDesc = propertyElement
1057:                                                                                                    .getAttribute(VALUE);
1058:                                                                                            String trimDesc = null;
1059:                                                                                            if (topicDesc != null
1060:                                                                                                    && topicDesc
1061:                                                                                                            .length() > 0) {
1062:                                                                                                trimDesc = trimToNull(topicDesc);
1063:                                                                                                if (trimDesc != null
1064:                                                                                                        && trimDesc
1065:                                                                                                                .length() > 0) {
1066:                                                                                                    byte[] decoded = base64Encoder
1067:                                                                                                            .decode(trimDesc
1068:                                                                                                                    .getBytes());
1069:                                                                                                    trimDesc = new String(
1070:                                                                                                            decoded,
1071:                                                                                                            "UTF-8");
1072:                                                                                                }
1073:                                                                                            }
1074:                                                                                            if (trimDesc != null) {
1075:                                                                                                dfTopic
1076:                                                                                                        .setExtendedDescription(trimDesc);
1077:                                                                                            }
1078:                                                                                        } else
1079:                                                                                            dfTopic
1080:                                                                                                    .setExtendedDescription(propertyElement
1081:                                                                                                            .getAttribute(VALUE));
1082:                                                                                    }
1083:                                                                                }
1084:                                                                            }
1085:                                                                        }
1086:                                                                    } else if (propertiesElement
1087:                                                                            .getTagName()
1088:                                                                            .equals(
1089:                                                                                    ATTACHMENT)) {
1090:                                                                        String oldAttachId = propertiesElement
1091:                                                                                .getAttribute(ATTACH_ID);
1092:                                                                        if (oldAttachId != null
1093:                                                                                && oldAttachId
1094:                                                                                        .trim()
1095:                                                                                        .length() > 0) {
1096:                                                                            String oldUrl = oldAttachId;
1097:                                                                            if (oldUrl
1098:                                                                                    .startsWith("/content/attachment/")) {
1099:                                                                                String newUrl = (String) attachmentNames
1100:                                                                                        .get(oldUrl);
1101:                                                                                if (newUrl != null) {
1102:                                                                                    oldAttachId = Validator
1103:                                                                                            .escapeQuestionMark(newUrl);
1104:                                                                                }
1105:                                                                            } else if (oldUrl
1106:                                                                                    .startsWith("/content/group/"
1107:                                                                                            + fromSiteId
1108:                                                                                            + "/")) {
1109:                                                                                String newUrl = "/content/group/"
1110:                                                                                        + siteId
1111:                                                                                        + oldUrl
1112:                                                                                                .substring(15 + fromSiteId
1113:                                                                                                        .length());
1114:                                                                                oldAttachId = Validator
1115:                                                                                        .escapeQuestionMark(newUrl);
1116:                                                                            }
1117:                                                                            Attachment newAttachment = copyAttachment(oldAttachId);
1118:                                                                            if (newAttachment != null)
1119:                                                                                dfTopic
1120:                                                                                        .addAttachment(newAttachment);
1121:                                                                        }
1122:                                                                    }
1123:
1124:                                                                    else if (propertiesElement
1125:                                                                            .getTagName()
1126:                                                                            .equals(
1127:                                                                                    PERMISSIONS)) {
1128:                                                                        Set membershipItemSet = getMembershipItemSetFromPermissionElement(
1129:                                                                                propertiesElement,
1130:                                                                                siteId);
1131:                                                                        if (membershipItemSet != null
1132:                                                                                && membershipItemSet
1133:                                                                                        .size() > 0) {
1134:                                                                            Iterator membershipIter = membershipItemSet
1135:                                                                                    .iterator();
1136:                                                                            while (membershipIter
1137:                                                                                    .hasNext()) {
1138:                                                                                DBMembershipItem oldItem = (DBMembershipItem) membershipIter
1139:                                                                                        .next();
1140:                                                                                DBMembershipItem newItem = getMembershipItemCopy(oldItem);
1141:                                                                                if (newItem != null) {
1142:                                                                                    permissionManager
1143:                                                                                            .saveDBMembershipItem(newItem);
1144:                                                                                    dfTopic
1145:                                                                                            .addMembershipItem(newItem);
1146:                                                                                }
1147:
1148:                                                                            }
1149:                                                                        }
1150:                                                                    }
1151:                                                                }
1152:                                                            }
1153:
1154:                                                            if (!hasTopic) {
1155:                                                                Area area = areaManager
1156:                                                                        .getDiscusionArea();
1157:                                                                dfForum
1158:                                                                        .setArea(area);
1159:                                                                if ("false"
1160:                                                                        .equalsIgnoreCase(ServerConfigurationService
1161:                                                                                .getString("import.importAsDraft"))) {
1162:                                                                    forumManager
1163:                                                                            .saveDiscussionForum(
1164:                                                                                    dfForum,
1165:                                                                                    dfForum
1166:                                                                                            .getDraft()
1167:                                                                                            .booleanValue());
1168:                                                                } else {
1169:                                                                    dfForum
1170:                                                                            .setDraft(new Boolean(
1171:                                                                                    "true"));
1172:                                                                    forumManager
1173:                                                                            .saveDiscussionForum(
1174:                                                                                    dfForum,
1175:                                                                                    true);
1176:                                                                }
1177:                                                            }
1178:                                                            hasTopic = true;
1179:
1180:                                                            forumManager
1181:                                                                    .saveDiscussionForumTopic(
1182:                                                                            dfTopic,
1183:                                                                            dfForum
1184:                                                                                    .getDraft()
1185:                                                                                    .booleanValue());
1186:                                                        }
1187:                                                    }
1188:                                                }
1189:
1190:                                                if (!hasTopic) {
1191:                                                    Area area = areaManager
1192:                                                            .getDiscusionArea();
1193:                                                    dfForum.setArea(area);
1194:                                                    if ("false"
1195:                                                            .equalsIgnoreCase(ServerConfigurationService
1196:                                                                    .getString("import.importAsDraft"))) {
1197:                                                        forumManager
1198:                                                                .saveDiscussionForum(
1199:                                                                        dfForum,
1200:                                                                        dfForum
1201:                                                                                .getDraft()
1202:                                                                                .booleanValue());
1203:                                                    } else {
1204:                                                        dfForum
1205:                                                                .setDraft(new Boolean(
1206:                                                                        "true"));
1207:                                                        forumManager
1208:                                                                .saveDiscussionForum(
1209:                                                                        dfForum,
1210:                                                                        true);
1211:                                                    }
1212:                                                }
1213:                                            }
1214:                                        }
1215:                                    }
1216:                                }
1217:                            }
1218:                        }
1219:                    } catch (Exception e) {
1220:                        results.append("merging " + getLabel() + " failed.\n");
1221:                        e.printStackTrace();
1222:                    }
1223:
1224:                }
1225:                return null;
1226:            }
1227:
1228:            public boolean parseEntityReference(String reference, Reference ref) {
1229:                if (reference.startsWith(REFERENCE_ROOT)) {
1230:                    // /syllabus/siteid/syllabusid
1231:                    String[] parts = split(reference, Entity.SEPARATOR);
1232:
1233:                    String subType = null;
1234:                    String context = null;
1235:                    String id = null;
1236:                    String container = null;
1237:
1238:                    if (parts.length > 2) {
1239:                        // the site/context
1240:                        context = parts[2];
1241:
1242:                        // the id
1243:                        if (parts.length > 3) {
1244:                            id = parts[3];
1245:                        }
1246:                    }
1247:
1248:                    ref.set(SERVICE_NAME, subType, id, container, context);
1249:
1250:                    return true;
1251:                }
1252:
1253:                return false;
1254:            }
1255:
1256:            public boolean willArchiveMerge() {
1257:                return true;
1258:            }
1259:
1260:            protected String[] split(String source, String splitter) {
1261:                // hold the results as we find them
1262:                Vector rv = new Vector();
1263:                int last = 0;
1264:                int next = 0;
1265:                do {
1266:                    // find next splitter in source
1267:                    next = source.indexOf(splitter, last);
1268:                    if (next != -1) {
1269:                        // isolate from last thru before next
1270:                        rv.add(source.substring(last, next));
1271:                        last = next + splitter.length();
1272:                    }
1273:                } while (next != -1);
1274:                if (last < source.length()) {
1275:                    rv.add(source.substring(last, source.length()));
1276:                }
1277:
1278:                // convert to array
1279:                return (String[]) rv.toArray(new String[rv.size()]);
1280:
1281:            } // split
1282:
1283:            public MessageForumsForumManager getForumManager() {
1284:                return forumManager;
1285:            }
1286:
1287:            public void setForumManager(MessageForumsForumManager forumManager) {
1288:                this .forumManager = forumManager;
1289:            }
1290:
1291:            public AreaManager getAreaManager() {
1292:                return areaManager;
1293:            }
1294:
1295:            public void setAreaManager(AreaManager areaManager) {
1296:                this .areaManager = areaManager;
1297:            }
1298:
1299:            public String trimToNull(String value) {
1300:                if (value == null)
1301:                    return null;
1302:                value = value.trim();
1303:                if (value.length() == 0)
1304:                    return null;
1305:                return value;
1306:            }
1307:
1308:            private Attachment copyAttachment(String attachmentId) {
1309:                try {
1310:                    ContentResource oldAttachment = ContentHostingService
1311:                            .getResource(attachmentId);
1312:                    ContentResource attachment = ContentHostingService
1313:                            .addAttachmentResource(
1314:                                    oldAttachment
1315:                                            .getProperties()
1316:                                            .getProperty(
1317:                                                    ResourceProperties.PROP_DISPLAY_NAME),
1318:                                    ToolManager.getCurrentPlacement()
1319:                                            .getContext(), ToolManager.getTool(
1320:                                            "sakai.forums").getTitle(),
1321:                                    oldAttachment.getContentType(),
1322:                                    oldAttachment.getContent(), oldAttachment
1323:                                            .getProperties());
1324:                    Attachment this DFAttach = dfManager.createDFAttachment(
1325:                            attachment.getId(),
1326:                            attachment.getProperties().getProperty(
1327:                                    ResourceProperties.PROP_DISPLAY_NAME));
1328:                    return this DFAttach;
1329:                } catch (IdUnusedException iue) {
1330:                    LOG.error("Error with attachment id: " + attachmentId);
1331:                    LOG.error(iue.getMessage(), iue);
1332:                } catch (Exception e) {
1333:                    //e.printStackTrace();
1334:                    LOG.error("Error with attachment id: " + attachmentId);
1335:                    LOG.error(e.getMessage(), e);
1336:                }
1337:
1338:                return null;
1339:            }
1340:
1341:            private Set getMembershipItemSetFromPermissionElement(
1342:                    Element permissionsElement, String siteId) {
1343:                Set membershipItemSet = new HashSet();
1344:                List allowedPermNames = getSiteRolesAndGroups(siteId);
1345:                List allowedPermLevels = permissionManager
1346:                        .getOrderedPermissionLevelNames();
1347:
1348:                NodeList permissionsNodes = permissionsElement.getChildNodes();
1349:                for (int m = 0; m < permissionsNodes.getLength(); m++) {
1350:                    Node permissionsNode = permissionsNodes.item(m);
1351:                    if (permissionsNode.getNodeType() == Node.ELEMENT_NODE) {
1352:                        Element permissionElement = (Element) permissionsNode;
1353:                        if (permissionElement.getTagName().equals(PERMISSION)) {
1354:                            try {
1355:                                if (permissionElement
1356:                                        .getAttribute(PERMISSION_NAME) != null
1357:                                        && permissionElement
1358:                                                .getAttribute(PERMISSION_LEVEL_NAME) != null
1359:                                        && permissionElement
1360:                                                .getAttribute(PERMISSION_TYPE) != null) {
1361:                                    String permissionName = permissionElement
1362:                                            .getAttribute(PERMISSION_NAME);
1363:                                    String permissionLevelName = permissionElement
1364:                                            .getAttribute(PERMISSION_LEVEL_NAME);
1365:                                    if (allowedPermNames != null
1366:                                            && allowedPermLevels != null
1367:                                            && allowedPermNames
1368:                                                    .contains(permissionName)
1369:                                            && allowedPermLevels
1370:                                                    .contains(permissionLevelName)) {
1371:
1372:                                        Integer permissionType = new Integer(
1373:                                                permissionElement
1374:                                                        .getAttribute(PERMISSION_TYPE));
1375:                                        DBMembershipItem membershipItem = permissionManager
1376:                                                .createDBMembershipItem(
1377:                                                        permissionName,
1378:                                                        permissionLevelName,
1379:                                                        permissionType);
1380:
1381:                                        if (PermissionLevelManager.PERMISSION_LEVEL_NAME_CUSTOM
1382:                                                .equals(membershipItem
1383:                                                        .getPermissionLevelName())) {
1384:                                            NodeList customPermNodes = permissionElement
1385:                                                    .getChildNodes();
1386:                                            for (int l = 0; l < customPermNodes
1387:                                                    .getLength(); l++) {
1388:                                                Node customPermNode = customPermNodes
1389:                                                        .item(l);
1390:                                                if (customPermNode
1391:                                                        .getNodeType() == Node.ELEMENT_NODE) {
1392:                                                    Element customPermElement = (Element) customPermNode;
1393:                                                    if (customPermElement
1394:                                                            .getTagName()
1395:                                                            .equals(
1396:                                                                    CUSTOM_PERMISSIONS)) {
1397:                                                        PermissionsMask mask = new PermissionsMask();
1398:                                                        List customPermList = permissionManager
1399:                                                                .getCustomPermissions();
1400:                                                        for (int c = 0; c < customPermList
1401:                                                                .size(); c++) {
1402:                                                            String customPermName = (String) customPermList
1403:                                                                    .get(c);
1404:                                                            Boolean hasPermission = new Boolean(
1405:                                                                    customPermElement
1406:                                                                            .getAttribute(customPermName));
1407:                                                            mask
1408:                                                                    .put(
1409:                                                                            customPermName,
1410:                                                                            hasPermission);
1411:                                                        }
1412:
1413:                                                        PermissionLevel level = permissionManager
1414:                                                                .createPermissionLevel(
1415:                                                                        membershipItem
1416:                                                                                .getPermissionLevelName(),
1417:                                                                        typeManager
1418:                                                                                .getCustomLevelType(),
1419:                                                                        mask);
1420:                                                        membershipItem
1421:                                                                .setPermissionLevel(level);
1422:                                                    }
1423:                                                }
1424:                                            }
1425:                                        }
1426:                                        // save DBMembershipItem here to get an id so we can add to the set
1427:                                        permissionManager
1428:                                                .saveDBMembershipItem(membershipItem);
1429:                                        membershipItemSet.add(membershipItem);
1430:                                    }
1431:                                }
1432:
1433:                            } catch (NumberFormatException nfe) {
1434:                                LOG.error(nfe);
1435:                            } catch (Exception e) {
1436:                                LOG.error(e);
1437:                            }
1438:                        }
1439:                    }
1440:                }
1441:                return membershipItemSet;
1442:            }
1443:
1444:            private List getSiteRolesAndGroups(String contextId) {
1445:                // get the roles in the site
1446:                AuthzGroup realm;
1447:                List rolesAndGroups = new ArrayList();
1448:                try {
1449:                    realm = AuthzGroupService.getAuthzGroup("/site/"
1450:                            + contextId);
1451:                    Set roleSet = realm.getRoles();
1452:
1453:                    if (roleSet != null && roleSet.size() > 0) {
1454:                        Iterator roleIter = roleSet.iterator();
1455:                        while (roleIter.hasNext()) {
1456:                            Role role = (Role) roleIter.next();
1457:                            if (role != null) {
1458:                                rolesAndGroups.add(role.getId());
1459:                            }
1460:                        }
1461:                    }
1462:
1463:                    // get any groups/sections in site
1464:                    Site currentSite = SiteService.getSite(contextId);
1465:                    Collection groups = currentSite.getGroups();
1466:                    for (Iterator groupIterator = groups.iterator(); groupIterator
1467:                            .hasNext();) {
1468:                        Group currentGroup = (Group) groupIterator.next();
1469:                        rolesAndGroups.add(currentGroup.getTitle());
1470:                    }
1471:                } catch (GroupNotDefinedException e) {
1472:                    // TODO Auto-generated catch block
1473:                    LOG
1474:                            .error(
1475:                                    "GroupNotDefinedException retrieving site's roles and groups",
1476:                                    e);
1477:                } catch (Exception e) {
1478:                    LOG
1479:                            .error(
1480:                                    "Exception retrieving site's roles and groups",
1481:                                    e);
1482:                }
1483:
1484:                return rolesAndGroups;
1485:            }
1486:
1487:            private DBMembershipItem getMembershipItemCopy(
1488:                    DBMembershipItem itemToCopy) {
1489:                DBMembershipItem newItem = permissionManager
1490:                        .createDBMembershipItem(itemToCopy.getName(),
1491:                                itemToCopy.getPermissionLevelName(), itemToCopy
1492:                                        .getType());
1493:                PermissionLevel oldPermLevel = itemToCopy.getPermissionLevel();
1494:                if (newItem.getPermissionLevelName().equals(
1495:                        PermissionLevelManager.PERMISSION_LEVEL_NAME_CUSTOM)) {
1496:                    PermissionsMask mask = new PermissionsMask();
1497:                    List customPermList = permissionManager
1498:                            .getCustomPermissions();
1499:                    for (int c = 0; c < customPermList.size(); c++) {
1500:                        String customPermName = (String) customPermList.get(c);
1501:                        Boolean hasPermission = permissionManager
1502:                                .getCustomPermissionByName(customPermName,
1503:                                        oldPermLevel);
1504:                        mask.put(customPermName, hasPermission);
1505:                    }
1506:
1507:                    PermissionLevel level = permissionManager
1508:                            .createPermissionLevel(newItem
1509:                                    .getPermissionLevelName(), typeManager
1510:                                    .getCustomLevelType(), mask);
1511:                    newItem.setPermissionLevel(level);
1512:                }
1513:                return newItem;
1514:            }
1515:
1516:            public MessageForumsMessageManager getMessageManager() {
1517:                return messageManager;
1518:            }
1519:
1520:            public void setMessageManager(
1521:                    MessageForumsMessageManager messageManager) {
1522:                this .messageManager = messageManager;
1523:            }
1524:
1525:            public MessageForumsTypeManager getTypeManager() {
1526:                return typeManager;
1527:            }
1528:
1529:            public void setTypeManager(MessageForumsTypeManager typeManager) {
1530:                this .typeManager = typeManager;
1531:            }
1532:
1533:            public DiscussionForumManager getDfManager() {
1534:                return dfManager;
1535:            }
1536:
1537:            public void setDfManager(DiscussionForumManager dfManager) {
1538:                this .dfManager = dfManager;
1539:            }
1540:
1541:            public void setPermissionManager(
1542:                    PermissionLevelManager permissionManager) {
1543:                this .permissionManager = permissionManager;
1544:            }
1545:
1546:            public PermissionLevelManager getPermissionManager() {
1547:                return permissionManager;
1548:            }
1549:
1550:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.