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


001:        /**
002:         * LibreSource
003:         * Copyright (C) 2004-2008 Artenum SARL / INRIA
004:         * http://www.libresource.org - contact@artenum.com
005:         *
006:         * This file is part of the LibreSource software, 
007:         * which can be used and distributed under license conditions.
008:         * The license conditions are provided in the LICENSE.TXT file 
009:         * at the root path of the packaging that enclose this file. 
010:         * More information can be found at 
011:         * - http://dev.libresource.org/home/license
012:         *
013:         * Initial authors :
014:         *
015:         * Guillaume Bort / INRIA
016:         * Francois Charoy / Universite Nancy 2
017:         * Julien Forest / Artenum
018:         * Claude Godart / Universite Henry Poincare
019:         * Florent Jouille / INRIA
020:         * Sebastien Jourdain / INRIA / Artenum
021:         * Yves Lerumeur / Artenum
022:         * Pascal Molli / Universite Henry Poincare
023:         * Gerald Oster / INRIA
024:         * Mariarosa Penzi / Artenum
025:         * Gerard Sookahet / Artenum
026:         * Raphael Tani / INRIA
027:         *
028:         * Contributors :
029:         *
030:         * Stephane Bagnier / Artenum
031:         * Amadou Dia / Artenum-IUP Blois
032:         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033:         */package org.libresource.subversion.ejb;
034:
035:        import org.libresource.Libresource;
036:        import org.libresource.LibresourceEvent;
037:        import org.libresource.LibresourceException;
038:        import org.libresource.LibresourceResourceIdentifier;
039:        import org.libresource.LibresourceResourceValue;
040:        import org.libresource.LibresourceServiceBase;
041:
042:        import org.libresource.kernel.KernelConstants;
043:        import org.libresource.kernel.LibresourceSecurityException;
044:        import org.libresource.kernel.URINotExistException;
045:        import org.libresource.kernel.interfaces.KernelService;
046:
047:        import org.libresource.membership.MembershipConstants;
048:        import org.libresource.membership.interfaces.MembershipService;
049:
050:        import org.libresource.search.LibresourceIndexableContent;
051:
052:        import org.libresource.subversion.LibresourceSubversionException;
053:        import org.libresource.subversion.SubversionConstants;
054:        import org.libresource.subversion.ejb.model.SubversionRepositoryResourceValue;
055:        import org.libresource.subversion.interfaces.SubversionRepositoryResourceLocal;
056:        import org.libresource.subversion.util.SubversionRepositoryResourceUtil;
057:
058:        import org.libresource.xml.LibresourceExportHandler;
059:        import org.libresource.xml.LibresourceImportHandler;
060:
061:        import java.io.BufferedWriter;
062:        import java.io.File;
063:        import java.io.FileWriter;
064:        import java.io.IOException;
065:        import java.io.InputStream;
066:        import java.io.Writer;
067:
068:        import java.net.URI;
069:
070:        import java.util.ArrayList;
071:        import java.util.Arrays;
072:        import java.util.Collection;
073:        import java.util.Date;
074:        import java.util.Iterator;
075:        import java.util.Vector;
076:
077:        import javax.naming.InitialContext;
078:
079:        /**
080:         * The Libresource Sycnhronization service
081:         *
082:         * @author <a href="mailto:jourdain@artenum.com">Sebastien Jourdain</a> - <a
083:         *         href="http://www.artenum.com">Artenum</a>
084:         *
085:         * @libresource.service name="LibresourceSubversion" depends="Kernel,Membership"
086:         *
087:         */
088:        public abstract class LibresourceSubversionServiceBean extends
089:                LibresourceServiceBase {
090:            private static transient String authzFilePath;
091:            private static transient String svnRepository;
092:            private static transient String svnCreateRepositoryCmd;
093:            private static transient String svnRenameRepositoryCmd;
094:            private static final String READERS = "_readers";
095:            private static final String WRITERS = "_writers";
096:            private static final String END_LINE = "\n";
097:            private static final String EQUAL = " = ";
098:            private static final String R = "r";
099:            private static final String RW = "rw";
100:            private static final String REPOSITORY_HEAD = "[";
101:            private static final String REPOSITORY_TAIL = ":/]\n";
102:            private static final String GROUP_HEAD = "@";
103:            private static final String GROUP_DEFINITION = "[groups]\n";
104:
105:            /**
106:             * @ejb.interface-method
107:             * @ejb.transaction type="Required"
108:             */
109:            public void createRepository(URI uri, String name,
110:                    String description, String commiters, String readers)
111:                    throws LibresourceSubversionException,
112:                    LibresourceSecurityException, URINotExistException {
113:                try {
114:                    KernelService kernelService = (KernelService) Libresource
115:                            .getService(KernelConstants.SERVICE);
116:                    SubversionRepositoryResourceLocal subversionRepositoryResourceLocal = SubversionRepositoryResourceUtil
117:                            .getLocalHome().create(name, description,
118:                                    commiters, readers);
119:                    kernelService.bind(subversionRepositoryResourceLocal
120:                            .getLibresourceResourceIdentifier(), uri, name);
121:
122:                    // Create SVN repository
123:                    String repositoryName = subversionRepositoryResourceLocal
124:                            .getId();
125:
126:                    while (!canCreateRepository(repositoryName)) {
127:                        repositoryName = subversionRepositoryResourceLocal
128:                                .getId()
129:                                + "_" + System.currentTimeMillis();
130:                    }
131:
132:                    subversionRepositoryResourceLocal
133:                            .setSvnName(repositoryName);
134:
135:                    // Exec the cmd line
136:                    exec(getSVNRootRepositoryPath(),
137:                            getRepositoryCreationCmdLine(repositoryName));
138:
139:                    // Update security
140:                    buildAuthzFile();
141:
142:                    // event
143:                    LibresourceEvent event = new LibresourceEvent(uri,
144:                            subversionRepositoryResourceLocal
145:                                    .getLibresourceResourceIdentifier(),
146:                            kernelService.getConnectedResource(),
147:                            SubversionConstants.EVENT_REPOSITORY_CREATE);
148:                    Libresource.throwEvent(event);
149:                } catch (LibresourceSecurityException se) {
150:                    ctx.setRollbackOnly();
151:                    throw se;
152:                } catch (Exception e) {
153:                    ctx.setRollbackOnly();
154:                    throw new LibresourceSubversionException(
155:                            "Error in createRepository : " + e.getMessage(), e);
156:                }
157:            }
158:
159:            /**
160:             * @ejb.interface-method
161:             * @ejb.transaction type="Required"
162:             */
163:            public void editRepository(URI uri, String name, String svnName,
164:                    String description, String commiters, String readers)
165:                    throws LibresourceSubversionException,
166:                    LibresourceSecurityException, URINotExistException {
167:                try {
168:                    KernelService kernelService = (KernelService) Libresource
169:                            .getService(KernelConstants.SERVICE);
170:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
171:                            .lookup(uri);
172:
173:                    if (!kernelService.checkSecurity(uri,
174:                            KernelConstants.SECURITY_UPDATE)) {
175:                        throw new LibresourceSecurityException(uri,
176:                                KernelConstants.SECURITY_UPDATE);
177:                    }
178:
179:                    SubversionRepositoryResourceLocal subversionRepositoryResourceLocal = (SubversionRepositoryResourceLocal) Libresource
180:                            .findResource(resourceIdentifier,
181:                                    SubversionRepositoryResourceLocal.class);
182:
183:                    // Keep old svn name
184:                    String oldSvnName = subversionRepositoryResourceLocal
185:                            .getSvnName();
186:
187:                    // make the change
188:                    subversionRepositoryResourceLocal.setName(name);
189:                    subversionRepositoryResourceLocal
190:                            .setDescription(description);
191:                    subversionRepositoryResourceLocal.setCommiters(commiters);
192:                    subversionRepositoryResourceLocal.setReaders(readers);
193:                    subversionRepositoryResourceLocal.setSvnName(svnName);
194:
195:                    // Rename the svn directory
196:                    if (!oldSvnName.equals(svnName)) {
197:                        if (!canCreateRepository(svnName)) {
198:                            throw new LibresourceSubversionException(
199:                                    "This repository name is not available");
200:                        }
201:
202:                        exec(getSVNRootRepositoryPath(),
203:                                getRepositoryRenameCmdLine(oldSvnName, svnName));
204:                    }
205:
206:                    // Filter inconsistant user
207:                    subversionRepositoryResourceLocal
208:                            .setCommiters(convertResourceToSubversionUserString(listCommiters(uri)));
209:                    subversionRepositoryResourceLocal
210:                            .setReaders(convertResourceToSubversionUserString(listReaders(uri)));
211:
212:                    // update node
213:                    kernelService.setShortName(uri, name);
214:                    kernelService.setUpdateDate(uri, new Date());
215:
216:                    // event
217:                    LibresourceEvent event = new LibresourceEvent(uri,
218:                            resourceIdentifier, kernelService
219:                                    .getConnectedResource(),
220:                            SubversionConstants.EVENT_REPOSITORY_EDIT);
221:                    Libresource.throwEvent(event);
222:
223:                    // Build subversion secu file
224:                    buildAuthzFile();
225:
226:                    // indexation
227:                    Libresource.index(uri);
228:                } catch (LibresourceSecurityException se) {
229:                    ctx.setRollbackOnly();
230:                    throw se;
231:                } catch (URINotExistException se) {
232:                    ctx.setRollbackOnly();
233:                    throw se;
234:                } catch (Exception e) {
235:                    ctx.setRollbackOnly();
236:                    throw new LibresourceSubversionException(
237:                            "Error in editRepository : " + e.getMessage(), e);
238:                }
239:            }
240:
241:            /**
242:             * @ejb.interface-method
243:             * @ejb.transaction type="Required"
244:             */
245:            public void deleteRepository(URI uri)
246:                    throws LibresourceSubversionException,
247:                    LibresourceSecurityException, URINotExistException {
248:                try {
249:                    KernelService kernelService = (KernelService) Libresource
250:                            .getService(KernelConstants.SERVICE);
251:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
252:                            .lookup(uri);
253:
254:                    // Remove in the SVN repository
255:                    SubversionRepositoryResourceLocal subversionRepositoryResourceLocal = (SubversionRepositoryResourceLocal) Libresource
256:                            .findResource(resourceIdentifier,
257:                                    SubversionRepositoryResourceLocal.class);
258:                    subversionRepositoryResourceLocal.remove();
259:
260:                    // Build subversion secu file
261:                    buildAuthzFile();
262:
263:                    // event
264:                    LibresourceEvent event = new LibresourceEvent(uri,
265:                            resourceIdentifier, kernelService
266:                                    .getConnectedResource(),
267:                            SubversionConstants.EVENT_REPOSITORY_DELETE);
268:                    Libresource.throwEvent(event);
269:
270:                    Libresource.checkType(resourceIdentifier,
271:                            SubversionRepositoryResourceLocal.class);
272:                    kernelService.deleteURI(uri);
273:                } catch (LibresourceSecurityException se) {
274:                    ctx.setRollbackOnly();
275:                    throw se;
276:                } catch (URINotExistException se) {
277:                    ctx.setRollbackOnly();
278:                    throw se;
279:                } catch (Exception e) {
280:                    ctx.setRollbackOnly();
281:                    throw new LibresourceSubversionException(
282:                            "Error in deleteRepository : " + e.getMessage(), e);
283:                }
284:            }
285:
286:            /**
287:             * @ejb.interface-method
288:             * @ejb.transaction type="Supports"
289:             */
290:            public SubversionRepositoryResourceValue getRepository(URI uri)
291:                    throws LibresourceSubversionException,
292:                    LibresourceSecurityException, URINotExistException {
293:                try {
294:                    KernelService kernelService = (KernelService) Libresource
295:                            .getService(KernelConstants.SERVICE);
296:
297:                    if (!kernelService.checkSecurity(uri,
298:                            KernelConstants.SECURITY_READ)) {
299:                        throw new LibresourceSecurityException(uri,
300:                                KernelConstants.SECURITY_READ);
301:                    }
302:
303:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
304:                            .lookup(uri);
305:                    SubversionRepositoryResourceLocal subversionRepositoryResourceLocal = (SubversionRepositoryResourceLocal) Libresource
306:                            .findResource(resourceIdentifier,
307:                                    SubversionRepositoryResourceLocal.class);
308:                    SubversionRepositoryResourceValue resourceValue = subversionRepositoryResourceLocal
309:                            .getSubversionRepositoryResourceValue();
310:                    resourceValue.setUri(kernelService.normalizeURI(uri));
311:
312:                    return resourceValue;
313:                } catch (LibresourceSecurityException se) {
314:                    throw se;
315:                } catch (URINotExistException se) {
316:                    throw se;
317:                } catch (Exception e) {
318:                    throw new LibresourceSubversionException(
319:                            "Error in getRepository : " + e.getMessage(), e);
320:                }
321:            }
322:
323:            /**
324:             * @ejb.interface-method
325:             * @ejb.transaction type="Supports"
326:             */
327:            public SubversionRepositoryResourceValue[] listRepositoryAt(URI uri)
328:                    throws LibresourceSubversionException,
329:                    LibresourceSecurityException, URINotExistException {
330:                try {
331:                    KernelService kernelService = (KernelService) Libresource
332:                            .getService(KernelConstants.SERVICE);
333:                    LibresourceResourceValue[] resources = kernelService
334:                            .listResourcesAt(
335:                                    uri,
336:                                    SubversionRepositoryResourceLocal.LIBRESOURCE_RESOURCE_SERVICE,
337:                                    SubversionRepositoryResourceLocal.LIBRESOURCE_RESOURCE_TYPE);
338:                    SubversionRepositoryResourceValue[] subversionRepositoryResourceValue = new SubversionRepositoryResourceValue[resources.length];
339:
340:                    for (int i = 0; i < subversionRepositoryResourceValue.length; i++) {
341:                        LibresourceResourceIdentifier resourceIdentifier = resources[i]
342:                                .getLibresourceResourceIdentifier();
343:                        subversionRepositoryResourceValue[i] = ((SubversionRepositoryResourceLocal) Libresource
344:                                .findResource(resourceIdentifier))
345:                                .getSubversionRepositoryResourceValue();
346:                        subversionRepositoryResourceValue[i]
347:                                .setUri(kernelService.normalizeURI(resources[i]
348:                                        .getUri()));
349:                    }
350:
351:                    return subversionRepositoryResourceValue;
352:                } catch (LibresourceSecurityException se) {
353:                    throw se;
354:                } catch (URINotExistException se) {
355:                    throw se;
356:                } catch (Exception e) {
357:                    throw new LibresourceSubversionException(
358:                            "Error in listRepositoryAt : " + e.getMessage(), e);
359:                }
360:            }
361:
362:            /**
363:             * @ejb.interface-method
364:             * @ejb.transaction type="Supports"
365:             */
366:            public SubversionRepositoryResourceValue[] listAllRepositories()
367:                    throws LibresourceSubversionException {
368:                try {
369:                    KernelService kernelService = (KernelService) Libresource
370:                            .getService(KernelConstants.SERVICE);
371:                    Collection repositories = SubversionRepositoryResourceUtil
372:                            .getLocalHome().findAll();
373:                    Vector allRepositories = new Vector();
374:
375:                    for (Iterator i = repositories.iterator(); i.hasNext();) {
376:                        SubversionRepositoryResourceLocal subversionRepositoryResourceLocal = (SubversionRepositoryResourceLocal) i
377:                                .next();
378:                        LibresourceResourceIdentifier identifier = subversionRepositoryResourceLocal
379:                                .getLibresourceResourceIdentifier();
380:
381:                        try {
382:                            URI syncURI = kernelService.getMyURI(identifier);
383:                            SubversionRepositoryResourceValue resourceValue = subversionRepositoryResourceLocal
384:                                    .getSubversionRepositoryResourceValue();
385:                            resourceValue.setUri(syncURI);
386:                            allRepositories.add(resourceValue);
387:                        } catch (Exception e) {
388:                            // lazy
389:                        }
390:                    }
391:
392:                    SubversionRepositoryResourceValue[] result = new SubversionRepositoryResourceValue[repositories
393:                            .size()];
394:
395:                    for (int i = 0; i < result.length; i++) {
396:                        result[i] = (SubversionRepositoryResourceValue) allRepositories
397:                                .get(i);
398:                    }
399:
400:                    return result;
401:                } catch (Exception e) {
402:                    throw new LibresourceSubversionException(
403:                            "Can't list all repositories", e);
404:                }
405:            }
406:
407:            // libresource service
408:
409:            /**
410:             * @ejb.interface-method
411:             * @ejb.transaction type="Supports"
412:             */
413:            public LibresourceExportHandler getXmlExportHandlerForResource(
414:                    URI uri) throws LibresourceException {
415:                return super .getXmlExportHandlerForResource(uri);
416:            }
417:
418:            /**
419:             * @ejb.interface-method
420:             * @ejb.transaction type="Supports"
421:             */
422:            public LibresourceImportHandler getXmlImportHandler(String type)
423:                    throws LibresourceException {
424:                return super .getXmlImportHandler(type);
425:            }
426:
427:            /**
428:             * @ejb.interface-method
429:             * @ejb.transaction type="Supports"
430:             */
431:            public String[] listAvailablesPermissions(
432:                    LibresourceResourceIdentifier resourceIdentifier)
433:                    throws LibresourceException {
434:                return null;
435:            }
436:
437:            /**
438:             * @ejb.interface-method
439:             * @ejb.transaction type="Supports"
440:             */
441:            public String[] listAvailablesEvents(
442:                    LibresourceResourceIdentifier resourceIdentifier)
443:                    throws LibresourceException {
444:                if (resourceIdentifier.getService().equals(
445:                        SubversionConstants.SERVICE)) {
446:                    if (resourceIdentifier.getResourceType().equals(
447:                            SubversionConstants.RESOURCE)) {
448:                        return new String[] {
449:                                SubversionConstants.EVENT_REPOSITORY_CREATE,
450:                                SubversionConstants.EVENT_REPOSITORY_EDIT,
451:                                SubversionConstants.EVENT_REPOSITORY_DELETE };
452:                    }
453:                }
454:
455:                return super .listAvailablesPermissions(resourceIdentifier);
456:            }
457:
458:            /**
459:             * @ejb.interface-method
460:             * @ejb.transaction type="Supports"
461:             */
462:            public LibresourceIndexableContent getIndexableContent(
463:                    LibresourceResourceIdentifier resourceIdentifier)
464:                    throws LibresourceException {
465:                try {
466:                    try {
467:                        Libresource.checkType(resourceIdentifier,
468:                                SubversionRepositoryResourceLocal.class);
469:
470:                        LibresourceIndexableContent content = new LibresourceIndexableContent();
471:                        SubversionRepositoryResourceLocal subversionRepositoryResourceLocal = (SubversionRepositoryResourceLocal) Libresource
472:                                .findResource(resourceIdentifier);
473:                        content
474:                                .addContentPart(subversionRepositoryResourceLocal
475:                                        .getName());
476:                        content
477:                                .addContentPart(subversionRepositoryResourceLocal
478:                                        .getDescription());
479:
480:                        return content;
481:                    } catch (LibresourceException e) {
482:                        //
483:                    }
484:
485:                    return null;
486:                } catch (Exception e) {
487:                    throw new LibresourceException(
488:                            "error in LibresourceSubversion.getIndexableContent("
489:                                    + resourceIdentifier + ")", e);
490:                }
491:            }
492:
493:            /**
494:             * @ejb.interface-method
495:             * @ejb.transaction type="Supports"
496:             */
497:            public String getAuthzFilePath()
498:                    throws LibresourceSubversionException {
499:                try {
500:                    if (authzFilePath == null) {
501:                        // authzFilePath = (String) new
502:                        // InitialContext().lookup("java:comp/env/svn-authz");
503:                        authzFilePath = Libresource
504:                                .getLibresourceConfiguration("subversion.authz.file.path");
505:                    }
506:
507:                    return authzFilePath;
508:                } catch (Exception e) {
509:                    throw new LibresourceSubversionException(e);
510:                }
511:            }
512:
513:            /**
514:             * @ejb.interface-method
515:             * @ejb.transaction type="Supports"
516:             */
517:            public String getSVNRootRepositoryPath()
518:                    throws LibresourceSubversionException {
519:                try {
520:                    if (svnRepository == null) {
521:                        // svnRepository = (String) new
522:                        // InitialContext().lookup("java:comp/env/svn-repository");
523:                        svnRepository = Libresource
524:                                .getLibresourceConfiguration("subversion.repository.base.path");
525:                    }
526:
527:                    return svnRepository;
528:                } catch (Exception e) {
529:                    throw new LibresourceSubversionException(e);
530:                }
531:            }
532:
533:            /**
534:             * @ejb.interface-method
535:             * @ejb.transaction type="Supports"
536:             */
537:            public String getRepositoryCreationCmdLine(String repositoryName)
538:                    throws LibresourceSubversionException {
539:                try {
540:                    if (svnCreateRepositoryCmd == null) {
541:                        svnCreateRepositoryCmd = Libresource
542:                                .getLibresourceConfiguration("subversion.create.repository.cmd");
543:                    }
544:
545:                    String result = new StringBuffer(svnCreateRepositoryCmd)
546:                            .append(" ").append(repositoryName).toString();
547:                    System.out.println(result);
548:
549:                    return result;
550:                } catch (Exception e) {
551:                    throw new LibresourceSubversionException(e);
552:                }
553:            }
554:
555:            /**
556:             * @ejb.interface-method
557:             * @ejb.transaction type="Supports"
558:             */
559:            public String getRepositoryRenameCmdLine(String oldRepositoryName,
560:                    String newRepositoryName)
561:                    throws LibresourceSubversionException {
562:                try {
563:                    if (svnRenameRepositoryCmd == null) {
564:                        svnRenameRepositoryCmd = Libresource
565:                                .getLibresourceConfiguration("subversion.rename.repository.cmd");
566:                    }
567:
568:                    String result = new StringBuffer(svnRenameRepositoryCmd)
569:                            .append(" ").append(oldRepositoryName).append(" ")
570:                            .append(newRepositoryName).toString();
571:                    System.out.println(result);
572:
573:                    return result;
574:                } catch (Exception e) {
575:                    throw new LibresourceSubversionException(e);
576:                }
577:            }
578:
579:            /**
580:             * @ejb.interface-method
581:             * @ejb.transaction type="Supports"
582:             */
583:            public boolean canCreateRepository(String repositoryName)
584:                    throws LibresourceSubversionException {
585:                File repositoryDirectory = new File(getSVNRootRepositoryPath());
586:
587:                return !Arrays.asList(repositoryDirectory.list()).contains(
588:                        repositoryName);
589:            }
590:
591:            public static void exec(String basePath, String command)
592:                    throws LibresourceSubversionException, IOException {
593:                Process process = Runtime.getRuntime().exec(command);
594:                final InputStream err = process.getErrorStream();
595:                final InputStream in = process.getInputStream();
596:                final byte[] bufferErr = new byte[1024];
597:                final byte[] bufferIn = new byte[1024];
598:                Thread errThread = new Thread() {
599:                    public void run() {
600:                        int length = 0;
601:
602:                        try {
603:                            while ((length = err.read(bufferErr)) != -1) {
604:                                System.out.print(new String(bufferErr, 0,
605:                                        length));
606:                            }
607:                        } catch (Exception e) {
608:                        }
609:                    }
610:                };
611:
612:                errThread.start();
613:
614:                Thread outThread = new Thread() {
615:                    public void run() {
616:                        int length = 0;
617:
618:                        try {
619:                            while ((length = in.read(bufferIn)) != -1) {
620:                                System.out
621:                                        .print(new String(bufferIn, 0, length));
622:                            }
623:                        } catch (Exception e) {
624:                        }
625:                    }
626:                };
627:
628:                outThread.start();
629:
630:                try {
631:                    errThread.join();
632:                    outThread.join();
633:                } catch (InterruptedException e) {
634:                    e.printStackTrace();
635:                }
636:            }
637:
638:            /**
639:             * @ejb.interface-method
640:             * @ejb.transaction type="Supports"
641:             */
642:            public void buildAuthzFile() throws LibresourceSubversionException {
643:                Writer authzWriter = null;
644:
645:                try {
646:                    // Prepare the file to build
647:                    authzWriter = new BufferedWriter(new FileWriter(
648:                            getAuthzFilePath()));
649:
650:                    // Loop over the whole repositories
651:                    Collection subversionRepositoryList = SubversionRepositoryResourceUtil
652:                            .getLocalHome().findAll();
653:                    SubversionRepositoryResourceLocal currentRepository = null;
654:
655:                    // Define the groups
656:                    authzWriter.write(GROUP_DEFINITION);
657:
658:                    for (Iterator iterator = subversionRepositoryList
659:                            .iterator(); iterator.hasNext();) {
660:                        // Get repository info
661:                        currentRepository = (SubversionRepositoryResourceLocal) iterator
662:                                .next();
663:
664:                        // Write groups
665:                        authzWriter.write(currentRepository.getSvnName());
666:                        authzWriter.write(READERS);
667:                        authzWriter.write(EQUAL);
668:                        authzWriter.write(currentRepository.getReaders());
669:                        authzWriter.write(END_LINE);
670:                        authzWriter.write(currentRepository.getSvnName());
671:                        authzWriter.write(WRITERS);
672:                        authzWriter.write(EQUAL);
673:                        authzWriter.write(currentRepository.getCommiters());
674:                        authzWriter.write(END_LINE);
675:                        authzWriter.write(END_LINE);
676:                    }
677:
678:                    // Define repositories security
679:                    for (Iterator iterator = subversionRepositoryList
680:                            .iterator(); iterator.hasNext();) {
681:                        // Get repository info
682:                        currentRepository = (SubversionRepositoryResourceLocal) iterator
683:                                .next();
684:
685:                        // Write security
686:                        authzWriter.write(REPOSITORY_HEAD);
687:                        authzWriter.write(currentRepository.getSvnName());
688:                        authzWriter.write(REPOSITORY_TAIL);
689:                        authzWriter.write(GROUP_HEAD);
690:                        authzWriter.write(currentRepository.getSvnName());
691:                        authzWriter.write(READERS);
692:                        authzWriter.write(EQUAL);
693:                        authzWriter.write(R);
694:                        authzWriter.write(END_LINE);
695:                        authzWriter.write(GROUP_HEAD);
696:                        authzWriter.write(currentRepository.getSvnName());
697:                        authzWriter.write(WRITERS);
698:                        authzWriter.write(EQUAL);
699:                        authzWriter.write(RW);
700:                        authzWriter.write(END_LINE);
701:                        authzWriter.write(END_LINE);
702:                    }
703:                } catch (Exception e) {
704:                    throw new LibresourceSubversionException(e);
705:                } finally {
706:                    try {
707:                        if (authzWriter != null) {
708:                            authzWriter.close();
709:                        }
710:                    } catch (Exception e) {
711:                    }
712:                }
713:            }
714:
715:            /**
716:             * @ejb.interface-method
717:             * @ejb.transaction type="Supports"
718:             */
719:            public LibresourceResourceValue[] listReaders(
720:                    URI subversionRepositoryURI)
721:                    throws LibresourceSubversionException,
722:                    LibresourceSecurityException, URINotExistException {
723:                try {
724:                    KernelService kernelService = (KernelService) Libresource
725:                            .getService(KernelConstants.SERVICE);
726:                    MembershipService membershipService = (MembershipService) Libresource
727:                            .getService(MembershipConstants.SERVICE);
728:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
729:                            .lookup(subversionRepositoryURI);
730:                    SubversionRepositoryResourceLocal subversionRepository = (SubversionRepositoryResourceLocal) Libresource
731:                            .findResource(resourceIdentifier,
732:                                    SubversionRepositoryResourceLocal.class);
733:                    String[] memberIds = subversionRepository.getReaderList();
734:                    Vector members = new Vector();
735:
736:                    for (int i = 0; i < memberIds.length; i++) {
737:                        String memberId = memberIds[i];
738:                        URI memberUri = null;
739:                        memberUri = kernelService.normalizeURI(new URI(
740:                                membershipService.getUsersRootURI().getPath()
741:                                        + "/" + memberId));
742:
743:                        try {
744:                            members.add(kernelService.getResource(memberUri));
745:                        } catch (Exception e) {
746:                            //
747:                        }
748:                    }
749:
750:                    LibresourceResourceValue[] result = new LibresourceResourceValue[members
751:                            .size()];
752:
753:                    for (int i = 0; i < members.size(); i++) {
754:                        result[i] = (LibresourceResourceValue) members.get(i);
755:                    }
756:
757:                    return result;
758:                } catch (LibresourceSecurityException se) {
759:                    throw se;
760:                } catch (URINotExistException se) {
761:                    throw se;
762:                } catch (Exception e) {
763:                    throw new LibresourceSubversionException(
764:                            "Error in listReaders : " + e.getMessage(), e);
765:                }
766:            }
767:
768:            private static String convertResourceToSubversionUserString(
769:                    LibresourceResourceValue[] userList) {
770:                StringBuffer result = new StringBuffer();
771:                String currentUser = null;
772:
773:                for (int i = 0; i < userList.length; i++) {
774:                    currentUser = userList[i].getUri().getPath().substring(
775:                            "/users/".length());
776:
777:                    if (currentUser.equals("guest")) {
778:                        result.append("*");
779:                    } else {
780:                        result.append(currentUser);
781:                    }
782:
783:                    if ((i + 1) < userList.length) {
784:                        result.append(", ");
785:                    }
786:                }
787:
788:                return result.toString();
789:            }
790:
791:            /**
792:             * @ejb.interface-method
793:             * @ejb.transaction type="Supports"
794:             */
795:            public LibresourceResourceValue[] listCommiters(
796:                    URI subversionRepositoryURI)
797:                    throws LibresourceSubversionException,
798:                    LibresourceSecurityException, URINotExistException {
799:                try {
800:                    KernelService kernelService = (KernelService) Libresource
801:                            .getService(KernelConstants.SERVICE);
802:                    MembershipService membershipService = (MembershipService) Libresource
803:                            .getService(MembershipConstants.SERVICE);
804:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
805:                            .lookup(subversionRepositoryURI);
806:                    SubversionRepositoryResourceLocal subversionRepository = (SubversionRepositoryResourceLocal) Libresource
807:                            .findResource(resourceIdentifier,
808:                                    SubversionRepositoryResourceLocal.class);
809:                    String[] memberIds = subversionRepository.getCommiterList();
810:                    Vector members = new Vector();
811:
812:                    for (int i = 0; i < memberIds.length; i++) {
813:                        String memberId = memberIds[i];
814:                        URI memberUri = null;
815:                        memberUri = kernelService.normalizeURI(new URI(
816:                                membershipService.getUsersRootURI().getPath()
817:                                        + "/" + memberId));
818:
819:                        try {
820:                            members.add(kernelService.getResource(memberUri));
821:                        } catch (Exception e) {
822:                            //
823:                            e.printStackTrace();
824:                        }
825:                    }
826:
827:                    LibresourceResourceValue[] result = new LibresourceResourceValue[members
828:                            .size()];
829:
830:                    for (int i = 0; i < members.size(); i++) {
831:                        result[i] = (LibresourceResourceValue) members.get(i);
832:                    }
833:
834:                    return result;
835:                } catch (LibresourceSecurityException se) {
836:                    throw se;
837:                } catch (URINotExistException se) {
838:                    throw se;
839:                } catch (Exception e) {
840:                    throw new LibresourceSubversionException(
841:                            "Error in listCommiters : " + e.getMessage(), e);
842:                }
843:            }
844:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.