1 31 32 package org.opencms.staticexport; 33 34 import org.opencms.db.CmsPublishedResource; 35 import org.opencms.file.CmsObject; 36 import org.opencms.file.CmsResource; 37 import org.opencms.file.CmsResourceFilter; 38 import org.opencms.main.CmsException; 39 40 import java.util.ArrayList ; 41 import java.util.Collections ; 42 import java.util.HashSet ; 43 import java.util.Iterator ; 44 import java.util.List ; 45 import java.util.Set ; 46 import java.util.regex.Pattern ; 47 48 55 public class CmsStaticExportExportRule { 56 57 58 private String m_description; 59 60 61 private List m_exportResources; 62 63 64 private List m_modifiedResources; 65 66 67 private String m_name; 68 69 75 public CmsStaticExportExportRule(String name, String description) { 76 77 m_name = name; 78 m_description = description; 79 m_exportResources = new ArrayList (); 80 m_modifiedResources = new ArrayList (); 81 } 82 83 91 public CmsStaticExportExportRule( 92 String name, 93 String description, 94 List modifiedResources, 95 List exportResourcePatterns) { 96 97 this(name, description); 98 m_modifiedResources.addAll(modifiedResources); 99 m_exportResources.addAll(exportResourcePatterns); 100 } 101 102 107 public void addExportResourcePattern(String exportResource) { 108 109 m_exportResources.add(exportResource); 110 } 111 112 117 public void addModifiedResource(String modifiedRegex) { 118 119 m_modifiedResources.add(Pattern.compile(modifiedRegex)); 120 } 121 122 127 public String getDescription() { 128 129 return m_description; 130 } 131 132 137 public List getExportResourcePatterns() { 138 139 return Collections.unmodifiableList(m_exportResources); 140 } 141 142 152 public Set getExportResources(CmsObject cms) throws CmsException { 153 154 Set resources = new HashSet (128); 155 Iterator itExpRes = m_exportResources.iterator(); 156 while (itExpRes.hasNext()) { 157 String exportRes = (String )itExpRes.next(); 158 List vfsResources = cms.readResources( 160 exportRes, 161 CmsResourceFilter.ALL.addExcludeFlags(CmsResource.FLAG_INTERNAL)); 162 Iterator itRes = vfsResources.iterator(); 164 while (itRes.hasNext()) { 165 CmsResource vfsResource = (CmsResource)itRes.next(); 166 CmsPublishedResource resource = new CmsPublishedResource(vfsResource); 167 resources.add(resource); 168 } 169 } 170 return resources; 171 } 172 173 178 public List getModifiedResources() { 179 180 return Collections.unmodifiableList(m_modifiedResources); 181 } 182 183 188 public String getName() { 189 190 return m_name; 191 } 192 193 205 public Set getRelatedResources(CmsObject cms, CmsPublishedResource publishedResource) throws CmsException { 206 207 if (match(publishedResource.getRootPath())) { 208 return getExportResources(cms); 209 } 210 return null; 211 } 212 213 219 public boolean match(String vfsName) { 220 221 for (int j = 0; j < m_modifiedResources.size(); j++) { 222 Pattern pattern = (Pattern )m_modifiedResources.get(j); 223 if (pattern.matcher(vfsName).matches()) { 224 return true; 225 } 226 } 227 return false; 228 } 229 230 233 public String toString() { 234 235 StringBuffer ret = new StringBuffer (getClass().getName()); 236 ret.append(":["); 237 ret.append("name: ").append(m_name).append("; "); 238 ret.append("description: ").append(m_description).append("; "); 239 ret.append("modified patterns: ").append(m_modifiedResources).append("; "); 240 ret.append("export resources: ").append(m_exportResources).append("; "); 241 return ret.append("]").toString(); 242 } 243 } 244 | Popular Tags |