1 17 package org.alfresco.repo.webdav; 18 19 import java.io.InputStream ; 20 import java.io.Serializable ; 21 import java.util.HashMap ; 22 import java.util.Map ; 23 24 import javax.servlet.http.HttpServletResponse ; 25 26 import org.alfresco.model.ContentModel; 27 import org.alfresco.service.cmr.model.FileExistsException; 28 import org.alfresco.service.cmr.model.FileFolderService; 29 import org.alfresco.service.cmr.model.FileInfo; 30 import org.alfresco.service.cmr.model.FileNotFoundException; 31 import org.alfresco.service.cmr.repository.ContentWriter; 32 import org.alfresco.service.namespace.QName; 33 34 39 public class PutMethod extends WebDAVMethod 40 { 41 private String m_strLockToken = null; 43 private String m_strContentType = null; 44 private boolean m_expectHeaderPresent = false; 45 46 49 public PutMethod() 50 { 51 } 52 53 58 protected void parseRequestHeaders() throws WebDAVServerException 59 { 60 m_strContentType = m_request.getHeader(WebDAV.HEADER_CONTENT_TYPE); 61 String strExpect = m_request.getHeader(WebDAV.HEADER_EXPECT); 62 63 if (strExpect != null && strExpect.equals(WebDAV.HEADER_EXPECT_CONTENT)) 64 { 65 m_expectHeaderPresent = true; 66 } 67 68 70 m_strLockToken = parseIfHeader(); 71 } 72 73 78 protected void parseRequestBody() throws WebDAVServerException 79 { 80 } 83 84 89 protected void executeImpl() throws WebDAVServerException, Exception 90 { 91 FileFolderService fileFolderService = getFileFolderService(); 92 93 FileInfo contentNodeInfo = null; 95 boolean created = false; 96 try 97 { 98 contentNodeInfo = getDAVHelper().getNodeForPath(getRootNodeRef(), getPath(), getServletPath()); 99 if (contentNodeInfo.isFolder()) 101 { 102 throw new WebDAVServerException(HttpServletResponse.SC_BAD_REQUEST); 103 } 104 } 105 catch (FileNotFoundException e) 106 { 107 String [] paths = getDAVHelper().splitPath(getPath()); 109 try 110 { 111 FileInfo parentNodeInfo = getDAVHelper().getNodeForPath(getRootNodeRef(), paths[0], getServletPath()); 112 contentNodeInfo = fileFolderService.create(parentNodeInfo.getNodeRef(), paths[1], ContentModel.TYPE_CONTENT); 114 created = true; 115 116 Map <QName, Serializable > titledProps = new HashMap <QName, Serializable >(3, 1.0f); 118 titledProps.put(ContentModel.PROP_TITLE, paths[1]); 119 titledProps.put(ContentModel.PROP_DESCRIPTION, ""); 120 getNodeService().addAspect(contentNodeInfo.getNodeRef(), ContentModel.ASPECT_TITLED, titledProps); 121 } 122 catch (FileNotFoundException ee) 123 { 124 throw new WebDAVServerException(HttpServletResponse.SC_BAD_REQUEST); 126 } 127 catch (FileExistsException ee) 128 { 129 throw new WebDAVServerException(HttpServletResponse.SC_BAD_REQUEST); 131 } 132 } 133 134 ContentWriter writer = fileFolderService.getWriter(contentNodeInfo.getNodeRef()); 136 if (m_strContentType != null) 138 { 139 writer.setMimetype(m_strContentType); 140 } 141 else 142 { 143 String guessedMimetype = getServiceRegistry().getMimetypeService().guessMimetype(contentNodeInfo.getName()); 144 writer.setMimetype(guessedMimetype); 145 } 146 writer.setEncoding("UTF-8"); 148 149 InputStream input = m_request.getInputStream(); 151 152 writer.putContent(input); 154 155 m_response.setStatus(created ? HttpServletResponse.SC_CREATED : HttpServletResponse.SC_NO_CONTENT); 157 } 158 } 159 | Popular Tags |