/*
* Copyright 2011 France Télécom
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ro.isdc.wro.model.resource.util;

import java.io.InputStream;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * This naming strategy append a timestamp to the name of the file.
 * 
 * This is especially useful when wro4j is used at build time with the
 * maven plugin.
 * 
 * @author Julien Wajsberg
 */
public class TimestampNamingStrategy implements NamingStrategy {

	public String rename(String originalName, InputStream inputStream) {
	    final String baseName = FilenameUtils.getBaseName(originalName);
	    final String extension = FilenameUtils.getExtension(originalName);
	    final long timestamp = getTimestamp();
	    final StringBuilder sb = new StringBuilder(baseName).append("-").append(timestamp);
	    if (!StringUtils.isEmpty(extension)) {
	      sb.append(".").append(extension);
	    }
	    return sb.toString();
	}
	
	/* protected to make the class testable. Should we ? */
	protected long getTimestamp() {
		return System.currentTimeMillis();
	}
	
}

@@ -1,11 +1,12 @@
 /*%0A
+ 
 * Copyri
@@ -29,18 +29,21 @@
 T%C3%A9l%C3%A9com%0A
-*%0A
+ * %0A 
 * Licens
@@ -99,18 +99,16 @@
 cense%22);
-%0A*
  you may
@@ -120,16 +120,19 @@
 use this
+%0A *
  file ex
@@ -167,18 +167,16 @@
 License.
-%0A*
  You may
@@ -208,18 +208,21 @@
 ense at%0A
-*%0A
+ * %0A 
 * http:/
@@ -261,11 +261,15 @@
 -2.0
-%0A*%0A
+ %0A * %0A 
 * Un
@@ -334,16 +334,17 @@
 oftware%0A
+ 
 * distri
@@ -402,18 +402,16 @@
 %22 BASIS,
-%0A*
  WITHOUT
@@ -448,16 +448,19 @@
 NY KIND,
+%0A *
  either 
@@ -478,18 +478,16 @@
 implied.
-%0A*
  See the
@@ -546,18 +546,16 @@
 ions and
-%0A*
  limitat
@@ -560,32 +560,35 @@
 ations under the
+%0A *
  License.%0A*/%0A%0Apa
@@ -585,12 +585,12 @@
 se.%0A
+ 
 */%0A
-%0A
 pack
@@ -746,16 +746,17 @@
 Utils;%0A%0A
+%0A
 /**%0A * T
@@ -818,23 +818,16 @@
 he file.
-%0A * %0A *
  This is
@@ -866,16 +866,19 @@
  used at
+%0A *
  build t
@@ -889,19 +889,16 @@
 with the
-%0A *
  maven p
@@ -935,16 +935,32 @@
 ajsberg%0A
+ * @since 1.4.3%0A
  */%0Apubl
@@ -991,16 +991,20 @@
 Strategy
+%0A   
  impleme
@@ -1024,18 +1024,49 @@
 ategy %7B%0A
-%0A%09
+  /**%0A   * %7B@inheritDoc%7D%0A   */%0A  
 public S
@@ -1122,25 +1122,24 @@
 utStream) %7B%0A
-%09
     final St
@@ -1187,33 +1187,32 @@
 (originalName);%0A
-%09
     final String
@@ -1266,17 +1266,16 @@
 lName);%0A
-%09
     fina
@@ -1309,17 +1309,16 @@
 tamp();%0A
-%09
     fina
@@ -1397,17 +1397,16 @@
 stamp);%0A
-%09
     if (
@@ -1440,17 +1440,16 @@
 ion)) %7B%0A
-%09
       sb
@@ -1484,16 +1484,14 @@
 n);%0A
-%09
     %7D%0A
-%09
     
@@ -1516,14 +1516,17 @@
 ();%0A
-%09%7D%0A%09%0A%09
+  %7D%0A  %0A  
 /* p
@@ -1577,17 +1577,18 @@
 we ? */%0A
-%09
+  
 protecte
@@ -1615,10 +1615,12 @@
 ) %7B%0A
-%09%09
+    
 retu
@@ -1654,11 +1654,13 @@
 ();%0A
-%09%7D%0A%09
+  %7D%0A  
 %0A%7D%0A

update javadoc