1 17 package org.alfresco.repo.webdav; 18 19 import java.io.Serializable ; 20 import java.util.ArrayList ; 21 import java.util.Date ; 22 import java.util.HashMap ; 23 import java.util.List ; 24 import java.util.Map ; 25 26 import javax.servlet.http.HttpServletResponse ; 27 28 import org.alfresco.error.AlfrescoRuntimeException; 29 import org.alfresco.model.ContentModel; 30 import org.alfresco.service.cmr.lock.LockService; 31 import org.alfresco.service.cmr.lock.LockStatus; 32 import org.alfresco.service.cmr.model.FileFolderService; 33 import org.alfresco.service.cmr.model.FileInfo; 34 import org.alfresco.service.cmr.model.FileNotFoundException; 35 import org.alfresco.service.cmr.repository.ContentData; 36 import org.alfresco.service.cmr.repository.NodeRef; 37 import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; 38 import org.alfresco.service.cmr.repository.datatype.TypeConverter; 39 import org.alfresco.service.namespace.QName; 40 import org.dom4j.DocumentHelper; 41 import org.dom4j.io.XMLWriter; 42 import org.w3c.dom.Document ; 43 import org.w3c.dom.Element ; 44 import org.w3c.dom.Node ; 45 import org.w3c.dom.NodeList ; 46 import org.xml.sax.Attributes ; 47 import org.xml.sax.helpers.AttributesImpl ; 48 49 54 public class PropFindMethod extends WebDAVMethod 55 { 56 private static final int GET_ALL_PROPS = 0; 58 private static final int GET_NAMED_PROPS = 1; 59 private static final int FIND_PROPS = 2; 60 61 private int m_depth = WebDAV.DEPTH_INFINITY; 63 private int m_mode = GET_ALL_PROPS; 64 65 private ArrayList <WebDAVProperty> m_properties = null; 67 68 private HashMap <String , String > m_namespaces = null; 70 71 74 public PropFindMethod() 75 { 76 m_namespaces = new HashMap <String , String >(); 77 } 78 79 84 public final int getDepth() 85 { 86 return m_depth; 87 } 88 89 94 public final int getMode() 95 { 96 return m_mode; 97 } 98 99 104 protected void parseRequestHeaders() throws WebDAVServerException 105 { 106 108 String strDepth = m_request.getHeader(WebDAV.HEADER_DEPTH); 109 if (strDepth != null && strDepth.length() > 0) 110 { 111 if (strDepth.equals(WebDAV.ZERO)) 112 { 113 m_depth = WebDAV.DEPTH_0; 114 } 115 else if (strDepth.equals(WebDAV.ONE)) 116 { 117 m_depth = WebDAV.DEPTH_1; 118 } 119 else 120 { 121 m_depth = WebDAV.DEPTH_INFINITY; 122 } 123 } 124 } 125 126 131 protected void parseRequestBody() throws WebDAVServerException 132 { 133 Document body = getRequestBodyAsDocument(); 134 if (body != null) 135 { 136 Element rootElement = body.getDocumentElement(); 137 NodeList childList = rootElement.getChildNodes(); 138 Node node = null; 139 140 for (int i = 0; i < childList.getLength(); i++) 141 { 142 Node currentNode = childList.item(i); 143 switch (currentNode.getNodeType()) 144 { 145 case Node.TEXT_NODE: 146 break; 147 case Node.ELEMENT_NODE: 148 if (currentNode.getNodeName().endsWith(WebDAV.XML_ALLPROP)) 149 { 150 m_mode = GET_ALL_PROPS; 151 } 152 else if (currentNode.getNodeName().endsWith(WebDAV.XML_PROP)) 153 { 154 m_mode = GET_NAMED_PROPS; 155 node = currentNode; 156 } 157 else if (currentNode.getNodeName().endsWith(WebDAV.XML_PROPNAME)) 158 { 159 m_mode = FIND_PROPS; 160 } 161 162 break; 163 } 164 } 165 166 if (m_mode == GET_NAMED_PROPS) 167 { 168 m_properties = new ArrayList <WebDAVProperty>(); 169 childList = node.getChildNodes(); 170 171 for (int i = 0; i < childList.getLength(); i++) 172 { 173 Node currentNode = childList.item(i); 174 switch (currentNode.getNodeType()) 175 { 176 case Node.TEXT_NODE: 177 break; 178 case Node.ELEMENT_NODE: 179 m_properties.add(createProperty(currentNode)); 180 break; 181 } 182 } 183 } 184 } 185 } 186 187 192 protected void executeImpl() throws WebDAVServerException, Exception 193 { 194 m_response.setStatus(WebDAV.WEBDAV_SC_MULTI_STATUS); 195 196 FileFolderService fileFolderService = getFileFolderService(); 197 198 FileInfo pathNodeInfo = null; 199 try 200 { 201 pathNodeInfo = getDAVHelper().getNodeForPath(getRootNodeRef(), m_strPath, m_request.getServletPath()); 203 } 204 catch (FileNotFoundException e) 205 { 206 throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND); 208 } 209 210 212 m_response.setContentType(WebDAV.XML_CONTENT_TYPE); 213 214 216 XMLWriter xml = createXMLWriter(); 217 218 xml.startDocument(); 219 220 String nsdec = generateNamespaceDeclarations(m_namespaces); 221 xml.startElement( 222 WebDAV.DAV_NS, 223 WebDAV.XML_MULTI_STATUS + nsdec, 224 WebDAV.XML_NS_MULTI_STATUS + nsdec, 225 getDAVHelper().getNullAttributes()); 226 227 StringBuilder baseBuild = new StringBuilder (256); 229 baseBuild.append(getPath()); 230 if (baseBuild.length() == 0 || baseBuild.charAt(baseBuild.length() - 1) != WebDAVHelper.PathSeperatorChar) 231 { 232 baseBuild.append(WebDAVHelper.PathSeperatorChar); 233 } 234 String basePath = baseBuild.toString(); 235 236 generateResponseForNode(xml, pathNodeInfo, basePath); 238 239 if (getDepth() != WebDAV.DEPTH_0 && pathNodeInfo.isFolder()) 242 { 243 List <FileInfo> nodeInfos = new ArrayList <FileInfo>(10); 245 nodeInfos.add(pathNodeInfo); 246 247 int curDepth = WebDAV.DEPTH_1; 248 249 int baseLen = baseBuild.length(); 251 252 List <FileInfo> nextNodeInfos = null; 254 if (getDepth() > WebDAV.DEPTH_1) 255 { 256 nextNodeInfos = new ArrayList <FileInfo>(10); 257 } 258 259 while (curDepth <= getDepth() && nodeInfos != null) 261 { 262 if (nextNodeInfos != null) 264 { 265 nextNodeInfos.clear(); 266 } 267 268 271 for (FileInfo curNodeInfo : nodeInfos) 272 { 273 List <FileInfo> childNodeInfos = fileFolderService.list(curNodeInfo.getNodeRef()); 275 276 if (childNodeInfos.size() == 0) 278 { 279 continue; 280 } 281 282 285 baseBuild.setLength(baseLen); 286 try 287 { 288 String pathSnippet = getDAVHelper().getPathFromNode(pathNodeInfo.getNodeRef(), curNodeInfo.getNodeRef()); 289 baseBuild.append(pathSnippet); 290 } 291 catch (FileNotFoundException e) 292 { 293 continue; 295 } 296 297 int curBaseLen = baseBuild.length(); 298 299 for (FileInfo curChildInfo : childNodeInfos) 301 { 302 baseBuild.setLength(curBaseLen); 304 305 baseBuild.append(curChildInfo.getName()); 306 307 generateResponseForNode(xml, curChildInfo, baseBuild.toString()); 309 310 if (nextNodeInfos != null && curChildInfo.isFolder()) 312 { 313 nextNodeInfos.add(curChildInfo); 314 } 315 } 316 } 317 318 curDepth++; 320 321 nodeInfos = nextNodeInfos; 323 } 324 } 325 326 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS, WebDAV.XML_NS_MULTI_STATUS); 328 329 xml.flush(); 331 } 332 333 336 private WebDAVProperty createProperty(Node node) 337 { 338 WebDAVProperty property = null; 339 340 String strName = node.getLocalName(); 341 String strNamespaceUri = node.getNamespaceURI(); 342 343 if (strNamespaceUri.equals(WebDAV.DEFAULT_NAMESPACE_URI)) 344 { 345 property = new WebDAVProperty(strName); 346 } 347 else 348 { 349 property = new WebDAVProperty(strName, strNamespaceUri, getNamespaceName(strNamespaceUri)); 350 } 351 352 return property; 353 } 354 355 359 private String getNamespaceName(String strNamespaceUri) 360 { 361 String strNamespaceName = m_namespaces.get(strNamespaceUri); 362 if (strNamespaceName == null) 363 { 364 strNamespaceName = "ns" + m_namespaces.size(); 365 m_namespaces.put(strNamespaceUri, strNamespaceName); 366 } 367 368 return strNamespaceName; 369 } 370 371 378 private void generateResponseForNode(XMLWriter xml, FileInfo nodeInfo, String path) throws Exception 379 { 380 NodeRef nodeRef = nodeInfo.getNodeRef(); 381 boolean isFolder = nodeInfo.isFolder(); 382 383 xml.startElement( 385 WebDAV.DAV_NS, 386 WebDAV.XML_RESPONSE, 387 WebDAV.XML_NS_RESPONSE, 388 getDAVHelper().getNullAttributes()); 389 390 String strHRef = WebDAV.getURLForPath(m_request, path, isFolder); 392 393 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF, getDAVHelper().getNullAttributes()); 394 xml.write(strHRef); 395 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF); 396 397 switch (m_mode) 398 { 399 case GET_NAMED_PROPS: 400 generateNamedPropertiesResponse(xml, nodeInfo); 401 break; 402 case GET_ALL_PROPS: 403 generateAllPropertiesResponse(xml, nodeRef, isFolder); 404 break; 405 case FIND_PROPS: 406 generateFindPropertiesResponse(xml, nodeRef, isFolder); 407 break; 408 } 409 410 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE); 412 } 413 414 422 private void generateNamedPropertiesResponse(XMLWriter xml, FileInfo nodeInfo) throws Exception 423 { 424 NodeRef nodeRef = nodeInfo.getNodeRef(); 425 boolean isFolder = nodeInfo.isFolder(); 426 427 Map <QName, Serializable > props = getNodeService().getProperties(nodeRef); 429 430 Attributes nullAttr = getDAVHelper().getNullAttributes(); 432 433 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT, nullAttr); 434 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP, nullAttr); 435 436 ArrayList <WebDAVProperty> propertiesNotFound = new ArrayList <WebDAVProperty>(); 437 438 TypeConverter typeConv = DefaultTypeConverter.INSTANCE; 439 440 for (WebDAVProperty property : m_properties) 442 { 443 445 String propName = property.getName(); 446 String propNamespaceUri = property.getNamespaceUri(); 447 449 451 Object davValue = null; 452 453 if (propNamespaceUri.equals(WebDAV.DEFAULT_NAMESPACE_URI)) 454 { 455 if (propName.equals(WebDAV.XML_LOCK_DISCOVERY)) { 458 generateLockDiscoveryResponse(xml, nodeRef, isFolder); 459 } 460 else if (propName.equals(WebDAV.XML_SUPPORTED_LOCK)) 461 { 462 writeLockTypes(xml); 464 } 465 466 468 else if (propName.equals(WebDAV.XML_RESOURCE_TYPE)) 469 { 470 472 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_RESOURCE_TYPE, WebDAV.XML_NS_RESOURCE_TYPE, nullAttr); 473 if (isFolder) 474 { 475 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_COLLECTION)); 476 } 477 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESOURCE_TYPE, WebDAV.XML_NS_RESOURCE_TYPE); 478 } 479 else if (propName.equals(WebDAV.XML_DISPLAYNAME)) 480 { 481 if (getRootNodeRef().equals(nodeRef)) 483 { 484 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_SOURCE)); 486 } 487 else 488 { 489 davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_DISPLAYNAME); 491 492 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_DISPLAYNAME, WebDAV.XML_NS_DISPLAYNAME, nullAttr); 494 if (davValue != null) 495 { 496 String name = typeConv.convert(String .class, davValue); 497 if (name == null || name.length() == 0) 498 { 499 logger.error("WebDAV name is null, value=" + davValue.getClass().getName() + ", node=" + nodeRef); 500 } 501 xml.write(name); 502 } 503 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_DISPLAYNAME, WebDAV.XML_NS_DISPLAYNAME); 504 } 505 } 506 else if (propName.equals(WebDAV.XML_SOURCE)) 507 { 508 511 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_SOURCE)); 512 } 513 else if (propName.equals(WebDAV.XML_GET_LAST_MODIFIED)) 514 { 515 517 davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_GET_LAST_MODIFIED); 518 519 521 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_LAST_MODIFIED, WebDAV.XML_NS_GET_LAST_MODIFIED, 522 nullAttr); 523 if (davValue != null) 524 xml.write(WebDAV.formatModifiedDate(typeConv.convert(Date .class, davValue))); 525 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_LAST_MODIFIED, WebDAV.XML_NS_GET_LAST_MODIFIED); 526 } 527 else if (propName.equals(WebDAV.XML_GET_CONTENT_LANGUAGE) && !isFolder) 528 { 529 xml.startElement( 533 WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LANGUAGE, 534 WebDAV.XML_NS_GET_CONTENT_LANGUAGE, nullAttr); 535 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LANGUAGE, WebDAV.XML_NS_GET_CONTENT_LANGUAGE); 537 } 538 else if (propName.equals(WebDAV.XML_GET_CONTENT_TYPE) && !isFolder) 539 { 540 davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_GET_CONTENT_TYPE); 542 543 xml.startElement( 545 WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_TYPE, 546 WebDAV.XML_NS_GET_CONTENT_TYPE, nullAttr); 547 if (davValue != null) 548 xml.write(typeConv.convert(String .class, davValue)); 549 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_TYPE, WebDAV.XML_NS_GET_CONTENT_TYPE); 550 } 551 else if (propName.equals(WebDAV.XML_GET_ETAG) && !isFolder) 552 { 553 555 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_ETAG, WebDAV.XML_NS_GET_ETAG, nullAttr); 556 xml.write(getDAVHelper().makeETag(nodeRef)); 557 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_ETAG, WebDAV.XML_NS_GET_ETAG); 558 } 559 else if (propName.equals(WebDAV.XML_GET_CONTENT_LENGTH)) 560 { 561 long len = 0; 563 564 if (!isFolder) 565 { 566 ContentData contentData = (ContentData) props.get(ContentModel.PROP_CONTENT); 567 if (contentData != null) 568 len = contentData.getSize(); 569 } 570 571 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LENGTH, WebDAV.XML_NS_GET_CONTENT_LENGTH, 573 nullAttr); 574 xml.write("" + len); 575 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LENGTH, WebDAV.XML_NS_GET_CONTENT_LENGTH); 576 } 577 else if (propName.equals(WebDAV.XML_CREATION_DATE)) 578 { 579 davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_CREATION_DATE); 581 582 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_CREATION_DATE, WebDAV.XML_NS_CREATION_DATE, nullAttr); 584 if (davValue != null) 585 xml.write(WebDAV.formatCreationDate(typeConv.convert(Date .class, davValue))); 586 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_CREATION_DATE, WebDAV.XML_NS_CREATION_DATE); 587 } 588 else 589 { 590 if (property.getName().equals(WebDAV.XML_HREF) == false) 592 propertiesNotFound.add(property); 593 } 594 } 595 else 596 { 597 599 propertiesNotFound.add(property); 602 } 603 } 604 605 607 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP); 608 609 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS, nullAttr); 610 xml.write(WebDAV.HTTP1_1 + " " + HttpServletResponse.SC_OK + " " + WebDAV.SC_OK_DESC); 611 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS); 612 613 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT); 614 615 618 if (propertiesNotFound.size() > 0) 619 { 620 622 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT, nullAttr); 623 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP, nullAttr); 624 625 627 for (WebDAVProperty property : propertiesNotFound) 628 { 629 631 String propName = property.getName(); 632 String propNamespaceName = property.getNamespaceName(); 633 String propQName = propName; 634 if (propNamespaceName != null && propNamespaceName.length() > 0) 635 propQName = propNamespaceName + ":" + propName; 636 637 xml.write(DocumentHelper.createElement(propQName)); 638 } 639 640 642 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP); 643 644 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS, nullAttr); 645 xml.write(WebDAV.HTTP1_1 + " " + HttpServletResponse.SC_NOT_FOUND + " " + WebDAV.SC_NOT_FOUND_DESC); 646 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS); 647 648 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT); 649 } 650 } 651 652 660 private void generateAllPropertiesResponse(XMLWriter xml, NodeRef node, boolean isDir) throws Exception 661 { 662 664 Map <QName, Serializable > props = getNodeService().getProperties(node); 665 666 668 Attributes nullAttr = getDAVHelper().getNullAttributes(); 669 670 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT, nullAttr); 671 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP, nullAttr); 672 673 675 generateLockDiscoveryResponse(xml, node, isDir); 676 677 679 writeLockTypes(xml); 680 681 683 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_RESOURCE_TYPE, WebDAV.XML_NS_RESOURCE_TYPE, nullAttr); 684 if (isDir) 685 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_COLLECTION)); 686 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESOURCE_TYPE, WebDAV.XML_NS_RESOURCE_TYPE); 687 688 690 Object davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_DISPLAYNAME); 691 692 TypeConverter typeConv = DefaultTypeConverter.INSTANCE; 693 694 696 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_DISPLAYNAME, WebDAV.XML_NS_DISPLAYNAME, nullAttr); 697 if (davValue != null) 698 { 699 String name = typeConv.convert(String .class, davValue); 700 if (name == null || name.length() == 0) 701 { 702 logger.error("WebDAV name is null, value=" + davValue.getClass().getName() + ", node=" + node); 703 } 704 xml.write(name); 705 } 706 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_DISPLAYNAME, WebDAV.XML_NS_DISPLAYNAME); 707 708 712 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_SOURCE)); 713 714 716 davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_CREATION_DATE); 717 718 720 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_CREATION_DATE, WebDAV.XML_NS_CREATION_DATE, nullAttr); 721 if (davValue != null) 722 xml.write(WebDAV.formatCreationDate(typeConv.convert(Date .class, davValue))); 723 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_CREATION_DATE, WebDAV.XML_NS_CREATION_DATE); 724 725 727 davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_GET_LAST_MODIFIED); 728 729 731 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_LAST_MODIFIED, WebDAV.XML_NS_GET_LAST_MODIFIED, nullAttr); 732 if (davValue != null) 733 xml.write(WebDAV.formatModifiedDate(typeConv.convert(Date .class, davValue))); 734 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_LAST_MODIFIED, WebDAV.XML_NS_GET_LAST_MODIFIED); 735 736 738 if (isDir == false) 739 { 740 742 745 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LANGUAGE, WebDAV.XML_NS_GET_CONTENT_LANGUAGE, 746 nullAttr); 747 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LANGUAGE, WebDAV.XML_NS_GET_CONTENT_LANGUAGE); 749 750 davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_GET_CONTENT_TYPE); 752 753 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_TYPE, WebDAV.XML_NS_GET_CONTENT_TYPE, nullAttr); 755 if (davValue != null) 756 xml.write(typeConv.convert(String .class, davValue)); 757 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_TYPE, WebDAV.XML_NS_GET_CONTENT_TYPE); 758 759 761 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_ETAG, WebDAV.XML_NS_GET_ETAG, nullAttr); 762 xml.write(getDAVHelper().makeETag(node)); 763 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_ETAG, WebDAV.XML_NS_GET_ETAG); 764 } 765 766 768 long len = 0; 769 770 if (isDir == false) 771 { 772 ContentData contentData = (ContentData) props.get(ContentModel.PROP_CONTENT); 773 if (contentData != null) 774 len = contentData.getSize(); 775 } 776 777 779 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LENGTH, WebDAV.XML_NS_GET_CONTENT_LENGTH, nullAttr); 780 xml.write("" + len); 781 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LENGTH, WebDAV.XML_NS_GET_CONTENT_LENGTH); 782 783 785 787 789 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP); 790 791 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS, nullAttr); 792 xml.write(WebDAV.HTTP1_1 + " " + HttpServletResponse.SC_OK + " " + WebDAV.SC_OK_DESC); 793 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS); 794 795 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT); 796 } 797 798 806 private void generateFindPropertiesResponse(XMLWriter xml, NodeRef node, boolean isDir) 807 { 808 try 809 { 810 812 Attributes nullAttr = getDAVHelper().getNullAttributes(); 813 814 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT, nullAttr); 815 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP, nullAttr); 816 817 819 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_LOCK_DISCOVERY)); 820 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_SUPPORTED_LOCK)); 821 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_RESOURCE_TYPE)); 822 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_DISPLAYNAME)); 823 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_LAST_MODIFIED)); 824 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_CONTENT_LENGTH)); 825 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_CREATION_DATE)); 826 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_ETAG)); 827 828 if (isDir) 829 { 830 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_CONTENT_LANGUAGE)); 831 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_CONTENT_TYPE)); 832 } 833 834 836 838 840 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP); 841 842 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS, nullAttr); 843 xml.write(WebDAV.HTTP1_1 + " " + HttpServletResponse.SC_OK + " " + WebDAV.SC_OK_DESC); 844 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS); 845 846 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT); 847 } 848 catch (Exception ex) 849 { 850 852 throw new AlfrescoRuntimeException("XML processing error", ex); 853 } 854 } 855 856 864 private void generateLockDiscoveryResponse(XMLWriter xml, NodeRef node, boolean isDir) throws Exception 865 { 866 868 LockService lockService = getLockService(); 869 LockStatus lockSts = lockService.getLockStatus(node); 870 871 873 if (lockSts != LockStatus.NO_LOCK) 874 generateLockDiscoveryXML(xml, node); 875 } 876 877 882 private void writeLockTypes(XMLWriter xml) 883 { 884 try 885 { 886 AttributesImpl nullAttr = getDAVHelper().getNullAttributes(); 887 888 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_SUPPORTED_LOCK, WebDAV.XML_NS_SUPPORTED_LOCK, nullAttr); 889 890 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_LOCK_SCOPE, WebDAV.XML_NS_LOCK_SCOPE, nullAttr); 891 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_EXCLUSIVE)); 892 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_LOCK_SCOPE, WebDAV.XML_NS_LOCK_SCOPE); 893 894 xml.startElement(WebDAV.DAV_NS, WebDAV.XML_LOCK_TYPE, WebDAV.XML_NS_LOCK_TYPE, nullAttr); 895 xml.write(DocumentHelper.createElement(WebDAV.XML_NS_WRITE)); 896 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_LOCK_TYPE, WebDAV.XML_NS_LOCK_TYPE); 897 898 xml.endElement(WebDAV.DAV_NS, WebDAV.XML_SUPPORTED_LOCK, WebDAV.XML_NS_SUPPORTED_LOCK); 899 } 900 catch (Exception ex) 901 { 902 throw new AlfrescoRuntimeException("XML write error", ex); 903 } 904 } 905 } 906 | Popular Tags |