Source Code Cross Referenced for HarmoniseNamespaceManager.java in  » Content-Management-System » harmonise » org » openharmonise » dav » server » managers » 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 » Content Management System » harmonise » org.openharmonise.dav.server.managers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * The contents of this file are subject to the 
0003:         * Mozilla Public License Version 1.1 (the "License"); 
0004:         * you may not use this file except in compliance with the License. 
0005:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
0006:         *
0007:         * Software distributed under the License is distributed on an "AS IS"
0008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
0009:         * See the License for the specific language governing rights and 
0010:         * limitations under the License.
0011:         *
0012:         * The Initial Developer of the Original Code is Simulacra Media Ltd.
0013:         * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
0014:         *
0015:         * All Rights Reserved.
0016:         *
0017:         * Contributor(s):
0018:         */
0019:
0020:        package org.openharmonise.dav.server.managers;
0021:
0022:        import java.io.*;
0023:        import java.net.*;
0024:        import java.util.*;
0025:        import java.util.logging.*;
0026:
0027:        import javax.xml.parsers.DocumentBuilderFactory;
0028:
0029:        import org.openharmonise.commons.dsi.AbstractDataStoreInterface;
0030:        import org.openharmonise.commons.net.MimeTypeMapping;
0031:        import org.openharmonise.commons.xml.XMLUtils;
0032:        import org.openharmonise.commons.xml.namespace.NamespaceType;
0033:        import org.openharmonise.dav.server.adapters.WebPageResourceAdapter;
0034:        import org.openharmonise.dav.server.apm.*;
0035:        import org.openharmonise.dav.server.utils.*;
0036:        import org.openharmonise.rm.*;
0037:        import org.openharmonise.rm.config.ConfigSettings;
0038:        import org.openharmonise.rm.dsi.DataStoreInterfaceFactory;
0039:        import org.openharmonise.rm.metadata.*;
0040:        import org.openharmonise.rm.resources.*;
0041:        import org.openharmonise.rm.resources.content.*;
0042:        import org.openharmonise.rm.resources.lifecycle.*;
0043:        import org.openharmonise.rm.resources.lifecycle.Status;
0044:        import org.openharmonise.rm.resources.metadata.properties.*;
0045:        import org.openharmonise.rm.resources.metadata.properties.ranges.*;
0046:        import org.openharmonise.rm.resources.metadata.values.Value;
0047:        import org.openharmonise.rm.resources.publishing.WebPage;
0048:        import org.openharmonise.rm.resources.users.User;
0049:        import org.openharmonise.rm.resources.xml.*;
0050:        import org.openharmonise.rm.security.authorization.*;
0051:        import org.w3c.dom.*;
0052:
0053:        import com.ibm.webdav.*;
0054:        import com.ibm.webdav.impl.*;
0055:        import com.ibm.webdav.protocol.http.*;
0056:
0057:        /**
0058:         * Open Harmonise implementation of <code>NamespaceManager</code>.
0059:         * 
0060:         * @author Michael Bell
0061:         * @version $Revision: 1.4 $
0062:         *
0063:         */
0064:        /**
0065:         * FIXME - Michael Bell DIDN'T GIVE ME A DESCRIPTION!!
0066:         * @author Michael Bell
0067:         * @version $Revision: 1.4 $
0068:         *
0069:         */
0070:        public class HarmoniseNamespaceManager implements 
0071:                com.ibm.webdav.impl.NamespaceManager {
0072:            public static final String TAG_AFTER = "after";
0073:            public static final String TAG_BEFORE = "before";
0074:            public static final String TAG_LAST = "last";
0075:            public static final String TAG_FIRST = "first";
0076:            public static final String TAG_POSITION = "position";
0077:            public static final String TAG_SEGMENT = "segment";
0078:            public static final String TAG_ORDER_MEMBER = "order-member";
0079:            private static final int bufferSize = 8192;
0080:            protected AuxillaryProcessManager m_auxillary = null;
0081:            private static final String PNAME_WEBDAV_APM = "WEBDAV_APM";
0082:
0083:            private boolean m_bIsArchived = false;
0084:            protected ResourceImpl m_resource = null;
0085:            protected AbstractChildObject m_child = null;
0086:            private OutputStream m_openedOutputStream = null;
0087:            protected AbstractDataStoreInterface m_dsi = null;
0088:            static private List STD_ALLOWED_METHODS = new Vector();
0089:            static private List VIRTUAL_DIR_ALLOWED_METHODS = new Vector();
0090:            static private List ARCHIVE_ALLOWED_METHODS = new Vector();
0091:            static private Map DAV_HARMONISE_COMMAND_MAPPING = new Hashtable();
0092:
0093:            private static Logger m_logger = Logger
0094:                    .getLogger(HarmoniseNamespaceManager.class.getName());
0095:
0096:            static {
0097:                STD_ALLOWED_METHODS.add("PUT");
0098:                STD_ALLOWED_METHODS.add("GET");
0099:                STD_ALLOWED_METHODS.add("PROPFIND");
0100:                STD_ALLOWED_METHODS.add("PROPPATCH");
0101:                STD_ALLOWED_METHODS.add("OPTIONS");
0102:                STD_ALLOWED_METHODS.add("SEARCH");
0103:                STD_ALLOWED_METHODS.add("COPY");
0104:                STD_ALLOWED_METHODS.add("DELETE");
0105:                STD_ALLOWED_METHODS.add("MOVE");
0106:                STD_ALLOWED_METHODS.add("BIND");
0107:                STD_ALLOWED_METHODS.add("HEAD");
0108:                STD_ALLOWED_METHODS.add("LOCK");
0109:                STD_ALLOWED_METHODS.add("UNLOCK");
0110:
0111:                VIRTUAL_DIR_ALLOWED_METHODS.add("PROPFIND");
0112:                VIRTUAL_DIR_ALLOWED_METHODS.add("OPTIONS");
0113:                VIRTUAL_DIR_ALLOWED_METHODS.add("SEARCH");
0114:
0115:                ARCHIVE_ALLOWED_METHODS.addAll(VIRTUAL_DIR_ALLOWED_METHODS);
0116:                ARCHIVE_ALLOWED_METHODS.add("GET");
0117:
0118:                DAV_HARMONISE_COMMAND_MAPPING.put("PUT", "Save");
0119:                DAV_HARMONISE_COMMAND_MAPPING.put("PROPPATCH", "Save");
0120:                DAV_HARMONISE_COMMAND_MAPPING.put("COPY", "Save");
0121:                DAV_HARMONISE_COMMAND_MAPPING.put("MOVE", "Save");
0122:                DAV_HARMONISE_COMMAND_MAPPING.put("MKCOL", "Save");
0123:                DAV_HARMONISE_COMMAND_MAPPING.put("BIND", "Save");
0124:                DAV_HARMONISE_COMMAND_MAPPING.put("LOCK", "Lock");
0125:                DAV_HARMONISE_COMMAND_MAPPING.put("UNLOCK", "Unlock");
0126:                DAV_HARMONISE_COMMAND_MAPPING.put("GET", "View");
0127:                DAV_HARMONISE_COMMAND_MAPPING.put("PROPFIND", "View");
0128:                DAV_HARMONISE_COMMAND_MAPPING.put("DELETE", "Archive");
0129:                DAV_HARMONISE_COMMAND_MAPPING.put("CHECKIN", "ChangeStatus");
0130:                DAV_HARMONISE_COMMAND_MAPPING.put("VERSION-CONTROL",
0131:                        "ChangeStatus");
0132:                DAV_HARMONISE_COMMAND_MAPPING.put("CHECKOUT", "Save");
0133:            }
0134:
0135:            /** Create a NamespaceManager for creating resources. (This is necessary because
0136:             * createResource can't be static and declared in the NamespaceManager interface.)
0137:             */
0138:            public HarmoniseNamespaceManager() {
0139:            }
0140:
0141:            /** Create a NamesapceManager for a given resource.
0142:             * @param resource the resource to manage
0143:             */
0144:            public HarmoniseNamespaceManager(ResourceImpl resource) {
0145:                initialize(resource);
0146:            }
0147:
0148:            public void closeContentsOutputStream() throws WebDAVException {
0149:                closeContentsOutputStream(null);
0150:            }
0151:
0152:            /** 
0153:             * @see com.ibm.webdav.impl.NamespaceManager#closeContentsOutputStream()
0154:             */
0155:            public void closeContentsOutputStream(String sContentType)
0156:                    throws WebDAVException {
0157:
0158:                if (m_logger.isLoggable(Level.FINE)) {
0159:                    m_logger.logp(Level.FINE, this .getClass().getName(),
0160:                            "closeContentsOutputStream",
0161:                            "Closing output stream");
0162:                }
0163:
0164:                // close any opened output stream
0165:                if (m_openedOutputStream == null) {
0166:                    throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST,
0167:                            "No output stream is opened");
0168:                }
0169:
0170:                try {
0171:                    m_openedOutputStream.close();
0172:                } catch (WebDAVException exc) {
0173:                    throw exc;
0174:                } catch (java.io.IOException exc) {
0175:                    throw new WebDAVException(
0176:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, "IO Error");
0177:                }
0178:
0179:                try {
0180:                    String contentType = sContentType;
0181:
0182:                    if (contentType == null) {
0183:                        contentType = m_resource.getContext()
0184:                                .getRequestContext().contentType();
0185:                    }
0186:
0187:                    String fileName = HarmoniseNameResolver
0188:                            .getFilePath(m_resource.getURL());
0189:
0190:                    if ((contentType == null)
0191:                            || (contentType.equals("application/octet-stream") == true)) {
0192:                        String decodedFileName = java.net.URLDecoder.decode(
0193:                                fileName, HarmoniseNameResolver.UTF_8);
0194:
0195:                        if (m_logger.isLoggable(Level.FINE)) {
0196:                            String sMsg = "DAV: Getting extension from ["
0197:                                    + decodedFileName + "]";
0198:                            m_logger.logp(Level.FINE,
0199:                                    this .getClass().getName(),
0200:                                    "closeContentsOutputStream", sMsg);
0201:                        }
0202:
0203:                        int dotIndex = decodedFileName.lastIndexOf(".");
0204:                        if (dotIndex > 0) {
0205:                            String ext = decodedFileName
0206:                                    .substring(dotIndex + 1);
0207:
0208:                            contentType = MimeTypeMapping
0209:                                    .getMimeTypeFromExtension(ext);
0210:                        }
0211:                    }
0212:
0213:                    User usr = ((HarmoniseSessionManager) m_resource
0214:                            .getUserAuthenticator()).getUser(m_resource);
0215:
0216:                    //if this is an existing child object
0217:                    if (m_child != null) {
0218:                        //if this is a live resource make sure that we remove the 'START' prop
0219:                        if (m_child.isLiveVersion() == true) {
0220:                            Profile prof = m_child.getProfile();
0221:                            Property startProp = PropertyFactory
0222:                                    .getPropertyFromName(
0223:                                            m_dsi,
0224:                                            HarmoniseNameResolver.START_PROP_NAME);
0225:                            prof.removeProperty(startProp);
0226:                        }
0227:
0228:                        if (m_child instanceof  Asset) {
0229:                            if (m_logger.isLoggable(Level.FINE)) {
0230:                                m_logger.logp(Level.FINE, this .getClass()
0231:                                        .getName(),
0232:                                        "closeContentsOutputStream",
0233:                                        "Saving existng asset");
0234:                            }
0235:
0236:                            Asset asset = (Asset) m_child;
0237:
0238:                            if (isAssetSavedAsText(contentType) == true) {
0239:
0240:                                asset.setURI(getOutputStreamAsString());
0241:                            } else {
0242:                                File file = new File(fileName);
0243:                                asset.setContentFile(file);
0244:
0245:                                if (m_logger.isLoggable(Level.FINE)) {
0246:                                    m_logger.logp(Level.FINE, this .getClass()
0247:                                            .getName(),
0248:                                            "closeContentsOutputStream",
0249:                                            "Guessed content type - "
0250:                                                    + asset.getContentType());
0251:                                }
0252:
0253:                            }
0254:
0255:                            if (contentType != null) {
0256:                                asset.setContentType(contentType);
0257:                            }
0258:                        } else if (m_child instanceof  TextResource) {
0259:                            if (m_logger.isLoggable(Level.FINE)) {
0260:                                m_logger.logp(Level.FINE, this .getClass()
0261:                                        .getName(),
0262:                                        "closeContentsOutputStream",
0263:                                        "saving existing document");
0264:                            }
0265:
0266:                            TextResource txt = (TextResource) m_child;
0267:
0268:                            txt.setContent(getOutputStreamAsString());
0269:                            if (contentType != null) {
0270:
0271:                                if (m_child instanceof  XMLResource
0272:                                        && contentType
0273:                                                .equals("application/octet-stream")) {
0274:                                    txt.setContentType(MimeTypeMapping.XML
0275:                                            .getMimeType());
0276:                                } else {
0277:                                    txt.setContentType(contentType);
0278:                                }
0279:
0280:                            }
0281:
0282:                        } else if (m_child instanceof  WebPage) {
0283:                            WebPageResourceAdapter page = new WebPageResourceAdapter(
0284:                                    (WebPage) m_child);
0285:                            page.populate(getOutputStreamAsString());
0286:                        }
0287:
0288:                        m_child = (AbstractChildObject) CommandWrapper.save(
0289:                                m_dsi, m_child, usr);
0290:
0291:                    } else {
0292:                        // if this is a new child object
0293:
0294:                        String sResourcePath = URLDecoder.decode(m_resource
0295:                                .getURL().getPath(),
0296:                                HarmoniseNameResolver.UTF_8);
0297:
0298:                        String sResourceName = HarmoniseNameResolver
0299:                                .getLastSegment(sResourcePath);
0300:
0301:                        String parentPath = HarmoniseNameResolver
0302:                                .getPathParent(sResourcePath);
0303:
0304:                        AbstractParentObject parentObj = (AbstractParentObject) HarmoniseNameResolver
0305:                                .getObjectFromURL(m_dsi, parentPath);
0306:
0307:                        //now we have the parent, check that it's live
0308:                        if (parentObj.isLiveVersion() == false) {
0309:                            throw new WebDAVException(
0310:                                    WebDAVStatus.SC_FORBIDDEN,
0311:                                    "Collection must be live to add a child");
0312:                        }
0313:
0314:                        if (m_logger.isLoggable(Level.FINE)) {
0315:                            m_logger.logp(Level.FINE,
0316:                                    this .getClass().getName(),
0317:                                    "closeContentsOutputStream",
0318:                                    "child's parent's name:" + parentPath);
0319:                        }
0320:
0321:                        m_child = (AbstractChildObject) Class.forName(
0322:                                HarmoniseNameResolver
0323:                                        .getChildTypeFromURL(sResourcePath))
0324:                                .newInstance();
0325:                        m_child.setDataStoreInterface(m_dsi);
0326:
0327:                        m_child.setName(sResourceName);
0328:
0329:                        Profile prof = new Profile(this .m_dsi, m_child);
0330:                        prof.setName(sResourceName);
0331:                        m_child.setProfile(prof);
0332:
0333:                        //set content
0334:                        if (m_child instanceof  Asset) {
0335:                            Asset asset = (Asset) m_child;
0336:
0337:                            if (isAssetSavedAsText(contentType) == true) {
0338:
0339:                                asset.setURI(getOutputStreamAsString());
0340:                            } else {
0341:                                File file = new File(fileName);
0342:                                asset.setContentFile(file);
0343:                            }
0344:
0345:                            if (contentType != null) {
0346:                                asset.setContentType(contentType);
0347:                            }
0348:                        } else if (m_child instanceof  TextResource) {
0349:                            TextResource doc = (TextResource) m_child;
0350:
0351:                            doc.setContent(getOutputStreamAsString());
0352:
0353:                            if (m_child instanceof  XMLResource
0354:                                    && (contentType == null || contentType
0355:                                            .equals("application/octet-stream"))) {
0356:                                doc.setContentType(MimeTypeMapping.XML
0357:                                        .getMimeType());
0358:                            } else {
0359:                                doc.setContentType(contentType);
0360:                            }
0361:                        } else if (m_child instanceof  Property) {
0362:                            //new prop gets String range as default
0363:                            try {
0364:                                ((Property) m_child)
0365:                                        .setRange(new StringRange());
0366:                            } catch (InvalidRangeException e) {
0367:                                //ignore as if it's not allowed it's not allowed
0368:                            }
0369:
0370:                        } else if (m_child instanceof  WebPage) {
0371:                            WebPageResourceAdapter page = new WebPageResourceAdapter(
0372:                                    (WebPage) m_child);
0373:                            page.populate(getOutputStreamAsString());
0374:                        }
0375:
0376:                        m_child = (AbstractChildObject) CommandWrapper.save(
0377:                                m_dsi, m_child, usr);
0378:
0379:                        parentObj.acquireEditWriteLock();
0380:                        try {
0381:                            parentObj.addChild(m_child);
0382:
0383:                            //bypass RBS as we're not interested for this operation
0384:                            parentObj.save();
0385:                        } finally {
0386:                            parentObj.releaseEditWriteLock();
0387:                        }
0388:
0389:                        //have to do this after the child has a parent so that
0390:                        //role can be attached
0391:                        if (m_child instanceof  User) {
0392:                            //new users get BROWSER role
0393:                            AuthorityProfile secProf = new AuthorityProfile(
0394:                                    m_dsi);
0395:                            m_child.addProfile(secProf);
0396:
0397:                            Property roleProp = PropertyFactory
0398:                                    .getPropertyFromName(m_dsi,
0399:                                            AuthorizationValidator.PROP_ROLE);
0400:                            ChildObjectPropertyInstance roleInst = new ChildObjectPropertyInstance(
0401:                                    m_dsi, roleProp);
0402:
0403:                            List vals = ((AbsoluteChildObjectRange) roleProp
0404:                                    .getRange()).getAvailableValues();
0405:
0406:                            boolean bFound = false;
0407:
0408:                            Iterator iter = vals.iterator();
0409:
0410:                            while (iter.hasNext() && bFound == false) {
0411:                                Value tmpVal = (Value) iter.next();
0412:
0413:                                if (tmpVal.getName().equals("BROWSER")) {
0414:                                    roleInst.addValue(tmpVal);
0415:                                    secProf.addPropertyInstance(roleInst);
0416:                                    bFound = true;
0417:                                }
0418:                            }
0419:
0420:                        }
0421:
0422:                        if (m_logger.isLoggable(Level.FINE)) {
0423:                            m_logger.logp(Level.FINE,
0424:                                    this .getClass().getName(),
0425:                                    "closeContentsOutputStream",
0426:                                    "Adding new document or asset:"
0427:                                            + sResourceName);
0428:                        }
0429:
0430:                    }
0431:
0432:                    if (m_auxillary != null) {
0433:                        m_auxillary.save(usr, m_child);
0434:                    }
0435:                } catch (WebDAVException e) {
0436:                    //ensure WEBDAVExceptions get thrown up - be warned WebDAVException is a subclass of IOException!
0437:                    throw e;
0438:                } catch (ClassCastException e) {
0439:                    m_logger.log(Level.WARNING, "closeContentsOutputStream", e);
0440:                    throw new WebDAVException(
0441:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0442:                                    .getLocalizedMessage());
0443:                } catch (APMException e) {
0444:                    throw new WebDAVException(
0445:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0446:                                    .getLocalizedMessage());
0447:                } catch (NameResolverException e) {
0448:                    throw new WebDAVException(
0449:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0450:                                    .getLocalizedMessage());
0451:                } catch (InstantiationException e) {
0452:                    throw new WebDAVException(
0453:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0454:                                    .getLocalizedMessage());
0455:                } catch (IllegalAccessException e) {
0456:                    throw new WebDAVException(
0457:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0458:                                    .getLocalizedMessage());
0459:                } catch (ClassNotFoundException e) {
0460:                    throw new WebDAVException(
0461:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0462:                                    .getLocalizedMessage());
0463:                } catch (IOException e) {
0464:                    m_logger.log(Level.WARNING, "closeContentsOutputStream", e);
0465:                    throw new WebDAVException(
0466:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0467:                                    .getLocalizedMessage());
0468:                } catch (InvalidChildException e) {
0469:                    m_logger.log(Level.WARNING, "closeContentsOutputStream", e);
0470:
0471:                    throw new WebDAVException(WebDAVStatus.SC_FORBIDDEN, e
0472:                            .getLocalizedMessage());
0473:                } catch (InvalidNameException e) {
0474:                    throw new WebDAVException(WebDAVStatus.SC_FORBIDDEN, e
0475:                            .getLocalizedMessage());
0476:                } catch (InvalidXMLContentException e) {
0477:                    m_logger.log(Level.WARNING, "closeContentsOutputStream", e);
0478:                    throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, e
0479:                            .getLocalizedMessage());
0480:                } catch (HarmoniseException e) {
0481:                    m_logger.log(Level.WARNING, "closeContentsOutputStream", e);
0482:                    throw new WebDAVException(
0483:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0484:                                    .getLocalizedMessage());
0485:                }
0486:
0487:                m_openedOutputStream = null;
0488:            }
0489:
0490:            /**
0491:             * @see com.ibm.webdav.impl.NamespaceManager#createBinding(java.net.URL)
0492:             */
0493:            public void createBinding(String bindName, URL sourceURL)
0494:                    throws WebDAVException {
0495:                try {
0496:
0497:                    if ((m_child instanceof  AbstractParentObject) == false) {
0498:                        throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST,
0499:                                "Resource not collection");
0500:                    }
0501:
0502:                    AbstractParentObject parentObj = (AbstractParentObject) m_child;
0503:
0504:                    AbstractChildObject child = HarmoniseNameResolver
0505:                            .getObjectFromURL(m_dsi, sourceURL);
0506:
0507:                    if (child.getName().equals(bindName) == false) {
0508:                        throw new WebDAVException(WebDAVStatus.SC_FORBIDDEN,
0509:                                "Server doesn't support changing the name of the resource for the binding");
0510:                    }
0511:
0512:                    parentObj.acquireEditWriteLock();
0513:                    try {
0514:                        parentObj.addChild(child, true);
0515:
0516:                        if (parentObj == null) {
0517:                            throw new WebDAVException(
0518:                                    WebDAVStatus.SC_BAD_REQUEST,
0519:                                    "Parent not found");
0520:                        }
0521:
0522:                        CommandWrapper.save(m_dsi, parentObj,
0523:                                ((HarmoniseSessionManager) m_resource
0524:                                        .getUserAuthenticator())
0525:                                        .getUser(m_resource));
0526:                    } finally {
0527:                        parentObj.releaseEditWriteLock();
0528:                    }
0529:
0530:                } catch (NameResolverException e) {
0531:                    throw new WebDAVException(
0532:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0533:                                    .getLocalizedMessage());
0534:                } catch (InvalidChildException e) {
0535:                    throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, e
0536:                            .getLocalizedMessage());
0537:                } catch (PopulateException e) {
0538:                    throw new WebDAVException(
0539:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0540:                                    .getLocalizedMessage());
0541:                } catch (DataAccessException e) {
0542:                    throw new WebDAVException(
0543:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0544:                                    .getLocalizedMessage());
0545:                } catch (EditException e) {
0546:                    throw new WebDAVException(
0547:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0548:                                    .getLocalizedMessage());
0549:                }
0550:            }
0551:
0552:            /** 
0553:             * @see com.ibm.webdav.impl.NamespaceManager#createCollection(java.lang.String)
0554:             */
0555:            public void createCollection(String localName)
0556:                    throws WebDAVException {
0557:
0558:                try {
0559:                    String newURL = localName.replace(File.separatorChar, '/');
0560:
0561:                    newURL = new URL(m_resource.getURL(), newURL).getPath();
0562:
0563:                    if (m_logger.isLoggable(Level.FINE)) {
0564:                        m_logger.logp(Level.FINE, this .getClass().getName(),
0565:                                "createCollection", "========== local name - "
0566:                                        + localName);
0567:                        m_logger.logp(Level.FINE, this .getClass().getName(),
0568:                                "createCollection", "Creating collection:"
0569:                                        + newURL);
0570:                    }
0571:
0572:                    String parentURL = HarmoniseNameResolver
0573:                            .getPathParent(newURL);
0574:
0575:                    if (m_logger.isLoggable(Level.FINE)) {
0576:                        m_logger.logp(Level.FINE, this .getClass().getName(),
0577:                                "createCollection", "New collection parent:"
0578:                                        + parentURL);
0579:                    }
0580:
0581:                    AbstractParentObject parent = (AbstractParentObject) HarmoniseNameResolver
0582:                            .getObjectFromURL(m_dsi, parentURL);
0583:
0584:                    if (parent != null) {
0585:                        List childClassnames = parent.getChildClassNames();
0586:                        Class clss = parent.getClass();
0587:
0588:                        Iterator iter = childClassnames.iterator();
0589:                        boolean bFound = false;
0590:
0591:                        while (iter.hasNext() && bFound == false) {
0592:                            String sClassname = (String) iter.next();
0593:                            Class tmpClass = Class.forName(sClassname);
0594:                            if (AbstractParentObject.class
0595:                                    .isAssignableFrom(tmpClass)) {
0596:                                clss = tmpClass;
0597:                                bFound = true;
0598:                            }
0599:                        }
0600:
0601:                        AbstractParentObject newObj = (AbstractParentObject) clss
0602:                                .newInstance();
0603:                        newObj.setDataStoreInterface(m_dsi);
0604:
0605:                        String newName = HarmoniseNameResolver
0606:                                .getLastSegment(newURL);
0607:
0608:                        newObj.setName(newName);
0609:
0610:                        Profile parentPro = parent.getProfile();
0611:
0612:                        Profile pro = null;
0613:
0614:                        if (parentPro != null) {
0615:                            pro = (Profile) parentPro.clone();
0616:                        }
0617:
0618:                        if (pro == null) {
0619:                            pro = new Profile(this .m_dsi);
0620:                        }
0621:
0622:                        pro.setName(newName);
0623:                        newObj.setProfile(pro);
0624:
0625:                        User usr = ((HarmoniseSessionManager) m_resource
0626:                                .getUserAuthenticator()).getUser(m_resource);
0627:
0628:                        newObj = (AbstractParentObject) CommandWrapper.save(
0629:                                m_dsi, newObj, usr);
0630:
0631:                        parent.acquireEditWriteLock();
0632:                        try {
0633:                            parent.addChild(newObj);
0634:
0635:                            //save parent
0636:                            CommandWrapper.save(m_dsi, parent, usr);
0637:                        } finally {
0638:                            parent.releaseEditWriteLock();
0639:                        }
0640:
0641:                        if (ConfigSettings
0642:                                .getBoolProperty(
0643:                                        HarmoniseNameResolver.PNAME_AUTO_APPROVE_COLLECTIONS,
0644:                                        "true") == true) {
0645:
0646:                            //change status on newObj
0647:                            CommandWrapper.changeStatus(m_dsi, newObj, usr,
0648:                                    Status.APPROVED);
0649:
0650:                            if (m_auxillary != null) {
0651:                                m_auxillary.changeStatus(usr, newObj,
0652:                                        Status.UNAPPROVED, Status.APPROVED);
0653:                            }
0654:                        }
0655:                    } else {
0656:                        m_logger.logp(Level.WARNING, this .getClass().getName(),
0657:                                "createCollection", "Parent section not found:"
0658:                                        + parentURL);
0659:                        throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST,
0660:                                "problem creating new section");
0661:                    }
0662:
0663:                } catch (Exception e) {
0664:                    throw ExceptionTransformer.transform(e);
0665:                }
0666:
0667:            }
0668:
0669:            /**
0670:             * @see com.ibm.webdav.impl.NamespaceManager#createLockNullResource()
0671:             */
0672:            public void createLockNullResource() throws WebDAVException {
0673:                org.w3c.dom.Document document = m_resource.loadProperties();
0674:                m_resource.saveProperties(document);
0675:            }
0676:
0677:            /**
0678:             * @see com.ibm.webdav.impl.NamespaceManager#move(java.lang.String)
0679:             */
0680:            public void move(String destLocation) throws WebDAVException {
0681:                try {
0682:                    destLocation = destLocation
0683:                            .replace(File.separatorChar, '/');
0684:                    destLocation = new URL(m_resource.getURL(), destLocation)
0685:                            .getPath();
0686:
0687:                    String oldParentURL = HarmoniseNameResolver
0688:                            .getPathParent(URLDecoder.decode(m_resource
0689:                                    .getURL().getPath(),
0690:                                    HarmoniseNameResolver.UTF_8));
0691:
0692:                    AbstractParentObject oldParentObj = (AbstractParentObject) HarmoniseNameResolver
0693:                            .getObjectFromURL(this .m_dsi, oldParentURL);
0694:
0695:                    AbstractParentObject newParent = (AbstractParentObject) HarmoniseNameResolver
0696:                            .getObjectFromURL(this .m_dsi, HarmoniseNameResolver
0697:                                    .getPathParent(destLocation));
0698:
0699:                    if (newParent == null) {
0700:                        throw new WebDAVException(WebDAVStatus.SC_NOT_FOUND,
0701:                                "Destination not found");
0702:                    }
0703:
0704:                    //modify resource
0705:                    if (m_logger.isLoggable(Level.FINE)) {
0706:                        m_logger.logp(Level.FINE, this .getClass().getName(),
0707:                                "move", "Saving "
0708:                                        + m_child.getClass().getName());
0709:                    }
0710:
0711:                    String sCurrentName = m_child.getName();
0712:                    String sNewName = HarmoniseNameResolver
0713:                            .getLastSegment(destLocation);
0714:
0715:                    if (sCurrentName.equals(sNewName) == false) {
0716:                        if (m_child.getStatus() != Status.APPROVED
0717:                                || m_child.getPendingVersions().size() > 0) {
0718:                            throw new WebDAVException(
0719:                                    WebDAVStatus.SC_FORBIDDEN,
0720:                                    "Resource must be published before name change and can't have any pending versions");
0721:                        } else {
0722:                            m_child.setName(sNewName);
0723:                        }
0724:                    }
0725:
0726:                    User usr = ((HarmoniseSessionManager) m_resource
0727:                            .getUserAuthenticator()).getUser(m_resource);
0728:
0729:                    if (oldParentObj.equals(newParent) == false) {
0730:                        boolean bIsDefault = false;
0731:
0732:                        if (oldParentObj.equals(m_child.getRealParent())) {
0733:                            bIsDefault = true;
0734:                        }
0735:
0736:                        oldParentObj.removeChild(m_child);
0737:
0738:                        CommandWrapper.save(m_dsi, oldParentObj, usr);
0739:
0740:                        newParent.acquireEditWriteLock();
0741:                        try {
0742:                            if (bIsDefault == true) {
0743:                                if (m_logger.isLoggable(Level.FINE)) {
0744:                                    m_logger.logp(Level.FINE, this .getClass()
0745:                                            .getName(), "move",
0746:                                            "Setting as default group "
0747:                                                    + newParent.getName());
0748:                                }
0749:
0750:                                newParent.addChild(m_child);
0751:                            } else {
0752:                                newParent.addChild(m_child, true);
0753:                            }
0754:
0755:                            CommandWrapper.save(m_dsi, newParent, usr);
0756:                        } finally {
0757:                            newParent.releaseEditWriteLock();
0758:                        }
0759:
0760:                        if (m_logger.isLoggable(Level.FINE)) {
0761:                            m_logger.logp(Level.FINE,
0762:                                    this .getClass().getName(), "move",
0763:                                    "new mapping - " + destLocation + ":"
0764:                                            + m_child.getId());
0765:                        }
0766:
0767:                    }
0768:
0769:                    // in case child name has changed
0770:                    if (m_child.isChanged() == true) {
0771:                        m_child = CommandWrapper.save(m_dsi, m_child, usr);
0772:                        m_child = CommandWrapper.changeStatus(m_dsi, m_child,
0773:                                usr, Status.APPROVED);
0774:                    }
0775:
0776:                } catch (DataAccessException e) {
0777:                    throw new WebDAVException(
0778:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0779:                                    .getLocalizedMessage());
0780:                } catch (UnsupportedEncodingException e) {
0781:                    throw new WebDAVException(
0782:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0783:                                    .getLocalizedMessage());
0784:                } catch (MalformedURLException e) {
0785:                    throw new WebDAVException(
0786:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0787:                                    .getLocalizedMessage());
0788:                } catch (NameResolverException e) {
0789:                    throw new WebDAVException(
0790:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0791:                                    .getLocalizedMessage());
0792:                } catch (PopulateException e) {
0793:                    throw new WebDAVException(
0794:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0795:                                    .getLocalizedMessage());
0796:                } catch (InvalidChildException e) {
0797:                    m_logger.log(Level.INFO, "move", e);
0798:
0799:                    throw new WebDAVException(WebDAVStatus.SC_FORBIDDEN, e
0800:                            .getLocalizedMessage());
0801:                } catch (InvalidNameException e) {
0802:                    throw new WebDAVException(WebDAVStatus.SC_FORBIDDEN, e
0803:                            .getLocalizedMessage());
0804:                } catch (EditException e) {
0805:                    throw new WebDAVException(
0806:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0807:                                    .getLocalizedMessage());
0808:                }
0809:            }
0810:
0811:            /** 
0812:             * @see com.ibm.webdav.impl.NamespaceManager#delete()
0813:             */
0814:            public void delete() throws WebDAVException {
0815:                try {
0816:                    if (m_logger.isLoggable(Level.FINE)) {
0817:                        m_logger.logp(Level.FINE, this .getClass().getName(),
0818:                                "delete", "Deleting " + m_child.getName());
0819:                    }
0820:
0821:                    //enforce rule about not deleting collections with members
0822:                    if (m_child instanceof  AbstractParentObject) {
0823:
0824:                        if (((AbstractParentObject) m_child).getChildren()
0825:                                .size() > 0) {
0826:                            throw new WebDAVException(
0827:                                    WebDAVStatus.SC_FORBIDDEN,
0828:                                    "Can't delete collection with members");
0829:                        }
0830:
0831:                    }
0832:
0833:                    String sResourcePath = m_resource.getURL().getPath();
0834:
0835:                    boolean bArchive = true;
0836:                    AbstractParentObject parentObj = null;
0837:
0838:                    if (HarmoniseNameResolver.isVersionPath(sResourcePath) == false) {
0839:                        AbstractParentObject defaultParentObj = m_child
0840:                                .getRealParent();
0841:
0842:                        String parentPath = HarmoniseNameResolver
0843:                                .getPathParent(URLDecoder.decode(sResourcePath,
0844:                                        HarmoniseNameResolver.UTF_8));
0845:
0846:                        if (m_logger.isLoggable(Level.FINE)) {
0847:                            m_logger.logp(Level.FINE,
0848:                                    this .getClass().getName(), "delete",
0849:                                    "Going to look for " + parentPath);
0850:                        }
0851:
0852:                        parentObj = (AbstractParentObject) HarmoniseNameResolver
0853:                                .getObjectFromURL(this .m_dsi, parentPath);
0854:
0855:                        if (m_logger.isLoggable(Level.FINE)) {
0856:                            m_logger.logp(Level.FINE,
0857:                                    this .getClass().getName(), "delete",
0858:                                    "default parent - "
0859:                                            + defaultParentObj.getName());
0860:
0861:                            m_logger.logp(Level.FINE,
0862:                                    this .getClass().getName(), "delete",
0863:                                    " current parent - " + parentObj.getName());
0864:                        }
0865:
0866:                        bArchive = parentObj.getFullPath().equals(
0867:                                defaultParentObj.getFullPath());
0868:                    }
0869:
0870:                    if (bArchive == true) {
0871:                        if (m_logger.isLoggable(Level.FINE)) {
0872:                            m_logger.logp(Level.FINE,
0873:                                    this .getClass().getName(), "delete",
0874:                                    "Deleting " + m_child.getName());
0875:                        }
0876:
0877:                        User usr = ((HarmoniseSessionManager) m_resource
0878:                                .getUserAuthenticator()).getUser(m_resource);
0879:
0880:                        //do any auxilliary processing before deletion
0881:                        if (m_auxillary != null) {
0882:                            m_auxillary.delete(usr, m_child);
0883:                        }
0884:
0885:                        CommandWrapper.archive(m_dsi, m_child, usr);
0886:
0887:                    } else {
0888:                        if (m_logger.isLoggable(Level.FINE)) {
0889:                            m_logger.logp(Level.FINE,
0890:                                    this .getClass().getName(), "delete",
0891:                                    "Removing child " + m_child.getName());
0892:                        }
0893:
0894:                        parentObj.removeChild(m_child);
0895:                        parentObj.save();
0896:                    }
0897:
0898:                    if (m_logger.isLoggable(Level.FINE)) {
0899:                        m_logger.logp(Level.FINE, this .getClass().getName(),
0900:                                "delete", "Deleted");
0901:                    }
0902:                } catch (Exception e) {
0903:                    m_logger.log(Level.WARNING, "delete", e);
0904:
0905:                    throw new WebDAVException(
0906:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0907:                                    .getMessage());
0908:                }
0909:            }
0910:
0911:            /** 
0912:             * @see com.ibm.webdav.impl.NamespaceManager#exists()
0913:             */
0914:            public boolean exists() throws WebDAVException {
0915:                boolean bExists = false;
0916:
0917:                if (m_child != null) {
0918:                    if (m_logger.isLoggable(Level.FINE)) {
0919:                        m_logger.logp(Level.FINE, this .getClass().getName(),
0920:                                "exists", "Checking " + m_child.getClass()
0921:                                        + " " + m_child.getId());
0922:                    }
0923:
0924:                    bExists = m_child.exists();
0925:                } else {
0926:                    URL url = m_resource.getURL();
0927:                    bExists = HarmoniseNameResolver.isVirtualCollection(url)
0928:                            || HarmoniseNameResolver
0929:                                    .isArchivedVirtualCollection(url)
0930:                            || HarmoniseNameResolver.isVirtualResource(url);
0931:                }
0932:
0933:                if (m_logger.isLoggable(Level.FINE)) {
0934:                    m_logger.logp(Level.FINE, this .getClass().getName(),
0935:                            "exists", m_resource.getURL().getPath()
0936:                                    + " exists:" + bExists);
0937:                }
0938:
0939:                return bExists;
0940:            }
0941:
0942:            /** 
0943:             * @see com.ibm.webdav.impl.NamespaceManager#getContentsInputStream()
0944:             */
0945:            public InputStream getContentsInputStream() throws WebDAVException {
0946:                InputStream is = null;
0947:
0948:                if (m_child == null) {
0949:                    throw new WebDAVException(WebDAVStatus.SC_NOT_FOUND,
0950:                            "Resource does not exist");
0951:                }
0952:
0953:                long nResLength = 0;
0954:
0955:                if (m_child instanceof  Asset) {
0956:                    try {
0957:                        if (m_logger.isLoggable(Level.FINE)) {
0958:                            m_logger.logp(Level.FINE,
0959:                                    this .getClass().getName(),
0960:                                    "getContentsInputStream",
0961:                                    "Getting inputstream for Asset");
0962:                        }
0963:
0964:                        Asset asset = (Asset) m_child;
0965:
0966:                        if (isAssetSavedAsText(asset.getContentType()) == true) {
0967:                            String sContent = asset.getURI();
0968:                            is = new BufferedInputStream(
0969:                                    new ByteArrayInputStream(
0970:                                            sContent
0971:                                                    .getBytes(HarmoniseNameResolver.UTF_8)));
0972:
0973:                            nResLength = sContent.getBytes().length;
0974:                        } else {
0975:                            File file = asset.getContentFile();
0976:
0977:                            if (m_logger.isLoggable(Level.FINE)) {
0978:                                m_logger.logp(Level.FINE, this .getClass()
0979:                                        .getName(), "getContentsInputStream",
0980:                                        "Asset file name - "
0981:                                                + file.getAbsolutePath());
0982:                            }
0983:
0984:                            is = new BufferedInputStream(new FileInputStream(
0985:                                    file), bufferSize);
0986:
0987:                            nResLength = file.length();
0988:                        }
0989:
0990:                        m_resource.getResponseContext().contentType(
0991:                                asset.getContentType());
0992:
0993:                        String cdstring = new SimpleRFC1123DateFormat()
0994:                                .format(new Date());
0995:                        m_resource.getResponseContext().lastModified(cdstring);
0996:                        m_resource.getResponseContext().contentLength(
0997:                                nResLength);
0998:                    } catch (Exception e) {
0999:                        m_logger
1000:                                .log(Level.WARNING, "getContentsInputStream", e);
1001:
1002:                        throw new WebDAVException(
1003:                                WebDAVStatus.SC_SERVICE_UNAVAILABLE,
1004:                                "Had problem creating asset input stream");
1005:                    }
1006:                } else if (m_child instanceof  TextResource) {
1007:                    try {
1008:                        if (m_logger.isLoggable(Level.FINE)) {
1009:                            m_logger.logp(Level.FINE,
1010:                                    this .getClass().getName(),
1011:                                    "getContentsInputStream",
1012:                                    "Getting inputstream for Document");
1013:                        }
1014:
1015:                        TextResource textResource = (TextResource) m_child;
1016:                        User usr = ((HarmoniseSessionManager) m_resource
1017:                                .getUserAuthenticator()).getUser(m_resource);
1018:
1019:                        String sContent = null;
1020:                        if (m_auxillary != null) {
1021:                            // get the content by calling the auxiliary process manager
1022:                            // it will only pre-process the content if the status is
1023:                            // approved and the textResource is either a 
1024:                            // Template or XMLResource  
1025:
1026:                            sContent = m_auxillary.getContent(usr,
1027:                                    textResource, textResource.getStatus());
1028:                        } else {
1029:                            sContent = textResource.getContent();
1030:                        }
1031:
1032:                        if (sContent != null) {
1033:                            is = new BufferedInputStream(
1034:                                    new ByteArrayInputStream(
1035:                                            sContent
1036:                                                    .getBytes(HarmoniseNameResolver.UTF_8),
1037:                                            0,
1038:                                            sContent
1039:                                                    .getBytes(HarmoniseNameResolver.UTF_8).length),
1040:                                    bufferSize);
1041:                        } else {
1042:                            //return an input stream for the empty string
1043:                            is = new ByteArrayInputStream("".getBytes());
1044:                        }
1045:
1046:                        // get the content type. Default to text/plain
1047:                        //String contentType = doc.GetDocumentType();
1048:                        String sContentType = textResource.getContentType();
1049:
1050:                        if (sContentType == null
1051:                                && textResource instanceof  XMLResource) {
1052:                            sContentType = MimeTypeMapping.XML.getMimeType();
1053:                        }
1054:
1055:                        m_resource.getResponseContext().contentType(
1056:                                sContentType);
1057:
1058:                        String cdstring = new SimpleRFC1123DateFormat()
1059:                                .format(textResource.getVersionDate());
1060:                        m_resource.getResponseContext().lastModified(cdstring);
1061:                    } catch (Exception e) {
1062:                        m_logger
1063:                                .log(Level.WARNING, "getContentsInputStream", e);
1064:
1065:                        throw new WebDAVException(
1066:                                WebDAVStatus.SC_SERVICE_UNAVAILABLE,
1067:                                "Had problem creating document input stream");
1068:                    }
1069:                } else if (m_child instanceof  WebPage) {
1070:                    WebPageResourceAdapter page = new WebPageResourceAdapter(
1071:                            (WebPage) m_child);
1072:
1073:                    String sXML = page.asString();
1074:
1075:                    is = new BufferedInputStream(new ByteArrayInputStream(sXML
1076:                            .getBytes(), 0, sXML.length()), bufferSize);
1077:
1078:                    m_resource.getResponseContext().contentType(
1079:                            MimeTypeMapping.XML.getMimeType());
1080:
1081:                } else if (m_child instanceof  AbstractParentObject) {
1082:                    AbstractParentObject parent = (AbstractParentObject) m_child;
1083:
1084:                    if (parent != null) {
1085:                        m_resource.getResponseContext().contentType(
1086:                                MimeTypeMapping.XML.getMimeType());
1087:                        is = parentToXMLStream(parent);
1088:                    }
1089:                }
1090:
1091:                return is;
1092:            }
1093:
1094:            /** 
1095:             * @see com.ibm.webdav.impl.NamespaceManager#getContentsOutputStream()
1096:             */
1097:            public OutputStream getContentsOutputStream()
1098:                    throws WebDAVException {
1099:                OutputStream os = null;
1100:
1101:                User usr = ((HarmoniseSessionManager) m_resource
1102:                        .getUserAuthenticator()).getUser(m_resource);
1103:
1104:                try {
1105:                    String sPath = m_resource.getURL().getPath();
1106:                    String sChildClass = null;
1107:
1108:                    if (HarmoniseNameResolver.isVersionPath(sPath) == true) {
1109:                        sChildClass = HarmoniseNameResolver
1110:                                .getTypeFromVersionURL(sPath);
1111:                    } else {
1112:                        sChildClass = HarmoniseNameResolver
1113:                                .getChildTypeFromURL(sPath);
1114:                    }
1115:
1116:                    Class clss = Class.forName(sChildClass);
1117:
1118:                    if ((m_child != null && CommandWrapper.isSaveAllowed(usr,
1119:                            m_child) == false)
1120:                            || (m_child == null && CommandWrapper
1121:                                    .isSaveAllowed(usr, clss) == false)) {
1122:                        throw new WebDAVException(WebDAVStatus.SC_FORBIDDEN,
1123:                                "User is not allowed to save resource");
1124:                    }
1125:
1126:                    //ensure that if this is a new property it's name doesn't start 
1127:                    //with a numeric character
1128:                    if (m_child == null
1129:                            && Property.class.isAssignableFrom(clss)) {
1130:                        String sName = null;
1131:                        try {
1132:                            sName = HarmoniseNameResolver
1133:                                    .getResourceName(m_resource.getURL());
1134:                        } catch (UnsupportedEncodingException e) {
1135:                            throw new WebDAVException(
1136:                                    WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1137:                                            .getLocalizedMessage());
1138:                        }
1139:
1140:                        if (Character.isDigit(sName.charAt(0)) == true) {
1141:                            throw new WebDAVException(
1142:                                    WebDAVStatus.SC_BAD_REQUEST,
1143:                                    "Invalid property name - not allowed digit as first character");
1144:                        }
1145:                    }
1146:
1147:                    String contentType = m_resource.getContext()
1148:                            .getRequestContext().contentType();
1149:
1150:                    if (Asset.class.isAssignableFrom(clss)) {
1151:                        if (isAssetSavedAsText(contentType) == true) {
1152:                            os = new ByteArrayOutputStream();
1153:                        } else {
1154:                            try {
1155:                                String fileName = HarmoniseNameResolver
1156:                                        .getFilePath(m_resource.getURL());
1157:
1158:                                if (m_logger.isLoggable(Level.FINE)) {
1159:                                    m_logger.logp(Level.FINE, this .getClass()
1160:                                            .getName(),
1161:                                            "getContentsOutputStream",
1162:                                            "Returning buffered FileOutputStream for file: "
1163:                                                    + fileName);
1164:                                }
1165:
1166:                                File file = new File(fileName);
1167:                                os = new BufferedOutputStream(
1168:                                        new FileOutputStream(file), bufferSize);
1169:                            } catch (NameResolverException e) {
1170:                                m_logger.log(Level.WARNING,
1171:                                        "getContentsOutputStream", e);
1172:
1173:                                throw new WebDAVException(
1174:                                        WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
1175:                                        "problem opening outputstream");
1176:                            } catch (FileNotFoundException e) {
1177:                                m_logger.log(Level.WARNING,
1178:                                        "getContentsOutputStream", e);
1179:
1180:                                throw new WebDAVException(
1181:                                        WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
1182:                                        "problem opening outputstream");
1183:                            }
1184:                        }
1185:                    } else if (TextResource.class.isAssignableFrom(clss)) {
1186:                        if (m_logger.isLoggable(Level.FINE)) {
1187:                            m_logger.logp(Level.FINE,
1188:                                    this .getClass().getName(),
1189:                                    "getContentsOutputStream",
1190:                                    "Returning buffered ByteArrayOutputStream");
1191:                        }
1192:
1193:                        os = new ByteArrayOutputStream();
1194:                    } else {
1195:                        os = new ByteArrayOutputStream();
1196:                    }
1197:                } catch (NameResolverException e) {
1198:                    throw new WebDAVException(
1199:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1200:                                    .getLocalizedMessage());
1201:                } catch (ClassNotFoundException e) {
1202:                    throw new WebDAVException(
1203:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1204:                                    .getLocalizedMessage());
1205:                }
1206:
1207:                m_openedOutputStream = os;
1208:
1209:                return os;
1210:            }
1211:
1212:            /** 
1213:             * @see com.ibm.webdav.impl.NamespaceManager#getMembers()
1214:             */
1215:            public Vector getMembers() throws WebDAVException {
1216:                Vector members = new Vector();
1217:                String parentName = m_resource.getName().replace(
1218:                        File.separatorChar, '/');
1219:
1220:                if (HarmoniseNameResolver.isVersionPath(parentName) == true
1221:                        && m_child != null) {
1222:                    try {
1223:                        parentName = HarmoniseNameResolver.getDAVPath(m_child);
1224:                    } catch (NameResolverException e) {
1225:                        throw new WebDAVException(
1226:                                WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1227:                                        .getLocalizedMessage());
1228:                    }
1229:                }
1230:
1231:                if ((parentName != null) && !parentName.endsWith("/")) {
1232:                    parentName = parentName + "/";
1233:                }
1234:
1235:                if (parentName == null) {
1236:                    parentName = "";
1237:                }
1238:
1239:                AbstractParentObject grpObj = null;
1240:
1241:                try {
1242:                    grpObj = (AbstractParentObject) m_child;
1243:                } catch (ClassCastException e) {
1244:                    throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST,
1245:                            "resource not a collection");
1246:                }
1247:
1248:                URL resourceURL = m_resource.getURL();
1249:
1250:                try {
1251:                    if (grpObj == null) {
1252:
1253:                        if (HarmoniseNameResolver.isDAVRoot(resourceURL) == true) {
1254:
1255:                            List rootParents = HarmoniseNameResolver
1256:                                    .getRootCollections();
1257:
1258:                            Iterator iter = rootParents.iterator();
1259:
1260:                            while (iter.hasNext()) {
1261:                                members.addElement(createNewVirtualCollection(
1262:                                        parentName, (String) iter.next()));
1263:                            }
1264:                            members.addElement(createNewVirtualCollection(
1265:                                    parentName,
1266:                                    HarmoniseNameResolver.ARCHIVE_NAME));
1267:
1268:                        } else if (HarmoniseNameResolver
1269:                                .isArchiveRoot(resourceURL) == true) {
1270:                            List rootParents = HarmoniseNameResolver
1271:                                    .getRootCollections();
1272:
1273:                            Iterator iter = rootParents.iterator();
1274:
1275:                            while (iter.hasNext()) {
1276:                                members.addElement(createNewVirtualCollection(
1277:                                        parentName, (String) iter.next()));
1278:                            }
1279:                        } else if (HarmoniseNameResolver
1280:                                .isVirtualCollection(resourceURL) == true) {
1281:                            List vmembers = null;
1282:
1283:                            if (HarmoniseNameResolver.isArchiveURL(resourceURL) == true) {
1284:                                vmembers = HarmoniseNameResolver
1285:                                        .getArchivedVirtualCollectionMemberNames(resourceURL);
1286:                            } else {
1287:                                vmembers = HarmoniseNameResolver
1288:                                        .getVirtualCollectionMemberNames(resourceURL);
1289:                            }
1290:
1291:                            Iterator iter = vmembers.iterator();
1292:
1293:                            while (iter.hasNext()) {
1294:                                members.addElement(createNewVirtualCollection(
1295:                                        parentName, (String) iter.next()));
1296:                            }
1297:                        } else if (HarmoniseNameResolver
1298:                                .isArchivedVirtualCollection(resourceURL) == true) {
1299:                            List vmembers = HarmoniseNameResolver
1300:                                    .getArchivedVirtualCollectionMemberNames(resourceURL);
1301:
1302:                            Iterator iter = vmembers.iterator();
1303:
1304:                            while (iter.hasNext()) {
1305:                                members.addElement(createNewVirtualCollection(
1306:                                        parentName, (String) iter.next()));
1307:                            }
1308:                        }
1309:
1310:                    } else {
1311:                        List children = null;
1312:                        Vector subgroups = new Vector();
1313:
1314:                        if (HarmoniseNameResolver.isArchiveURL(resourceURL) == true) {
1315:                            children = grpObj.getArchivedChildren();
1316:
1317:                            children
1318:                                    .addAll(grpObj
1319:                                            .getChildrenByType(AbstractParentObject.BRANCH_NODES));
1320:
1321:                            if (m_logger.isLoggable(Level.FINE)) {
1322:                                m_logger.logp(Level.FINE, this .getClass()
1323:                                        .getName(), "getMembers", "Got "
1324:                                        + children.size()
1325:                                        + " archived children");
1326:                            }
1327:                        } else {
1328:                            children = grpObj.getChildren();
1329:                        }
1330:
1331:                        Iterator iter = children.iterator();
1332:
1333:                        while (iter.hasNext()) {
1334:                            AbstractChildObject child = (AbstractChildObject) iter
1335:                                    .next();
1336:
1337:                            StringBuffer sbuf = new StringBuffer();
1338:                            sbuf.append(child.getName());
1339:
1340:                            String sMemberName = sbuf.toString();
1341:
1342:                            // add resources and lock-null resources
1343:                            String childName = parentName + sMemberName;
1344:
1345:                            if (m_logger.isLoggable(Level.FINE)) {
1346:                                m_logger.logp(Level.FINE, this .getClass()
1347:                                        .getName(), "getMembers",
1348:                                        "adding document:" + childName + "("
1349:                                                + child.hashCode() + ")");
1350:                            }
1351:
1352:                            ResourceImpl member = null;
1353:
1354:                            if (child instanceof  AbstractParentObject) {
1355:                                member = new CollectionImpl(
1356:                                        getChildURL(sMemberName), childName,
1357:                                        null);
1358:
1359:                            } else {
1360:                                member = new ResourceImpl(
1361:                                        getChildURL(sMemberName), childName);
1362:                            }
1363:
1364:                            member.setRequestContext(m_resource.getContext());
1365:                            members.addElement(member);
1366:                        }
1367:                    }
1368:                } catch (DataAccessException e) {
1369:                    m_logger.log(Level.WARNING, "getMembers", e);
1370:
1371:                    throw new WebDAVException(
1372:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1373:                                    .getLocalizedMessage());
1374:                }
1375:
1376:                return members;
1377:            }
1378:
1379:            /**
1380:             * 
1381:             */
1382:            private URL getChildURL(String sChildName) throws WebDAVException {
1383:                URL childURL = null;
1384:
1385:                String parentName = m_resource.getName().replace(
1386:                        File.separatorChar, '/');
1387:
1388:                try {
1389:                    if (HarmoniseNameResolver.isVersionPath(parentName) == true
1390:                            && m_child != null) {
1391:                        URL resourceURL = m_resource.getURL();
1392:                        StringBuffer sParentURL = new StringBuffer();
1393:                        sParentURL.append(resourceURL.getProtocol());
1394:                        sParentURL.append("://");
1395:                        sParentURL.append(resourceURL.getHost());
1396:                        sParentURL.append(":");
1397:                        sParentURL.append(resourceURL.getPort());
1398:                        sParentURL.append("/");
1399:                        sParentURL.append(HarmoniseNameResolver
1400:                                .getDAVPath(m_child));
1401:                        if (sParentURL.toString().endsWith("/") == false) {
1402:                            sParentURL.append("/");
1403:                        }
1404:
1405:                        childURL = new URL(sParentURL.append(sChildName)
1406:                                .toString());
1407:
1408:                    } else {
1409:                        childURL = ((CollectionImpl) m_resource)
1410:                                .getChildURL(URLEncoder.encode(sChildName,
1411:                                        HarmoniseNameResolver.UTF_8));
1412:                    }
1413:                } catch (MalformedURLException e) {
1414:                    throw new WebDAVException(
1415:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1416:                                    .getLocalizedMessage());
1417:                } catch (NameResolverException e) {
1418:                    throw new WebDAVException(
1419:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1420:                                    .getLocalizedMessage());
1421:                } catch (UnsupportedEncodingException e) {
1422:                    throw new WebDAVException(
1423:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1424:                                    .getLocalizedMessage());
1425:                }
1426:
1427:                return childURL;
1428:
1429:            }
1430:
1431:            /**
1432:             * Creates new virtual collection, i.e. a collection represented in the DAV hierarchy
1433:             * that does not have an equivalent Harmonise parent object
1434:             * 
1435:             * @param parentName
1436:             * @param sColName
1437:             * @return
1438:             * @throws WebDAVException
1439:             */
1440:            private CollectionImpl createNewVirtualCollection(
1441:                    String parentName, String sColName) throws WebDAVException {
1442:                CollectionImpl collection = null;
1443:
1444:                collection = new CollectionImpl(((CollectionImpl) m_resource)
1445:                        .getChildURL(sColName), parentName + sColName, null);
1446:
1447:                collection.setRequestContext(m_resource.getContext());
1448:
1449:                return collection;
1450:            }
1451:
1452:            /**
1453:             * @see com.ibm.webdav.impl.NamespaceManager#initialize(com.ibm.webdav.impl.ResourceImpl)
1454:             */
1455:            public void initialize(ResourceImpl resource) {
1456:                this .m_resource = resource;
1457:
1458:                try {
1459:                    this .m_dsi = DataStoreInterfaceFactory
1460:                            .getDataStoreInterface();
1461:
1462:                    URL resourceURL = m_resource.getURL();
1463:
1464:                    if (HarmoniseNameResolver.isDAVRoot(resourceURL) == false
1465:                            && HarmoniseNameResolver
1466:                                    .isVirtualCollection(resourceURL) == false) {
1467:                        m_child = HarmoniseNameResolver.getObjectFromURL(m_dsi,
1468:                                resourceURL);
1469:                    }
1470:
1471:                    if (m_auxillary == null) {
1472:                        m_auxillary = APMFactory.getAPM();
1473:                    }
1474:                } catch (Exception e) {
1475:                    m_logger.log(Level.WARNING, "initialize", e);
1476:                }
1477:            }
1478:
1479:            /** 
1480:             * @see com.ibm.webdav.impl.NamespaceManager#isCollection()
1481:             */
1482:            public boolean isCollection() throws WebDAVException {
1483:                boolean bRtn = false;
1484:
1485:                if (m_child != null) {
1486:                    bRtn = m_child instanceof  AbstractParentObject;
1487:                } else {
1488:                    URL resourceURL = m_resource.getURL();
1489:                    bRtn = HarmoniseNameResolver
1490:                            .isVirtualCollection(resourceURL)
1491:                            || HarmoniseNameResolver
1492:                                    .isArchivedVirtualCollection(resourceURL);
1493:                }
1494:
1495:                if (m_logger.isLoggable(Level.FINE)) {
1496:                    m_logger.logp(Level.FINE, this .getClass().getName(),
1497:                            "isCollection", "Is collection - " + bRtn);
1498:                }
1499:
1500:                return bRtn;
1501:            }
1502:
1503:            /** 
1504:             * @see com.ibm.webdav.impl.NamespaceManager#isLockNull()
1505:             */
1506:            public boolean isLockNull() throws WebDAVException {
1507:                return false;
1508:            }
1509:
1510:            /** 
1511:             * @see com.ibm.webdav.impl.NamespaceManager#performWith(java.lang.String)
1512:             */
1513:            public byte[] performWith(String args) throws WebDAVException {
1514:                StringWriter buf = new StringWriter();
1515:
1516:                try {
1517:                    Runtime runtime = Runtime.getRuntime();
1518:                    Process p = runtime.exec(m_resource.getName() + " " + args);
1519:                    BufferedReader inputStream = new BufferedReader(
1520:                            new InputStreamReader(p.getInputStream()));
1521:                    int ch = -1;
1522:
1523:                    while ((ch = inputStream.read()) != -1) {
1524:                        buf.write(ch);
1525:                    }
1526:                } catch (Exception e) {
1527:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
1528:                }
1529:
1530:                return buf.toString().getBytes();
1531:            }
1532:
1533:            /** Create an XML file containing the contents of a collection.
1534:             * @param file the directory to read
1535:             * @return an InputStream on the resulting XML file.
1536:             * @exception com.ibm.webdav.WebDAVException
1537:             */
1538:            private InputStream parentToXMLStream(AbstractParentObject parent)
1539:                    throws WebDAVException {
1540:                org.w3c.dom.Document document = null;
1541:
1542:                try {
1543:                    document = DocumentBuilderFactory.newInstance()
1544:                            .newDocumentBuilder().newDocument();
1545:                } catch (Exception e) {
1546:                    throw new WebDAVException(
1547:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1548:                                    .getMessage());
1549:                }
1550:
1551:                Element collection = document.createElement("D:collection");
1552:                collection.setAttribute("xmlns:D", "DAV:");
1553:                document.appendChild(collection);
1554:
1555:                try {
1556:                    List children = parent.getChildren();
1557:
1558:                    Iterator iter = children.iterator();
1559:
1560:                    while (iter.hasNext()) {
1561:                        AbstractChildObject child = (AbstractChildObject) iter
1562:                                .next();
1563:                        String docName = child.getName();
1564:
1565:                        // add resources and lock-null resources
1566:                        Element uri = document.createElement("D:member");
1567:                        uri.appendChild(document.createTextNode(docName));
1568:                        collection.appendChild(uri);
1569:                    }
1570:                } catch (DataAccessException e) {
1571:                    throw new WebDAVException(
1572:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1573:                                    .getLocalizedMessage());
1574:                }
1575:
1576:                ByteArrayOutputStream os = new ByteArrayOutputStream();
1577:
1578:                try {
1579:                    PrintWriter pout = new PrintWriter(new OutputStreamWriter(
1580:                            os, Resource.defaultCharEncoding), false);
1581:                    pout.print(XMLUtility.printNode(document
1582:                            .getDocumentElement()));
1583:                } catch (UnsupportedEncodingException e) {
1584:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
1585:                    throw new WebDAVException(
1586:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1587:                                    .getMessage());
1588:                }
1589:
1590:                m_resource.getResponseContext().contentType("text/xml");
1591:
1592:                return new ByteArrayInputStream(os.toByteArray());
1593:            }
1594:
1595:            /** 
1596:             * @see com.ibm.webdav.impl.NamespaceManager#isVersionable()
1597:             */
1598:            public boolean isVersionable() throws WebDAVException {
1599:                return false;
1600:            }
1601:
1602:            /**
1603:             * @see com.ibm.webdav.impl.NamespaceManager#getAllowedMethods()
1604:             */
1605:            public List getAllowedMethods() throws WebDAVException {
1606:                List allowedMethods = null;
1607:
1608:                if (HarmoniseNameResolver.isVirtualCollection(m_resource
1609:                        .getURL()) == true) {
1610:                    allowedMethods = new ArrayList(VIRTUAL_DIR_ALLOWED_METHODS);
1611:                }
1612:                if (HarmoniseNameResolver
1613:                        .isArchivedVirtualCollection(m_resource.getURL()) == true) {
1614:                    allowedMethods = new ArrayList(VIRTUAL_DIR_ALLOWED_METHODS);
1615:                } else if (HarmoniseNameResolver.isArchiveURL(m_resource
1616:                        .getURL()) == true
1617:                        || (m_child != null && m_child.isHistorical())) {
1618:                    allowedMethods = new ArrayList(ARCHIVE_ALLOWED_METHODS);
1619:                    try {
1620:                        AbstractChildObject liveChild = (AbstractChildObject) m_child
1621:                                .getLiveVersion();
1622:                        if ((m_child instanceof  AbstractParentObject) == false) {
1623:                            if (liveChild == null
1624:                                    || liveChild.getPendingVersions().size() == 0) {
1625:                                allowedMethods.add(CheckOutMethod.METHOD_NAME);
1626:                            }
1627:                        }
1628:                    } catch (DataAccessException e) {
1629:                        throw new WebDAVException(
1630:                                WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1631:                                        .getLocalizedMessage());
1632:                    }
1633:                } else {
1634:
1635:                    allowedMethods = new Vector(STD_ALLOWED_METHODS);
1636:
1637:                    if (m_child instanceof  AbstractParentObject) {
1638:                        allowedMethods.add(OrderPatchMethod.METHOD_NAME);
1639:                        allowedMethods.add(MkcolMethod.METHOD_NAME);
1640:                    }
1641:
1642:                    allowedMethods = filterAllowedMethods(allowedMethods);
1643:                }
1644:
1645:                return allowedMethods;
1646:            }
1647:
1648:            /**
1649:             * Filters the list of methods allowed given the state of the resource by the
1650:             * permissions given by role based security
1651:             * 
1652:             * @param allowedMethods
1653:             * @return
1654:             */
1655:            protected List filterAllowedMethods(List allowedMethods)
1656:                    throws WebDAVException {
1657:                List filteredList = new Vector();
1658:
1659:                User usr = ((HarmoniseSessionManager) m_resource
1660:                        .getUserAuthenticator()).getUser(m_resource);
1661:
1662:                Iterator iter = allowedMethods.iterator();
1663:
1664:                while (iter.hasNext()) {
1665:                    String sMethod = (String) iter.next();
1666:
1667:                    if (VIRTUAL_DIR_ALLOWED_METHODS.contains(sMethod)) {
1668:                        filteredList.add(sMethod);
1669:                    } else {
1670:                        String sCmd = (String) DAV_HARMONISE_COMMAND_MAPPING
1671:                                .get(sMethod);
1672:
1673:                        if (sCmd != null) {
1674:                            try {
1675:                                if (AuthorizationValidator.isCommandAvailable(
1676:                                        usr, m_child, sCmd) == true) {
1677:                                    filteredList.add(sMethod);
1678:                                }
1679:                            } catch (AuthorizationException e) {
1680:                                //assume that we're not allowing the method and move on
1681:                                m_logger.log(Level.WARNING,
1682:                                        "filterAllowedMethods", e);
1683:                            }
1684:                        }
1685:
1686:                    }
1687:
1688:                }
1689:
1690:                return filteredList;
1691:            }
1692:
1693:            /**
1694:             * @see com.ibm.webdav.impl.NamespaceManager#setOrdering(org.w3c.dom.Document)
1695:             */
1696:            public void setOrdering(org.w3c.dom.Document orderPatch)
1697:                    throws WebDAVException {
1698:
1699:                if (m_child == null) {
1700:                    throw new WebDAVException(WebDAVStatus.SC_NOT_FOUND,
1701:                            "Resource not a collection");
1702:                }
1703:
1704:                if ((m_child instanceof  AbstractParentObject) == false) {
1705:                    throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST,
1706:                            "Resource not a collection");
1707:                }
1708:
1709:                try {
1710:                    AbstractParentObject parent = (AbstractParentObject) m_child;
1711:
1712:                    Element orderEl = orderPatch.getDocumentElement();
1713:
1714:                    NodeList nodes = orderEl.getElementsByTagNameNS(
1715:                            NamespaceType.DAV.getURI(), TAG_ORDER_MEMBER);
1716:
1717:                    LinkedList children = new LinkedList(parent.getChildren());
1718:
1719:                    for (int i = 0; i < nodes.getLength(); i++) {
1720:                        Element tmpEl = (Element) nodes.item(i);
1721:
1722:                        Element segmentEl = (Element) tmpEl
1723:                                .getElementsByTagNameNS(
1724:                                        NamespaceType.DAV.getURI(), TAG_SEGMENT)
1725:                                .item(0);
1726:                        Element positionEl = (Element) tmpEl
1727:                                .getElementsByTagNameNS(
1728:                                        NamespaceType.DAV.getURI(),
1729:                                        TAG_POSITION).item(0);
1730:
1731:                        String sChildName = segmentEl.getChildNodes().item(0)
1732:                                .getNodeValue();
1733:
1734:                        sChildName = HarmoniseNameResolver
1735:                                .stripExtension(sChildName);
1736:
1737:                        AbstractChildObject child = parent
1738:                                .getChildByName(sChildName);
1739:
1740:                        if (child == null) {
1741:                            throw new WebDAVException(
1742:                                    WebDAVStatus.SC_FORBIDDEN, sChildName
1743:                                            + " is not a collection member");
1744:                        }
1745:
1746:                        Element specEl = XMLUtils
1747:                                .getFirstElementChild(positionEl);
1748:
1749:                        String sSpecifier = specEl.getLocalName();
1750:
1751:                        //remove child before adding again in new position
1752:                        children.remove(child);
1753:                        if (sSpecifier.equals(TAG_FIRST)) {
1754:                            children.addFirst(child);
1755:                        } else if (sSpecifier.equals(TAG_LAST)) {
1756:                            children.addLast(child);
1757:                        } else if (sSpecifier.equals(TAG_BEFORE)) {
1758:                            String sBeforeChildName = specEl
1759:                                    .getElementsByTagNameNS(
1760:                                            NamespaceType.DAV.getURI(),
1761:                                            TAG_SEGMENT).item(0)
1762:                                    .getChildNodes().item(0).getNodeValue();
1763:                            sBeforeChildName = HarmoniseNameResolver
1764:                                    .stripExtension(sBeforeChildName);
1765:
1766:                            AbstractChildObject sBeforeChild = parent
1767:                                    .getChildByName(sBeforeChildName);
1768:
1769:                            int nIndex = children.indexOf(sBeforeChild);
1770:                            children.add(nIndex, child);
1771:
1772:                        } else if (sSpecifier.equals(TAG_AFTER)) {
1773:                            String sAfterChildName = specEl
1774:                                    .getElementsByTagNameNS(
1775:                                            NamespaceType.DAV.getURI(),
1776:                                            TAG_SEGMENT).item(0)
1777:                                    .getChildNodes().item(0).getNodeValue();
1778:                            sAfterChildName = HarmoniseNameResolver
1779:                                    .stripExtension(sAfterChildName);
1780:
1781:                            AbstractChildObject sAfterChild = parent
1782:                                    .getChildByName(sAfterChildName);
1783:
1784:                            int nIndex = children.indexOf(sAfterChild);
1785:                            children.add(nIndex + 1, child);
1786:                        }
1787:
1788:                    }
1789:
1790:                    if (m_logger.isLoggable(Level.FINE)) {
1791:                        m_logger.logp(Level.FINE, this .getClass().getName(),
1792:                                "setOrdering", "New order - " + children);
1793:                    }
1794:
1795:                    //now save changes to parent
1796:                    parent.setChildren(children);
1797:
1798:                    CommandWrapper.save(m_dsi, parent,
1799:                            ((HarmoniseSessionManager) m_resource
1800:                                    .getUserAuthenticator())
1801:                                    .getUser(m_resource));
1802:
1803:                } catch (DataAccessException e) {
1804:                    throw new WebDAVException(
1805:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1806:                                    .getLocalizedMessage());
1807:                } catch (InvalidChildException e) {
1808:                    throw new WebDAVException(
1809:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1810:                                    .getLocalizedMessage());
1811:                } catch (PopulateException e) {
1812:                    throw new WebDAVException(
1813:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1814:                                    .getLocalizedMessage());
1815:                }
1816:
1817:            }
1818:
1819:            /**
1820:             * @see com.ibm.webdav.impl.VersionedNamespaceManager#isVersionURL(java.lang.String)
1821:             */
1822:            public boolean isVersionURL(String url) {
1823:
1824:                return HarmoniseNameResolver.isVersionPath(url);
1825:            }
1826:
1827:            /**
1828:             * @see com.ibm.webdav.impl.VersionedNamespaceManager#getResourceURL()
1829:             */
1830:            public String getResourceURL() throws WebDAVException {
1831:                String sPath = null;
1832:
1833:                try {
1834:                    sPath = HarmoniseNameResolver.getDAVPath(m_child);
1835:                } catch (NameResolverException e) {
1836:                    throw new WebDAVException(
1837:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1838:                                    .getLocalizedMessage());
1839:                }
1840:
1841:                return sPath;
1842:            }
1843:
1844:            /**
1845:             * @see com.ibm.webdav.impl.NamespaceManager#getContentType()
1846:             */
1847:            public String getContentType() throws WebDAVException {
1848:                String sContentType = null;
1849:
1850:                try {
1851:                    if (m_child instanceof  Asset) {
1852:                        sContentType = ((Asset) m_child).getContentType();
1853:                    } else if (m_child instanceof  TextResource) {
1854:                        sContentType = ((TextResource) m_child)
1855:                                .getContentType();
1856:                    }
1857:                } catch (DataAccessException e) {
1858:                    throw new WebDAVException(
1859:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1860:                                    .getLocalizedMessage());
1861:                }
1862:
1863:                return sContentType;
1864:            }
1865:
1866:            private String getOutputStreamAsString() throws IOException {
1867:                byte[] byteArray = ((ByteArrayOutputStream) m_openedOutputStream)
1868:                        .toByteArray();
1869:                int length = byteArray.length;
1870:
1871:                ByteArrayInputStream byteInputStream = new ByteArrayInputStream(
1872:                        byteArray);
1873:                BufferedReader reader = new BufferedReader(
1874:                        new InputStreamReader(byteInputStream,
1875:                                HarmoniseNameResolver.UTF_8));
1876:
1877:                char[] cbuf = new char[bufferSize];
1878:                String sNewContents = "";
1879:                StringWriter writer = new StringWriter();
1880:
1881:                String temp = "";
1882:                while ((temp = reader.readLine()) != null) {
1883:                    writer.write(temp);
1884:                }
1885:
1886:                String sResult = writer.toString();
1887:
1888:                if (m_logger.isLoggable(Level.FINE)) {
1889:                    m_logger.logp(Level.FINE, this .getClass().getName(),
1890:                            "getOutputStreamAsString", "New doc contents: "
1891:                                    + sResult);
1892:                }
1893:
1894:                return sResult;
1895:            }
1896:
1897:            /**
1898:             * Returns <code>true</code> if asset is to be saved as text in database rather
1899:             * than file, given content type
1900:             * 
1901:             * @param sContentType
1902:             * @return
1903:             */
1904:            private boolean isAssetSavedAsText(String sContentType) {
1905:                boolean bIsFile = false;
1906:
1907:                bIsFile = (sContentType != null
1908:                        && MimeTypeMapping.XSLT.getMimeTypes().contains(
1909:                                sContentType) == false && (sContentType
1910:                        .startsWith("link") || sContentType.startsWith("text")));
1911:
1912:                return bIsFile;
1913:            }
1914:
1915:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.