1 /*
2 * Created on 2003-5-23 17:07:08 by joel guo
3 *
4 * vTradEx Information Technology Inc.
5 */
6 package com.cyclops.albumbuilder;
7 import java.io.File;
8 import java.util.Iterator;
9
10 import org.apache.commons.io.FileUtils;
11 import org.apache.stratum.lifecycle.Configurable;
12 import org.apache.stratum.lifecycle.Executable;
13 /***
14 * Add description for this class <font color="red">HERE</font>!
15 * <big><font face="黑体">惩前毖后,治病救人</font></big>
16 *
17 * @author <a href="mailto:joeblack.guo@vtradex.com">joel guo</a>
18 * @company <a href="http://www.vtradex.com">vTradEx</a>
19 * @since 2003-5-23 17:07:08
20 */
21 public class SourceResourceCopier
22 extends AlbumBuilderComponent
23 implements Executable, Configurable {
24 private boolean copySource;
25 private String targetDirectory;
26 private boolean forceOverWrite;
27 /*** Override method execute() in super class
28 * @see org.apache.stratum.lifecycle.Executable#execute()
29 */
30 public void execute() throws Exception {
31 if (!copySource) {
32 return;
33 }
34 for (Iterator i = getSourceRepository().values().iterator();
35 i.hasNext();
36 ) {
37 SourceResource res = (SourceResource) i.next();
38 if (res == null) {
39 continue;
40 }
41 File sourceFile = res.getSourceFile();
42 File targetFile = new File(targetDirectory + res.getRelativePath());
43 try {
44 if (targetFile.isFile()
45 && targetFile.lastModified() > sourceFile.lastModified()
46 && !forceOverWrite) {
47 logger.debug("File " + targetFile + " already exists!");
48 continue;
49 }
50 if (!targetFile.getParentFile().isDirectory()) {
51 targetFile.getParentFile().mkdirs();
52 }
53 FileUtils.copyFile(sourceFile, targetFile);
54 logger.debug(
55 "File copied from " + sourceFile + " to " + targetFile);
56 } catch (Exception e) {
57 logger.error(
58 "Can't copy " + sourceFile + " to " + targetFile,
59 e);
60 }
61 }
62 }
63 /*** Override method initialize() of super class
64 * @see org.apache.stratum.lifecycle.Initializable#initialize()
65 */
66 public void initialize() {
67 super.initialize();
68 copySource =
69 getConfiguration().getBoolean("generation.copysource", false);
70 targetDirectory =
71 getConfiguration().getString(
72 "target.directory",
73 "target/docs/album");
74 forceOverWrite = getConfiguration().getBoolean("forceoverwrite", false);
75 }
76 }
This page was automatically generated by Maven