01: /*
02: * XResourceTemplateProcessor.java
03: *
04: * Created on 11 June 2007, 15:41
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09:
10: package com.xoetrope.template;
11:
12: import java.io.File;
13: import java.io.FileInputStream;
14: import java.io.FileOutputStream;
15: import java.io.InputStream;
16: import java.io.OutputStream;
17: import net.xoetrope.xui.XProject;
18:
19: /**
20: *
21: * @author kingsley.elmes
22: */
23: public class XResourceTemplateProcessor extends XTemplateProcessor {
24: protected InputStream in;
25:
26: /** Creates a new instance of XResourceTemplateProcessor */
27: public XResourceTemplateProcessor(XProject proj, XTemplateEngine te) {
28: super (proj, te);
29: }
30:
31: public boolean process(String sourceName, String targetName,
32: int processingType) {
33: sourceFile = new File(sourceFileName = sourceName);
34: targetFile = new File(targetName);
35:
36: boolean rc = loadFile();
37:
38: if (rc)
39: rc = saveFile();
40:
41: return rc;
42: }
43:
44: public boolean loadFile() {
45: try {
46: in = new FileInputStream(sourceFileName);
47: } catch (Exception ex) {
48: ex.printStackTrace();
49: return false;
50: }
51:
52: return true;
53: }
54:
55: public boolean saveFile() {
56: try {
57: OutputStream out = new FileOutputStream(targetFile);
58:
59: // Transfer bytes from in to out
60: byte[] buf = new byte[1024];
61: int len;
62: while ((len = in.read(buf)) > 0) {
63: out.write(buf, 0, len);
64: }
65: in.close();
66: out.close();
67: } catch (Exception ex) {
68: ex.printStackTrace();
69: }
70:
71: return true;
72: }
73: }
|