1 16 package nl.hippo.cms.workflows.multiplesitesdocument; 17 18 import com.opensymphony.module.propertyset.PropertySet; 19 import com.opensymphony.workflow.WorkflowException; 20 import java.io.IOException ; 21 import java.util.Enumeration ; 22 import java.util.Map ; 23 import nl.hippo.cms.workflows.shared.FunctionProviderComponent; 24 import org.apache.commons.httpclient.HttpClient; 25 import org.apache.webdav.lib.Property; 26 import org.apache.webdav.lib.methods.MkcolMethod; 27 import org.apache.webdav.lib.methods.PropFindMethod; 28 import org.apache.webdav.lib.methods.PropPatchMethod; 29 30 public abstract class ObjectCopyingComponent extends FunctionProviderComponent 31 { 32 33 public ObjectCopyingComponent() 34 { 35 super(); 36 } 37 38 public void executeImpl(Map arg0, Map arg1, PropertySet arg2) throws WorkflowException 39 { 40 } 41 42 protected static void copyProperties(HttpClient httpClient, String previewLocation, String liveLocation) throws IOException 43 { 44 PropFindMethod propfind = null; 45 PropPatchMethod proppatch = null; 46 try 47 { 48 propfind = new PropFindMethod(previewLocation); 49 propfind.setDoAuthentication(true); 50 propfind.setDepth(0); 51 httpClient.executeMethod(propfind); 52 proppatch = new PropPatchMethod(liveLocation); 53 Enumeration responseUrls = propfind.getAllResponseURLs(); 54 if (responseUrls.hasMoreElements()) 55 { 56 Enumeration properties = propfind.getResponseProperties((String ) responseUrls 57 .nextElement()); 58 boolean executeProppatch = false; 59 while (properties.hasMoreElements()) 60 { 61 Property property = (Property) properties.nextElement(); 62 String namespace = property.getNamespaceURI(); 63 if (!namespace.equals("DAV:")) 64 { 65 String name = property.getLocalName(); 66 String value = property.getPropertyAsString(); 67 proppatch.addPropertyToSet(name, "<![CDATA[" + value + "]]>", "property", 68 namespace); 69 executeProppatch = true; 70 } 71 } 72 if (executeProppatch) 73 { 74 try 75 { 76 proppatch.setDoAuthentication(true); 77 int status = httpClient.executeMethod(proppatch); 78 } 80 catch (IOException e) 81 { 82 } 84 finally 85 { 86 proppatch.releaseConnection(); 87 } 88 } 89 propfind.releaseConnection(); 90 } 91 } 92 finally 93 { 94 if (propfind != null) 95 { 96 propfind.releaseConnection(); 97 } 98 if (proppatch != null) 99 { 100 proppatch.releaseConnection(); 101 } 102 } 103 } 104 105 protected static void ensureAncestorCollectionsExist(HttpClient httpClient, String liveLocation) throws IOException 106 { 107 MkcolMethod mkcol = null; 108 try 109 { 110 int locationOfThirdSlash = liveLocation.indexOf('/', liveLocation.indexOf('/', 111 liveLocation.indexOf('/') + 1) + 1); 112 String protocolHostAndPort = liveLocation.substring(0, locationOfThirdSlash); 113 String path = liveLocation.substring(locationOfThirdSlash); 114 path = path.substring(0, path.lastIndexOf('/')); 115 if (path.length() > 0) 116 { 117 String parentLocation = protocolHostAndPort + path; 118 ensureAncestorCollectionsExist(httpClient, parentLocation); 119 mkcol = new MkcolMethod(parentLocation); 120 mkcol.setDoAuthentication(true); 121 int mkcolResult = httpClient.executeMethod(mkcol); 122 if (mkcolResult != 201) 123 { 124 } 126 mkcol.releaseConnection(); 127 128 if (parentLocation.indexOf(".www/") != -1) 129 { 130 copyProperties(httpClient, parentLocation.replaceAll("\\.www/", ".preview/"), 131 parentLocation); 132 } 133 } 134 } 135 finally 136 { 137 if (mkcol != null) 138 { 139 mkcol.releaseConnection(); 140 } 141 } 142 } 143 144 } 145 | Popular Tags |