Skip to main content
summaryrefslogtreecommitdiffstats
blob: 069661a25da3534d3fde22800e4a84f49d251dae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*******************************************************************************
 * Copyright (c) 2005, 2006 committers of openArchitectureWare and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     committers of openArchitectureWare - initial API and implementation
 *******************************************************************************/
package org.eclipse.xpand2.output;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Outlet {
    
    private boolean append = false;

    private boolean overwrite = true;

    private String path = null;

    private String name = null;

    private String fileEncoding = System.getProperty("file.encoding");
    private boolean hasDefaultEncoding = true;

    public boolean hasDefaultEncoding () {
        return hasDefaultEncoding;
    }
    
    public boolean isAppend() {
        return append;
    }

    public void setAppend(final boolean append) {
        this.append = append;
    }

    public String getName() {
        return name;
    }

    public void setName(final String name) {
        this.name = name;
    }

    public boolean isOverwrite() {
        return overwrite;
    }

    public void setOverwrite(final boolean overwrite) {
        this.overwrite = overwrite;
    }

    public String getPath() {
        return path;
    }

    public void setPath(final String path) {
        this.path = path;
    }

    public FileHandleImpl createFileHandle(final String filePath) {
        filesCreated++;
        final File f = new File(path, filePath);
        return new FileHandleImpl(this, f);
    }

    public String getFileEncoding() {
        return fileEncoding;
    }

    public void setFileEncoding(final String fileEncoding) {
        this.fileEncoding = fileEncoding;
        hasDefaultEncoding = false;
    }

    public List<PostProcessor> postprocessors = new ArrayList<PostProcessor>();

    public void addPostprocessor(final PostProcessor b) {
        postprocessors.add(b);
    }
    public List<VetoStrategy> vetoStartegies = new ArrayList<VetoStrategy>();
    
    public void addVetoStrategy(final VetoStrategy b) {
    	vetoStartegies.add(b);
    }

    public void beforeWriteAndClose(final FileHandle impl) {
        filesWrittenAndClosed++;
        for (final Iterator<PostProcessor> iter = postprocessors.iterator(); iter.hasNext();) {
            final PostProcessor b = iter.next();
            b.beforeWriteAndClose(impl);
        }
    }

    public void afterClose(final FileHandle impl) {
        for (final Iterator<PostProcessor> iter = postprocessors.iterator(); iter.hasNext();) {
            final PostProcessor b = iter.next();
            b.afterClose(impl);
        }
    }

    private int filesCreated = 0;

    private int filesWrittenAndClosed = 0;

    public int getFilesCreated() {
        return filesCreated;
    }

    public int getFilesWrittenAndClosed() {
        return filesWrittenAndClosed;
    }

    public Outlet(String path) {
        this.path = path;
    }
    
    public Outlet() {
    }

    public Outlet (boolean append, String encoding, String name, boolean overwrite, String path) {
        this.append = append;
        this.fileEncoding = encoding;
        this.name = name;
        this.overwrite = overwrite;
        this.path = path;
    }
    
	public boolean shouldWrite(FileHandleImpl fileHandleImpl) {
		for (VetoStrategy vs : vetoStartegies) {
			if (vs.hasVeto(fileHandleImpl))
            	return false;
        }
		return true;
	}

}

Back to the top