Source Code Cross Referenced for LibresourceFilesServiceBean.java in  » Groupware » LibreSource » org » libresource » files » ejb » 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 » Groupware » LibreSource » org.libresource.files.ejb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * LibreSource
0003:         * Copyright (C) 2004-2008 Artenum SARL / INRIA
0004:         * http://www.libresource.org - contact@artenum.com
0005:         *
0006:         * This file is part of the LibreSource software, 
0007:         * which can be used and distributed under license conditions.
0008:         * The license conditions are provided in the LICENSE.TXT file 
0009:         * at the root path of the packaging that enclose this file. 
0010:         * More information can be found at 
0011:         * - http://dev.libresource.org/home/license
0012:         *
0013:         * Initial authors :
0014:         *
0015:         * Guillaume Bort / INRIA
0016:         * Francois Charoy / Universite Nancy 2
0017:         * Julien Forest / Artenum
0018:         * Claude Godart / Universite Henry Poincare
0019:         * Florent Jouille / INRIA
0020:         * Sebastien Jourdain / INRIA / Artenum
0021:         * Yves Lerumeur / Artenum
0022:         * Pascal Molli / Universite Henry Poincare
0023:         * Gerald Oster / INRIA
0024:         * Mariarosa Penzi / Artenum
0025:         * Gerard Sookahet / Artenum
0026:         * Raphael Tani / INRIA
0027:         *
0028:         * Contributors :
0029:         *
0030:         * Stephane Bagnier / Artenum
0031:         * Amadou Dia / Artenum-IUP Blois
0032:         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0033:         */package org.libresource.files.ejb;
0034:
0035:        import org.libresource.Libresource;
0036:        import org.libresource.LibresourceEvent;
0037:        import org.libresource.LibresourceException;
0038:        import org.libresource.LibresourceResourceIdentifier;
0039:        import org.libresource.LibresourceResourceValue;
0040:        import org.libresource.LibresourceServiceBase;
0041:
0042:        import org.libresource.core.CoreConstants;
0043:        import org.libresource.core.FileData;
0044:        import org.libresource.core.interfaces.LibresourceCoreService;
0045:
0046:        import org.libresource.files.DownloadLogEntry;
0047:        import org.libresource.files.DropBoxExportHandler;
0048:        import org.libresource.files.DropBoxImportHandler;
0049:        import org.libresource.files.FileConstants;
0050:        import org.libresource.files.FileExportHandler;
0051:        import org.libresource.files.FileImportHandler;
0052:        import org.libresource.files.LibresourceFilesException;
0053:        import org.libresource.files.RepositoryExportHandler;
0054:        import org.libresource.files.RepositoryImportHandler;
0055:        import org.libresource.files.ejb.model.DropBoxResourceValue;
0056:        import org.libresource.files.ejb.model.FileResourceValue;
0057:        import org.libresource.files.ejb.model.RepositoryResourceValue;
0058:        import org.libresource.files.interfaces.DropBoxResourceLocal;
0059:        import org.libresource.files.interfaces.FileResourceLocal;
0060:        import org.libresource.files.interfaces.RepositoryResourceLocal;
0061:        import org.libresource.files.parsers.FileContentParser;
0062:        import org.libresource.files.parsers.Types2Parsers;
0063:        import org.libresource.files.util.DropBoxResourceUtil;
0064:        import org.libresource.files.util.FileResourceUtil;
0065:        import org.libresource.files.util.RepositoryResourceUtil;
0066:
0067:        import org.libresource.kernel.KernelConstants;
0068:        import org.libresource.kernel.LibresourceSecurityException;
0069:        import org.libresource.kernel.URINotExistException;
0070:        import org.libresource.kernel.ejb.model.AclValue;
0071:        import org.libresource.kernel.interfaces.KernelService;
0072:
0073:        import org.libresource.membership.MembershipConstants;
0074:        import org.libresource.membership.interfaces.MembershipService;
0075:
0076:        import org.libresource.search.LibresourceIndexableContent;
0077:
0078:        import org.libresource.xml.LibresourceExportHandler;
0079:        import org.libresource.xml.LibresourceImportHandler;
0080:
0081:        import java.io.File;
0082:
0083:        import java.net.URI;
0084:
0085:        import java.util.ArrayList;
0086:        import java.util.Arrays;
0087:        import java.util.Collection;
0088:        import java.util.Comparator;
0089:        import java.util.Date;
0090:        import java.util.HashMap;
0091:        import java.util.Vector;
0092:
0093:        import javax.activation.MimetypesFileTypeMap;
0094:
0095:        /**
0096:         * The Libresource Files service
0097:         *
0098:         * @libresource.service name="LibresourceFiles" depends="Kernel, Membership,
0099:         *                      LibresourceCore"
0100:         */
0101:        public abstract class LibresourceFilesServiceBean extends
0102:                LibresourceServiceBase {
0103:            private static MimetypesFileTypeMap typesFileMap = new MimetypesFileTypeMap();
0104:
0105:            static {
0106:                // for indexation engine
0107:                typesFileMap.addMimeTypes("text/xml		xml");
0108:                typesFileMap.addMimeTypes("text/plain		txt text properties");
0109:                typesFileMap.addMimeTypes("application/pdf		pdf");
0110:                typesFileMap.addMimeTypes("application/vnd.ms-word		doc");
0111:                typesFileMap.addMimeTypes("application/vnd.ms-excel		xls");
0112:                typesFileMap.addMimeTypes("application/vnd.ms-powerpoint		ppt");
0113:                typesFileMap
0114:                        .addMimeTypes("application/vnd.sun.xml.writer		sxw");
0115:                typesFileMap.addMimeTypes("application/vnd.sun.xml.calc		sxc");
0116:                typesFileMap
0117:                        .addMimeTypes("application/vnd.sun.xml.impress		sxi");
0118:            }
0119:
0120:            private String getMimeType(String name) {
0121:                return typesFileMap.getContentType(new File(name));
0122:            }
0123:
0124:            /**
0125:             * @ejb.interface-method
0126:             * @ejb.transaction type="Required"
0127:             */
0128:            public void createFile(URI uri, String description, String author,
0129:                    FileData fileData, boolean throwEvent, Date date)
0130:                    throws LibresourceFilesException,
0131:                    LibresourceSecurityException {
0132:                try {
0133:                    KernelService kernelService = (KernelService) Libresource
0134:                            .getService(KernelConstants.SERVICE);
0135:                    LibresourceCoreService coreService = (LibresourceCoreService) Libresource
0136:                            .getService(CoreConstants.SERVICE);
0137:
0138:                    if (!kernelService.checkSecurity(uri,
0139:                            KernelConstants.SECURITY_CREATE)) {
0140:                        throw new LibresourceSecurityException(uri,
0141:                                KernelConstants.SECURITY_CREATE);
0142:                    }
0143:
0144:                    FileResourceLocal fileResourceLocal = null;
0145:
0146:                    String name;
0147:
0148:                    if (fileData != null) {
0149:                        name = fileData.getName();
0150:
0151:                        String type = getMimeType(fileData.getName());
0152:                        fileResourceLocal = FileResourceUtil.getLocalHome()
0153:                                .create(name, description, author, type,
0154:                                        fileData.getSize(), throwEvent, date);
0155:                        coreService.putFileData("files_content_",
0156:                                fileResourceLocal.getId(), fileData);
0157:                    } else {
0158:                        name = "(Empty)";
0159:                        fileResourceLocal = FileResourceUtil.getLocalHome()
0160:                                .create("(Empty)", description, author, null,
0161:                                        0, throwEvent, date);
0162:                    }
0163:
0164:                    kernelService.bind(fileResourceLocal
0165:                            .getLibresourceResourceIdentifier(), uri, name);
0166:
0167:                    // event
0168:                    LibresourceEvent event = new LibresourceEvent(uri,
0169:                            fileResourceLocal
0170:                                    .getLibresourceResourceIdentifier(),
0171:                            kernelService.getConnectedResource(),
0172:                            FileConstants.EVENT_FILE_CREATE);
0173:                    Libresource.throwEvent(event);
0174:                } catch (LibresourceSecurityException se) {
0175:                    ctx.setRollbackOnly();
0176:                    throw se;
0177:                } catch (Exception e) {
0178:                    ctx.setRollbackOnly();
0179:                    throw new LibresourceFilesException(
0180:                            "Error in createFile : " + e.getMessage(), e);
0181:                }
0182:            }
0183:
0184:            /**
0185:             * @ejb.interface-method
0186:             * @ejb.transaction type="Required"
0187:             */
0188:            public void editFile(URI uri, String displayName,
0189:                    String description, FileData fileData, boolean throwEvent)
0190:                    throws LibresourceFilesException,
0191:                    LibresourceSecurityException, URINotExistException {
0192:                try {
0193:                    KernelService kernelService = (KernelService) Libresource
0194:                            .getService(KernelConstants.SERVICE);
0195:                    LibresourceCoreService coreService = (LibresourceCoreService) Libresource
0196:                            .getService(CoreConstants.SERVICE);
0197:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0198:                            .lookup(uri);
0199:
0200:                    if (!kernelService.checkSecurity(uri,
0201:                            KernelConstants.SECURITY_UPDATE)) {
0202:                        throw new LibresourceSecurityException(uri,
0203:                                KernelConstants.SECURITY_UPDATE);
0204:                    }
0205:
0206:                    FileResourceLocal fileResourceLocal = (FileResourceLocal) Libresource
0207:                            .findResource(resourceIdentifier,
0208:                                    FileResourceLocal.class);
0209:                    fileResourceLocal.setDescription(description);
0210:                    fileResourceLocal.setThrowEvent(throwEvent);
0211:
0212:                    if (fileData != null) {
0213:                        String type = getMimeType(fileData.getName());
0214:                        coreService.putFileData("files_content_",
0215:                                fileResourceLocal.getId(), fileData);
0216:                        fileResourceLocal.setName(fileData.getName());
0217:                        fileResourceLocal.setDate(new Date());
0218:                        fileResourceLocal
0219:                                .setSize(((fileData != null) ? fileData
0220:                                        .getSize() : 0));
0221:                        fileResourceLocal.setType(type);
0222:
0223:                        if ((displayName == null)
0224:                                || (displayName.trim().length() == 0)
0225:                                || (displayName.compareTo("(Empty)") == 0)) {
0226:                            displayName = fileData.getName();
0227:                        }
0228:
0229:                        coreService.getTempFile(fileResourceLocal.getId())
0230:                                .delete();
0231:                    }
0232:
0233:                    fileResourceLocal.setDisplayName(displayName);
0234:
0235:                    // update node
0236:                    kernelService.setShortName(uri, displayName);
0237:                    kernelService.setUpdateDate(uri, new Date());
0238:
0239:                    // event
0240:                    LibresourceEvent event = new LibresourceEvent(uri,
0241:                            resourceIdentifier, kernelService
0242:                                    .getConnectedResource(),
0243:                            FileConstants.EVENT_FILE_EDIT);
0244:                    Libresource.throwEvent(event);
0245:
0246:                    // indexation
0247:                    Libresource.index(uri);
0248:                } catch (LibresourceSecurityException se) {
0249:                    ctx.setRollbackOnly();
0250:                    throw se;
0251:                } catch (URINotExistException se) {
0252:                    ctx.setRollbackOnly();
0253:                    throw se;
0254:                } catch (Exception e) {
0255:                    ctx.setRollbackOnly();
0256:                    throw new LibresourceFilesException("Error in editFile : "
0257:                            + e.getMessage(), e);
0258:                }
0259:            }
0260:
0261:            /**
0262:             * @ejb.interface-method
0263:             * @ejb.transaction type="Required"
0264:             */
0265:            public void deleteFile(URI uri) throws LibresourceFilesException,
0266:                    LibresourceSecurityException, URINotExistException {
0267:                try {
0268:                    KernelService kernelService = (KernelService) Libresource
0269:                            .getService(KernelConstants.SERVICE);
0270:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0271:                            .lookup(uri);
0272:
0273:                    // event
0274:                    LibresourceEvent event = new LibresourceEvent(uri,
0275:                            resourceIdentifier, kernelService
0276:                                    .getConnectedResource(),
0277:                            FileConstants.EVENT_FILE_DELETE);
0278:                    Libresource.throwEvent(event);
0279:
0280:                    Libresource.checkType(resourceIdentifier,
0281:                            FileResourceLocal.class);
0282:                    kernelService.deleteURI(uri);
0283:                } catch (LibresourceSecurityException se) {
0284:                    ctx.setRollbackOnly();
0285:                    throw se;
0286:                } catch (URINotExistException se) {
0287:                    ctx.setRollbackOnly();
0288:                    throw se;
0289:                } catch (Exception e) {
0290:                    ctx.setRollbackOnly();
0291:                    throw new LibresourceFilesException(
0292:                            "Error in deleteFile : " + e.getMessage(), e);
0293:                }
0294:            }
0295:
0296:            /**
0297:             * @ejb.interface-method
0298:             * @ejb.transaction type="Supports"
0299:             */
0300:            public FileResourceValue getFile(URI uri)
0301:                    throws LibresourceFilesException,
0302:                    LibresourceSecurityException, URINotExistException {
0303:                try {
0304:                    KernelService kernelService = (KernelService) Libresource
0305:                            .getService(KernelConstants.SERVICE);
0306:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0307:                            .lookup(uri);
0308:                    FileResourceLocal fileResourceLocal = (FileResourceLocal) Libresource
0309:                            .findResource(resourceIdentifier,
0310:                                    FileResourceLocal.class);
0311:                    FileResourceValue resourceValue = fileResourceLocal
0312:                            .getFileResourceValue();
0313:                    resourceValue.setUri(kernelService.normalizeURI(uri));
0314:
0315:                    return resourceValue;
0316:                } catch (LibresourceSecurityException se) {
0317:                    throw se;
0318:                } catch (URINotExistException se) {
0319:                    throw se;
0320:                } catch (Exception e) {
0321:                    throw new LibresourceFilesException("Error in getFile : "
0322:                            + e.getMessage(), e);
0323:                }
0324:            }
0325:
0326:            /**
0327:             * @ejb.interface-method
0328:             * @ejb.transaction type="Supports"
0329:             */
0330:            public FileData getFileContent(URI uri, HashMap downloadInfos)
0331:                    throws LibresourceFilesException,
0332:                    LibresourceSecurityException, URINotExistException {
0333:                try {
0334:                    KernelService kernelService = (KernelService) Libresource
0335:                            .getService(KernelConstants.SERVICE);
0336:                    LibresourceCoreService coreService = (LibresourceCoreService) Libresource
0337:                            .getService(CoreConstants.SERVICE);
0338:                    MembershipService membershipService = (MembershipService) Libresource
0339:                            .getService(MembershipConstants.SERVICE);
0340:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0341:                            .lookup(uri);
0342:                    FileResourceLocal fileResourceLocal = (FileResourceLocal) Libresource
0343:                            .findResource(resourceIdentifier,
0344:                                    FileResourceLocal.class);
0345:
0346:                    // event
0347:                    if (fileResourceLocal.getThrowEvent()) {
0348:                        fileResourceLocal.setNbOfDownloads(fileResourceLocal
0349:                                .getNbOfDownloads() + 1);
0350:
0351:                        LibresourceEvent event = new LibresourceEvent(uri,
0352:                                resourceIdentifier, kernelService
0353:                                        .getConnectedResource(),
0354:                                FileConstants.EVENT_FILE_DOWNLOAD);
0355:                        Libresource.throwEvent(event);
0356:
0357:                        if (downloadInfos != null) {
0358:                            DownloadLogEntry entry = new DownloadLogEntry(
0359:                                    membershipService.getProfile()
0360:                                            .getFullName(),
0361:                                    (String) downloadInfos.get("ip"));
0362:                            Collection logs = fileResourceLocal
0363:                                    .getDownloadInfos();
0364:
0365:                            if (logs == null) {
0366:                                logs = new Vector();
0367:                            }
0368:
0369:                            logs.add(entry);
0370:                            fileResourceLocal.setDownloadInfos(logs);
0371:                        }
0372:                    }
0373:
0374:                    return coreService.getFileData("files_content_",
0375:                            fileResourceLocal.getId());
0376:                } catch (LibresourceSecurityException se) {
0377:                    throw se;
0378:                } catch (URINotExistException se) {
0379:                    throw se;
0380:                } catch (Exception e) {
0381:                    throw new LibresourceFilesException(
0382:                            "Error in getFileContent : " + e.getMessage(), e);
0383:                }
0384:            }
0385:
0386:            /**
0387:             * @ejb.interface-method
0388:             * @ejb.transaction type="Supports"
0389:             */
0390:            public FileResourceValue[] listFilesAt(URI uri)
0391:                    throws LibresourceFilesException,
0392:                    LibresourceSecurityException, URINotExistException {
0393:                try {
0394:                    KernelService kernelService = (KernelService) Libresource
0395:                            .getService(KernelConstants.SERVICE);
0396:                    LibresourceResourceValue[] files = kernelService
0397:                            .listResourcesAt(
0398:                                    uri,
0399:                                    FileResourceLocal.LIBRESOURCE_RESOURCE_SERVICE,
0400:                                    FileResourceLocal.LIBRESOURCE_RESOURCE_TYPE);
0401:
0402:                    ArrayList result = new ArrayList();
0403:                    FileResourceValue fileValue = null;
0404:
0405:                    for (int i = 0; i < files.length; i++) {
0406:                        if (kernelService.checkSecurity(kernelService
0407:                                .normalizeURI(files[i].getUri()),
0408:                                KernelConstants.SECURITY_READ)) {
0409:                            LibresourceResourceIdentifier resourceIdentifier = files[i]
0410:                                    .getLibresourceResourceIdentifier();
0411:                            fileValue = ((FileResourceLocal) Libresource
0412:                                    .findResource(resourceIdentifier))
0413:                                    .getFileResourceValue();
0414:                            fileValue.setUri(kernelService
0415:                                    .normalizeURI(files[i].getUri()));
0416:
0417:                            //
0418:                            result.add(fileValue);
0419:                        }
0420:                    }
0421:
0422:                    FileResourceValue[] fileResourceValues = new FileResourceValue[result
0423:                            .size()];
0424:
0425:                    for (int i = 0; i < fileResourceValues.length; i++) {
0426:                        fileResourceValues[i] = (FileResourceValue) result
0427:                                .get(i);
0428:                    }
0429:
0430:                    return fileResourceValues;
0431:                } catch (LibresourceSecurityException se) {
0432:                    throw se;
0433:                } catch (URINotExistException se) {
0434:                    throw se;
0435:                } catch (Exception e) {
0436:                    throw new LibresourceFilesException(
0437:                            "Error in listFilesAt : " + e.getMessage(), e);
0438:                }
0439:            }
0440:
0441:            /**
0442:             * @ejb.interface-method
0443:             * @ejb.transaction type="Required"
0444:             */
0445:            public void createRepository(URI uri, String name,
0446:                    String description) throws LibresourceFilesException,
0447:                    LibresourceSecurityException {
0448:                try {
0449:                    KernelService kernelService = (KernelService) Libresource
0450:                            .getService(KernelConstants.SERVICE);
0451:
0452:                    if (!kernelService.checkSecurity(uri,
0453:                            KernelConstants.SECURITY_CREATE)) {
0454:                        throw new LibresourceSecurityException(uri,
0455:                                KernelConstants.SECURITY_CREATE);
0456:                    }
0457:
0458:                    RepositoryResourceLocal repositoryResourceLocal = RepositoryResourceUtil
0459:                            .getLocalHome().create(name, description);
0460:                    kernelService.bind(repositoryResourceLocal
0461:                            .getLibresourceResourceIdentifier(), uri, name);
0462:
0463:                    // event
0464:                    LibresourceEvent event = new LibresourceEvent(uri,
0465:                            repositoryResourceLocal
0466:                                    .getLibresourceResourceIdentifier(),
0467:                            kernelService.getConnectedResource(),
0468:                            FileConstants.EVENT_REPOSITORY_CREATE);
0469:                    Libresource.throwEvent(event);
0470:                } catch (LibresourceSecurityException se) {
0471:                    ctx.setRollbackOnly();
0472:                    throw se;
0473:                } catch (Exception e) {
0474:                    ctx.setRollbackOnly();
0475:                    throw new LibresourceFilesException(
0476:                            "Error in createRepository : " + e.getMessage(), e);
0477:                }
0478:            }
0479:
0480:            /**
0481:             * @ejb.interface-method
0482:             * @ejb.transaction type="Required"
0483:             */
0484:            public void createDropBox(URI uri, String name, String description)
0485:                    throws LibresourceFilesException,
0486:                    LibresourceSecurityException {
0487:                try {
0488:                    KernelService kernelService = (KernelService) Libresource
0489:                            .getService(KernelConstants.SERVICE);
0490:
0491:                    if (!kernelService.checkSecurity(uri,
0492:                            KernelConstants.SECURITY_CREATE)) {
0493:                        throw new LibresourceSecurityException(uri,
0494:                                KernelConstants.SECURITY_CREATE);
0495:                    }
0496:
0497:                    DropBoxResourceLocal dropBoxResourceLocal = DropBoxResourceUtil
0498:                            .getLocalHome().create(name, description);
0499:                    kernelService.bind(dropBoxResourceLocal
0500:                            .getLibresourceResourceIdentifier(), uri, name);
0501:
0502:                    // event
0503:                    LibresourceEvent event = new LibresourceEvent(uri,
0504:                            dropBoxResourceLocal
0505:                                    .getLibresourceResourceIdentifier(),
0506:                            kernelService.getConnectedResource(),
0507:                            FileConstants.EVENT_DROP_BOX_CREATE);
0508:                    Libresource.throwEvent(event);
0509:                } catch (LibresourceSecurityException se) {
0510:                    ctx.setRollbackOnly();
0511:                    throw se;
0512:                } catch (Exception e) {
0513:                    ctx.setRollbackOnly();
0514:                    throw new LibresourceFilesException(
0515:                            "Error in createDropBox : " + e.getMessage(), e);
0516:                }
0517:            }
0518:
0519:            /**
0520:             * @ejb.interface-method
0521:             * @ejb.transaction type="Required"
0522:             */
0523:            public void editRepository(URI uri, String name, String description)
0524:                    throws LibresourceFilesException,
0525:                    LibresourceSecurityException, URINotExistException {
0526:                try {
0527:                    KernelService kernelService = (KernelService) Libresource
0528:                            .getService(KernelConstants.SERVICE);
0529:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0530:                            .lookup(uri);
0531:
0532:                    if (!kernelService.checkSecurity(uri,
0533:                            KernelConstants.SECURITY_UPDATE)) {
0534:                        throw new LibresourceSecurityException(uri,
0535:                                KernelConstants.SECURITY_UPDATE);
0536:                    }
0537:
0538:                    RepositoryResourceLocal repositoryResourceLocal = (RepositoryResourceLocal) Libresource
0539:                            .findResource(resourceIdentifier,
0540:                                    RepositoryResourceLocal.class);
0541:                    repositoryResourceLocal.setName(name);
0542:                    repositoryResourceLocal.setDescription(description);
0543:
0544:                    // update node
0545:                    kernelService.setShortName(uri, name);
0546:                    kernelService.setUpdateDate(uri, new Date());
0547:
0548:                    // event
0549:                    LibresourceEvent event = new LibresourceEvent(uri,
0550:                            resourceIdentifier, kernelService
0551:                                    .getConnectedResource(),
0552:                            FileConstants.EVENT_REPOSITORY_EDIT);
0553:                    Libresource.throwEvent(event);
0554:
0555:                    // indexation
0556:                    Libresource.index(uri);
0557:                } catch (LibresourceSecurityException se) {
0558:                    ctx.setRollbackOnly();
0559:                    throw se;
0560:                } catch (URINotExistException se) {
0561:                    ctx.setRollbackOnly();
0562:                    throw se;
0563:                } catch (Exception e) {
0564:                    ctx.setRollbackOnly();
0565:                    throw new LibresourceFilesException(
0566:                            "Error in editRepository : " + e.getMessage(), e);
0567:                }
0568:            }
0569:
0570:            /**
0571:             * @ejb.interface-method
0572:             * @ejb.transaction type="Required"
0573:             */
0574:            public void editDropBox(URI uri, String name, String description)
0575:                    throws LibresourceFilesException,
0576:                    LibresourceSecurityException, URINotExistException {
0577:                try {
0578:                    KernelService kernelService = (KernelService) Libresource
0579:                            .getService(KernelConstants.SERVICE);
0580:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0581:                            .lookup(uri);
0582:
0583:                    if (!kernelService.checkSecurity(uri,
0584:                            KernelConstants.SECURITY_UPDATE)) {
0585:                        throw new LibresourceSecurityException(uri,
0586:                                KernelConstants.SECURITY_UPDATE);
0587:                    }
0588:
0589:                    DropBoxResourceLocal dropBoxResourceLocal = (DropBoxResourceLocal) Libresource
0590:                            .findResource(resourceIdentifier,
0591:                                    DropBoxResourceLocal.class);
0592:                    dropBoxResourceLocal.setName(name);
0593:                    dropBoxResourceLocal.setDescription(description);
0594:
0595:                    // update node
0596:                    kernelService.setShortName(uri, name);
0597:                    kernelService.setUpdateDate(uri, new Date());
0598:
0599:                    // event
0600:                    LibresourceEvent event = new LibresourceEvent(uri,
0601:                            resourceIdentifier, kernelService
0602:                                    .getConnectedResource(),
0603:                            FileConstants.EVENT_DROP_BOX_EDIT);
0604:                    Libresource.throwEvent(event);
0605:
0606:                    // indexation
0607:                    Libresource.index(uri);
0608:                } catch (LibresourceSecurityException se) {
0609:                    ctx.setRollbackOnly();
0610:                    throw se;
0611:                } catch (URINotExistException se) {
0612:                    ctx.setRollbackOnly();
0613:                    throw se;
0614:                } catch (Exception e) {
0615:                    ctx.setRollbackOnly();
0616:                    throw new LibresourceFilesException(
0617:                            "Error in editDropBox : " + e.getMessage(), e);
0618:                }
0619:            }
0620:
0621:            /**
0622:             * @ejb.interface-method
0623:             * @ejb.transaction type="Required"
0624:             */
0625:            public void deleteRepository(URI uri)
0626:                    throws LibresourceFilesException,
0627:                    LibresourceSecurityException, URINotExistException {
0628:                try {
0629:                    KernelService kernelService = (KernelService) Libresource
0630:                            .getService(KernelConstants.SERVICE);
0631:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0632:                            .lookup(uri);
0633:
0634:                    // event
0635:                    LibresourceEvent event = new LibresourceEvent(uri,
0636:                            resourceIdentifier, kernelService
0637:                                    .getConnectedResource(),
0638:                            FileConstants.EVENT_REPOSITORY_DELETE);
0639:                    Libresource.throwEvent(event);
0640:
0641:                    Libresource.checkType(resourceIdentifier,
0642:                            RepositoryResourceLocal.class);
0643:                    kernelService.deleteURI(uri);
0644:                } catch (LibresourceSecurityException se) {
0645:                    ctx.setRollbackOnly();
0646:                    throw se;
0647:                } catch (URINotExistException se) {
0648:                    ctx.setRollbackOnly();
0649:                    throw se;
0650:                } catch (Exception e) {
0651:                    ctx.setRollbackOnly();
0652:                    throw new LibresourceFilesException(
0653:                            "Error in deleteRepository : " + e.getMessage(), e);
0654:                }
0655:            }
0656:
0657:            /**
0658:             * @ejb.interface-method
0659:             * @ejb.transaction type="Required"
0660:             */
0661:            public void deleteDropBox(URI uri)
0662:                    throws LibresourceFilesException,
0663:                    LibresourceSecurityException, URINotExistException {
0664:                try {
0665:                    KernelService kernelService = (KernelService) Libresource
0666:                            .getService(KernelConstants.SERVICE);
0667:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0668:                            .lookup(uri);
0669:
0670:                    // event
0671:                    LibresourceEvent event = new LibresourceEvent(uri,
0672:                            resourceIdentifier, kernelService
0673:                                    .getConnectedResource(),
0674:                            FileConstants.EVENT_DROP_BOX_DELETE);
0675:                    Libresource.throwEvent(event);
0676:
0677:                    Libresource.checkType(resourceIdentifier,
0678:                            RepositoryResourceLocal.class);
0679:                    kernelService.deleteURI(uri);
0680:                } catch (LibresourceSecurityException se) {
0681:                    ctx.setRollbackOnly();
0682:                    throw se;
0683:                } catch (URINotExistException se) {
0684:                    ctx.setRollbackOnly();
0685:                    throw se;
0686:                } catch (Exception e) {
0687:                    ctx.setRollbackOnly();
0688:                    throw new LibresourceFilesException(
0689:                            "Error in deleteDropBox : " + e.getMessage(), e);
0690:                }
0691:            }
0692:
0693:            /**
0694:             * @ejb.interface-method
0695:             * @ejb.transaction type="Supports"
0696:             */
0697:            public RepositoryResourceValue getRepository(URI uri)
0698:                    throws LibresourceFilesException,
0699:                    LibresourceSecurityException, URINotExistException {
0700:                try {
0701:                    KernelService kernelService = (KernelService) Libresource
0702:                            .getService(KernelConstants.SERVICE);
0703:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0704:                            .lookup(uri);
0705:                    RepositoryResourceLocal repositoryResourceLocal = (RepositoryResourceLocal) Libresource
0706:                            .findResource(resourceIdentifier,
0707:                                    RepositoryResourceLocal.class);
0708:                    RepositoryResourceValue resourceValue = repositoryResourceLocal
0709:                            .getRepositoryResourceValue();
0710:                    resourceValue.setUri(kernelService.normalizeURI(uri));
0711:
0712:                    return resourceValue;
0713:                } catch (LibresourceSecurityException se) {
0714:                    throw se;
0715:                } catch (URINotExistException se) {
0716:                    throw se;
0717:                } catch (Exception e) {
0718:                    throw new LibresourceFilesException(
0719:                            "Error in getRepository : " + e.getMessage(), e);
0720:                }
0721:            }
0722:
0723:            /**
0724:             * @ejb.interface-method
0725:             * @ejb.transaction type="Supports"
0726:             */
0727:            public DropBoxResourceValue getDropBox(URI uri)
0728:                    throws LibresourceFilesException,
0729:                    LibresourceSecurityException, URINotExistException {
0730:                try {
0731:                    KernelService kernelService = (KernelService) Libresource
0732:                            .getService(KernelConstants.SERVICE);
0733:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0734:                            .lookup(uri);
0735:                    DropBoxResourceLocal dropBoxResourceLocal = (DropBoxResourceLocal) Libresource
0736:                            .findResource(resourceIdentifier,
0737:                                    DropBoxResourceLocal.class);
0738:                    DropBoxResourceValue resourceValue = dropBoxResourceLocal
0739:                            .getDropBoxResourceValue();
0740:                    resourceValue.setUri(kernelService.normalizeURI(uri));
0741:
0742:                    return resourceValue;
0743:                } catch (LibresourceSecurityException se) {
0744:                    throw se;
0745:                } catch (URINotExistException se) {
0746:                    throw se;
0747:                } catch (Exception e) {
0748:                    throw new LibresourceFilesException(
0749:                            "Error in getDropBox : " + e.getMessage(), e);
0750:                }
0751:            }
0752:
0753:            /**
0754:             * @ejb.interface-method
0755:             * @ejb.transaction type="Supports"
0756:             */
0757:            public RepositoryResourceValue[] listRepositoriesAt(URI uri)
0758:                    throws LibresourceFilesException,
0759:                    LibresourceSecurityException, URINotExistException {
0760:                try {
0761:                    KernelService kernelService = (KernelService) Libresource
0762:                            .getService(KernelConstants.SERVICE);
0763:                    LibresourceResourceValue[] pages = kernelService
0764:                            .listResourcesAt(
0765:                                    uri,
0766:                                    RepositoryResourceLocal.LIBRESOURCE_RESOURCE_SERVICE,
0767:                                    RepositoryResourceLocal.LIBRESOURCE_RESOURCE_TYPE);
0768:                    RepositoryResourceValue[] repositoryResourceValues = new RepositoryResourceValue[pages.length];
0769:
0770:                    for (int i = 0; i < repositoryResourceValues.length; i++) {
0771:                        LibresourceResourceIdentifier resourceIdentifier = pages[i]
0772:                                .getLibresourceResourceIdentifier();
0773:                        repositoryResourceValues[i] = ((RepositoryResourceLocal) Libresource
0774:                                .findResource(resourceIdentifier))
0775:                                .getRepositoryResourceValue();
0776:                        repositoryResourceValues[i].setUri(kernelService
0777:                                .normalizeURI(pages[i].getUri()));
0778:                    }
0779:
0780:                    return repositoryResourceValues;
0781:                } catch (LibresourceSecurityException se) {
0782:                    throw se;
0783:                } catch (URINotExistException se) {
0784:                    throw se;
0785:                } catch (Exception e) {
0786:                    throw new LibresourceFilesException(
0787:                            "Error in listRepositoriesAt : " + e.getMessage(),
0788:                            e);
0789:                }
0790:            }
0791:
0792:            /**
0793:             * @ejb.interface-method
0794:             * @ejb.transaction type="Supports"
0795:             */
0796:            public DropBoxResourceValue[] listDropBoxesAt(URI uri)
0797:                    throws LibresourceFilesException,
0798:                    LibresourceSecurityException, URINotExistException {
0799:                try {
0800:                    KernelService kernelService = (KernelService) Libresource
0801:                            .getService(KernelConstants.SERVICE);
0802:                    LibresourceResourceValue[] pages = kernelService
0803:                            .listResourcesAt(
0804:                                    uri,
0805:                                    DropBoxResourceLocal.LIBRESOURCE_RESOURCE_SERVICE,
0806:                                    DropBoxResourceLocal.LIBRESOURCE_RESOURCE_TYPE);
0807:                    DropBoxResourceValue[] dropBoxResourceValues = new DropBoxResourceValue[pages.length];
0808:
0809:                    for (int i = 0; i < dropBoxResourceValues.length; i++) {
0810:                        LibresourceResourceIdentifier resourceIdentifier = pages[i]
0811:                                .getLibresourceResourceIdentifier();
0812:                        dropBoxResourceValues[i] = ((DropBoxResourceLocal) Libresource
0813:                                .findResource(resourceIdentifier))
0814:                                .getDropBoxResourceValue();
0815:                        dropBoxResourceValues[i].setUri(kernelService
0816:                                .normalizeURI(pages[i].getUri()));
0817:                    }
0818:
0819:                    return dropBoxResourceValues;
0820:                } catch (LibresourceSecurityException se) {
0821:                    throw se;
0822:                } catch (URINotExistException se) {
0823:                    throw se;
0824:                } catch (Exception e) {
0825:                    throw new LibresourceFilesException(
0826:                            "Error in listDropBoxesAt : " + e.getMessage(), e);
0827:                }
0828:            }
0829:
0830:            /**
0831:             * @ejb.interface-method
0832:             * @ejb.transaction type="Supports"
0833:             */
0834:            public FileResourceValue[] listFilesInRepository(URI uri)
0835:                    throws LibresourceFilesException,
0836:                    LibresourceSecurityException, URINotExistException {
0837:                try {
0838:                    KernelService kernelService = (KernelService) Libresource
0839:                            .getService(KernelConstants.SERVICE);
0840:
0841:                    if (!kernelService.checkSecurity(uri,
0842:                            KernelConstants.SECURITY_READ)) {
0843:                        throw new LibresourceSecurityException(uri,
0844:                                KernelConstants.SECURITY_READ);
0845:                    }
0846:
0847:                    return listFilesAt(uri);
0848:                } catch (LibresourceSecurityException se) {
0849:                    throw se;
0850:                } catch (URINotExistException se) {
0851:                    throw se;
0852:                } catch (Exception e) {
0853:                    throw new LibresourceFilesException(
0854:                            "Error in listFilesInRepository : "
0855:                                    + e.getMessage(), e);
0856:                }
0857:            }
0858:
0859:            /**
0860:             * @ejb.interface-method
0861:             * @ejb.transaction type="Supports"
0862:             */
0863:            public FileResourceValue[] listFilesInDropBox(URI uri)
0864:                    throws LibresourceFilesException,
0865:                    LibresourceSecurityException, URINotExistException {
0866:                try {
0867:                    KernelService kernelService = (KernelService) Libresource
0868:                            .getService(KernelConstants.SERVICE);
0869:
0870:                    if (!kernelService.checkSecurity(uri,
0871:                            FileConstants.SECURITY_DROP_BOX_SEE)) {
0872:                        throw new LibresourceSecurityException(uri,
0873:                                FileConstants.SECURITY_DROP_BOX_SEE);
0874:                    }
0875:
0876:                    return listFilesAt(uri);
0877:                } catch (LibresourceSecurityException se) {
0878:                    throw se;
0879:                } catch (URINotExistException se) {
0880:                    throw se;
0881:                } catch (Exception e) {
0882:                    throw new LibresourceFilesException(
0883:                            "Error in listFilesInDropBox : " + e.getMessage(),
0884:                            e);
0885:                }
0886:            }
0887:
0888:            /**
0889:             * @ejb.interface-method
0890:             * @ejb.transaction type="Supports"
0891:             */
0892:            public FileResourceValue[] listLastFilesInRepository(URI uri,
0893:                    int max) throws LibresourceFilesException,
0894:                    LibresourceSecurityException, URINotExistException {
0895:                try {
0896:                    KernelService kernelService = (KernelService) Libresource
0897:                            .getService(KernelConstants.SERVICE);
0898:
0899:                    if (!kernelService.checkSecurity(uri,
0900:                            KernelConstants.SECURITY_READ)) {
0901:                        throw new LibresourceSecurityException(uri,
0902:                                KernelConstants.SECURITY_READ);
0903:                    }
0904:
0905:                    FileResourceValue[] files = listFilesAt(uri);
0906:                    files = sortFilesResources(files);
0907:
0908:                    FileResourceValue[] result = new FileResourceValue[max];
0909:
0910:                    for (int i = 0; i < files.length; i++) {
0911:                        result[i] = files[i];
0912:                    }
0913:
0914:                    return result;
0915:                } catch (LibresourceSecurityException se) {
0916:                    throw se;
0917:                } catch (URINotExistException se) {
0918:                    throw se;
0919:                } catch (Exception e) {
0920:                    throw new LibresourceFilesException(
0921:                            "Error in listFilesInRepository : "
0922:                                    + e.getMessage(), e);
0923:                }
0924:            }
0925:
0926:            /**
0927:             * @ejb.interface-method
0928:             * @ejb.transaction type="Required"
0929:             */
0930:            public void uploadFileInRepository(URI uri, String description,
0931:                    String author, FileData fileData, boolean throwEvent)
0932:                    throws LibresourceFilesException,
0933:                    LibresourceSecurityException, URINotExistException {
0934:                try {
0935:                    KernelService kernelService = (KernelService) Libresource
0936:                            .getService(KernelConstants.SERVICE);
0937:
0938:                    if (!kernelService.checkSecurity(uri,
0939:                            FileConstants.SECURITY_FILE_UPLOAD)) {
0940:                        throw new LibresourceSecurityException(uri,
0941:                                FileConstants.SECURITY_FILE_UPLOAD);
0942:                    }
0943:
0944:                    // String id = FileResourceUtil.generateGUID(fileData.getName());
0945:                    String id = fileData.getName();
0946:
0947:                    id = Libresource.convertStringToId(id);
0948:
0949:                    URI fileUri = new URI(kernelService
0950:                            .normalizeAbsoluteURIPath(uri)
0951:                            + "/" + id);
0952:                    int suffix = 0;
0953:
0954:                    while (kernelService.exist(fileUri)) {
0955:                        fileUri = new URI(kernelService
0956:                                .normalizeAbsoluteURIPath(uri)
0957:                                + "/" + id + "_" + suffix);
0958:                        suffix++;
0959:                    }
0960:
0961:                    systemCreateFile(fileUri, description, author, fileData,
0962:                            throwEvent);
0963:                    kernelService.systemResetAcls(fileUri);
0964:                    kernelService.systemCopyAcl(uri, fileUri);
0965:                    kernelService.systemChown(fileUri, kernelService
0966:                            .getOwner(uri), false);
0967:
0968:                    // update node
0969:                    kernelService.setUpdateDate(uri, new Date());
0970:
0971:                    // event
0972:                    LibresourceEvent event = new LibresourceEvent(fileUri,
0973:                            kernelService.lookup(fileUri), kernelService
0974:                                    .getConnectedResource(),
0975:                            FileConstants.EVENT_FILE_CREATE);
0976:                    Libresource.throwEvent(event);
0977:                    event = new LibresourceEvent(uri,
0978:                            kernelService.lookup(uri), kernelService
0979:                                    .getConnectedResource(),
0980:                            FileConstants.EVENT_REPOSITORY_ADD_FILE, fileData
0981:                                    .getName());
0982:                    Libresource.throwEvent(event);
0983:                } catch (LibresourceSecurityException se) {
0984:                    throw se;
0985:                } catch (URINotExistException se) {
0986:                    throw se;
0987:                } catch (Exception e) {
0988:                    throw new LibresourceFilesException(
0989:                            "Error in uploadFileInRepository : "
0990:                                    + e.getMessage(), e);
0991:                }
0992:            }
0993:
0994:            /**
0995:             * @ejb.interface-method
0996:             * @ejb.transaction type="Required"
0997:             */
0998:            public void uploadFileInDropBox(URI uri, String description,
0999:                    String author, FileData fileData, boolean throwEvent)
1000:                    throws LibresourceFilesException,
1001:                    LibresourceSecurityException, URINotExistException {
1002:                try {
1003:                    KernelService kernelService = (KernelService) Libresource
1004:                            .getService(KernelConstants.SERVICE);
1005:
1006:                    if (!kernelService.checkSecurity(uri,
1007:                            FileConstants.SECURITY_FILE_UPLOAD)) {
1008:                        throw new LibresourceSecurityException(uri,
1009:                                FileConstants.SECURITY_FILE_UPLOAD);
1010:                    }
1011:
1012:                    // String id = FileResourceUtil.generateGUID(fileData.getName());
1013:                    String id = fileData.getName();
1014:
1015:                    id = Libresource.convertStringToId(id);
1016:
1017:                    URI fileUri = new URI(kernelService
1018:                            .normalizeAbsoluteURIPath(uri)
1019:                            + "/" + id);
1020:                    int suffix = 0;
1021:
1022:                    while (kernelService.exist(fileUri)) {
1023:                        fileUri = new URI(kernelService
1024:                                .normalizeAbsoluteURIPath(uri)
1025:                                + "/" + id + "_" + suffix);
1026:                        suffix++;
1027:                    }
1028:
1029:                    systemCreateFile(fileUri, description, author, fileData,
1030:                            throwEvent);
1031:                    kernelService.systemResetAcls(fileUri);
1032:                    kernelService.systemChown(fileUri, kernelService
1033:                            .getOwner(uri), false);
1034:
1035:                    // Set default security
1036:                    AclValue[] acls = kernelService.getAcls(uri);
1037:                    java.util.List currentPermissions = null;
1038:
1039:                    for (int i = 0; i < acls.length; i++) {
1040:                        currentPermissions = Arrays.asList(acls[i]
1041:                                .getPermissions());
1042:
1043:                        if (currentPermissions
1044:                                .contains(KernelConstants.SECURITY_UPDATE)
1045:                                || currentPermissions
1046:                                        .contains(FileConstants.SECURITY_DROP_BOX_SEE)) {
1047:                            kernelService.systemCreateAcl(fileUri, acls[i]
1048:                                    .getOwnerUri(), (String[]) acls[i]
1049:                                    .getPermissions().clone());
1050:                        } else {
1051:                            // Need to filter the right READ
1052:                            String[] filteredPermission = (String[]) acls[i]
1053:                                    .getPermissions().clone();
1054:
1055:                            for (int index = 0; index < filteredPermission.length; index++) {
1056:                                if (filteredPermission[index]
1057:                                        .equals(KernelConstants.SECURITY_READ)) {
1058:                                    filteredPermission[index] = null;
1059:                                }
1060:                            }
1061:
1062:                            kernelService.systemCreateAcl(fileUri, acls[i]
1063:                                    .getOwnerUri(), filteredPermission);
1064:                        }
1065:                    }
1066:
1067:                    // update node
1068:                    kernelService.setUpdateDate(uri, new Date());
1069:
1070:                    // event
1071:                    LibresourceEvent event = new LibresourceEvent(fileUri,
1072:                            kernelService.lookup(fileUri), kernelService
1073:                                    .getConnectedResource(),
1074:                            FileConstants.EVENT_FILE_CREATE);
1075:                    Libresource.throwEvent(event);
1076:                    event = new LibresourceEvent(uri,
1077:                            kernelService.lookup(uri), kernelService
1078:                                    .getConnectedResource(),
1079:                            FileConstants.EVENT_DROP_BOX_ADD_FILE, fileData
1080:                                    .getName());
1081:                    Libresource.throwEvent(event);
1082:                } catch (LibresourceSecurityException se) {
1083:                    throw se;
1084:                } catch (URINotExistException se) {
1085:                    throw se;
1086:                } catch (Exception e) {
1087:                    throw new LibresourceFilesException(
1088:                            "Error in uploadFileInDropBox : " + e.getMessage(),
1089:                            e);
1090:                }
1091:            }
1092:
1093:            // system
1094:
1095:            /**
1096:             * @ejb.interface-method
1097:             * @ejb.transaction type="Required"
1098:             */
1099:            public void systemCreateFile(URI uri, String description,
1100:                    String author, FileData fileData, boolean throwEvent)
1101:                    throws LibresourceFilesException,
1102:                    LibresourceSecurityException {
1103:                try {
1104:                    KernelService kernelService = (KernelService) Libresource
1105:                            .getService(KernelConstants.SERVICE);
1106:                    LibresourceCoreService coreService = (LibresourceCoreService) Libresource
1107:                            .getService(CoreConstants.SERVICE);
1108:                    FileResourceLocal fileResourceLocal = null;
1109:
1110:                    String name;
1111:
1112:                    if (fileData != null) {
1113:                        name = fileData.getName();
1114:
1115:                        String type = getMimeType(fileData.getName());
1116:                        fileResourceLocal = FileResourceUtil.getLocalHome()
1117:                                .create(name, description, author, type,
1118:                                        fileData.getSize(), throwEvent,
1119:                                        new Date());
1120:                        coreService.putFileData("files_content_",
1121:                                fileResourceLocal.getId(), fileData);
1122:                    } else {
1123:                        name = "(Empty)";
1124:                        fileResourceLocal = FileResourceUtil.getLocalHome()
1125:                                .create("(Empty)", description, author, null,
1126:                                        0, throwEvent, new Date());
1127:                    }
1128:
1129:                    kernelService.systemBind(fileResourceLocal
1130:                            .getLibresourceResourceIdentifier(), uri, name);
1131:
1132:                    // event
1133:                    // LibresourceEvent event = new LibresourceEvent(uri,
1134:                    // fileResourceLocal.getLibresourceResourceIdentifier(),
1135:                    // kernelService.getConnectedResource(),
1136:                    // FileConstants.EVENT_FILE_CREATE);
1137:                    // Libresource.throwEvent(event);
1138:                } catch (LibresourceSecurityException se) {
1139:                    ctx.setRollbackOnly();
1140:                    throw se;
1141:                } catch (Exception e) {
1142:                    ctx.setRollbackOnly();
1143:                    throw new LibresourceFilesException(
1144:                            "Error in systemCreateFile : " + e.getMessage(), e);
1145:                }
1146:            }
1147:
1148:            // libresource service
1149:
1150:            /**
1151:             * @ejb.interface-method
1152:             * @ejb.transaction type="Supports"
1153:             */
1154:            public LibresourceIndexableContent getIndexableContent(
1155:                    LibresourceResourceIdentifier resourceIdentifier)
1156:                    throws LibresourceException {
1157:                try {
1158:                    LibresourceCoreService coreService = (LibresourceCoreService) Libresource
1159:                            .getService(CoreConstants.SERVICE);
1160:
1161:                    try {
1162:                        Libresource.checkType(resourceIdentifier,
1163:                                FileResourceLocal.class);
1164:
1165:                        LibresourceIndexableContent content = new LibresourceIndexableContent();
1166:                        FileResourceLocal fileResourceLocal = (FileResourceLocal) Libresource
1167:                                .findResource(resourceIdentifier);
1168:                        content.addContentPart(fileResourceLocal.getName());
1169:                        content.addContentPart(fileResourceLocal
1170:                                .getDisplayName());
1171:                        content.addContentPart(fileResourceLocal
1172:                                .getDescription());
1173:
1174:                        FileContentParser parser = Types2Parsers
1175:                                .getParser(fileResourceLocal.getType());
1176:
1177:                        if (parser != null) {
1178:                            String indexableContent = new String();
1179:
1180:                            try {
1181:                                indexableContent = parser.parse(coreService
1182:                                        .getFileData("files_content_",
1183:                                                fileResourceLocal.getId()));
1184:                            } catch (Exception e) {
1185:                                // nothing
1186:                            }
1187:
1188:                            content.addContentPart(indexableContent);
1189:                        }
1190:
1191:                        return content;
1192:                    } catch (LibresourceException e) {
1193:                        //
1194:                    }
1195:
1196:                    try {
1197:                        Libresource.checkType(resourceIdentifier,
1198:                                RepositoryResourceLocal.class);
1199:
1200:                        LibresourceIndexableContent content = new LibresourceIndexableContent();
1201:                        RepositoryResourceLocal repositoryResourceLocal = (RepositoryResourceLocal) Libresource
1202:                                .findResource(resourceIdentifier);
1203:                        content.addContentPart(repositoryResourceLocal
1204:                                .getName());
1205:                        content.addContentPart(repositoryResourceLocal
1206:                                .getDescription());
1207:
1208:                        return content;
1209:                    } catch (LibresourceException e) {
1210:                        //
1211:                    }
1212:
1213:                    try {
1214:                        Libresource.checkType(resourceIdentifier,
1215:                                DropBoxResourceLocal.class);
1216:
1217:                        LibresourceIndexableContent content = new LibresourceIndexableContent();
1218:                        DropBoxResourceLocal dropBoxResourceLocal = (DropBoxResourceLocal) Libresource
1219:                                .findResource(resourceIdentifier);
1220:                        content.addContentPart(dropBoxResourceLocal.getName());
1221:                        content.addContentPart(dropBoxResourceLocal
1222:                                .getDescription());
1223:
1224:                        return content;
1225:                    } catch (LibresourceException e) {
1226:                        //
1227:                    }
1228:
1229:                    return null;
1230:                } catch (Exception e) {
1231:                    throw new LibresourceException(
1232:                            "error in LibresourceFiles.getIndexableContent("
1233:                                    + resourceIdentifier + ")", e);
1234:                }
1235:            }
1236:
1237:            /**
1238:             * @ejb.interface-method
1239:             * @ejb.transaction type="Supports"
1240:             */
1241:            public String[] listAvailablesPermissions(
1242:                    LibresourceResourceIdentifier resourceIdentifier)
1243:                    throws LibresourceException {
1244:                if (resourceIdentifier.getService().equals(
1245:                        FileConstants.SERVICE)) {
1246:                    if (resourceIdentifier.getResourceType().equals(
1247:                            FileConstants.RESOURCE_REPOSITORY)) {
1248:                        return new String[] { FileConstants.SECURITY_FILE_UPLOAD };
1249:                    }
1250:
1251:                    if (resourceIdentifier.getResourceType().equals(
1252:                            FileConstants.RESOURCE_DROP_BOX)) {
1253:                        return new String[] {
1254:                                FileConstants.SECURITY_DROP_BOX_SEE,
1255:                                FileConstants.SECURITY_FILE_UPLOAD };
1256:                    }
1257:                }
1258:
1259:                return super .listAvailablesPermissions(resourceIdentifier);
1260:            }
1261:
1262:            /**
1263:             * @ejb.interface-method
1264:             * @ejb.transaction type="Supports"
1265:             */
1266:            public String[] listAvailablesEvents(
1267:                    LibresourceResourceIdentifier resourceIdentifier)
1268:                    throws LibresourceException {
1269:                if (resourceIdentifier.getService().equals(
1270:                        FileConstants.SERVICE)) {
1271:                    if (resourceIdentifier.getResourceType().equals(
1272:                            FileConstants.RESOURCE_REPOSITORY)) {
1273:                        return new String[] {
1274:                                FileConstants.EVENT_REPOSITORY_CREATE,
1275:                                FileConstants.EVENT_REPOSITORY_EDIT,
1276:                                FileConstants.EVENT_REPOSITORY_DELETE,
1277:                                FileConstants.EVENT_REPOSITORY_ADD_FILE };
1278:                    }
1279:
1280:                    if (resourceIdentifier.getResourceType().equals(
1281:                            FileConstants.RESOURCE_DROP_BOX)) {
1282:                        return new String[] {
1283:                                FileConstants.EVENT_DROP_BOX_CREATE,
1284:                                FileConstants.EVENT_DROP_BOX_EDIT,
1285:                                FileConstants.EVENT_DROP_BOX_DELETE,
1286:                                FileConstants.EVENT_DROP_BOX_ADD_FILE };
1287:                    }
1288:
1289:                    if (resourceIdentifier.getResourceType().equals(
1290:                            FileConstants.RESOURCE_FILE)) {
1291:                        return new String[] { FileConstants.EVENT_FILE_CREATE,
1292:                                FileConstants.EVENT_FILE_EDIT,
1293:                                FileConstants.EVENT_FILE_DELETE,
1294:                                FileConstants.EVENT_FILE_DOWNLOAD };
1295:                    }
1296:                }
1297:
1298:                return super .listAvailablesPermissions(resourceIdentifier);
1299:            }
1300:
1301:            /**
1302:             * @ejb.interface-method
1303:             * @ejb.transaction type="Supports"
1304:             */
1305:            public LibresourceExportHandler getXmlExportHandlerForResource(
1306:                    URI uri) throws LibresourceException {
1307:                try {
1308:                    KernelService kernelService = (KernelService) Libresource
1309:                            .getService(KernelConstants.SERVICE);
1310:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
1311:                            .lookup(uri);
1312:
1313:                    try {
1314:                        Libresource.checkType(resourceIdentifier,
1315:                                RepositoryResourceLocal.class);
1316:
1317:                        return new RepositoryExportHandler(uri);
1318:                    } catch (Exception e) {
1319:                        //
1320:                    }
1321:
1322:                    try {
1323:                        Libresource.checkType(resourceIdentifier,
1324:                                DropBoxResourceLocal.class);
1325:
1326:                        return new DropBoxExportHandler(uri);
1327:                    } catch (Exception e) {
1328:                        //
1329:                    }
1330:
1331:                    try {
1332:                        Libresource.checkType(resourceIdentifier,
1333:                                FileResourceLocal.class);
1334:
1335:                        return new FileExportHandler(uri);
1336:                    } catch (Exception e) {
1337:                        //
1338:                    }
1339:
1340:                    return super .getXmlExportHandlerForResource(uri);
1341:                } catch (Exception e) {
1342:                    throw new LibresourceException(
1343:                            "Can't obtain exportHandler for uri " + uri, e);
1344:                }
1345:            }
1346:
1347:            /**
1348:             * @ejb.interface-method
1349:             * @ejb.transaction type="Supports"
1350:             */
1351:            public LibresourceImportHandler getXmlImportHandler(String type)
1352:                    throws LibresourceException {
1353:                if (type.equals(FileConstants.RESOURCE_REPOSITORY)) {
1354:                    return new RepositoryImportHandler();
1355:                }
1356:
1357:                if (type.equals(FileConstants.RESOURCE_DROP_BOX)) {
1358:                    return new DropBoxImportHandler();
1359:                }
1360:
1361:                if (type.equals(FileConstants.RESOURCE_FILE)) {
1362:                    return new FileImportHandler();
1363:                }
1364:
1365:                return super .getXmlImportHandler(type);
1366:            }
1367:
1368:            // helpers
1369:            private FileResourceValue[] sortFilesResources(
1370:                    FileResourceValue[] files) throws Exception {
1371:                Arrays.sort(files, new Comparator() {
1372:                    public int compare(Object o1, Object o2) {
1373:                        if (!(o1 instanceof  FileResourceValue)) {
1374:                            return 0;
1375:                        }
1376:
1377:                        return (((FileResourceValue) o1).getDate())
1378:                                .compareTo(((FileResourceValue) o2).getDate());
1379:                    }
1380:                });
1381:
1382:                return files;
1383:            }
1384:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.