Source Code Cross Referenced for HarmonisePropertiesManager.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.text.*;
0025:        import java.util.*;
0026:        import java.util.logging.*;
0027:
0028:        import javax.xml.parsers.*;
0029:
0030:        import org.openharmonise.commons.dsi.*;
0031:        import org.openharmonise.commons.net.MimeTypeMapping;
0032:        import org.openharmonise.commons.xml.XMLUtils;
0033:        import org.openharmonise.commons.xml.namespace.NamespaceType;
0034:        import org.openharmonise.dav.server.adapters.WebPageResourceAdapter;
0035:        import org.openharmonise.dav.server.apm.*;
0036:        import org.openharmonise.dav.server.property.domains.DAVDomain;
0037:        import org.openharmonise.dav.server.property.ranges.*;
0038:        import org.openharmonise.dav.server.utils.*;
0039:        import org.openharmonise.rm.*;
0040:        import org.openharmonise.rm.config.ConfigSettings;
0041:        import org.openharmonise.rm.dsi.DataStoreInterfaceFactory;
0042:        import org.openharmonise.rm.factory.HarmoniseFactoryException;
0043:        import org.openharmonise.rm.metadata.*;
0044:        import org.openharmonise.rm.resources.*;
0045:        import org.openharmonise.rm.resources.content.*;
0046:        import org.openharmonise.rm.resources.lifecycle.Status;
0047:        import org.openharmonise.rm.resources.metadata.properties.*;
0048:        import org.openharmonise.rm.resources.metadata.properties.domains.Domain;
0049:        import org.openharmonise.rm.resources.metadata.properties.ranges.*;
0050:        import org.openharmonise.rm.resources.metadata.values.Value;
0051:        import org.openharmonise.rm.resources.publishing.WebPage;
0052:        import org.openharmonise.rm.resources.users.User;
0053:        import org.openharmonise.rm.resources.workflow.values.WorkflowStageValue;
0054:        import org.openharmonise.rm.resources.xml.*;
0055:        import org.openharmonise.rm.workflow.WorkflowPropertyInstance;
0056:        import org.w3c.dom.*;
0057:
0058:        import com.ibm.webdav.*;
0059:        import com.ibm.webdav.impl.*;
0060:
0061:        /**
0062:         * Harmonise subclass of <code>CachedPropertiesManager</code>
0063:         * implementing <code>PropertiesManager</code> to provide DAV4j with
0064:         * access to property management functionality.
0065:         * 
0066:         * @author Michael Bell
0067:         * @version $Revision: 1.3 $
0068:         *
0069:         */
0070:        public class HarmonisePropertiesManager extends CachedPropertiesManager
0071:                implements  com.ibm.webdav.impl.PropertiesManager {
0072:
0073:            public static final String TAG_LOCKDISCOVERY = "lockdiscovery";
0074:            public static final String TAG_ARCHIVEDATE = "archivedate";
0075:            public static final String TAG_HARMONISE_ID = "harmonise-id";
0076:            public static final String TAG_PARENT = "parent";
0077:            public static final String TAG_DESCRIPTION = "description";
0078:            public static final String TAG_TITLE = "title";
0079:            public static final String TAG_PARENT_SET = "parent-set";
0080:            public static final String TAG_PROPERTY_RESOURCE = "property-resource";
0081:            public static final String TAG_RESOURCETYPE = "resourcetype";
0082:            public static final String TAG_RESOURCE = "resource";
0083:            public static final String TAG_COLLECTION = "collection";
0084:            private static String W3C_XMLSCHEMA_URI = "http://www.w3.org/2001/XMLSchema";
0085:            public static String propertiesSuffix = ".wdp"; // a WebDAV properties file
0086:            public static final String ATTRIB_TYPE = "type";
0087:            public static final String ATTRIB_ITEM_TYPE = "itemType";
0088:            public static final String ARRAY_TYPE = "Array";
0089:            public static final String ATTRIB_ARRAY_SIZE = "arraySize";
0090:
0091:            private static final int bufferSize = 8192;
0092:            private static final String TAG_PENDING = NamespaceType.OHRM
0093:                    .getPrefix()
0094:                    + ":pending";
0095:            private static final String TAG_RELATED = NamespaceType.OHRM
0096:                    .getPrefix()
0097:                    + ":related";
0098:            private static final String TAG_IMAGE = NamespaceType.OHRM
0099:                    .getPrefix()
0100:                    + ":image";
0101:
0102:            private static final String TAG_STRING = "xs:string";
0103:            public static final String TAG_HREF = "href";
0104:            private static final String ATTRIB_DEFINITION = "definition";
0105:            private static final String ATTRIB_DEFINITION_VERSION = "definition-version";
0106:            private static final String ATTRIB_ARRAYTYPE = "arrayType";
0107:            private static final String TAG_PROP = "prop";
0108:
0109:            private static AuxillaryProcessManager m_auxillary = null;
0110:            private boolean m_bIsArchived = false;
0111:
0112:            protected AbstractDataStoreInterface m_dsi = null;
0113:            protected Profile resourceProfile = null;
0114:            protected org.w3c.dom.Document cachedPropertiesDocument = null;
0115:            protected long cacheTimeStamp = 0;
0116:            protected AbstractChildObject m_child = null;
0117:
0118:            /**
0119:             * Logger for this class
0120:             */
0121:            private final static Logger m_logger = Logger
0122:                    .getLogger(HarmonisePropertiesManager.class.getName());
0123:
0124:            public HarmonisePropertiesManager() {
0125:            }
0126:
0127:            // Constructors:
0128:            public HarmonisePropertiesManager(ResourceImpl resource,
0129:                    com.ibm.webdav.impl.NamespaceManager namespaceManager) {
0130:                super (resource, namespaceManager);
0131:            }
0132:
0133:            /* (non-Javadoc)
0134:             * @see com.ibm.webdav.impl.PropertiesManager#initialize(com.ibm.webdav.impl.ResourceImpl, com.ibm.webdav.impl.NamespaceManager)
0135:             */
0136:            public void initialize(ResourceImpl resource,
0137:                    com.ibm.webdav.impl.NamespaceManager namespaceManager) {
0138:                super .initialize(resource, namespaceManager);
0139:
0140:                try {
0141:
0142:                    m_dsi = DataStoreInterfaceFactory.getDataStoreInterface();
0143:
0144:                    populateChild();
0145:
0146:                    if (m_auxillary == null) {
0147:                        m_auxillary = APMFactory.getAPM();
0148:                    }
0149:                } catch (DataStoreException e) {
0150:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
0151:                } catch (WebDAVException e) {
0152:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
0153:                } catch (APMException e) {
0154:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
0155:                }
0156:
0157:                if (m_dsi == null) {
0158:                    throw new RuntimeException(
0159:                            "Datastore interface not started properly.");
0160:                }
0161:            }
0162:
0163:            /* (non-Javadoc)
0164:             * @see com.ibm.webdav.impl.PropertiesManager#deleteProperties()
0165:             */
0166:            public void deleteProperties() throws WebDAVException {
0167:
0168:                /************************************
0169:                 *
0170:                 * Properties should be deleted with the resource
0171:                 *
0172:                 ***********************************/
0173:
0174:                cachedPropertiesDocument = null;
0175:            }
0176:
0177:            /* (non-Javadoc)
0178:             * @see com.ibm.webdav.impl.PropertiesManager#loadProperties()
0179:             */
0180:            public org.w3c.dom.Document loadProperties() throws WebDAVException {
0181:                if (cachedPropertiesDocument != null) {
0182:                    return cachedPropertiesDocument;
0183:                }
0184:
0185:                try {
0186:
0187:                    populateChild();
0188:
0189:                    cachedPropertiesDocument = DocumentBuilderFactory
0190:                            .newInstance().newDocumentBuilder().newDocument();
0191:
0192:                    Element properties = (Element) cachedPropertiesDocument
0193:                            .createElement("properties");
0194:                    properties.setAttribute("xmlns:D", NamespaceType.DAV
0195:                            .getURI());
0196:                    cachedPropertiesDocument.appendChild(properties);
0197:
0198:                    if (m_child != null) {
0199:
0200:                        //add version comment property
0201:                        Element commentEl = cachedPropertiesDocument
0202:                                .createElementNS(NamespaceType.DAV.getURI(),
0203:                                        VersionedPropertiesManager.TAG_COMMENT);
0204:                        commentEl.setPrefix(NamespaceType.DAV.getPrefix());
0205:                        if (m_child.isPendingVersion() == false) {
0206:                            commentEl
0207:                                    .appendChild(cachedPropertiesDocument
0208:                                            .createTextNode(m_child
0209:                                                    .getVersionComment()));
0210:                        }
0211:                        properties.appendChild(commentEl);
0212:
0213:                        List doneProps = new ArrayList();
0214:                        List availProps = Domain.getAvailableProperties(m_dsi,
0215:                                m_child);
0216:
0217:                        //publish profiles
0218:                        Iterator profIter = m_child.getProfiles().iterator();
0219:
0220:                        while (profIter.hasNext()) {
0221:                            Profile tmpProf = (Profile) profIter.next();
0222:
0223:                            List propInsts = tmpProf.getPropertyInstances();
0224:
0225:                            Iterator propIter = propInsts.iterator();
0226:
0227:                            while (propIter.hasNext()) {
0228:                                AbstractPropertyInstance propInst = (AbstractPropertyInstance) propIter
0229:                                        .next();
0230:                                doneProps.add(propInst.getName());
0231:                                NamespaceType ns = HarmoniseNameResolver
0232:                                        .getPropertyNamespace(propInst
0233:                                                .getProperty());
0234:                                properties
0235:                                        .appendChild(getPropertyInstanceElement(
0236:                                                cachedPropertiesDocument,
0237:                                                propInst, ns));
0238:                            }
0239:                        }
0240:
0241:                        //deal with avail props that the profiles didn't have prop insts for
0242:                        Iterator propIter = availProps.iterator();
0243:                        while (propIter.hasNext()) {
0244:                            Property tmpProp = (Property) propIter.next();
0245:                            String sPropName = tmpProp.getName();
0246:                            if (doneProps.contains(sPropName) == false) {
0247:                                if (m_logger.isLoggable(Level.FINER)) {
0248:                                    m_logger.logp(Level.FINER, this .getClass()
0249:                                            .getName(), "loadProperties",
0250:                                            "Adding empty property - "
0251:                                                    + sPropName);
0252:                                }
0253:
0254:                                NamespaceType ns = HarmoniseNameResolver
0255:                                        .getPropertyNamespace(tmpProp);
0256:
0257:                                Element propEl = this .getPropertyEmptyElement(
0258:                                        cachedPropertiesDocument, tmpProp, ns);
0259:
0260:                                //deal with display name and summary
0261:                                if (propEl.getLocalName().equals(TAG_TITLE)) {
0262:                                    propEl.appendChild(cachedPropertiesDocument
0263:                                            .createTextNode(m_child
0264:                                                    .getDisplayName()));
0265:                                } else if (propEl.getLocalName().equals(
0266:                                        TAG_DESCRIPTION)) {
0267:                                    propEl.appendChild(cachedPropertiesDocument
0268:                                            .createTextNode(m_child
0269:                                                    .getSummary()));
0270:                                }
0271:
0272:                                properties.appendChild(propEl);
0273:                            }
0274:                        }
0275:
0276:                        if (m_child.isLocked() == true) {
0277:                            if (m_logger.isLoggable(Level.FINER)) {
0278:                                m_logger.logp(Level.FINER, this .getClass()
0279:                                        .getName(), "loadProperties", m_child
0280:                                        .getName()
0281:                                        + " is locked");
0282:                            }
0283:
0284:                            Element lockdiscovery = cachedPropertiesDocument
0285:                                    .createElementNS(
0286:                                            NamespaceType.DAV.getURI(),
0287:                                            "D:lockdiscovery");
0288:
0289:                            addLockData(lockdiscovery);
0290:                            properties.appendChild(lockdiscovery);
0291:                        } else {
0292:                            if (m_logger.isLoggable(Level.FINER)) {
0293:                                m_logger.logp(Level.FINER, this .getClass()
0294:                                        .getName(), "loadProperties", m_child
0295:                                        .getName()
0296:                                        + " is not locked");
0297:                            }
0298:                        }
0299:
0300:                        //domain and range, if this resource is a property
0301:                        if (m_child instanceof  Property) {
0302:                            Property prop = (Property) m_child;
0303:
0304:                            properties.appendChild(getRangeElement(
0305:                                    cachedPropertiesDocument, prop));
0306:
0307:                            DAVDomain davDomain = new DAVDomain(m_dsi, prop
0308:                                    .getDomains());
0309:
0310:                            properties.appendChild(davDomain
0311:                                    .asXML(cachedPropertiesDocument));
0312:                        }
0313:
0314:                    } else if (HarmoniseNameResolver.isVirtualResource(resource
0315:                            .getURL())) {
0316:                        try {
0317:                            String sResourcePath = URLDecoder.decode(resource
0318:                                    .getURL().getPath(),
0319:                                    HarmoniseNameResolver.UTF_8);
0320:                            String sPath = HarmoniseNameResolver
0321:                                    .getRealPath(resource.getURL());
0322:
0323:                            String sChildName = HarmoniseNameResolver
0324:                                    .getChildTypeFromURL(sResourcePath);
0325:
0326:                            List props = Domain.getAvailableProperties(m_dsi,
0327:                                    Class.forName(sChildName), sPath);
0328:
0329:                            Iterator iter = props.iterator();
0330:
0331:                            while (iter.hasNext()) {
0332:                                Property prop = (Property) iter.next();
0333:
0334:                                NamespaceType ns = HarmoniseNameResolver
0335:                                        .getPropertyNamespace(prop);
0336:
0337:                                Element propEl = this .getPropertyEmptyElement(
0338:                                        cachedPropertiesDocument, prop, ns);
0339:
0340:                                properties.appendChild(propEl);
0341:                            }
0342:
0343:                        } catch (UnsupportedEncodingException e) {
0344:                            throw new WebDAVException(
0345:                                    WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0346:                                            .getLocalizedMessage());
0347:                        } catch (ClassNotFoundException e) {
0348:                            throw new WebDAVException(
0349:                                    WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0350:                                            .getLocalizedMessage());
0351:                        }
0352:                    } else if (HarmoniseNameResolver
0353:                            .isVirtualCollection(resource.getURL())) {
0354:                        try {
0355:                            String sResourcePath = URLDecoder.decode(resource
0356:                                    .getURL().getPath(),
0357:                                    HarmoniseNameResolver.UTF_8);
0358:                            String sPath = HarmoniseNameResolver
0359:                                    .getRealPath(resource.getURL());
0360:
0361:                            boolean bIsPropCol = HarmoniseNameResolver
0362:                                    .getLastSegment(sPath)
0363:                                    .equals(
0364:                                            HarmoniseNameResolver.VIRTUAL_COLLECTION_NAME);
0365:
0366:                            if (bIsPropCol == true) {
0367:
0368:                                String sChildName = HarmoniseNameResolver
0369:                                        .getParentTypeFromURL(sResourcePath);
0370:
0371:                                List props = Domain
0372:                                        .getAvailableProperties(m_dsi, Class
0373:                                                .forName(sChildName), sPath);
0374:
0375:                                Iterator iter = props.iterator();
0376:
0377:                                while (iter.hasNext()) {
0378:                                    Property prop = (Property) iter.next();
0379:
0380:                                    NamespaceType ns = HarmoniseNameResolver
0381:                                            .getPropertyNamespace(prop);
0382:
0383:                                    Element propEl = this 
0384:                                            .getPropertyEmptyElement(
0385:                                                    cachedPropertiesDocument,
0386:                                                    prop, ns);
0387:
0388:                                    properties.appendChild(propEl);
0389:                                }
0390:
0391:                            }
0392:
0393:                        } catch (UnsupportedEncodingException e) {
0394:                            throw new WebDAVException(
0395:                                    WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0396:                                            .getLocalizedMessage());
0397:                        } catch (ClassNotFoundException e) {
0398:                            throw new WebDAVException(
0399:                                    WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0400:                                            .getLocalizedMessage());
0401:                        }
0402:                    }
0403:
0404:                    if (m_logger.isLoggable(Level.FINEST)) {
0405:                        m_logger.logp(Level.FINEST, this .getClass().getName(),
0406:                                "loadProperties", "property results:");
0407:                        m_logger.log(Level.FINEST, XMLUtility
0408:                                .printNode(cachedPropertiesDocument
0409:                                        .getDocumentElement()));
0410:
0411:                    }
0412:                } catch (HarmoniseException exc) {
0413:                    m_logger.log(Level.WARNING, exc.getLocalizedMessage(), exc);
0414:                    throw new WebDAVException(
0415:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, exc
0416:                                    .getLocalizedMessage());
0417:                } catch (ParserConfigurationException exc) {
0418:                    throw new WebDAVException(
0419:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, exc
0420:                                    .getLocalizedMessage());
0421:                } catch (FactoryConfigurationError exc) {
0422:                    throw new WebDAVException(
0423:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, exc
0424:                                    .getLocalizedMessage());
0425:                } catch (NameResolverException exc) {
0426:                    m_logger.log(Level.WARNING, exc.getLocalizedMessage(), exc);
0427:                    throw new WebDAVException(
0428:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, exc
0429:                                    .getLocalizedMessage());
0430:                }
0431:
0432:                return cachedPropertiesDocument;
0433:            }
0434:
0435:            protected Element getRangeElement(org.w3c.dom.Document xmlDoc,
0436:                    Property prop) throws DataAccessException, WebDAVException {
0437:                Element rangeEl = null;
0438:
0439:                Range range = prop.getRange();
0440:
0441:                if (range != null) {
0442:                    DAVRange davRange = DAVRangeFactory.getDAVRange(m_dsi,
0443:                            range);
0444:                    rangeEl = davRange.asXML(xmlDoc);
0445:                } else {
0446:                    rangeEl = xmlDoc.createElementNS(
0447:                            NamespaceType.DAV.getURI(), NamespaceType.DAV
0448:                                    .getPrefix()
0449:                                    + ":" + DAVRange.TAG_RANGE);
0450:                }
0451:
0452:                return rangeEl;
0453:            }
0454:
0455:            protected void addLockData(Element lockdiscovery)
0456:                    throws NameResolverException, DataAccessException,
0457:                    WebDAVException {
0458:                org.w3c.dom.Document xmlDoc = lockdiscovery.getOwnerDocument();
0459:
0460:                String sOwner = HarmoniseNameResolver.getDAVPath(m_child
0461:                        .getLockOwner());
0462:
0463:                Element owner = xmlDoc.createElementNS(NamespaceType.DAV
0464:                        .getURI(), "owner");
0465:                owner.setPrefix(NamespaceType.DAV.getPrefix());
0466:
0467:                Element href = xmlDoc.createElementNS(NamespaceType.DAV
0468:                        .getURI(), TAG_HREF);
0469:                href.setPrefix(NamespaceType.DAV.getPrefix());
0470:                href.appendChild(xmlDoc.createTextNode(sOwner));
0471:                owner.appendChild(href);
0472:
0473:                ActiveLock alock = this .getActiveLockFor(m_child.getLockOwner()
0474:                        .getName(), ActiveLock.exclusive, ActiveLock.writeLock,
0475:                        -1, owner);
0476:
0477:                lockdiscovery.appendChild(xmlDoc
0478:                        .importNode(alock.asXML(), true));
0479:            }
0480:
0481:            /* (non-Javadoc)
0482:             * @see com.ibm.webdav.impl.PropertiesManager#removeLiveProperties(org.w3c.dom.Document)
0483:             */
0484:            public void removeLiveProperties(
0485:                    org.w3c.dom.Document propertiesDocument) {
0486:                Element properties = propertiesDocument.getDocumentElement();
0487:                Element p = null;
0488:                p = (Element) ((Element) properties).getElementsByTagNameNS(
0489:                        NamespaceType.DAV.getURI(), "getcontentlength").item(0);
0490:
0491:                if (p != null) {
0492:                    properties.removeChild(p);
0493:                }
0494:
0495:                p = XMLUtils.getFirstNamedChild(properties, "resourcetype");
0496:
0497:                if (p != null) {
0498:                    properties.removeChild(p);
0499:                }
0500:
0501:                p = (Element) ((Element) properties).getElementsByTagNameNS(
0502:                        NamespaceType.DAV.getURI(), "getlastmodified").item(0);
0503:
0504:                if (p != null) {
0505:                    properties.removeChild(p);
0506:                }
0507:
0508:                p = (Element) ((Element) properties).getElementsByTagNameNS(
0509:                        NamespaceType.OHRM.getURI(), TAG_ARCHIVEDATE).item(0);
0510:
0511:                if (p != null) {
0512:                    properties.removeChild(p);
0513:                }
0514:
0515:                p = (Element) ((Element) properties).getElementsByTagNameNS(
0516:                        NamespaceType.DAV.getURI(), "getcontenttype").item(0);
0517:
0518:                if (p != null) {
0519:                    properties.removeChild(p);
0520:                }
0521:
0522:                p = (Element) ((Element) properties).getElementsByTagNameNS(
0523:                        NamespaceType.DAV.getURI(), "resourceid").item(0);
0524:
0525:                if (p != null) {
0526:                    properties.removeChild(p);
0527:                }
0528:
0529:                p = (Element) ((Element) properties).getElementsByTagNameNS(
0530:                        NamespaceType.DAV.getURI(), "displayname").item(0);
0531:
0532:                if (p != null) {
0533:                    properties.removeChild(p);
0534:                }
0535:
0536:                p = (Element) ((Element) properties).getElementsByTagNameNS(
0537:                        NamespaceType.OHRM.getURI(), TAG_HARMONISE_ID).item(0);
0538:
0539:                if (p != null) {
0540:                    properties.removeChild(p);
0541:                }
0542:
0543:                p = (Element) ((Element) properties).getElementsByTagNameNS(
0544:                        NamespaceType.DAV.getURI(), TAG_PARENT_SET).item(0);
0545:
0546:                if (p != null) {
0547:                    properties.removeChild(p);
0548:                }
0549:            }
0550:
0551:            /* (non-Javadoc)
0552:             * @see com.ibm.webdav.impl.PropertiesManager#saveProperties(org.w3c.dom.Document)
0553:             */
0554:            public void saveProperties(org.w3c.dom.Document propertiesDocument)
0555:                    throws WebDAVException {
0556:                try {
0557:
0558:                    populateChild();
0559:
0560:                    boolean bSave = false;
0561:
0562:                    Element proproot = propertiesDocument.getDocumentElement();
0563:
0564:                    //sort out locking
0565:                    boolean bIsLockChanged = false;
0566:                    User usr = ((HarmoniseSessionManager) resource
0567:                            .getUserAuthenticator()).getUser(resource);
0568:                    if (resource.getContext().getMethodName().equalsIgnoreCase(
0569:                            "LOCK") == true
0570:                            || resource.getContext().getMethodName()
0571:                                    .equalsIgnoreCase("UNLOCK") == true) {
0572:                        Element lockdiscovery = (Element) proproot
0573:                                .getElementsByTagNameNS(
0574:                                        NamespaceType.DAV.getURI(),
0575:                                        TAG_LOCKDISCOVERY).item(0);
0576:
0577:                        if (m_logger.isLoggable(Level.FINER)) {
0578:                            m_logger.logp(Level.FINER, this .getClass()
0579:                                    .getName(), "saveProperties", "Got user - "
0580:                                    + usr.getName());
0581:                        }
0582:
0583:                        if (lockdiscovery != null) {
0584:                            NodeList locks = ((Element) lockdiscovery)
0585:                                    .getElementsByTagNameNS(NamespaceType.DAV
0586:                                            .getURI(), "activelock");
0587:                            Element lock = null;
0588:                            Date now = new Date();
0589:
0590:                            if (locks.getLength() > 0) {
0591:                                for (int i = 0; i < locks.getLength(); i++) {
0592:                                    lock = (Element) locks.item(i);
0593:
0594:                                    if ((m_child.isHistorical() == false)) {
0595:                                        if (m_child.isLocked() == false) {
0596:                                            bIsLockChanged = true;
0597:
0598:                                            CommandWrapper.lock(m_dsi, m_child,
0599:                                                    usr);
0600:
0601:                                        }
0602:                                    }
0603:                                }
0604:                            } else {
0605:
0606:                                if ((m_child.isLocked() == true)
0607:                                        && (m_child.isHistorical() == false)) {
0608:                                    bIsLockChanged = true;
0609:
0610:                                    CommandWrapper.unlock(m_dsi, m_child, usr);
0611:                                }
0612:                            }
0613:                        } else {
0614:                            if ((m_child.isLocked() == true)
0615:                                    && (m_child.isHistorical() == false)) {
0616:                                bIsLockChanged = true;
0617:
0618:                                CommandWrapper.unlock(m_dsi, m_child, usr);
0619:                            }
0620:                        }
0621:                    }
0622:
0623:                    //sort out profile
0624:
0625:                    if (bIsLockChanged == false) {
0626:                        if (CommandWrapper.isSaveAllowed(usr, m_child) == false) {
0627:                            throw new WebDAVException(
0628:                                    WebDAVStatus.SC_FORBIDDEN,
0629:                                    "User is not allowed to save resource");
0630:                        }
0631:
0632:                        Profile prof = m_child.getProfile();
0633:
0634:                        //if this is a live resource make sure that we remove the 'START' prop
0635:                        if ((m_child.isLiveVersion() == true)
0636:                                && (resource.getContext().getMethodName()
0637:                                        .equals("PROPPATCH") == true)) {
0638:                            prof
0639:                                    .removeProperty(PropertyFactory
0640:                                            .getPropertyFromName(
0641:                                                    m_dsi,
0642:                                                    HarmoniseNameResolver.START_PROP_NAME));
0643:                        }
0644:
0645:                        NodeList propNodes = proproot.getChildNodes();
0646:                        int nId = -1;
0647:                        boolean bHasPropChanged = false;
0648:                        List invalidProps = new ArrayList();
0649:
0650:                        for (int i = 0; i < propNodes.getLength(); i++) {
0651:                            Element propEl = (Element) propNodes.item(i);
0652:                            Profile tmpProf = null;
0653:
0654:                            if (m_logger.isLoggable(Level.FINER)) {
0655:                                m_logger.logp(Level.FINER, this .getClass()
0656:                                        .getName(), "saveProperties",
0657:                                        "Handling prop - "
0658:                                                + propEl.getTagName());
0659:                            }
0660:
0661:                            NamedNodeMap attribs = propEl.getAttributes();
0662:
0663:                            tmpProf = HarmoniseNameResolver
0664:                                    .getProfileForNamespaceURI(m_child, propEl
0665:                                            .getNamespaceURI());
0666:
0667:                            //only deal with Harmonise props
0668:                            if (tmpProf != null) {
0669:                                bSave = true;
0670:
0671:                                String propName = propEl.getTagName();
0672:
0673:                                if (m_logger.isLoggable(Level.FINER)) {
0674:                                    m_logger.logp(Level.FINER, this .getClass()
0675:                                            .getName(), "saveProperties",
0676:                                            "trying to save " + propName
0677:                                                    + " property");
0678:                                }
0679:
0680:                                int nIndex = propName.indexOf(":");
0681:
0682:                                String localPropName = propName;
0683:
0684:                                if ((propName.startsWith("DC") == false)
0685:                                        && (propName.startsWith("dc") == false)) {
0686:                                    localPropName = propName.substring(
0687:                                            nIndex + 1, propName.length());
0688:                                }
0689:
0690:                                //if property is 'id' don't save it
0691:                                if (localPropName.equalsIgnoreCase("id") == true) {
0692:                                    nId = Integer.parseInt(propEl
0693:                                            .getChildNodes().item(0)
0694:                                            .getNodeValue());
0695:
0696:                                    if (m_logger.isLoggable(Level.FINER)) {
0697:                                        m_logger.logp(Level.FINER, this 
0698:                                                .getClass().getName(),
0699:                                                "saveProperties",
0700:                                                "Found id prop " + nId);
0701:                                    }
0702:                                } else if (localPropName
0703:                                        .equalsIgnoreCase(TAG_DESCRIPTION)) {
0704:                                    if (propEl.getChildNodes().getLength() > 0) {
0705:                                        // deal with summary
0706:                                        m_child.setSummary(propEl
0707:                                                .getChildNodes().item(0)
0708:                                                .getNodeValue());
0709:                                    } else {
0710:                                        m_child.setSummary("");
0711:                                    }
0712:
0713:                                } else if (localPropName
0714:                                        .equalsIgnoreCase(TAG_TITLE)) {
0715:                                    if (propEl.getChildNodes().getLength() > 0) {
0716:                                        //deal with title
0717:                                        m_child.setDisplayName(propEl
0718:                                                .getChildNodes().item(0)
0719:                                                .getNodeValue());
0720:                                    } else {
0721:                                        m_child.setDisplayName("");
0722:                                    }
0723:                                } else {
0724:                                    if (m_logger.isLoggable(Level.FINER)) {
0725:                                        m_logger.logp(Level.FINER, this 
0726:                                                .getClass().getName(),
0727:                                                "saveProperties",
0728:                                                "trying to save "
0729:                                                        + localPropName
0730:                                                        + " property");
0731:                                    }
0732:
0733:                                    if (tmpProf != null) {
0734:                                        if (m_logger.isLoggable(Level.FINER)) {
0735:                                            m_logger.logp(Level.FINER, this 
0736:                                                    .getClass().getName(),
0737:                                                    "saveProperties",
0738:                                                    "trying to save "
0739:                                                            + localPropName);
0740:                                        }
0741:
0742:                                        try {
0743:                                            boolean bNewPropInst = false;
0744:                                            AbstractPropertyInstance propInst = tmpProf
0745:                                                    .getPropertyInstance(localPropName);
0746:                                            Property prop = null;
0747:                                            // if profile doesn't include property and there's a value
0748:                                            // generate a propertyInstance
0749:                                            if (propInst == null) {
0750:                                                prop = PropertyFactory
0751:                                                        .getPropertyFromName(
0752:                                                                this .m_dsi,
0753:                                                                localPropName);
0754:                                                propInst = PropertyInstanceFactory
0755:                                                        .getPropertyInstance(
0756:                                                                this .m_dsi,
0757:                                                                prop);
0758:                                                propInst.setProfile(tmpProf);
0759:
0760:                                                bNewPropInst = true;
0761:                                            } else {
0762:                                                prop = propInst.getProperty();
0763:                                            }
0764:
0765:                                            if (propInst != null) {
0766:                                                bHasPropChanged = populatePropertyInstance(
0767:                                                        propInst, propEl);
0768:
0769:                                                if (bHasPropChanged == true
0770:                                                        && bNewPropInst == true) {
0771:                                                    tmpProf
0772:                                                            .addPropertyInstance(propInst);
0773:
0774:                                                    if (m_logger
0775:                                                            .isLoggable(Level.FINER)) {
0776:                                                        m_logger
0777:                                                                .logp(
0778:                                                                        Level.FINER,
0779:                                                                        this 
0780:                                                                                .getClass()
0781:                                                                                .getName(),
0782:                                                                        "saveProperties",
0783:                                                                        "added new PropertyInsatnce:"
0784:                                                                                + localPropName);
0785:                                                    }
0786:                                                }
0787:
0788:                                                if (propInst.hasValues() == false
0789:                                                        && bNewPropInst == false) {
0790:                                                    tmpProf
0791:                                                            .removeProperty(propInst
0792:                                                                    .getProperty());
0793:
0794:                                                    if (m_logger
0795:                                                            .isLoggable(Level.FINER)) {
0796:                                                        m_logger
0797:                                                                .logp(
0798:                                                                        Level.FINER,
0799:                                                                        this 
0800:                                                                                .getClass()
0801:                                                                                .getName(),
0802:                                                                        "saveProperties",
0803:                                                                        "removing propertyinstance "
0804:                                                                                + prop
0805:                                                                                        .getName());
0806:                                                    }
0807:
0808:                                                    bHasPropChanged = true;
0809:                                                }
0810:
0811:                                            }
0812:
0813:                                        } catch (InvalidPropertyInstanceException e) {
0814:                                            if (m_logger.isLoggable(Level.INFO)) {
0815:                                                m_logger.log(Level.INFO, e
0816:                                                        .getLocalizedMessage(),
0817:                                                        e);
0818:                                            }
0819:
0820:                                            invalidProps.add(e);
0821:
0822:                                        } catch (InvalidPropertyValueException e) {
0823:                                            if (m_logger.isLoggable(Level.INFO)) {
0824:                                                m_logger.log(Level.INFO, e
0825:                                                        .getLocalizedMessage(),
0826:                                                        e);
0827:                                            }
0828:
0829:                                            invalidProps.add(e);
0830:                                        } catch (HarmoniseException e) {
0831:                                            if (m_logger.isLoggable(Level.INFO)) {
0832:                                                m_logger.log(Level.INFO, e
0833:                                                        .getLocalizedMessage(),
0834:                                                        e);
0835:                                            }
0836:                                            throw new WebDAVException(
0837:                                                    WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
0838:                                                    e.getLocalizedMessage());
0839:                                        } catch (NameResolverException e) {
0840:                                            throw new WebDAVException(
0841:                                                    WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
0842:                                                    e.getLocalizedMessage());
0843:                                        }
0844:                                    }
0845:                                }
0846:                            } else {
0847:                                NodeList nodes = propEl.getChildNodes();
0848:
0849:                                String sTagName = propEl.getLocalName();
0850:
0851:                                if (sTagName
0852:                                        .equals(VersionedPropertiesManager.TAG_COMMENT)) {
0853:                                    if (nodes.getLength() > 0) {
0854:
0855:                                        String sComment = nodes.item(0)
0856:                                                .getNodeValue();
0857:                                        m_child.setVersionComment(sComment);
0858:                                        if (m_child.isChanged() == true) {
0859:                                            bSave = true;
0860:                                        }
0861:                                    }
0862:                                } else if (m_child instanceof  Property) {
0863:                                    Property childProp = (Property) m_child;
0864:                                    if (sTagName.equals(DAVDomain.TAG_DOMAIN)) {
0865:                                        DAVDomain davDomain = new DAVDomain(
0866:                                                m_dsi);
0867:
0868:                                        davDomain.populate(propEl);
0869:
0870:                                        childProp.setDomains(davDomain
0871:                                                .getHarmoniseDomains());
0872:                                        if (m_child.isChanged() == true) {
0873:                                            bSave = true;
0874:                                        }
0875:
0876:                                    } else if (sTagName
0877:                                            .equals(DAVRange.TAG_RANGE)) {
0878:                                        DAVRange davRange = DAVRangeFactory
0879:                                                .getDAVRange(m_dsi, childProp,
0880:                                                        propEl);
0881:
0882:                                        if (davRange != null) {
0883:
0884:                                            Range range = davRange
0885:                                                    .getHarmoniseRange();
0886:
0887:                                            if (range != null) {
0888:                                                childProp.setRange(range);
0889:                                                if (m_child.isChanged() == true) {
0890:                                                    bSave = true;
0891:                                                }
0892:                                            }
0893:                                        }
0894:                                    }
0895:                                }
0896:                            }
0897:                        }
0898:
0899:                        String sMethodName = resource.getContext()
0900:                                .getMethodName();
0901:
0902:                        if ((bSave == true)
0903:                                && (prof != null || m_child instanceof  Property)) {
0904:                            try {
0905:
0906:                                if (m_logger.isLoggable(Level.FINER)) {
0907:                                    m_logger.logp(Level.FINER, this .getClass()
0908:                                            .getName(), "saveProperties",
0909:                                            "resource context method - "
0910:                                                    + sMethodName);
0911:                                }
0912:
0913:                                if (m_logger.isLoggable(Level.FINER)) {
0914:                                    m_logger.logp(Level.FINER, this .getClass()
0915:                                            .getName(), "saveProperties",
0916:                                            "before save:" + m_child);
0917:                                }
0918:
0919:                                m_child = CommandWrapper.save(m_dsi, m_child,
0920:                                        usr);
0921:
0922:                                if (m_logger.isLoggable(Level.FINER)) {
0923:                                    m_logger.logp(Level.FINER, this .getClass()
0924:                                            .getName(), "saveProperties",
0925:                                            "after save:" + m_child);
0926:                                }
0927:
0928:                                if (m_auxillary != null) {
0929:                                    m_auxillary.saveProperties(usr, m_child,
0930:                                            prof);
0931:                                }
0932:                            } catch (APMException e) {
0933:                                throw new WebDAVException(
0934:                                        WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
0935:                                        e.getMessage());
0936:                            }
0937:                        }
0938:
0939:                        if (invalidProps.size() > 0) {
0940:                            StringBuffer sbuf = new StringBuffer();
0941:
0942:                            for (Iterator iter = invalidProps.iterator(); iter
0943:                                    .hasNext();) {
0944:                                Exception e = (Exception) iter.next();
0945:                                sbuf.append("[").append(e.getMessage()).append(
0946:                                        "]\n");
0947:                            }
0948:
0949:                            throw new WebDAVException(WebDAVStatus.SC_CONFLICT,
0950:                                    sbuf.toString());
0951:                        }
0952:
0953:                        if (m_child instanceof  AbstractParentObject
0954:                                && m_child.isPendingVersion() == true
0955:                                && ConfigSettings
0956:                                        .getBoolProperty(
0957:                                                HarmoniseNameResolver.PNAME_AUTO_APPROVE_COLLECTIONS,
0958:                                                "true") == true) {
0959:                            //it's a section and we don't want unapproved sections
0960:                            CommandWrapper.changeStatus(m_dsi, m_child, usr,
0961:                                    Status.APPROVED);
0962:                        }
0963:                    }
0964:                } catch (HarmoniseException e) {
0965:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
0966:
0967:                    throw new WebDAVException(
0968:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
0969:                                    .getMessage());
0970:                }
0971:            }
0972:
0973:            /* (non-Javadoc)
0974:             * @see com.ibm.webdav.impl.PropertiesManager#updateLiveProperties(org.w3c.dom.Document)
0975:             */
0976:            public void updateLiveProperties(org.w3c.dom.Document document)
0977:                    throws WebDAVException {
0978:                populateChild();
0979:                boolean bIsVirtCollection = false;
0980:                boolean bIsVirtualResource = false;
0981:
0982:                try {
0983:                    if (m_child == null) {
0984:                        URL url = resource.getURL();
0985:
0986:                        bIsVirtCollection = HarmoniseNameResolver
0987:                                .isVirtualCollection(url)
0988:                                || HarmoniseNameResolver
0989:                                        .isArchivedVirtualCollection(url);
0990:
0991:                        if (bIsVirtCollection == false) {
0992:                            bIsVirtualResource = HarmoniseNameResolver
0993:                                    .isVirtualResource(url);
0994:                        }
0995:                    }
0996:
0997:                    if (m_child == null && bIsVirtCollection == false
0998:                            && bIsVirtualResource == false) {
0999:
1000:                        throw new WebDAVException(WebDAVStatus.SC_NOT_FOUND,
1001:                                "Could not find resource at this location");
1002:                    }
1003:
1004:                    Element properties = document.getDocumentElement();
1005:
1006:                    // update the repository specific live properties
1007:                    Element resourceType = document.createElementNS(
1008:                            NamespaceType.DAV.getURI(), "D:resourcetype");
1009:
1010:                    if (m_child instanceof  AbstractParentObject) {
1011:                        resourceType.appendChild(document.createElementNS(
1012:                                NamespaceType.DAV.getURI(), "D:collection"));
1013:                    } else if (bIsVirtCollection == true) {
1014:                        Element colEl = document.createElementNS(
1015:                                NamespaceType.DAV.getURI(), "D:collection");
1016:                        colEl.setAttribute(NamespaceType.OHRM.getPrefix()
1017:                                + ":isVirtual", "true");
1018:                        colEl.setAttribute("xmlns:"
1019:                                + NamespaceType.OHRM.getPrefix(),
1020:                                NamespaceType.OHRM.getURI());
1021:                        resourceType.appendChild(colEl);
1022:                    } else if (m_child instanceof  Property) {
1023:                        resourceType.appendChild(document.createElementNS(
1024:                                NamespaceType.DAV.getURI(),
1025:                                "D:property-resource"));
1026:                    } else if (m_child instanceof  Value) {
1027:                        resourceType.appendChild(document.createElementNS(
1028:                                NamespaceType.DAV.getURI(), "D:value"));
1029:                    } else {
1030:                        resourceType.appendChild(document.createElementNS(
1031:                                NamespaceType.DAV.getURI(), "D:resource"));
1032:                    }
1033:
1034:                    properties.appendChild(resourceType);
1035:
1036:                    Element lastModifiedDate = document.createElementNS(
1037:                            NamespaceType.DAV.getURI(), "D:getlastmodified");
1038:
1039:                    String cdstring = null;
1040:                    if (m_child != null) {
1041:                        Date versionDate = m_child.getVersionDate();
1042:
1043:                        cdstring = new SimpleRFC1123DateFormat()
1044:                                .format(versionDate);
1045:                        lastModifiedDate.appendChild(document
1046:                                .createTextNode(cdstring));
1047:                    }
1048:
1049:                    properties.appendChild(lastModifiedDate);
1050:
1051:                    Element creationDate = document.createElementNS(
1052:                            NamespaceType.DAV.getURI(), "D:creationdate");
1053:
1054:                    if (m_child != null) {
1055:                        cdstring = new SimpleISO8601DateFormat().format(m_child
1056:                                .getVersionDate());
1057:                        creationDate.appendChild(document
1058:                                .createTextNode(cdstring));
1059:
1060:                        if (m_child.isHistorical() == true) {
1061:                            Element archDateEl = document.createElementNS(
1062:                                    NamespaceType.OHRM.getURI(),
1063:                                    NamespaceType.OHRM.getPrefix() + ":"
1064:                                            + TAG_ARCHIVEDATE);
1065:                            archDateEl.setAttribute("xmlns:"
1066:                                    + NamespaceType.OHRM.getPrefix(),
1067:                                    NamespaceType.OHRM.getURI());
1068:
1069:                            Date archDate = m_child.getHistoryDate();
1070:
1071:                            String adstring = new SimpleRFC1123DateFormat()
1072:                                    .format(archDate);
1073:                            archDateEl.appendChild(document
1074:                                    .createTextNode(adstring));
1075:                            properties.appendChild(archDateEl);
1076:                        }
1077:                    }
1078:
1079:                    properties.appendChild(creationDate);
1080:
1081:                    Element displayname = document.createElementNS(
1082:                            NamespaceType.DAV.getURI(), "D:displayname");
1083:
1084:                    if (m_child != null) {
1085:                        displayname.appendChild(document.createTextNode(m_child
1086:                                .getDisplayName()));
1087:                    }
1088:
1089:                    properties.appendChild(displayname);
1090:
1091:                    Element getContentLength = document.createElementNS(
1092:                            NamespaceType.DAV.getURI(), "D:getcontentlength");
1093:                    long length = 0;
1094:
1095:                    if (m_child instanceof  Asset) {
1096:                        Asset asset = (Asset) m_child;
1097:                        String sType = asset.getContentType();
1098:
1099:                        if ((m_child instanceof  XSLResource) == false
1100:                                && sType.startsWith("link")
1101:                                || sType.startsWith("text")) {
1102:
1103:                            String sURI = asset.getURI();
1104:                            if (sURI != null) {
1105:                                length = sURI.getBytes().length;
1106:                            }
1107:                        } else {
1108:                            File file = asset.getContentFile();
1109:                            length = file.length();
1110:                        }
1111:                    } else if (m_child instanceof  TextResource) {
1112:                        TextResource txt = (TextResource) m_child;
1113:                        String sContent = txt.getContent();
1114:
1115:                        if (sContent != null) {
1116:                            length = sContent.getBytes().length;
1117:                        }
1118:
1119:                    } else if (m_child instanceof  WebPage) {
1120:                        WebPageResourceAdapter page = new WebPageResourceAdapter(
1121:                                (WebPage) m_child);
1122:                        String sContent = page.asString();
1123:
1124:                        if (sContent != null) {
1125:                            length = sContent.getBytes().length;
1126:                        }
1127:                    }
1128:
1129:                    getContentLength.appendChild(document.createTextNode(String
1130:                            .valueOf(length)));
1131:
1132:                    properties.appendChild(getContentLength);
1133:
1134:                    Element contentType = document.createElementNS(
1135:                            NamespaceType.DAV.getURI(), "D:getcontenttype");
1136:
1137:                    String type = "";
1138:
1139:                    if (m_child instanceof  AbstractParentObject
1140:                            || bIsVirtCollection == true) {
1141:                        type = "Folder";
1142:                    } else if (m_child instanceof  TextResource) {
1143:                        TextResource txt = (TextResource) m_child;
1144:                        if (txt instanceof  XMLResource) {
1145:                            type = MimeTypeMapping.XML.getMimeType();
1146:                        } else {
1147:                            type = txt.getContentType();
1148:                        }
1149:                    } else if (m_child instanceof  Asset) {
1150:                        type = ((Asset) m_child).getContentType();
1151:                    } else if (m_child instanceof  WebPage) {
1152:                        type = MimeTypeMapping.XML.getMimeType();
1153:                    }
1154:
1155:                    contentType.appendChild(document.createTextNode(type));
1156:
1157:                    properties.appendChild(contentType);
1158:
1159:                    if (m_child != null) {
1160:                        Element resourceId = document.createElementNS(
1161:                                NamespaceType.DAV.getURI(), "D:resourceid");
1162:
1163:                        String sClassname = m_child.getClass().getName();
1164:                        StringBuffer uniqueId = new StringBuffer();
1165:                        uniqueId.append(
1166:                                sClassname.substring(sClassname
1167:                                        .lastIndexOf(".") + 1)).append("#")
1168:                                .append(m_child.getKey());
1169:
1170:                        resourceId.appendChild(document.createTextNode(uniqueId
1171:                                .toString()));
1172:
1173:                        properties.appendChild(resourceId);
1174:
1175:                        Element harmoniseId = document.createElementNS(
1176:                                NamespaceType.OHRM.getURI(), TAG_HARMONISE_ID);
1177:                        harmoniseId.setPrefix(NamespaceType.OHRM.getPrefix());
1178:
1179:                        harmoniseId.setAttribute("xmlns:"
1180:                                + NamespaceType.OHRM.getPrefix(),
1181:                                NamespaceType.OHRM.getURI());
1182:
1183:                        harmoniseId.appendChild(document.createTextNode(String
1184:                                .valueOf(m_child.getId())));
1185:
1186:                        properties.appendChild(harmoniseId);
1187:                    }
1188:
1189:                    //deal with parent-set property
1190:                    if (m_child != null) {
1191:                        List parents = m_child.getParents();
1192:
1193:                        if (parents.size() > 1) {
1194:                            Element parentSetEl = document.createElementNS(
1195:                                    NamespaceType.DAV.getURI(), TAG_PARENT_SET);
1196:                            parentSetEl
1197:                                    .setPrefix(NamespaceType.DAV.getPrefix());
1198:
1199:                            Iterator iter = parents.iterator();
1200:
1201:                            while (iter.hasNext()) {
1202:                                AbstractParentObject parent = (AbstractParentObject) iter
1203:                                        .next();
1204:
1205:                                if (m_child.isRealParent(parent) == false) {
1206:                                    Element parentEl = document
1207:                                            .createElementNS(NamespaceType.DAV
1208:                                                    .getURI(), TAG_PARENT);
1209:                                    parentEl.setPrefix(NamespaceType.DAV
1210:                                            .getPrefix());
1211:
1212:                                    String sHREF = HarmoniseNameResolver
1213:                                            .getDAVPath(parent);
1214:
1215:                                    Element hrefEl = document.createElementNS(
1216:                                            NamespaceType.DAV.getURI(),
1217:                                            TAG_HREF);
1218:                                    hrefEl.setPrefix(NamespaceType.DAV
1219:                                            .getPrefix());
1220:                                    hrefEl.appendChild(document
1221:                                            .createTextNode(sHREF));
1222:                                    parentEl.appendChild(hrefEl);
1223:
1224:                                    Element segmentEl = document
1225:                                            .createElementNS(NamespaceType.DAV
1226:                                                    .getURI(), TAG_HREF);
1227:                                    segmentEl.setPrefix(NamespaceType.DAV
1228:                                            .getPrefix());
1229:
1230:                                    String sName = URLEncoder.encode(m_child
1231:                                            .getName(),
1232:                                            HarmoniseNameResolver.UTF_8);
1233:                                    segmentEl.appendChild(document
1234:                                            .createTextNode(sName));
1235:
1236:                                    parentEl.appendChild(segmentEl);
1237:
1238:                                    parentSetEl.appendChild(parentEl);
1239:                                }
1240:                            }
1241:
1242:                            properties.appendChild(parentSetEl);
1243:                        }
1244:
1245:                    }
1246:
1247:                } catch (HarmoniseException e) {
1248:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
1249:                    throw new WebDAVException(
1250:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1251:                                    .getMessage());
1252:                } catch (NameResolverException e) {
1253:                    throw new WebDAVException(
1254:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1255:                                    .getMessage());
1256:                } catch (UnsupportedEncodingException e) {
1257:                    throw new WebDAVException(
1258:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
1259:                                    .getMessage());
1260:                }
1261:            }
1262:
1263:            /** Returns a copy of the given node, copied to this document
1264:             *
1265:             * @param originalEl Node to be copied
1266:             * @exception Exception
1267:             */
1268:            public Node copyNode(org.w3c.dom.Document xmldoc, Node originalEl)
1269:                    throws Exception {
1270:                int i = 0;
1271:
1272:                Node returnNode = null;
1273:
1274:                if (originalEl.getNodeType() == Node.ELEMENT_NODE) {
1275:                    Element el = xmldoc.createElement(((Element) originalEl)
1276:                            .getTagName());
1277:                    NamedNodeMap attribs = originalEl.getAttributes();
1278:
1279:                    for (i = 0; i < attribs.getLength(); i++) {
1280:                        Attr nextAtt = (Attr) attribs.item(i);
1281:                        el.setAttribute(nextAtt.getNodeName(), nextAtt
1282:                                .getValue());
1283:                    }
1284:
1285:                    NodeList nodes = originalEl.getChildNodes();
1286:
1287:                    for (i = 0; i < nodes.getLength(); i++) {
1288:                        el.appendChild(copyNode(xmldoc, nodes.item(i)));
1289:                    }
1290:
1291:                    returnNode = (Node) el;
1292:                } else if (originalEl.getNodeType() == Node.TEXT_NODE) {
1293:                    Text el = xmldoc.createTextNode(originalEl.getNodeValue());
1294:
1295:                    returnNode = (Node) el;
1296:                }
1297:
1298:                return returnNode;
1299:            }
1300:
1301:            protected ActiveLock getActiveLockFor(String sOwner, String scope,
1302:                    String type, int timeout, Element owner)
1303:                    throws WebDAVException {
1304:                if (sOwner == null) {
1305:                    throw new WebDAVException(WebDAVStatus.SC_UNAUTHORIZED,
1306:                            "missing authorization identification");
1307:                }
1308:
1309:                // check all the parameters
1310:                if ((scope == null)
1311:                        || (!scope.equals(ActiveLock.exclusive) && !scope
1312:                                .equals(ActiveLock.shared))) {
1313:                    throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST,
1314:                            "unsupported or missing lock scope: " + scope);
1315:                }
1316:
1317:                if ((type == null)
1318:                        || type.equals(ActiveLock.writeLock) == false) {
1319:                    throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST,
1320:                            "unsupported or missing lock type: " + type);
1321:                }
1322:
1323:                // We extend ActiveLock to include the principal and expiration date
1324:                ActiveLock activeLock = new ActiveLock();
1325:                activeLock.setScope(scope);
1326:                activeLock.setLockType(type);
1327:                activeLock.setDepth(com.ibm.webdav.Collection.shallow);
1328:
1329:                if (owner != null) {
1330:                    activeLock.setOwner(owner);
1331:                }
1332:
1333:                if (timeout < 0) {
1334:                    activeLock.setTimeout("Infinite");
1335:                } else {
1336:                    activeLock.setTimeout("Second-" + timeout);
1337:                }
1338:
1339:                try {
1340:                    String lockToken = getLockToken();
1341:
1342:                    activeLock.setLockToken(lockToken);
1343:                } catch (Exception e) {
1344:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
1345:                    throw new WebDAVException(
1346:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
1347:                            "Trouble creating UUID");
1348:                }
1349:
1350:                activeLock.setPrincipal(sOwner);
1351:
1352:                return activeLock;
1353:            }
1354:
1355:            /**
1356:             * Returns the prefix to use for the given property name
1357:             * 
1358:             * @param sPropName
1359:             * @return
1360:             */
1361:            private String getPrefix(String sPropName) {
1362:                String prefix = NamespaceType.OHRM.getPrefix();
1363:                int nIndex = sPropName.indexOf(":");
1364:
1365:                if (nIndex > 0) {
1366:                    prefix = sPropName.substring(0, nIndex);
1367:                } else if (sPropName
1368:                        .equals(VersionedPropertiesManager.TAG_CREATOR_DISPLAYNAME)) {
1369:                    prefix = NamespaceType.DAV.getPrefix();
1370:                }
1371:
1372:                return prefix;
1373:            }
1374:
1375:            /**
1376:             * Returns the namespace uri for the given property name
1377:             * 
1378:             * @param sPropName
1379:             * @return
1380:             */
1381:            private String getNameSpace(String sPropName) {
1382:                String ns = NamespaceType.OHRM.getURI();
1383:                int nIndex = sPropName.indexOf(":");
1384:
1385:                if (nIndex > 0) {
1386:                    ns = sPropName.substring(0, nIndex);
1387:                } else if (sPropName
1388:                        .equals(VersionedPropertiesManager.TAG_CREATOR_DISPLAYNAME)) {
1389:                    ns = NamespaceType.DAV.getURI();
1390:                }
1391:
1392:                return ns;
1393:            }
1394:
1395:            /**
1396:             * Returns the tagname to use for the given property name
1397:             * 
1398:             * @param sPropName
1399:             * @return
1400:             */
1401:            private String getTagname(String sPropName) {
1402:                String sTagname = sPropName;
1403:                int nIndex = sPropName.indexOf(":");
1404:
1405:                if (nIndex > 0) {
1406:                    sTagname = sPropName.substring(nIndex + 1);
1407:                }
1408:
1409:                return sTagname;
1410:            }
1411:
1412:            /**
1413:             * Returns the property element for the given property instance
1414:             * 
1415:             * @param xdoc
1416:             * @param propInst
1417:             * @return
1418:             * @throws DataAccessException
1419:             * @throws NameResolverException
1420:             */
1421:            private Element getPropertyInstanceElement(
1422:                    org.w3c.dom.Document xdoc, AbstractPropertyInstance propInst)
1423:                    throws DataAccessException, NameResolverException,
1424:                    WebDAVException {
1425:                return getPropertyInstanceElement(xdoc, propInst, null);
1426:            }
1427:
1428:            /**
1429:             * Returns the property element for the given property instance
1430:             * 
1431:             * @param xdoc
1432:             * @param propInst
1433:             * @return
1434:             * @throws DataAccessException
1435:             * @throws NameResolverException
1436:             */
1437:            private Element getPropertyInstanceElement(
1438:                    org.w3c.dom.Document xdoc,
1439:                    AbstractPropertyInstance propInst, NamespaceType nsType)
1440:                    throws DataAccessException, NameResolverException,
1441:                    WebDAVException {
1442:                String sPropName = propInst.getName();
1443:
1444:                Property prop = propInst.getProperty();
1445:
1446:                Element propEl = getPropertyEmptyElement(xdoc, prop, nsType);
1447:
1448:                List propValues = propInst.getValues();
1449:
1450:                if (propValues != null) {
1451:
1452:                    if (propInst instanceof  GeneralPropertyInstance) {
1453:                        if (propValues.size() == 1) {
1454:                            String sVal = null;
1455:                            Range range = prop.getRange();
1456:
1457:                            // make sure we're dealing with string values
1458:                            if (range instanceof  DateRange) {
1459:                                Date dtVal = (Date) propValues.get(0);
1460:                                sVal = getDateString((DateRange) range, dtVal);
1461:                            } else {
1462:                                sVal = (String) propValues.get(0);
1463:                            }
1464:
1465:                            propEl.appendChild(cachedPropertiesDocument
1466:                                    .createTextNode(sVal));
1467:
1468:                        } else if (propValues.size() > 1) {
1469:                            List davVals = propValues;
1470:
1471:                            Range range = prop.getRange();
1472:
1473:                            //make sure we're dealing with string values
1474:                            if (range instanceof  DateRange) {
1475:                                davVals = new ArrayList();
1476:                                Iterator iter = propValues.iterator();
1477:
1478:                                while (iter.hasNext()) {
1479:                                    Date dtVal = (Date) iter.next();
1480:
1481:                                    davVals.add(getDateString(
1482:                                            (DateRange) range, dtVal));
1483:                                }
1484:                            }
1485:
1486:                            try {
1487:                                addValueArrayToProperty(xdoc, propEl, davVals,
1488:                                        DataType.getDataType(prop.getRange()
1489:                                                .getObject()));
1490:                            } catch (ClassNotFoundException e) {
1491:                                throw new WebDAVException(
1492:                                        WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
1493:                                        e.getLocalizedMessage());
1494:                            }
1495:
1496:                        }
1497:                    } else if (propInst instanceof  ChildObjectPropertyInstance) {
1498:
1499:                        if (propValues.size() == 1) {
1500:                            Element hrefEl = xdoc.createElementNS(
1501:                                    NamespaceType.DAV.getURI(), TAG_HREF);
1502:                            hrefEl.setPrefix(NamespaceType.DAV.getPrefix());
1503:                            String davPath = HarmoniseNameResolver
1504:                                    .getDAVPath((AbstractChildObject) propValues
1505:                                            .get(0));
1506:                            hrefEl.appendChild(xdoc.createTextNode(davPath));
1507:                            propEl.appendChild(hrefEl);
1508:                        } else if (propValues.size() > 1) {
1509:                            List davVals = new Vector();
1510:                            Iterator iter = propValues.iterator();
1511:
1512:                            while (iter.hasNext()) {
1513:                                AbstractChildObject child = (AbstractChildObject) iter
1514:                                        .next();
1515:                                davVals.add(HarmoniseNameResolver
1516:                                        .getDAVPath(child));
1517:                            }
1518:
1519:                            addValueArrayToProperty(xdoc, propEl, davVals,
1520:                                    DataType.HREF);
1521:
1522:                        }
1523:                    } else if (propInst instanceof  ProfilePropertyInstance) {
1524:                        if (propValues.size() == 1) {
1525:                            Element propPropEl = xdoc.createElementNS(
1526:                                    NamespaceType.DAV.getURI(), TAG_PROP);
1527:                            propPropEl.setPrefix(NamespaceType.DAV.getPrefix());
1528:
1529:                            Profile prof = (Profile) propValues.get(0);
1530:
1531:                            List propInsts = prof.getPropertyInstances();
1532:
1533:                            Iterator iter = propInsts.iterator();
1534:
1535:                            while (iter.hasNext()) {
1536:                                AbstractPropertyInstance tmpPropInst = (AbstractPropertyInstance) iter
1537:                                        .next();
1538:                                Element subPropEl = getPropertyInstanceElement(
1539:                                        xdoc, tmpPropInst);
1540:                                if (subPropEl != null) {
1541:                                    propPropEl.appendChild(subPropEl);
1542:                                }
1543:                            }
1544:
1545:                            propEl.appendChild(propPropEl);
1546:                        } else {
1547:
1548:                            List davVals = new Vector();
1549:                            Iterator iter = propValues.iterator();
1550:
1551:                            while (iter.hasNext()) {
1552:                                Profile prof = (Profile) iter.next();
1553:
1554:                                Element tmpPropEl = xdoc.createElementNS(
1555:                                        NamespaceType.DAV.getURI(), TAG_PROP);
1556:                                tmpPropEl.setPrefix(NamespaceType.DAV
1557:                                        .getPrefix());
1558:
1559:                                List propInsts = prof.getPropertyInstances();
1560:
1561:                                Iterator propInstIter = propInsts.iterator();
1562:
1563:                                while (propInstIter.hasNext()) {
1564:                                    AbstractPropertyInstance tmpPropInst = (AbstractPropertyInstance) propInstIter
1565:                                            .next();
1566:                                    Element subPropEl = getPropertyInstanceElement(
1567:                                            xdoc, tmpPropInst);
1568:                                    tmpPropEl.appendChild(subPropEl);
1569:
1570:                                }
1571:                                davVals.add(tmpPropEl);
1572:                            }
1573:
1574:                            addValueArrayToProperty(xdoc, propEl, davVals,
1575:                                    DataType.PROP);
1576:                        }
1577:                    }
1578:
1579:                }
1580:
1581:                return propEl;
1582:            }
1583:
1584:            /**
1585:             * Returns empty property element for property.
1586:             * 
1587:             * @param xdoc
1588:             * @param prop
1589:             * @return
1590:             * @throws DataAccessException
1591:             * @throws DOMException
1592:             * @throws NameResolverException
1593:             */
1594:            private Element getPropertyEmptyElement(org.w3c.dom.Document xdoc,
1595:                    Property prop, NamespaceType nsType)
1596:                    throws DataAccessException, DOMException,
1597:                    NameResolverException {
1598:                String sPropName = prop.getName();
1599:
1600:                String ns = null;
1601:                String prefix = null;
1602:
1603:                if (nsType != null) {
1604:                    ns = nsType.getURI();
1605:                    prefix = nsType.getPrefix();
1606:                } else {
1607:                    ns = this .getNameSpace(sPropName);
1608:                    prefix = this .getPrefix(sPropName);
1609:                }
1610:
1611:                Element propEl = xdoc.createElementNS(ns, prefix + ":"
1612:                        + this .getTagname(sPropName));
1613:                propEl.setAttribute("xmlns:" + prefix, ns);
1614:
1615:                propEl
1616:                        .setAttributeNS(NamespaceType.DAV.getURI(),
1617:                                NamespaceType.DAV.getPrefix() + ":"
1618:                                        + ATTRIB_DEFINITION,
1619:                                HarmoniseNameResolver.getDAVPath(prop));
1620:
1621:                propEl.setAttributeNS(NamespaceType.DAV.getURI(),
1622:                        NamespaceType.DAV.getPrefix() + ":"
1623:                                + ATTRIB_DEFINITION_VERSION, "Version "
1624:                                + String.valueOf(prop.getVersionNumber()));
1625:
1626:                return propEl;
1627:
1628:            }
1629:
1630:            /**
1631:             * Adds a value array to the property element provided with values from the 
1632:             * list of values given.
1633:             * 
1634:             * @param xdoc
1635:             * @param propEl
1636:             * @param vals
1637:             * @param sTypeTag
1638:             */
1639:            private void addValueArrayToProperty(org.w3c.dom.Document xdoc,
1640:                    Element propEl, List vals, DataType dataType) {
1641:
1642:                String sTypeTag = dataType.getPrefix() + ":"
1643:                        + dataType.getType();
1644:                propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(),
1645:                        NamespaceType.SOAP_ENCODING.getPrefix() + ":"
1646:                                + ATTRIB_ARRAY_SIZE, String
1647:                                .valueOf(vals.size()));
1648:                propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(),
1649:                        NamespaceType.SOAP_ENCODING.getPrefix() + ":"
1650:                                + ATTRIB_ITEM_TYPE, sTypeTag);
1651:                propEl.setAttribute("xmlns:"
1652:                        + NamespaceType.SOAP_ENCODING.getPrefix(),
1653:                        NamespaceType.SOAP_ENCODING.getURI());
1654:
1655:                propEl.setAttribute("xmlns:" + dataType.getPrefix(), dataType
1656:                        .getURI());
1657:
1658:                Iterator valIter = vals.iterator();
1659:
1660:                while (valIter.hasNext()) {
1661:                    Object objVal = valIter.next();
1662:                    Element valEl = null;
1663:                    if (objVal instanceof  String) {
1664:                        String val = (String) objVal;
1665:                        valEl = xdoc.createElement(sTypeTag);
1666:
1667:                        valEl.appendChild(xdoc.createTextNode(val));
1668:                    } else if (objVal instanceof  Element) {
1669:                        valEl = (Element) objVal;
1670:                    }
1671:
1672:                    propEl.appendChild(valEl);
1673:                }
1674:            }
1675:
1676:            /**
1677:             * Returns a DAV representation of a profile property instance value.
1678:             * 
1679:             * @param xdoc
1680:             * @param prof
1681:             * @return
1682:             * @throws DOMException
1683:             * @throws DataAccessException
1684:             * @throws NameResolverException
1685:             */
1686:            private Element getProfileElement(org.w3c.dom.Document xdoc,
1687:                    Profile prof) throws WebDAVException, DataAccessException,
1688:                    NameResolverException {
1689:                Element profEl = xdoc.createElement(TAG_PROP);
1690:
1691:                List propInsts = prof.getPropertyInstances();
1692:
1693:                Iterator iter = propInsts.iterator();
1694:
1695:                while (iter.hasNext()) {
1696:                    profEl.appendChild(getPropertyInstanceElement(xdoc,
1697:                            (AbstractPropertyInstance) iter.next()));
1698:                }
1699:
1700:                return profEl;
1701:            }
1702:
1703:            /**
1704:             * Populates the given property instance in the profile <code>prof</code> from the 
1705:             * data contained in <code>propEl</code>.
1706:             * 
1707:             * 
1708:             * @param prof
1709:             * @param propInst
1710:             * @param propEl
1711:             * @return
1712:             * @throws NameResolverException
1713:             * @throws ProfileException
1714:             * @throws DataAccessException
1715:             * @throws InvalidPropertyValueException
1716:             */
1717:            private boolean populatePropertyInstance(
1718:                    AbstractPropertyInstance propInst, Element propEl)
1719:                    throws WebDAVException, HarmoniseFactoryException,
1720:                    ProfileException, PopulateException, InvalidNameException,
1721:                    DataAccessException, NameResolverException {
1722:                boolean bHasPropChanged = false;
1723:                Property prop = propInst.getProperty();
1724:                Vector newVals = new Vector();
1725:
1726:                if (m_logger.isLoggable(Level.FINER)) {
1727:                    m_logger.logp(Level.FINER, this .getClass().getName(),
1728:                            "populatePropertyInstance",
1729:                            "Populating property instance "
1730:                                    + propInst.getClass() + " prop "
1731:                                    + prop.getName());
1732:                    System.out.println(XMLUtility.printNode(propEl));
1733:                }
1734:
1735:                String sArraySize = propEl
1736:                        .getAttributeNS(NamespaceType.SOAP_ENCODING.getURI(),
1737:                                ATTRIB_ARRAY_SIZE);
1738:
1739:                if (sArraySize != null && sArraySize.trim().length() > 0) {
1740:                    String sItemType = propEl.getAttributeNS(
1741:                            NamespaceType.SOAP_ENCODING.getURI(),
1742:                            ATTRIB_ITEM_TYPE);
1743:
1744:                    if (m_logger.isLoggable(Level.FINER)) {
1745:                        m_logger.logp(Level.FINER, this .getClass().getName(),
1746:                                "populatePropertyInstance",
1747:                                "looking for array item - " + sItemType);
1748:                    }
1749:
1750:                    List nodes = XMLUtils.getChildrenByName(propEl, sItemType);
1751:
1752:                    if (m_logger.isLoggable(Level.FINER)) {
1753:                        m_logger.logp(Level.FINER, this .getClass().getName(),
1754:                                "populatePropertyInstance", "found - "
1755:                                        + nodes.size());
1756:                    }
1757:
1758:                    for (int i = 0; i < nodes.size(); i++) {
1759:                        Node node = (Node) nodes.get(i);
1760:
1761:                        Object objVal = getPropertyInstanceValue(propInst, node);
1762:                        if (objVal != null) {
1763:                            if (m_logger.isLoggable(Level.FINER)) {
1764:                                m_logger.logp(Level.FINER, this .getClass()
1765:                                        .getName(), "populatePropertyInstance",
1766:                                        "adding value " + objVal);
1767:                            }
1768:
1769:                            newVals.add(objVal);
1770:                        }
1771:                    }
1772:
1773:                } else {
1774:                    newVals
1775:                            .add(this 
1776:                                    .getPropertyInstanceValue(propInst, propEl));
1777:                }
1778:
1779:                List currVals = propInst.getValues();
1780:
1781:                //ensure we can mess about with the vector by creating a clone
1782:                if (currVals != null) {
1783:                    currVals = new Vector(currVals);
1784:                }
1785:
1786:                Iterator iter = null;
1787:
1788:                //remove all values in need of removing
1789:                if (currVals != null) {
1790:                    iter = currVals.iterator();
1791:
1792:                    while (iter.hasNext()) {
1793:                        Object objVal = iter.next();
1794:
1795:                        if (newVals.contains(objVal) == false) {
1796:                            if (propInst instanceof  WorkflowPropertyInstance) {
1797:                                WorkflowPropertyInstance wrkflwInst = (WorkflowPropertyInstance) propInst;
1798:
1799:                                User usr = ((HarmoniseSessionManager) resource
1800:                                        .getUserAuthenticator())
1801:                                        .getUser(resource);
1802:
1803:                                wrkflwInst.removeWorkflowStage(
1804:                                        (WorkflowStageValue) objVal, usr);
1805:
1806:                            } else if (objVal instanceof  AbstractChildObject) {
1807:                                ((ChildObjectPropertyInstance) propInst)
1808:                                        .removeValue((AbstractChildObject) objVal);
1809:                            } else {
1810:                                propInst.removeValue(objVal);
1811:                            }
1812:
1813:                            if (m_logger.isLoggable(Level.FINER)) {
1814:                                m_logger.logp(Level.FINER, this .getClass()
1815:                                        .getName(), "populatePropertyInstance",
1816:                                        "removing value " + objVal);
1817:                            }
1818:
1819:                            bHasPropChanged = true;
1820:                        }
1821:                    }
1822:                }
1823:
1824:                iter = newVals.iterator();
1825:
1826:                while (iter.hasNext() == true) {
1827:                    Object tmpValue = iter.next();
1828:                    if (tmpValue != null) {
1829:                        if ((currVals == null)
1830:                                || (currVals.contains(tmpValue) == false)) {
1831:                            if (m_logger.isLoggable(Level.FINER)) {
1832:                                m_logger.logp(Level.FINER, this .getClass()
1833:                                        .getName(), "populatePropertyInstance",
1834:                                        "adding value " + tmpValue);
1835:                            }
1836:
1837:                            if (propInst instanceof  WorkflowPropertyInstance) {
1838:                                WorkflowPropertyInstance wrkflwInst = (WorkflowPropertyInstance) propInst;
1839:
1840:                                User usr = ((HarmoniseSessionManager) resource
1841:                                        .getUserAuthenticator())
1842:                                        .getUser(resource);
1843:
1844:                                wrkflwInst.addWorkflowStage(
1845:                                        (WorkflowStageValue) tmpValue, usr);
1846:
1847:                            } else if (propInst instanceof  GeneralPropertyInstance) {
1848:                                GeneralPropertyInstance genInst = (GeneralPropertyInstance) propInst;
1849:
1850:                                if (tmpValue instanceof  String) {
1851:                                    genInst.addValue((String) tmpValue);
1852:                                } else if (tmpValue instanceof  Date) {
1853:                                    genInst.addValue((Date) tmpValue);
1854:                                }
1855:
1856:                            } else if (propInst instanceof  ChildObjectPropertyInstance) {
1857:                                ChildObjectPropertyInstance childInst = (ChildObjectPropertyInstance) propInst;
1858:
1859:                                childInst
1860:                                        .addValue((AbstractChildObject) tmpValue);
1861:
1862:                            } else if (propInst instanceof  ProfilePropertyInstance) {
1863:                                ProfilePropertyInstance profPropInst = (ProfilePropertyInstance) propInst;
1864:
1865:                                profPropInst.addValue((Profile) tmpValue);
1866:
1867:                            }
1868:
1869:                            bHasPropChanged = true;
1870:                        }
1871:                    }
1872:
1873:                }
1874:
1875:                return bHasPropChanged;
1876:            }
1877:
1878:            /**
1879:             * Returns the value to be added to a property instance from the given node.
1880:             * 
1881:             * @param propInst
1882:             * @param node
1883:             * @return
1884:             * @throws WebDAVException
1885:             * @throws HarmoniseFactoryException
1886:             * @throws ProfileException
1887:             * @throws DataAccessException
1888:             * @throws InvalidPropertyValueException
1889:             * @throws NameResolverException
1890:             */
1891:            private Object getPropertyInstanceValue(
1892:                    AbstractPropertyInstance propInst, Node node)
1893:                    throws WebDAVException, HarmoniseFactoryException,
1894:                    ProfileException, PopulateException, InvalidNameException,
1895:                    DataAccessException, NameResolverException {
1896:                Object objVal = null;
1897:
1898:                if (propInst instanceof  ProfilePropertyInstance
1899:                        && (node instanceof  Element)
1900:                        && ((Element) node).getLocalName().equals(TAG_PROP)) {
1901:                    Profile tmpProf = getProfileFromElement(
1902:                            (ProfilePropertyInstance) propInst, (Element) node);
1903:                    if (tmpProf.getPropertyInstances().size() > 0) {
1904:                        objVal = tmpProf;
1905:                    }
1906:
1907:                } else {
1908:
1909:                    NodeList nl = node.getChildNodes();
1910:
1911:                    for (int i = 0; i < nl.getLength(); i++) {
1912:                        Node tmpNode = (Node) nl.item(i);
1913:
1914:                        if (tmpNode instanceof  Text) {
1915:                            String sVal = ((Text) tmpNode).getData().trim();
1916:
1917:                            if (sVal != null && sVal.length() > 0) {
1918:                                if (m_logger.isLoggable(Level.FINER)) {
1919:                                    m_logger.logp(Level.FINER, this .getClass()
1920:                                            .getName(),
1921:                                            "getPropertyInstanceValue",
1922:                                            "Adding value '" + sVal
1923:                                                    + "' to property "
1924:                                                    + propInst.getName());
1925:                                }
1926:
1927:                                if (propInst instanceof  GeneralPropertyInstance) {
1928:                                    if (propInst.getProperty().getRange() instanceof  DateRange) {
1929:                                        DateRange range = (DateRange) propInst
1930:                                                .getProperty().getRange();
1931:                                        try {
1932:                                            objVal = getDate(range, sVal);
1933:                                        } catch (ParseException e) {
1934:                                            objVal = sVal;
1935:                                        }
1936:                                    } else {
1937:                                        objVal = sVal;
1938:                                    }
1939:
1940:                                } else if (propInst instanceof  ChildObjectPropertyInstance) {
1941:                                    AbstractChildObject child = HarmoniseNameResolver
1942:                                            .getObjectFromURL(m_dsi, sVal);
1943:                                    objVal = child;
1944:                                }
1945:                            }
1946:
1947:                        } else if (tmpNode instanceof  Element
1948:                                && ((Element) tmpNode).getLocalName().equals(
1949:                                        TAG_HREF)
1950:                                && propInst instanceof  ChildObjectPropertyInstance) {
1951:                            String sVal = tmpNode.getChildNodes().item(0)
1952:                                    .getNodeValue();
1953:
1954:                            if (sVal != null && sVal.trim().length() > 0) {
1955:                                AbstractChildObject child = HarmoniseNameResolver
1956:                                        .getObjectFromURL(m_dsi, sVal);
1957:                                objVal = child;
1958:                            }
1959:                        } else if (propInst instanceof  ProfilePropertyInstance) {
1960:                            if (tmpNode instanceof  Element
1961:                                    && ((Element) tmpNode).getLocalName()
1962:                                            .equals(TAG_PROP)) {
1963:                                Profile tmpProf = getProfileFromElement(
1964:                                        (ProfilePropertyInstance) propInst,
1965:                                        (Element) tmpNode);
1966:                                if (tmpProf.getPropertyInstances().size() > 0) {
1967:                                    objVal = tmpProf;
1968:                                }
1969:
1970:                            }
1971:                        }
1972:                    }
1973:                }
1974:
1975:                return objVal;
1976:
1977:            }
1978:
1979:            /**
1980:             * Returns a Profile instantiated based on the xml element given.
1981:             * 
1982:             * @param parentPropInst
1983:             * @param propEl
1984:             * @return
1985:             * @throws HarmoniseFactoryException
1986:             * @throws ProfileException
1987:             * @throws DataAccessException
1988:             * @throws InvalidPropertyValueException
1989:             * @throws NameResolverException
1990:             */
1991:            private Profile getProfileFromElement(
1992:                    ProfilePropertyInstance parentPropInst, Element propEl)
1993:                    throws WebDAVException, HarmoniseFactoryException,
1994:                    ProfileException, PopulateException, NameResolverException,
1995:                    InvalidNameException, DataAccessException {
1996:
1997:                if (m_logger.isLoggable(Level.FINER)) {
1998:                    m_logger.logp(Level.FINER, this .getClass().getName(),
1999:                            "getProfileFromElement",
2000:                            "Creating new profile value");
2001:                }
2002:
2003:                ProfileValue prof = new ProfileValue(m_dsi);
2004:
2005:                prof.setName(parentPropInst.getName());
2006:                prof.setProfiledObject(m_child);
2007:                prof.setProperty(parentPropInst.getProperty());
2008:
2009:                NodeList nl = propEl.getChildNodes();
2010:
2011:                for (int i = 0; i < nl.getLength(); i++) {
2012:                    Node tmpNode = nl.item(i);
2013:
2014:                    if (tmpNode.getNodeType() != Node.ELEMENT_NODE) {
2015:                        continue;
2016:                    }
2017:                    Element el = (Element) tmpNode;
2018:
2019:                    Property prop = PropertyFactory.getPropertyFromName(
2020:                            this .m_dsi, el.getLocalName());
2021:
2022:                    AbstractPropertyInstance propInst = prof
2023:                            .getPropertyInstance(prop);
2024:                    boolean bNewProp = false;
2025:                    if (propInst == null) {
2026:                        if (m_logger.isLoggable(Level.FINER)) {
2027:                            m_logger.logp(Level.FINER, this .getClass()
2028:                                    .getName(), "getProfileFromElement",
2029:                                    "Creating new property instance");
2030:                        }
2031:
2032:                        propInst = PropertyInstanceFactory.getPropertyInstance(
2033:                                this .m_dsi, prop);
2034:                        propInst.setProfile(prof);
2035:                        bNewProp = true;
2036:                    }
2037:
2038:                    populatePropertyInstance(propInst, el);
2039:
2040:                    if (propInst.hasValues() == true && bNewProp == true) {
2041:                        prof.addPropertyInstance(propInst);
2042:                    } else if (bNewProp == false
2043:                            && propInst.hasValues() == false) {
2044:                        prof.removeProperty(prop);
2045:                    }
2046:
2047:                }
2048:
2049:                return prof;
2050:            }
2051:
2052:            /**
2053:             * Populates local field with the Harmonise child object which is associated to
2054:             * the current resource, if it isn't already populated.
2055:             * 
2056:             * @throws WebDAVException
2057:             */
2058:            private void populateChild() throws WebDAVException {
2059:                try {
2060:
2061:                    URL url = resource.getURL();
2062:                    if (m_child == null
2063:                            && HarmoniseNameResolver.isVirtualCollection(url) == false
2064:                            && HarmoniseNameResolver.isVirtualResource(url) == false) {
2065:                        m_child = HarmoniseNameResolver.getObjectFromURL(m_dsi,
2066:                                resource.getURL());
2067:                    }
2068:                } catch (NameResolverException e) {
2069:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
2070:                    throw new WebDAVException(
2071:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
2072:                                    .getLocalizedMessage());
2073:                }
2074:            }
2075:
2076:            private String getLockToken() throws WebDAVException {
2077:                String sToken = null;
2078:
2079:                try {
2080:                    if (m_child.isLocked() == true) {
2081:                        sToken = HarmoniseLockManager.getLockToken(resource
2082:                                .getURL().getFile(), m_child.getLockOwner()
2083:                                .getName());
2084:                    }
2085:
2086:                } catch (DataAccessException e) {
2087:                    throw new WebDAVException(
2088:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
2089:                                    .getLocalizedMessage());
2090:                } catch (NameResolverException e) {
2091:                    throw new WebDAVException(
2092:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
2093:                                    .getLocalizedMessage());
2094:                }
2095:
2096:                return sToken;
2097:            }
2098:
2099:            /**
2100:             * Returns a Date object given a string representation.
2101:             * 
2102:             * @param range
2103:             * @param sDate
2104:             * @return
2105:             * @throws ParseException
2106:             */
2107:            private Date getDate(DateRange range, String sDate)
2108:                    throws ParseException {
2109:                Date date = null;
2110:                SimpleDateFormat format = null;
2111:                if (range.includeTime() == true) {
2112:                    format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss G");
2113:                } else {
2114:                    format = new SimpleDateFormat("yyyy-MM-dd G");
2115:                }
2116:
2117:                date = format.parse(sDate);
2118:                return date;
2119:            }
2120:
2121:            /**
2122:             * Returns String representation of date.
2123:             * 
2124:             * @param range
2125:             * @param date
2126:             * @return
2127:             */
2128:            private String getDateString(DateRange range, Date date) {
2129:                String sDate = null;
2130:
2131:                SimpleDateFormat format = null;
2132:                if (range.includeTime() == true) {
2133:                    format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss G");
2134:                } else {
2135:                    format = new SimpleDateFormat("yyyy-MM-dd G");
2136:                }
2137:
2138:                sDate = format.format(date);
2139:
2140:                return sDate;
2141:            }
2142:
2143:            /**
2144:             * @param names
2145:             * @return
2146:             */
2147:            protected boolean isAllNonPropertyInstanceProperties(
2148:                    PropertyName[] names) {
2149:                boolean bIsAllLive = true;
2150:                int i = 0;
2151:
2152:                while (bIsAllLive == true && i < names.length) {
2153:                    String sLocalPropName = names[i].getLocal();
2154:
2155:                    bIsAllLive = false;
2156:
2157:                    bIsAllLive = isLive(sLocalPropName);
2158:
2159:                    if (bIsAllLive == false) {
2160:                        bIsAllLive = sLocalPropName.equals(TAG_TITLE)
2161:                                || sLocalPropName.equals(DAVRange.TAG_RANGE)
2162:                                || sLocalPropName.equals(DAVDomain.TAG_DOMAIN)
2163:                                || sLocalPropName.equals(TAG_LOCKDISCOVERY)
2164:                                || sLocalPropName.equals(TAG_HARMONISE_ID)
2165:                                || sLocalPropName.equals(TAG_DESCRIPTION);
2166:                    }
2167:
2168:                    i++;
2169:                }
2170:
2171:                return bIsAllLive;
2172:            }
2173:
2174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.