Revision 1962
org.gvsig.report/tags/org.gvsig.report-1.0.35/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/UnmodifiableBasicList64ToListAdapter.java | ||
---|---|---|
1 |
package org.gvsig.report.lib.impl; |
|
2 |
|
|
3 |
import java.util.Collection; |
|
4 |
import java.util.Iterator; |
|
5 |
import java.util.List; |
|
6 |
import java.util.ListIterator; |
|
7 |
import java.util.NoSuchElementException; |
|
8 |
import org.gvsig.tools.util.UnmodifiableBasicList64; |
|
9 |
|
|
10 |
/** |
|
11 |
* |
|
12 |
* @author jjdelcerro |
|
13 |
* @param <T> |
|
14 |
*/ |
|
15 |
public class UnmodifiableBasicList64ToListAdapter<T> implements List<T> { |
|
16 |
|
|
17 |
private final UnmodifiableBasicList64<T> basiclist; |
|
18 |
|
|
19 |
public UnmodifiableBasicList64ToListAdapter(UnmodifiableBasicList64<T> basiclist) { |
|
20 |
this.basiclist = basiclist; |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
public int size() { |
|
25 |
return (int) this.basiclist.size64(); |
|
26 |
} |
|
27 |
|
|
28 |
@Override |
|
29 |
public boolean isEmpty() { |
|
30 |
return this.basiclist.isEmpty(); |
|
31 |
} |
|
32 |
|
|
33 |
@Override |
|
34 |
public boolean contains(Object o) { |
|
35 |
return indexOf(o) >= 0; |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public Iterator<T> iterator() { |
|
40 |
return this.basiclist.iterator(); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public Object[] toArray() { |
|
45 |
int size = this.size(); |
|
46 |
Object[] result = new Object[size]; |
|
47 |
int i = 0; |
|
48 |
for (int j = 0; j < size; j++) { |
|
49 |
result[i++] = this.get(j); |
|
50 |
} |
|
51 |
return result; |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public <T> T[] toArray(T[] a) { |
|
56 |
int size = this.size(); |
|
57 |
if (a.length < size) |
|
58 |
a = (T[])java.lang.reflect.Array.newInstance( |
|
59 |
a.getClass().getComponentType(), size |
|
60 |
); |
|
61 |
int i = 0; |
|
62 |
Object[] result = a; |
|
63 |
for (int j = 0; j < size; j++) { |
|
64 |
result[i++] = this.get(j); |
|
65 |
} |
|
66 |
if (a.length > size) |
|
67 |
a[size] = null; |
|
68 |
return a; |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public boolean add(T e) { |
|
73 |
throw new UnsupportedOperationException("Not supported yet."); |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public boolean remove(Object o) { |
|
78 |
throw new UnsupportedOperationException("Not supported yet."); |
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public boolean containsAll(Collection<?> c) { |
|
83 |
for (Object e : c) |
|
84 |
if (!contains(e)) |
|
85 |
return false; |
|
86 |
return true; |
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
90 |
public boolean addAll(Collection<? extends T> c) { |
|
91 |
throw new UnsupportedOperationException("Not supported yet."); |
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
95 |
public boolean addAll(int index, Collection<? extends T> c) { |
|
96 |
throw new UnsupportedOperationException("Not supported yet."); |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public boolean removeAll(Collection<?> c) { |
|
101 |
throw new UnsupportedOperationException("Not supported yet."); |
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
public boolean retainAll(Collection<?> c) { |
|
106 |
throw new UnsupportedOperationException("Not supported yet."); |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public void clear() { |
|
111 |
throw new UnsupportedOperationException("Not supported yet."); |
|
112 |
} |
|
113 |
|
|
114 |
@Override |
|
115 |
public T get(int index) { |
|
116 |
return this.basiclist.get64(index); |
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
public T set(int index, T element) { |
|
121 |
throw new UnsupportedOperationException("Not supported yet."); |
|
122 |
} |
|
123 |
|
|
124 |
@Override |
|
125 |
public void add(int index, T element) { |
|
126 |
throw new UnsupportedOperationException("Not supported yet."); |
|
127 |
} |
|
128 |
|
|
129 |
@Override |
|
130 |
public T remove(int index) { |
|
131 |
throw new UnsupportedOperationException("Not supported yet."); |
|
132 |
} |
|
133 |
|
|
134 |
@Override |
|
135 |
public int indexOf(Object o) { |
|
136 |
int size = (int) this.basiclist.size64(); |
|
137 |
if (o == null) { |
|
138 |
for (int i = 0; i < size; i++) |
|
139 |
if (this.basiclist.get64(i)==null) |
|
140 |
return i; |
|
141 |
} else { |
|
142 |
for (int i = 0; i < size; i++) |
|
143 |
if (o.equals(this.basiclist.get64(i))) |
|
144 |
return i; |
|
145 |
} |
|
146 |
return -1; |
|
147 |
} |
|
148 |
|
|
149 |
@Override |
|
150 |
public int lastIndexOf(Object o) { |
|
151 |
int size = (int) this.basiclist.size64(); |
|
152 |
if (o == null) { |
|
153 |
for (int i = size-1; i >= 0; i--) |
|
154 |
if (this.basiclist.get64(i)==null) |
|
155 |
return i; |
|
156 |
} else { |
|
157 |
for (int i = size-1; i >= 0; i--) |
|
158 |
if (o.equals(this.basiclist.get64(i))) |
|
159 |
return i; |
|
160 |
} |
|
161 |
return -1; |
|
162 |
} |
|
163 |
|
|
164 |
@Override |
|
165 |
public ListIterator<T> listIterator() { |
|
166 |
return new ListItr(0); |
|
167 |
} |
|
168 |
|
|
169 |
@Override |
|
170 |
public ListIterator<T> listIterator(int index) { |
|
171 |
if (index < 0 || index > size()) |
|
172 |
throw new IndexOutOfBoundsException("Index: "+index); |
|
173 |
return new ListItr(index); |
|
174 |
} |
|
175 |
|
|
176 |
@Override |
|
177 |
public List<T> subList(int fromIndex, int toIndex) { |
|
178 |
throw new UnsupportedOperationException("Not supported yet."); |
|
179 |
} |
|
180 |
|
|
181 |
private class Itr implements Iterator<T> { |
|
182 |
int cursor; // index of next element to return |
|
183 |
|
|
184 |
Itr() {} |
|
185 |
|
|
186 |
@Override |
|
187 |
public boolean hasNext() { |
|
188 |
return cursor != size(); |
|
189 |
} |
|
190 |
|
|
191 |
@Override |
|
192 |
public T next() { |
|
193 |
int i = cursor; |
|
194 |
if (i >= size()) |
|
195 |
throw new NoSuchElementException(); |
|
196 |
cursor = i + 1; |
|
197 |
return basiclist.get64(i); |
|
198 |
} |
|
199 |
|
|
200 |
@Override |
|
201 |
public void remove() { |
|
202 |
throw new UnsupportedOperationException("Not supported yet."); |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
private class ListItr extends Itr implements ListIterator<T> { |
|
207 |
ListItr(int index) { |
|
208 |
super(); |
|
209 |
cursor = index; |
|
210 |
} |
|
211 |
|
|
212 |
@Override |
|
213 |
public boolean hasPrevious() { |
|
214 |
return cursor != 0; |
|
215 |
} |
|
216 |
|
|
217 |
@Override |
|
218 |
public int nextIndex() { |
|
219 |
return cursor; |
|
220 |
} |
|
221 |
|
|
222 |
@Override |
|
223 |
public int previousIndex() { |
|
224 |
return cursor - 1; |
|
225 |
} |
|
226 |
|
|
227 |
@Override |
|
228 |
public T previous() { |
|
229 |
int i = cursor - 1; |
|
230 |
if (i < 0) |
|
231 |
throw new NoSuchElementException(); |
|
232 |
cursor = i; |
|
233 |
return (T)basiclist.get64(i); |
|
234 |
} |
|
235 |
|
|
236 |
@Override |
|
237 |
public void set(T e) { |
|
238 |
throw new UnsupportedOperationException("Not supported yet."); |
|
239 |
} |
|
240 |
|
|
241 |
@Override |
|
242 |
public void add(T e) { |
|
243 |
throw new UnsupportedOperationException("Not supported yet."); |
|
244 |
} |
|
245 |
} |
|
246 |
|
|
247 |
} |
org.gvsig.report/tags/org.gvsig.report-1.0.35/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/DefaultReportConfig.java | ||
---|---|---|
1 |
package org.gvsig.report.lib.impl; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.io.InputStream; |
|
5 |
import java.net.URL; |
|
6 |
import java.util.Objects; |
|
7 |
import javax.json.Json; |
|
8 |
import javax.json.JsonArray; |
|
9 |
import javax.json.JsonArrayBuilder; |
|
10 |
import javax.json.JsonObject; |
|
11 |
import javax.json.JsonObjectBuilder; |
|
12 |
import javax.json.JsonValue; |
|
13 |
import org.apache.commons.lang3.StringUtils; |
|
14 |
import org.apache.commons.lang3.builder.ToStringBuilder; |
|
15 |
import org.apache.commons.lang3.builder.ToStringStyle; |
|
16 |
import org.gvsig.fmap.dal.DALLocator; |
|
17 |
import org.gvsig.fmap.dal.DataManager; |
|
18 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
19 |
import org.gvsig.report.lib.api.Report; |
|
20 |
import org.gvsig.report.lib.api.ReportConfig; |
|
21 |
import org.gvsig.report.lib.api.ReportDataSet; |
|
22 |
import org.gvsig.report.lib.api.ReportLocator; |
|
23 |
import org.gvsig.report.lib.api.ReportServer; |
|
24 |
import org.gvsig.tools.resourcesstorage.FilesResourcesStorage; |
|
25 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
|
26 |
|
|
27 |
/** |
|
28 |
* |
|
29 |
* @author jjdelcerro |
|
30 |
*/ |
|
31 |
public class DefaultReportConfig implements ReportConfig { |
|
32 |
|
|
33 |
private String name; |
|
34 |
private String dataSetName; |
|
35 |
private String templateName; |
|
36 |
private String filterFieldPrefix; |
|
37 |
|
|
38 |
private ResourcesStorage reportResourcesStorage; // Persisten for FileResourcesStorage |
|
39 |
|
|
40 |
private ReportDataSet dataset; // not-persistent |
|
41 |
private ReportServer server; // not-persistent |
|
42 |
private int layout; |
|
43 |
|
|
44 |
public DefaultReportConfig() { |
|
45 |
|
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public void fromJSON(JsonObject json) { |
|
50 |
this.name = json.getString("name", null); |
|
51 |
this.dataSetName = json.getString("dataSetName", null); |
|
52 |
this.templateName = json.getString("templateName", null); |
|
53 |
this.filterFieldPrefix = json.getString("filterFieldPrefix", null); |
|
54 |
if (json.containsKey("FilesResourcesStorage") && !json.isNull("FilesResourcesStorage")) { |
|
55 |
JsonArray arrayJson = json.getJsonArray("FilesResourcesStorage"); |
|
56 |
FilesResourcesStorage storage = null; |
|
57 |
for (JsonValue jsonValue : arrayJson) { |
|
58 |
if (storage == null) { |
|
59 |
storage = new FilesResourcesStorage(jsonValue.toString()); |
|
60 |
} else { |
|
61 |
storage.getPaths().add(jsonValue.toString()); |
|
62 |
} |
|
63 |
} |
|
64 |
this.reportResourcesStorage = storage; |
|
65 |
} else { |
|
66 |
this.reportResourcesStorage = null; |
|
67 |
} |
|
68 |
this.dataset = null; |
|
69 |
this.server = null; |
|
70 |
} |
|
71 |
|
|
72 |
@Override |
|
73 |
public JsonObject toJSON() { |
|
74 |
JsonObjectBuilder builder = Json.createObjectBuilder(); |
|
75 |
builder.add("name", this.name); |
|
76 |
builder.add("dataSetName", this.getDataSetName()); |
|
77 |
builder.add("templateName", this.templateName); |
|
78 |
if (this.filterFieldPrefix == null) { |
|
79 |
builder.addNull("filterFieldPrefix"); |
|
80 |
} else { |
|
81 |
builder.add("filterFieldPrefix", this.filterFieldPrefix); |
|
82 |
} |
|
83 |
|
|
84 |
if (this.reportResourcesStorage instanceof FilesResourcesStorage) { |
|
85 |
// Esto lo usa el documento report del proyecto. |
|
86 |
FilesResourcesStorage storage = (FilesResourcesStorage) this.reportResourcesStorage; |
|
87 |
JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); |
|
88 |
for (String path : storage.getPaths()) { |
|
89 |
arrayBuilder.add(path); |
|
90 |
} |
|
91 |
builder.add("FilesResourcesStorage", arrayBuilder); |
|
92 |
} else { |
|
93 |
builder.addNull("FilesResourcesStorage"); |
|
94 |
} |
|
95 |
return builder.build(); |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public String toString() { |
|
100 |
ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); |
|
101 |
builder.append("name", this.name); |
|
102 |
builder.append("dataSetName", this.dataSetName); |
|
103 |
builder.append("templateName", this.templateName); |
|
104 |
builder.append("filterFieldPrefix", this.filterFieldPrefix); |
|
105 |
if (this.reportResourcesStorage instanceof FilesResourcesStorage) { |
|
106 |
FilesResourcesStorage storage = (FilesResourcesStorage) this.reportResourcesStorage; |
|
107 |
builder.append("reportResourcesStorage", storage.getPaths().toArray()); |
|
108 |
} |
|
109 |
return builder.toString(); |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public String getName() { |
|
114 |
if (StringUtils.isBlank(name)) { |
|
115 |
if (StringUtils.isBlank(this.templateName)) { |
|
116 |
return this.getDataSetName(); |
|
117 |
} |
|
118 |
return this.templateName; |
|
119 |
} |
|
120 |
return this.name; |
|
121 |
} |
|
122 |
|
|
123 |
@Override |
|
124 |
public void setName(String name) { |
|
125 |
this.name = name; |
|
126 |
} |
|
127 |
|
|
128 |
@Override |
|
129 |
public String getFilterFieldPrefix() { |
|
130 |
return this.filterFieldPrefix; |
|
131 |
} |
|
132 |
|
|
133 |
@Override |
|
134 |
public String getDataSetName() { |
|
135 |
if (StringUtils.isBlank(this.dataSetName)) { |
|
136 |
if (this.dataset == null) { |
|
137 |
return null; |
|
138 |
} |
|
139 |
return this.dataset.getName(); |
|
140 |
} |
|
141 |
return this.dataSetName; |
|
142 |
} |
|
143 |
|
|
144 |
@Override |
|
145 |
public void setDataSetName(String name) { |
|
146 |
this.dataSetName = name; |
|
147 |
} |
|
148 |
|
|
149 |
@Override |
|
150 |
public String getReportTemplateName() { |
|
151 |
return this.templateName; |
|
152 |
} |
|
153 |
|
|
154 |
@Override |
|
155 |
public void setReportTemplate(String templateName) { |
|
156 |
this.templateName = templateName; |
|
157 |
} |
|
158 |
|
|
159 |
@Override |
|
160 |
public void setReportResourcesStorage(ResourcesStorage storage) { |
|
161 |
this.reportResourcesStorage = storage; |
|
162 |
} |
|
163 |
|
|
164 |
@Override |
|
165 |
public boolean hasDataSet() { |
|
166 |
if (this.dataset != null) { |
|
167 |
return true; |
|
168 |
} |
|
169 |
return !StringUtils.isBlank(this.dataSetName); |
|
170 |
} |
|
171 |
|
|
172 |
private ReportServer getServer() { |
|
173 |
if (this.server == null) { |
|
174 |
this.server = ReportLocator.getReportManager().getDefaultServer(); |
|
175 |
} |
|
176 |
return this.server; |
|
177 |
} |
|
178 |
|
|
179 |
@Override |
|
180 |
public ReportDataSet getDataSet() { |
|
181 |
if (this.dataset == null) { |
|
182 |
if (StringUtils.isBlank(this.dataSetName)) { |
|
183 |
return null; |
|
184 |
} |
|
185 |
this.dataset = this.getServer().getConfig().getDataset(this.dataSetName); |
|
186 |
if (dataset == null) { |
|
187 |
DataManager dataManager = DALLocator.getDataManager(); |
|
188 |
FeatureStore store = (FeatureStore) dataManager.getStoresRepository().getStore(this.dataSetName); |
|
189 |
if (store != null) { |
|
190 |
this.dataset = ReportLocator.getReportManager().createDataSet(store); |
|
191 |
} |
|
192 |
} |
|
193 |
} |
|
194 |
return this.dataset; |
|
195 |
} |
|
196 |
|
|
197 |
@Override |
|
198 |
public void setDataSet(ReportDataSet dataset) { |
|
199 |
this.dataset = dataset; |
|
200 |
} |
|
201 |
|
|
202 |
@Override |
|
203 |
public ResourcesStorage getResources() { |
|
204 |
return this.getDataSet().getStore().getResourcesStorage(); |
|
205 |
} |
|
206 |
|
|
207 |
@Override |
|
208 |
public ResourcesStorage.Resource getReportTemplateAsResource() { |
|
209 |
ResourcesStorage storage = this.getResources(); |
|
210 |
ResourcesStorage.Resource resource = storage.getResource(templateName); |
|
211 |
return resource; |
|
212 |
} |
|
213 |
|
|
214 |
@Override |
|
215 |
public InputStream getReportTemplateAsStream() { |
|
216 |
URL url = null; |
|
217 |
try { |
|
218 |
ResourcesStorage.Resource resource = this.getReportTemplateAsResource(); |
|
219 |
url = resource.getURL(); |
|
220 |
return resource.asInputStream(); |
|
221 |
} catch (IOException ex) { |
|
222 |
throw new RuntimeException("Can't access to report template '" + Objects.toString(url) + "'.", ex); |
|
223 |
} |
|
224 |
} |
|
225 |
|
|
226 |
@Override |
|
227 |
public URL getReportTemplateAsURL() { |
|
228 |
ResourcesStorage.Resource resource = this.getReportTemplateAsResource(); |
|
229 |
URL url = resource.getURL(); |
|
230 |
return url; |
|
231 |
} |
|
232 |
|
|
233 |
@Override |
|
234 |
public Report createReport() { |
|
235 |
Report r = new DefaultReport(this); |
|
236 |
return r; |
|
237 |
} |
|
238 |
|
|
239 |
@Override |
|
240 |
public int getLayoutManager() { |
|
241 |
return this.layout; |
|
242 |
} |
|
243 |
|
|
244 |
@Override |
|
245 |
public void setLayoutManager(int layout) { |
|
246 |
this.layout = layout; |
|
247 |
} |
|
248 |
|
|
249 |
} |
org.gvsig.report/tags/org.gvsig.report-1.0.35/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/DefaultReportServer.java | ||
---|---|---|
1 |
package org.gvsig.report.lib.impl; |
|
2 |
|
|
3 |
import java.net.MalformedURLException; |
|
4 |
import java.net.URL; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.HashSet; |
|
7 |
import java.util.LinkedHashMap; |
|
8 |
import java.util.List; |
|
9 |
import java.util.Map; |
|
10 |
import java.util.Set; |
|
11 |
import java.util.concurrent.TimeUnit; |
|
12 |
import org.apache.commons.lang3.StringUtils; |
|
13 |
import org.apache.http.ExceptionLogger; |
|
14 |
import org.apache.http.impl.nio.bootstrap.HttpServer; |
|
15 |
import org.apache.http.impl.nio.bootstrap.ServerBootstrap; |
|
16 |
import org.apache.http.impl.nio.reactor.IOReactorConfig; |
|
17 |
import org.gvsig.report.lib.api.ReportDataSet; |
|
18 |
import org.gvsig.report.lib.api.ReportManager; |
|
19 |
import org.gvsig.report.lib.api.ReportServer; |
|
20 |
import org.gvsig.report.lib.api.ReportServerConfig; |
|
21 |
import org.gvsig.report.lib.api.ReportServices; |
|
22 |
import org.gvsig.report.lib.api.ReportViewCapture; |
|
23 |
import org.gvsig.report.lib.api.commands.Command; |
|
24 |
import org.gvsig.report.lib.api.commands.CommandFactory; |
|
25 |
import org.slf4j.Logger; |
|
26 |
import org.slf4j.LoggerFactory; |
|
27 |
|
|
28 |
public class DefaultReportServer implements ReportServer { |
|
29 |
|
|
30 |
private static final Logger LOG = LoggerFactory.getLogger(DefaultReportServer.class); |
|
31 |
|
|
32 |
private static final List<HttpServer> servers = new ArrayList<>(); |
|
33 |
|
|
34 |
static { |
|
35 |
|
|
36 |
Runtime.getRuntime().addShutdownHook(new Thread() { |
|
37 |
@Override |
|
38 |
public void run() { |
|
39 |
for (HttpServer server : servers) { |
|
40 |
server.shutdown(5, TimeUnit.SECONDS); |
|
41 |
} |
|
42 |
} |
|
43 |
}); |
|
44 |
} |
|
45 |
|
|
46 |
private HttpServer server; |
|
47 |
private final Set<LoggerListener> loglisteners; |
|
48 |
private Map<String, Command> commands; |
|
49 |
private final ReportServerConfig config; |
|
50 |
private final ReportManager manager; |
|
51 |
|
|
52 |
public DefaultReportServer(ReportManager manager, ReportServerConfig config) { |
|
53 |
this.manager = manager; |
|
54 |
this.config = config; |
|
55 |
this.loglisteners = new HashSet<>(); |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public Map<String, Command> getCommands() { |
|
60 |
if (this.commands == null) { |
|
61 |
Map<String, Command>theCommands = new LinkedHashMap<>(); |
|
62 |
for (CommandFactory factory : this.manager.getCommandFactories()) { |
|
63 |
theCommands.put(factory.getName(), factory.create(this)); |
|
64 |
} |
|
65 |
this.commands = theCommands; |
|
66 |
} |
|
67 |
return this.commands; |
|
68 |
} |
|
69 |
|
|
70 |
public Command getCommand(String commandName) { |
|
71 |
if (commandName == null) { |
|
72 |
return null; |
|
73 |
} |
|
74 |
Command command = this.getCommands().get(commandName.toLowerCase()); |
|
75 |
return command; |
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public ReportServerConfig getConfig() { |
|
80 |
return this.config; |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
public ReportServices getServices() { |
|
85 |
if (this.getConfig() == null) { |
|
86 |
return null; |
|
87 |
} |
|
88 |
return this.getConfig().getServices(); |
|
89 |
} |
|
90 |
|
|
91 |
@Override |
|
92 |
public void addLogListener(LoggerListener logger) { |
|
93 |
this.loglisteners.add(logger); |
|
94 |
} |
|
95 |
|
|
96 |
@Override |
|
97 |
public void removeLogListener(LoggerListener logger) { |
|
98 |
this.loglisteners.remove(logger); |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
|
102 |
public URL getURL(String path) { |
|
103 |
if( StringUtils.isBlank(path) ) { |
|
104 |
return null; |
|
105 |
} |
|
106 |
try { |
|
107 |
URL url = new URL("http", "localhost", this.config.getPort(),path); |
|
108 |
return url; |
|
109 |
} catch (MalformedURLException ex) { |
|
110 |
return null; |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
@Override |
|
115 |
public String getHost() { |
|
116 |
String host = "http://localhost:" + this.config.getPort(); |
|
117 |
return host; |
|
118 |
} |
|
119 |
|
|
120 |
@Override |
|
121 |
public void log(int level, String message) { |
|
122 |
switch (level) { |
|
123 |
default: |
|
124 |
case INFO: |
|
125 |
LOG.info(message); |
|
126 |
break; |
|
127 |
case WARN: |
|
128 |
LOG.warn(message); |
|
129 |
break; |
|
130 |
case DEBUG: |
|
131 |
LOG.debug(message); |
|
132 |
break; |
|
133 |
} |
|
134 |
for (LoggerListener logger : loglisteners) { |
|
135 |
logger.log(level, message); |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
@Override |
|
140 |
public synchronized void start() { |
|
141 |
if (this.server != null) { |
|
142 |
this.stop(); |
|
143 |
} |
|
144 |
|
|
145 |
final IOReactorConfig theConfig = IOReactorConfig.custom() |
|
146 |
.setSoTimeout(this.config.getTimeout()) |
|
147 |
.setTcpNoDelay(true) |
|
148 |
.build(); |
|
149 |
|
|
150 |
this.server = ServerBootstrap.bootstrap() |
|
151 |
.setListenerPort(this.config.getPort()) |
|
152 |
.setServerInfo(this.config.getServerInfo()) |
|
153 |
.setIOReactorConfig(theConfig) |
|
154 |
.setExceptionLogger(ExceptionLogger.STD_ERR) |
|
155 |
.registerHandler("*", new HttpHandler(this)) |
|
156 |
.create(); |
|
157 |
|
|
158 |
try { |
|
159 |
this.server.start(); |
|
160 |
//this.server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); |
|
161 |
servers.add(this.server); |
|
162 |
log(INFO, "Server started."); |
|
163 |
} catch (Exception ex) { |
|
164 |
} |
|
165 |
|
|
166 |
} |
|
167 |
|
|
168 |
@Override |
|
169 |
public void reload() { |
|
170 |
|
|
171 |
} |
|
172 |
|
|
173 |
@Override |
|
174 |
public synchronized boolean isStarted() { |
|
175 |
return this.server != null; |
|
176 |
} |
|
177 |
|
|
178 |
@Override |
|
179 |
@SuppressWarnings("SleepWhileHoldingLock") |
|
180 |
public synchronized void stop() { |
|
181 |
if (this.server == null) { |
|
182 |
log(INFO, "Server already stoped."); |
|
183 |
return; |
|
184 |
} |
|
185 |
this.server.shutdown(5, TimeUnit.SECONDS); |
|
186 |
try { |
|
187 |
Thread.sleep(6000); |
|
188 |
} catch (InterruptedException ex) { |
|
189 |
} |
|
190 |
servers.remove(this.server); |
|
191 |
this.server = null; |
|
192 |
log(INFO, "Server stoped."); |
|
193 |
} |
|
194 |
|
|
195 |
} |
org.gvsig.report/tags/org.gvsig.report-1.0.35/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/ReportSymbolTable.java | ||
---|---|---|
1 |
package org.gvsig.report.lib.impl; |
|
2 |
|
|
3 |
import org.apache.commons.lang3.Range; |
|
4 |
import org.gvsig.expressionevaluator.Interpreter; |
|
5 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
|
6 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
|
7 |
import static org.gvsig.report.lib.api.ReportManager.FUNCTION_REPORT_VALUE; |
|
8 |
|
|
9 |
/** |
|
10 |
* |
|
11 |
* @author jjdelcerro |
|
12 |
*/ |
|
13 |
public class ReportSymbolTable extends AbstractSymbolTable { |
|
14 |
|
|
15 |
private Object currentValue; |
|
16 |
|
|
17 |
public class ReportValueFunction extends AbstractFunction { |
|
18 |
|
|
19 |
public ReportValueFunction() { |
|
20 |
super( |
|
21 |
"Report", |
|
22 |
FUNCTION_REPORT_VALUE, |
|
23 |
Range.is(1), |
|
24 |
"Access to the fields of the current row of the report.", |
|
25 |
FUNCTION_REPORT_VALUE+"({{field_name}})", |
|
26 |
new String[] { |
|
27 |
"field_name - Name of the field in the current row to acess" |
|
28 |
}, |
|
29 |
"Object", |
|
30 |
false |
|
31 |
); |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
36 |
return currentValue; |
|
37 |
} |
|
38 |
|
|
39 |
} |
|
40 |
|
|
41 |
public ReportSymbolTable() { |
|
42 |
this.addFunction(new ReportValueFunction()); |
|
43 |
} |
|
44 |
|
|
45 |
public void setCurrentValue(Object value) { |
|
46 |
this.currentValue = value; |
|
47 |
} |
|
48 |
} |
org.gvsig.report/tags/org.gvsig.report-1.0.35/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/DefaultReportDataSets.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.report.lib.impl; |
|
7 |
|
|
8 |
import java.beans.PropertyChangeListener; |
|
9 |
import java.beans.PropertyChangeSupport; |
|
10 |
import java.util.ArrayList; |
|
11 |
import org.apache.commons.lang3.StringUtils; |
|
12 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
13 |
import org.gvsig.report.lib.api.ReportDataSet; |
|
14 |
import org.gvsig.report.lib.api.ReportDataSets; |
|
15 |
import org.gvsig.report.lib.api.ReportManager; |
|
16 |
import org.gvsig.report.lib.api.ReportServices; |
|
17 |
|
|
18 |
/** |
|
19 |
* |
|
20 |
* @author jjdelcerro |
|
21 |
*/ |
|
22 |
public class DefaultReportDataSets |
|
23 |
extends ArrayList<ReportDataSet> |
|
24 |
implements ReportDataSets |
|
25 |
{ |
|
26 |
|
|
27 |
private final ReportServices services; |
|
28 |
private final ReportManager manager; |
|
29 |
private final PropertyChangeSupport propertyChangeSupport; |
|
30 |
|
|
31 |
public DefaultReportDataSets(ReportManager manager, ReportServices services) { |
|
32 |
this.services = services; |
|
33 |
this.manager = manager; |
|
34 |
this.propertyChangeSupport = new PropertyChangeSupport(this); |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public ReportDataSet get(String name) { |
|
39 |
for (ReportDataSet dataset : this) { |
|
40 |
if( dataset.getName().equalsIgnoreCase(name) ) { |
|
41 |
return dataset; |
|
42 |
} |
|
43 |
} |
|
44 |
return null; |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
public void add(String name, FeatureStore store) { |
|
49 |
if( !this.isValidName(name) ) { |
|
50 |
name = this.getValidName(name); |
|
51 |
} |
|
52 |
name = this.getUniqueName(name); |
|
53 |
ReportDataSet dataset = this.manager.createDataSet(services, name, store); |
|
54 |
this.add(dataset); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public boolean add(ReportDataSet dataset) { |
|
59 |
String name = dataset.getName(); |
|
60 |
if( !this.isValidName(name) ) { |
|
61 |
name = this.getValidName(name); |
|
62 |
} |
|
63 |
name = this.getUniqueName(name); |
|
64 |
dataset.setName(name); |
|
65 |
boolean x= super.add(dataset); |
|
66 |
this.propertyChangeSupport.firePropertyChange("add", null, null); |
|
67 |
return x; |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
public void remove(String name) { |
|
72 |
ReportDataSet dataset = this.get(name); |
|
73 |
if( dataset == null ) { |
|
74 |
return; |
|
75 |
} |
|
76 |
this.remove(dataset); |
|
77 |
this.propertyChangeSupport.firePropertyChange("remove", null, null); |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
public boolean contains(FeatureStore store) { |
|
82 |
for (ReportDataSet dataset : this) { |
|
83 |
if( dataset.hasThisStore(store) ) { |
|
84 |
return true; |
|
85 |
} |
|
86 |
} |
|
87 |
return false; |
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public boolean contains(String name) { |
|
92 |
return this.get(name)!=null; |
|
93 |
} |
|
94 |
|
|
95 |
@Override |
|
96 |
public boolean isValidName(String name) { |
|
97 |
name = name.toLowerCase(); |
|
98 |
if( !StringUtils.isAlpha(name.substring(0, 1)) ) { |
|
99 |
return false; |
|
100 |
} |
|
101 |
if( StringUtils.containsOnly("abcdefghijklmnopqrstuvwxyz0987654321_") ) { |
|
102 |
return true; |
|
103 |
} |
|
104 |
return false; |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public String getValidName(String name) { |
|
109 |
name = name.toLowerCase(); |
|
110 |
name = StringUtils.normalizeSpace(name); |
|
111 |
name = StringUtils.replaceChars(name, '_', '_'); |
|
112 |
name = StringUtils.replaceChars(name, ' ', '_'); |
|
113 |
name = StringUtils.stripAccents(name); |
|
114 |
name = StringUtils.removeAll(name, "[^a-z0-9_]"); |
|
115 |
return name; |
|
116 |
} |
|
117 |
|
|
118 |
@Override |
|
119 |
public String getUniqueName(String name) { |
|
120 |
if( !this.contains(name) ) { |
|
121 |
return name; |
|
122 |
} |
|
123 |
for (int i = 0; i < 1000; i++) { |
|
124 |
String s = name + "_" + i; |
|
125 |
if( !this.contains(s) ) { |
|
126 |
return s; |
|
127 |
} |
|
128 |
} |
|
129 |
return name + "_" + Long.toHexString(System.currentTimeMillis()); |
|
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
@Override |
|
134 |
public void addPropertyChangeListener(PropertyChangeListener listener) { |
|
135 |
this.propertyChangeSupport.addPropertyChangeListener(listener); |
|
136 |
} |
|
137 |
|
|
138 |
@Override |
|
139 |
public void removePropertyChangeListener(PropertyChangeListener listener) { |
|
140 |
this.propertyChangeSupport.removePropertyChangeListener(listener); |
|
141 |
} |
|
142 |
|
|
143 |
} |
org.gvsig.report/tags/org.gvsig.report-1.0.35/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/ReportExpressionCodeFormatter.java | ||
---|---|---|
1 |
package org.gvsig.report.lib.impl; |
|
2 |
|
|
3 |
import org.apache.commons.lang3.StringUtils; |
|
4 |
import org.gvsig.expressionevaluator.Code; |
|
5 |
import org.gvsig.expressionevaluator.Code.Callable; |
|
6 |
import org.gvsig.expressionevaluator.Code.Constant; |
|
7 |
import org.gvsig.expressionevaluator.Code.Identifier; |
|
8 |
import org.gvsig.expressionevaluator.Codes; |
|
9 |
import org.gvsig.expressionevaluator.Formatter; |
|
10 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
11 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
12 |
import static org.gvsig.report.lib.api.ReportManager.FUNCTION_REPORT_VALUE; |
|
13 |
import org.gvsig.timesupport.DataTypes; |
|
14 |
|
|
15 |
/** |
|
16 |
* |
|
17 |
* @author jjdelcerro |
|
18 |
*/ |
|
19 |
public class ReportExpressionCodeFormatter implements Formatter<Code> { |
|
20 |
|
|
21 |
public class IdentifierQuotesFormatter implements Formatter<Code> { |
|
22 |
|
|
23 |
@Override |
|
24 |
public boolean canApply(Code code) { |
|
25 |
if( code instanceof Identifier ) { |
|
26 |
return true; |
|
27 |
} |
|
28 |
return false; |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public String format(Code code) { |
|
33 |
// https://www.w3schools.com/tags/ref_urlencode.asp |
|
34 |
// Uff, es peor escaparlo, asi que de momento pondre corchetes. |
|
35 |
// return "%22"+((Identifier)code).name()+"%22"; |
|
36 |
return "["+((Identifier)code).name()+"]"; |
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
public class ReportValueFormatter implements Formatter<Code> { |
|
41 |
|
|
42 |
@Override |
|
43 |
public boolean canApply(Code value) { |
|
44 |
if (value instanceof Callable) { |
|
45 |
String name = ((Callable) value).name(); |
|
46 |
if (StringUtils.equals(name, FUNCTION_REPORT_VALUE)) { |
|
47 |
Codes args = ((Callable) value).parameters(); |
|
48 |
if (args.get(0) instanceof Constant |
|
49 |
&& ((Constant) (args.get(0))).value() instanceof String) { |
|
50 |
return true; |
|
51 |
} |
|
52 |
} |
|
53 |
} |
|
54 |
return false; |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public String format(Code value) { |
|
59 |
Codes args = ((Callable) value).parameters(); |
|
60 |
String fieldName = ((Constant) (args.get(0))).value().toString(); |
|
61 |
FeatureAttributeDescriptor attrdesc = featureType.getAttributeDescriptor(fieldName); |
|
62 |
switch(attrdesc.getType()) { |
|
63 |
case DataTypes.STRING: |
|
64 |
return "'\"+$F{" + fieldName + "}+\"'"; |
|
65 |
case DataTypes.INT: |
|
66 |
case DataTypes.LONG: |
|
67 |
case DataTypes.FLOAT: |
|
68 |
case DataTypes.DOUBLE: |
|
69 |
return "\"+$F{" + fieldName + "}+\""; |
|
70 |
default: // ??? |
|
71 |
return "'\"+$F{" + fieldName + "}+\"'"; |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
} |
|
76 |
|
|
77 |
private final Formatter<Code>[] formatters; |
|
78 |
private final FeatureType featureType; |
|
79 |
|
|
80 |
public ReportExpressionCodeFormatter(FeatureType featureType) { |
|
81 |
this.featureType = featureType; |
|
82 |
this.formatters = new Formatter[]{ |
|
83 |
new IdentifierQuotesFormatter(), |
|
84 |
new ReportValueFormatter() |
|
85 |
}; |
|
86 |
} |
|
87 |
|
|
88 |
@Override |
|
89 |
public boolean canApply(Code code) { |
|
90 |
for (Formatter<Code> formatter : formatters) { |
|
91 |
if (formatter.canApply(code)) { |
|
92 |
return true; |
|
93 |
} |
|
94 |
} |
|
95 |
return false; |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public String format(Code code) { |
|
100 |
for (Formatter<Code> formatter : formatters) { |
|
101 |
if (formatter.canApply(code)) { |
|
102 |
return formatter.format(code); |
|
103 |
} |
|
104 |
} |
|
105 |
return code.toString(); |
|
106 |
} |
|
107 |
|
|
108 |
} |
org.gvsig.report/tags/org.gvsig.report-1.0.35/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/DefaultReportManager.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.report.lib.impl; |
|
25 |
|
|
26 |
import java.util.Collection; |
|
27 |
import java.util.LinkedHashMap; |
|
28 |
import java.util.Map; |
|
29 |
import javax.json.JsonObject; |
|
30 |
import org.apache.commons.lang3.StringUtils; |
|
31 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
32 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
34 |
import org.gvsig.report.lib.api.Report; |
|
35 |
import org.gvsig.report.lib.api.ReportBuilder; |
|
36 |
import org.gvsig.report.lib.api.ReportConfig; |
|
37 |
import org.json.JSONObject; |
|
38 |
import org.gvsig.report.lib.api.ReportDataSet; |
|
39 |
import org.gvsig.report.lib.api.ReportManager; |
|
40 |
import org.gvsig.report.lib.api.ReportServer; |
|
41 |
import org.gvsig.report.lib.api.ReportServerConfig; |
|
42 |
import org.gvsig.report.lib.api.ReportServices; |
|
43 |
import org.gvsig.report.lib.api.ReportViewCapture; |
|
44 |
import org.gvsig.report.lib.api.commands.CommandFactory; |
|
45 |
import org.gvsig.report.lib.impl.commands.CaptureViewFactory; |
|
46 |
import org.gvsig.report.lib.impl.commands.GetDatasetFactory; |
|
47 |
import org.gvsig.report.lib.impl.commands.GetImageFactory; |
|
48 |
import org.gvsig.report.lib.impl.commands.HelpFactory; |
|
49 |
import org.gvsig.report.lib.impl.commands.ListDatasetsFactory; |
|
50 |
import org.gvsig.report.lib.impl.commands.ListViewsFactory; |
|
51 |
import org.gvsig.report.lib.impl.reportbuilder.DefaultReportBuilder; |
|
52 |
import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
|
53 |
import org.gvsig.tools.bookmarksandhistory.History; |
|
54 |
import org.gvsig.tools.bookmarksandhistory.impl.BaseBookmarks; |
|
55 |
import org.gvsig.tools.bookmarksandhistory.impl.BaseHistory; |
|
56 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
|
57 |
|
|
58 |
/** |
|
59 |
* |
|
60 |
* @author jjdelcerro |
|
61 |
*/ |
|
62 |
public class DefaultReportManager implements ReportManager { |
|
63 |
|
|
64 |
private ReportServer defaultServer = null; |
|
65 |
|
|
66 |
private final Map<String, CommandFactory> commandFactories; |
|
67 |
private Bookmarks<ReportBuilder> userDefinedReportBookmarks; |
|
68 |
private History<ReportBuilder> userDefinedReportHistory; |
|
69 |
|
|
70 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
|
71 |
public DefaultReportManager() { |
|
72 |
this.commandFactories = new LinkedHashMap<>(); |
|
73 |
|
|
74 |
this.registerCommandFactory(new CaptureViewFactory()); |
|
75 |
this.registerCommandFactory(new GetDatasetFactory()); |
|
76 |
this.registerCommandFactory(new HelpFactory()); |
|
77 |
this.registerCommandFactory(new ListDatasetsFactory()); |
|
78 |
this.registerCommandFactory(new ListViewsFactory()); |
|
79 |
this.registerCommandFactory(new GetImageFactory()); |
|
80 |
|
|
81 |
this.userDefinedReportBookmarks = new BaseBookmarks<>(); |
|
82 |
this.userDefinedReportHistory = new BaseHistory<>(20); |
|
83 |
} |
|
84 |
|
|
85 |
@Override |
|
86 |
public Collection<CommandFactory> getCommandFactories() { |
|
87 |
return commandFactories.values(); |
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public void registerCommandFactory(CommandFactory factory) { |
|
92 |
this.commandFactories.put(factory.getName(), factory); |
|
93 |
} |
|
94 |
|
|
95 |
@Override |
|
96 |
public ReportServer getDefaultServer() { |
|
97 |
return this.defaultServer; |
|
98 |
} |
|
99 |
|
|
100 |
@Override |
|
101 |
public void setDefaultServer(ReportServer server) { |
|
102 |
this.defaultServer = server; |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
public ReportServer createServer(ReportServerConfig config) { |
|
107 |
DefaultReportServer server = new DefaultReportServer(this, config); |
|
108 |
if (this.defaultServer == null) { |
|
109 |
this.defaultServer = server; |
|
110 |
} |
|
111 |
return server; |
|
112 |
} |
|
113 |
|
|
114 |
@Override |
|
115 |
public ReportDataSet createDataSet( |
|
116 |
ReportServices services, |
|
117 |
String name, |
|
118 |
FeatureStore store |
|
119 |
) { |
|
120 |
return new DefaultReportDataSet(services, name, store); |
|
121 |
} |
|
122 |
|
|
123 |
@Override |
|
124 |
public ReportServerConfig createServerConfig(ReportServices services) { |
|
125 |
DefaultReportServerConfig config = new DefaultReportServerConfig(this, services); |
|
126 |
return config; |
|
127 |
} |
|
128 |
|
|
129 |
@Override |
|
130 |
public ReportServerConfig createServerConfig(ReportServices services, String jsonConfig) { |
|
131 |
DefaultReportServerConfig config = new DefaultReportServerConfig(this, services); |
|
132 |
if (!StringUtils.isEmpty(jsonConfig)) { |
|
133 |
config.fromJSON(new JSONObject(jsonConfig)); |
|
134 |
} |
|
135 |
return config; |
|
136 |
} |
|
137 |
|
|
138 |
@Override |
|
139 |
public ReportViewCapture createViewCapture(ReportServerConfig config) { |
|
140 |
return new DefaultReportViewCapture(config); |
|
141 |
} |
|
142 |
|
|
143 |
@Override |
|
144 |
public SymbolTable createReportSymbolTable() { |
|
145 |
return new ReportSymbolTable(); |
|
146 |
} |
|
147 |
|
|
148 |
@Override |
|
149 |
public ReportBuilder createReportBuilder() { |
|
150 |
ReportBuilder r = new DefaultReportBuilder(); |
|
151 |
return r; |
|
152 |
} |
|
153 |
|
|
154 |
@Override |
|
155 |
public Bookmarks<ReportBuilder> getUserDefinedReportBookmarks() { |
|
156 |
return this.userDefinedReportBookmarks; |
|
157 |
} |
|
158 |
|
|
159 |
@Override |
|
160 |
public History<ReportBuilder> getUserDefinedReportHistory() { |
|
161 |
return this.userDefinedReportHistory; |
|
162 |
} |
|
163 |
|
|
164 |
@Override |
|
165 |
public void setUserDefinedReportHistory(History<ReportBuilder> history) { |
|
166 |
this.userDefinedReportHistory = history; |
|
167 |
} |
|
168 |
|
|
169 |
@Override |
|
170 |
public void setUserDefinedReportBookmarks(Bookmarks<ReportBuilder> userDefinedReportBookmarks) { |
|
171 |
this.userDefinedReportBookmarks = userDefinedReportBookmarks; |
|
172 |
} |
|
173 |
|
|
174 |
@Override |
|
175 |
public ReportDataSet createDataSet(FeatureStore store) { |
|
176 |
return new DefaultReportDataSet(this.defaultServer.getServices(), store.getName(), store); |
|
177 |
} |
|
178 |
|
|
179 |
@Override |
|
180 |
public ReportDataSet createDataSet(FeatureStore store, FeatureQuery query) { |
|
181 |
return new DefaultReportDataSet(this.defaultServer.getServices(), store.getName(), store, query); |
|
182 |
} |
|
183 |
|
|
184 |
@Override |
|
185 |
public Report createReport(ReportConfig config) { |
|
186 |
DefaultReport r = new DefaultReport(config); |
|
187 |
return r; |
|
188 |
} |
|
189 |
|
|
190 |
@Override |
|
191 |
public ReportConfig createReportConfig() { |
|
192 |
DefaultReportConfig r = new DefaultReportConfig(); |
|
193 |
return r; |
|
194 |
} |
|
195 |
|
|
196 |
} |
org.gvsig.report/tags/org.gvsig.report-1.0.35/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/HttpHandler.java | ||
---|---|---|
1 |
package org.gvsig.report.lib.impl; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.net.URLDecoder; |
|
5 |
import java.util.Locale; |
|
6 |
import org.apache.commons.lang3.StringUtils; |
|
7 |
import org.apache.http.HttpException; |
|
8 |
import org.apache.http.HttpRequest; |
|
9 |
import org.apache.http.HttpResponse; |
|
10 |
import org.apache.http.HttpStatus; |
|
11 |
import org.apache.http.MethodNotSupportedException; |
|
12 |
import org.apache.http.entity.ByteArrayEntity; |
|
13 |
import org.apache.http.entity.ContentType; |
|
14 |
import org.apache.http.nio.entity.NStringEntity; |
|
15 |
import org.apache.http.nio.protocol.BasicAsyncRequestConsumer; |
|
16 |
import org.apache.http.nio.protocol.BasicAsyncResponseProducer; |
|
17 |
import org.apache.http.nio.protocol.HttpAsyncExchange; |
|
18 |
import org.apache.http.nio.protocol.HttpAsyncRequestConsumer; |
|
19 |
import org.apache.http.nio.protocol.HttpAsyncRequestHandler; |
|
20 |
import org.apache.http.protocol.HttpContext; |
|
21 |
import static org.gvsig.report.lib.api.ReportServer.INFO; |
|
22 |
import static org.gvsig.report.lib.api.ReportServer.WARN; |
|
23 |
import org.gvsig.report.lib.api.commands.Command; |
|
24 |
import org.slf4j.Logger; |
|
25 |
import org.slf4j.LoggerFactory; |
|
26 |
|
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
* @author jjdelcerro |
|
31 |
*/ |
|
32 |
public class HttpHandler implements HttpAsyncRequestHandler<HttpRequest> { |
|
33 |
|
|
34 |
private static final Logger LOG = LoggerFactory.getLogger(HttpHandler.class); |
|
35 |
|
|
36 |
private final DefaultReportServer server; |
|
37 |
|
|
38 |
public HttpHandler(DefaultReportServer server) { |
|
39 |
super(); |
|
40 |
this.server = server; |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public HttpAsyncRequestConsumer<HttpRequest> processRequest( |
|
45 |
final HttpRequest request, |
|
46 |
final HttpContext context) { |
|
47 |
// Buffer request content in memory for simplicity |
|
48 |
return new BasicAsyncRequestConsumer(); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public void handle( |
|
53 |
final HttpRequest request, |
|
54 |
final HttpAsyncExchange httpexchange, |
|
55 |
final HttpContext context) throws HttpException, IOException { |
|
56 |
final HttpResponse response = httpexchange.getResponse(); |
|
57 |
handleInternal(request, response, context); |
|
58 |
httpexchange.submitResponse(new BasicAsyncResponseProducer(response)); |
|
59 |
} |
|
60 |
|
|
61 |
private void handleInternal( |
|
62 |
final HttpRequest request, |
|
63 |
final HttpResponse response, |
|
64 |
final HttpContext context) throws HttpException, IOException { |
|
65 |
|
|
66 |
final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH); |
|
67 |
if (!method.equals("GET")) { |
|
68 |
this.server.log(WARN, "Method not supported, Only GET supported."); |
|
69 |
throw new MethodNotSupportedException(method + " method not supported"); |
|
70 |
} |
|
71 |
|
|
72 |
final String target = request.getRequestLine().getUri(); |
|
73 |
final String line = URLDecoder.decode(target, "UTF-8"); |
|
74 |
final String[] args = StringUtils.split(line, '/'); |
|
75 |
final int argc = args.length -1; |
|
76 |
|
|
77 |
Command command = this.server.getCommand(args[0]); |
|
78 |
if( command == null) { |
|
79 |
this.server.log(WARN, "Command '"+line+"' not found."); |
|
80 |
response.setStatusCode(HttpStatus.SC_NOT_FOUND); |
|
81 |
final NStringEntity entity = new NStringEntity( |
|
82 |
"<html><body><h1>Command " + line |
|
83 |
+ " not found</h1></body></html>", |
|
84 |
ContentType.create("text/html", "UTF-8")); |
|
85 |
response.setEntity(entity); |
|
86 |
return; |
|
87 |
} |
|
88 |
if( !command.getNumArgs().contains(argc) ) { |
|
89 |
this.server.log(WARN, "Command '"+line+"', invalid number of arguments."); |
|
90 |
response.setStatusCode(HttpStatus.SC_BAD_REQUEST); |
|
91 |
final NStringEntity entity = new NStringEntity( |
|
92 |
"<html><body><h1>Number of arguments invalid in " + line |
|
93 |
+ "</h1></body></html>", |
|
94 |
ContentType.create("text/html", "UTF-8")); |
|
95 |
response.setEntity(entity); |
|
96 |
return; |
|
97 |
} |
|
98 |
Object ret; |
|
99 |
try { |
|
100 |
ret = command.call(argc, args); |
|
101 |
} catch(Exception ex) { |
|
102 |
LOG.warn("Can't server command '"+line+"'.", ex); |
|
103 |
this.server.log(WARN, "Command '"+line+"', error "+ex.getMessage()+"."); |
|
104 |
response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); |
|
105 |
final NStringEntity entity = new NStringEntity( |
|
106 |
"<html><body><h1>Error processing " + line |
|
107 |
+ "</h1><p>"+ex.toString()+"</p></body></html>", |
|
108 |
ContentType.create("text/html", "UTF-8")); |
|
109 |
response.setEntity(entity); |
|
110 |
return; |
|
111 |
} |
|
112 |
if( ret == null ) { |
|
113 |
this.server.log(WARN, "Command '"+line+"' return null."); |
|
114 |
response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); |
|
115 |
final NStringEntity entity = new NStringEntity( |
|
116 |
"<html><body><h1>Process " + line |
|
117 |
+ " return null</h1></body></html>", |
|
118 |
ContentType.create("text/html", "UTF-8")); |
|
119 |
response.setEntity(entity); |
|
120 |
return; |
|
121 |
} |
|
122 |
if( ret instanceof byte[] ) { |
|
123 |
response.setStatusCode(HttpStatus.SC_OK); |
|
124 |
final ByteArrayEntity entity = new ByteArrayEntity( |
|
125 |
(byte[]) ret, |
|
126 |
ContentType.create(command.getMimeType(), "UTF-8")); |
|
127 |
response.setEntity(entity); |
|
128 |
this.server.log(INFO, "Command '"+line+"' ok."); |
|
129 |
return; |
|
130 |
} |
|
131 |
response.setStatusCode(HttpStatus.SC_OK); |
|
132 |
final NStringEntity entity = new NStringEntity( |
|
133 |
ret.toString(), |
|
134 |
ContentType.create(command.getMimeType(), "UTF-8")); |
|
135 |
response.setEntity(entity); |
|
136 |
this.server.log(INFO, "Command '"+line+"' ok."); |
|
137 |
} |
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
} |
org.gvsig.report/tags/org.gvsig.report-1.0.35/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/DefaultSelectionOfFeatures.java | ||
---|---|---|
1 |
package org.gvsig.report.lib.impl; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Iterator; |
|
5 |
import java.util.List; |
|
6 |
import java.util.NoSuchElementException; |
|
7 |
import org.apache.commons.collections.CollectionUtils; |
|
8 |
import org.apache.commons.lang3.mutable.MutableInt; |
|
9 |
import org.gvsig.fmap.dal.exception.DataException; |
|
10 |
import org.gvsig.fmap.dal.feature.Feature; |
|
11 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
12 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
13 |
import org.gvsig.report.lib.api.ReportDataSet.SelectionOfFeatures; |
|
14 |
import org.gvsig.tools.ToolsLocator; |
|
15 |
import org.gvsig.tools.exception.BaseException; |
|
16 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
17 |
import org.gvsig.tools.task.TaskStatusManager; |
|
18 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
19 |
import org.gvsig.tools.visitor.Visitable; |
|
20 |
import org.gvsig.tools.visitor.Visitor; |
|
21 |
|
|
22 |
/** |
|
23 |
* |
|
24 |
* @author jjdelcerro |
|
25 |
*/ |
|
26 |
public class DefaultSelectionOfFeatures |
|
27 |
implements SelectionOfFeatures { |
|
28 |
|
|
29 |
private class FeatureReferenceIteratorToFeatureIteratorAdapter implements Iterator<Feature> { |
|
30 |
|
|
31 |
private final Iterator<FeatureReference> iterator; |
|
32 |
private int count; |
|
33 |
|
|
34 |
public FeatureReferenceIteratorToFeatureIteratorAdapter(Iterator<FeatureReference> iterator) { |
|
35 |
this.iterator = iterator; |
|
36 |
this.count = 0; |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public boolean hasNext() { |
|
41 |
int limit = dataSet.getLimit(); |
|
42 |
if (limit < this.count) { |
|
43 |
return false; |
|
44 |
} |
|
45 |
return this.iterator.hasNext(); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public Feature next() { |
|
50 |
int limit = dataSet.getLimit(); |
|
51 |
if (limit < this.count) { |
|
52 |
throw new NoSuchElementException(); |
|
53 |
} |
|
54 |
this.count++; |
|
55 |
FeatureReference fr = this.iterator.next(); |
|
56 |
try { |
|
57 |
return fr.getFeature(); |
|
58 |
} catch (DataException ex) { |
|
59 |
throw new RuntimeException(ex); |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
} |
|
64 |
|
|
65 |
private List<FeatureReference> references; |
|
66 |
private List<String> referenceCodes; |
|
67 |
private final DefaultReportDataSet dataSet; |
|
68 |
|
|
69 |
public DefaultSelectionOfFeatures(DefaultReportDataSet dataSet) { |
|
70 |
this.dataSet = dataSet; |
|
71 |
this.references = new ArrayList<>(); |
|
72 |
this.referenceCodes = null; |
|
73 |
} |
|
74 |
|
|
75 |
private void resolveReferenceCodes() { |
|
76 |
if (this.referenceCodes == null) { |
|
77 |
return; |
|
78 |
} |
|
79 |
for (String referenceCode : this.referenceCodes) { |
|
80 |
FeatureReference reference = this.dataSet.getStore().getFeatureReference(referenceCode); |
|
81 |
this.references.add(reference); |
|
82 |
} |
|
83 |
this.referenceCodes = null; |
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public Feature get64(long pos) { |
|
88 |
if (this.referenceCodes != null) { |
|
89 |
this.resolveReferenceCodes(); |
|
90 |
} |
|
91 |
int limit = this.dataSet.getLimit(); |
|
92 |
if (limit > 0 && pos > limit) { |
|
93 |
throw new ArrayIndexOutOfBoundsException((int) pos); |
|
94 |
} |
|
95 |
try { |
|
96 |
FeatureReference reference = this.references.get((int) pos); |
|
97 |
return reference.getFeature(); |
|
98 |
} catch (DataException ex) { |
|
99 |
throw new RuntimeException("Can't retrieve feature from reference.", ex); |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
public FeatureReference getReference(int pos) { |
|
104 |
if (this.referenceCodes != null) { |
|
105 |
this.resolveReferenceCodes(); |
|
106 |
} |
|
107 |
FeatureReference reference = this.references.get(pos); |
|
108 |
return reference; |
|
109 |
} |
|
110 |
|
|
111 |
|
|
112 |
@Override |
|
113 |
public long size64() { |
|
114 |
int limit = this.dataSet.getLimit(); |
|
115 |
int size; |
|
116 |
if (this.referenceCodes == null) { |
|
117 |
size = this.references.size(); |
|
118 |
} else { |
|
119 |
size = this.referenceCodes.size(); |
|
120 |
} |
|
121 |
if (limit > 0 && limit < size) { |
|
122 |
size = limit; |
|
123 |
} |
|
124 |
return size; |
|
125 |
} |
|
126 |
|
Also available in: Unified diff