1 /* 2 * #%L 3 * wcm.io 4 * %% 5 * Copyright (C) 2015 wcm.io 6 * %% 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * #L% 19 */ 20 package io.wcm.dam.assetservice.impl.dataversion; 21 22 import java.util.regex.Pattern; 23 24 import org.slf4j.Logger; 25 import org.slf4j.LoggerFactory; 26 27 import com.day.cq.dam.api.DamEvent; 28 29 /** 30 * Common functionality for data version strategy implementations. 31 */ 32 public abstract class DataVersionStrategy { 33 34 protected final String damPath; 35 protected final Logger log = LoggerFactory.getLogger(getClass()); 36 37 private final Pattern pathPattern; 38 39 /** 40 * @param damPath DAM root path 41 */ 42 protected DataVersionStrategy(String damPath) { 43 this.damPath = damPath; 44 this.pathPattern = Pattern.compile("^" + Pattern.quote(damPath) + "(/.*)?$"); 45 } 46 47 /** 48 * @param path DAM asset or asset folder path 49 * @return true if path matches. 50 */ 51 public final boolean matches(String path) { 52 return pathPattern.matcher(path).matches(); 53 } 54 55 /** 56 * Is called when a DAM event affecting any asset within the DAM path occurs. 57 * @param damEvent DAM event 58 */ 59 public abstract void handleDamEvent(DamEvent damEvent); 60 61 /** 62 * Returns data version for this DAM root path 63 * @return Data version. Never null. 64 */ 65 public abstract String getDataVersion(); 66 67 }