1 16 package org.apache.cocoon.components.repository.impl; 17 18 import java.io.IOException ; 19 import java.util.List ; 20 import java.util.Map ; 21 import java.util.Properties ; 22 import java.util.Set ; 23 24 import javax.xml.transform.OutputKeys ; 25 26 import org.apache.avalon.framework.activity.Disposable; 27 import org.apache.avalon.framework.component.Component; 28 import org.apache.avalon.framework.logger.AbstractLogEnabled; 29 import org.apache.avalon.framework.service.ServiceException; 30 import org.apache.avalon.framework.service.ServiceManager; 31 import org.apache.avalon.framework.service.Serviceable; 32 import org.apache.cocoon.ProcessingException; 33 import org.apache.cocoon.components.repository.helpers.CredentialsToken; 34 import org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper; 35 import org.apache.cocoon.components.source.helpers.SourceProperty; 36 import org.apache.cocoon.components.webdav.WebDAVUtil; 37 import org.apache.cocoon.xml.XMLUtils; 38 import org.apache.commons.httpclient.HttpException; 39 import org.w3c.dom.Node ; 40 41 45 public class WebDAVRepositoryPropertyHelper extends AbstractLogEnabled 46 implements RepositoryPropertyHelper, Serviceable, Disposable, Component { 47 48 49 private ServiceManager manager; 50 51 52 private WebDAVRepository repo; 53 54 55 private CredentialsToken credentials; 56 57 60 public void service(ServiceManager manager) throws ServiceException { 61 this.manager = manager; 62 } 63 64 67 public void dispose() { 68 this.manager = null; 69 } 70 71 77 public WebDAVRepositoryPropertyHelper (CredentialsToken credentials, WebDAVRepository repo) { 78 this.credentials = credentials; 79 this.repo = repo; 80 } 81 82 85 public SourceProperty getProperty(String uri, String name, String namespace) { 86 87 try { 88 return WebDAVUtil.getProperty(this.repo.getAbsoluteURI(uri), name, namespace); 89 90 } catch (HttpException he) { 91 this.getLogger().error("HTTP Error getting property " + namespace + ":" + name + " for " + uri, he); 92 93 } catch (IOException ioe) { 94 this.getLogger().error("IO Error getting property " + namespace + ":" + name + " for " + uri, ioe); 95 } 96 97 return null; 98 } 99 100 103 public Map getProperties(String uri, Set propNames) { 104 105 try { 106 return WebDAVUtil.getProperties(this.repo.getAbsoluteURI(uri), propNames); 107 108 } catch (HttpException he) { 109 this.getLogger().error("HTTP Error getting properties for " + uri, he); 110 111 } catch (IOException ioe) { 112 this.getLogger().error("IO Error getting properties for " + uri, ioe); 113 } 114 115 return null; 116 } 117 118 121 public List getAllProperties(String uri) { 122 123 try { 124 return WebDAVUtil.getAllProperties(this.repo.getAbsoluteURI(uri)); 125 126 } catch (HttpException he) { 127 this.getLogger().error("HTTP Error getting properties for " + uri, he); 128 129 } catch (IOException ioe) { 130 this.getLogger().error("IO Error getting properties for " + uri, ioe); 131 } 132 133 return null; 134 } 135 136 139 public boolean setProperty(String uri, String name, String namespace, String value) { 140 141 try { 142 WebDAVUtil.setProperty(this.repo.getAbsoluteURI(uri), name, namespace, value); 143 return true; 144 145 } catch (HttpException he) { 146 this.getLogger().error("HTTP Error setting property " + namespace + ":" + name + " for " + uri, he); 147 } catch (IOException ioe) { 148 this.getLogger().error("IO Error setting property " + namespace + ":" + name + " for " + uri, ioe); 149 } 150 151 return false; 152 } 153 154 157 public boolean setProperty(String uri, String name, String namespace, Node value) { 158 159 try { 160 Properties format = new Properties (); 161 format.put(OutputKeys.METHOD, "xml"); 162 format.put(OutputKeys.OMIT_XML_DECLARATION, "yes"); 163 return this.setProperty(uri, name, namespace, XMLUtils.serializeNode(value, format)); 164 165 } catch (ProcessingException pe) { 166 this.getLogger().error("Error serializing node " + value, pe); 167 } 168 169 return false; 170 } 171 172 175 public boolean setProperties(final String uri, final Map properties) { 176 177 try { 178 WebDAVUtil.setProperties(this.repo.getAbsoluteURI(uri), properties); 179 return true; 180 181 } catch (HttpException he) { 182 this.getLogger().error("HTTP Error setting properties for " + uri, he); 183 } catch (IOException ioe) { 184 this.getLogger().error("IO Error setting properties for " + uri, ioe); 185 } 186 187 return false; 188 } 189 190 } | Popular Tags |