Revision 2009
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.ods.lib.impl.ODSImplLibrary |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.impl/src/main/java/org/gvsig/ods/lib/impl/DefaultODSManager.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.ods.lib.impl; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
import org.gvsig.ods.lib.api.ODSDocument; |
|
28 |
import org.gvsig.ods.lib.api.ODSManager; |
|
29 |
|
|
30 |
public class DefaultODSManager implements ODSManager { |
|
31 |
|
|
32 |
@Override |
|
33 |
public ODSDocument createODSDocument(byte[] document) { |
|
34 |
DefaultODSDocument doc = new DefaultODSDocument(); |
|
35 |
doc.setSource(document); |
|
36 |
return doc; |
|
37 |
} |
|
38 |
|
|
39 |
// public ODSDocument createODSDocument(String document) { |
|
40 |
// DefaultODSDocument doc = new DefaultODSDocument(); |
|
41 |
// doc.setDocument(document); |
|
42 |
// return doc; |
|
43 |
// } |
|
44 |
|
|
45 |
@Override |
|
46 |
public ODSDocument createODSDocument(File document) { |
|
47 |
DefaultODSDocument doc = new DefaultODSDocument(); |
|
48 |
doc.setSource(document); |
|
49 |
return doc; |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public ODSDocument createODSDocument() { |
|
54 |
DefaultODSDocument doc = new DefaultODSDocument(); |
|
55 |
return doc; |
|
56 |
} |
|
57 |
|
|
58 |
} |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.impl/src/main/java/org/gvsig/ods/lib/impl/ODSProfile.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.ods.lib.impl; |
|
7 |
|
|
8 |
import java.io.File; |
|
9 |
import org.gvsig.fmap.dal.DALLocator; |
|
10 |
import org.gvsig.fmap.dal.DataManager; |
|
11 |
import org.gvsig.fmap.dal.feature.AbstractDataProfile; |
|
12 |
import org.gvsig.ods.lib.api.ODSDocument; |
|
13 |
import org.gvsig.ods.lib.api.ODSLocator; |
|
14 |
import org.gvsig.ods.lib.api.ODSManager; |
|
15 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
16 |
import org.gvsig.tools.dataTypes.DataType; |
|
17 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
18 |
import org.gvsig.tools.dynobject.Tags; |
|
19 |
|
|
20 |
public class ODSProfile extends AbstractDataProfile { |
|
21 |
|
|
22 |
public ODSProfile() { |
|
23 |
super("ODS", File.class); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public Object createData(Object ods, Tags tags) { |
|
28 |
ODSManager manager = ODSLocator.getODSManager(); |
|
29 |
ODSDocument odsdoc = manager.createODSDocument(); |
|
30 |
odsdoc.setSource(ods); |
|
31 |
return odsdoc; |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public Object coerce(DataType dataType, Object data, Tags tags) throws CoercionException { |
|
36 |
ODSDocument document; |
|
37 |
try { |
|
38 |
switch (dataType.getType()) { |
|
39 |
case DataTypes.BYTEARRAY: |
|
40 |
document = ODSLocator.getODSManager().createODSDocument(); |
|
41 |
document.setSource(data); |
|
42 |
return document.toByteArray(); |
|
43 |
case DataTypes.FILE: |
|
44 |
if (data instanceof File) { |
|
45 |
return data; |
|
46 |
} |
|
47 |
case DataTypes.STRING: |
|
48 |
document = ODSLocator.getODSManager().createODSDocument(); |
|
49 |
document.setSource(data); |
|
50 |
return document.toHexString(); |
|
51 |
default: |
|
52 |
break; |
|
53 |
} |
|
54 |
} catch (Exception ex) { |
|
55 |
throw new CoercionException("Can't convert ODS to " + dataType.getName(), ex); |
|
56 |
} |
|
57 |
throw new CoercionException("Can't convert ODS to " + dataType.getName()); |
|
58 |
} |
|
59 |
|
|
60 |
public static void selfRegister() { |
|
61 |
DataManager dataManager = DALLocator.getDataManager(); |
|
62 |
dataManager.registerDataProfile(new ODSProfile()); |
|
63 |
} |
|
64 |
} |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.impl/src/main/java/org/gvsig/ods/lib/impl/SpreadSODS.java | ||
---|---|---|
1 |
package org.gvsig.ods.lib.impl; |
|
2 |
|
|
3 |
import com.github.miachm.SODS.spreadsheet.SpreadSheet; |
|
4 |
import java.io.File; |
|
5 |
import java.io.FileInputStream; |
|
6 |
import java.io.IOException; |
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.Collections; |
|
9 |
import java.util.List; |
|
10 |
import java.util.Locale; |
|
11 |
import java.util.Objects; |
|
12 |
import org.apache.commons.lang3.StringUtils; |
|
13 |
import com.github.miachm.SODS.spreadsheet.Range; |
|
14 |
import java.awt.Rectangle; |
|
15 |
import java.io.FileNotFoundException; |
|
16 |
import java.io.InputStream; |
|
17 |
import org.apache.commons.io.IOUtils; |
|
18 |
import org.gvsig.ods.lib.api.ODSDocument.Sheet; |
|
19 |
import org.slf4j.Logger; |
|
20 |
import org.slf4j.LoggerFactory; |
|
21 |
|
|
22 |
/** |
|
23 |
* |
|
24 |
* @author jjdelcerro |
|
25 |
*/ |
|
26 |
public class SpreadSODS implements Spread { |
|
27 |
|
|
28 |
private static final Logger LOGGER = LoggerFactory.getLogger(SpreadSODS.class); |
|
29 |
|
|
30 |
@Override |
|
31 |
public File getFile() { |
|
32 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
33 |
} |
|
34 |
|
|
35 |
private static class SODSSheet implements Sheet { |
|
36 |
|
|
37 |
private int sheetIndex; |
|
38 |
private com.github.miachm.SODS.spreadsheet.Sheet ODSSheet; |
|
39 |
private Range usedRange = null; |
|
40 |
|
|
41 |
public SODSSheet(InputStream odsis, int sheetIndex, Locale locale) throws IOException { |
|
42 |
try { |
|
43 |
SpreadSheet spread = new SpreadSheet(odsis, locale); |
|
44 |
this.ODSSheet = spread.getSheet(sheetIndex); |
|
45 |
} finally { |
|
46 |
odsis.reset(); |
|
47 |
} |
|
48 |
this.sheetIndex = sheetIndex; |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public int getColumnCount() { |
|
53 |
// return this.ODSSheet.getMaxColumns(); |
|
54 |
return this.getUsedData().getNumColumns(); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public Rectangle getUsedRange() { |
|
59 |
Range x = this.getUsedData(); |
|
60 |
return new Rectangle(x.getColumn(), x.getRow(), x.getNumColumns(), x.getNumRows()); |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public List<String> getColumnNames(boolean isFirstLineHedaer) { |
|
65 |
int columns = this.getColumnCount(); |
|
66 |
List<String> columnNames = new ArrayList<>(columns); |
|
67 |
|
|
68 |
String abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
69 |
if (columns > abc.length()) { |
|
70 |
for (int i = 0; i < columns; i++) { |
|
71 |
columnNames.add("C" + i); |
|
72 |
} |
|
73 |
} else { |
|
74 |
for (int i = 0; i < columns; i++) { |
|
75 |
columnNames.add(abc.substring(i, i + 1)); |
|
76 |
} |
|
77 |
} |
|
78 |
if (isFirstLineHedaer) { |
|
79 |
for (int col = 0; col < columns; col++) { |
|
80 |
Object value = this.getValueAt(col, 0); |
|
81 |
String s = Objects.toString(value); |
|
82 |
if (!StringUtils.isBlank(s)) { |
|
83 |
columnNames.set(col, s); |
|
84 |
} |
|
85 |
} |
|
86 |
} |
|
87 |
return columnNames; |
|
88 |
} |
|
89 |
|
|
90 |
private Range getUsedData() { |
|
91 |
if (this.usedRange == null) { |
|
92 |
Range data = this.ODSSheet.getDataRange(); |
|
93 |
int minCol = -1, minRow = -1, maxCol = -1, maxRow = -1; |
|
94 |
final int colCount = data.getNumColumns(); |
|
95 |
final int rowCount = data.getNumRows(); |
|
96 |
for (int row = 0; row < rowCount; row++) { |
|
97 |
for (int col = 0; col < colCount; col++) { |
|
98 |
Object value = data.getCell(row, col).getValue(); |
|
99 |
if (value != null) { |
|
100 |
if (minCol < 0 || col < minCol) { |
|
101 |
minCol = col; |
|
102 |
} |
|
103 |
if (minRow < 0 || row < minRow) { |
|
104 |
minRow = row; |
|
105 |
} |
|
106 |
|
|
107 |
if (maxCol < 0 || col > maxCol) { |
|
108 |
maxCol = col; |
|
109 |
} |
|
110 |
if (maxRow < 0 || row > maxRow) { |
|
111 |
maxRow = row; |
|
112 |
} |
|
113 |
} |
|
114 |
} |
|
115 |
} |
|
116 |
this.usedRange = this.ODSSheet.getRange(minRow, minCol, maxRow - minRow+1, maxCol - minCol+1); |
|
117 |
} |
|
118 |
return this.usedRange; |
|
119 |
} |
|
120 |
|
|
121 |
@Override |
|
122 |
public String getName() { |
|
123 |
return this.ODSSheet.getName(); |
|
124 |
} |
|
125 |
|
|
126 |
@Override |
|
127 |
public int getRowCount() { |
|
128 |
// return this.ODSSheet.getMaxRows(); |
|
129 |
return this.getUsedData().getNumRows(); |
|
130 |
} |
|
131 |
|
|
132 |
@Override |
|
133 |
public int getSheetIndex() { |
|
134 |
return this.sheetIndex; |
|
135 |
} |
|
136 |
|
|
137 |
@Override |
|
138 |
public Object getValueAt(int col, int row) { |
|
139 |
// return this.ODSSheet.getRange(col, row).getValue(); |
|
140 |
Range data = this.getUsedData(); |
|
141 |
Object value = data.getCell(row, col).getValue(); |
|
142 |
if( row<5 && col<10 ) { |
|
143 |
LOGGER.info("getValueAt: row "+row+", col "+col+", value "+value); |
|
144 |
} |
|
145 |
|
|
146 |
return value; |
|
147 |
} |
|
148 |
|
|
149 |
@Override |
|
150 |
public void close() { |
|
151 |
this.ODSSheet = null; |
|
152 |
this.sheetIndex = -1; |
|
153 |
this.usedRange = null; |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
157 |
private InputStream source; |
|
158 |
private Locale locale; |
|
159 |
|
|
160 |
public SpreadSODS() { |
|
161 |
|
|
162 |
} |
|
163 |
|
|
164 |
@Override |
|
165 |
public void open(File source, Locale locale) { |
|
166 |
FileInputStream is; |
|
167 |
try { |
|
168 |
is = new FileInputStream(source); |
|
169 |
this.open(is, locale); |
|
170 |
} catch (FileNotFoundException ex) { |
|
171 |
throw new RuntimeException("Can' open ODS file '"+Objects.toString(source)+"'.", ex); |
|
172 |
} |
|
173 |
} |
|
174 |
|
|
175 |
public void open(InputStream source, Locale locale) { |
|
176 |
this.source = source; |
|
177 |
this.locale = locale; |
|
178 |
this.source.mark(Integer.MAX_VALUE); |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public void close() throws IOException { |
|
183 |
IOUtils.closeQuietly(this.source); |
|
184 |
this.source = null; |
|
185 |
this.locale = null; |
|
186 |
} |
|
187 |
|
|
188 |
@Override |
|
189 |
public Sheet getSheet(int sheetIndex) { |
|
190 |
try { |
|
191 |
if (source == null || sheetIndex < 0) { |
|
192 |
return null; |
|
193 |
} |
|
194 |
return new SODSSheet(source, sheetIndex, locale); |
|
195 |
} catch (IOException ex) { |
|
196 |
return null; |
|
197 |
} |
|
198 |
} |
|
199 |
|
|
200 |
@Override |
|
201 |
public List<String> getSheetNames() { |
|
202 |
try { |
|
203 |
SpreadSheet spread = new SpreadSheet(source); |
|
204 |
List<String> r = new ArrayList<>(); |
|
205 |
for (int n = 0; n < spread.getNumSheets(); n++) { |
|
206 |
r.add(spread.getSheet(n).getName()); |
|
207 |
} |
|
208 |
return r; |
|
209 |
} catch (IOException ex) { |
|
210 |
return Collections.emptyList(); |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
214 |
|
|
215 |
} |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.impl/src/main/java/org/gvsig/ods/lib/impl/DefaultODSDocument.java | ||
---|---|---|
1 |
package org.gvsig.ods.lib.impl; |
|
2 |
|
|
3 |
import java.awt.Graphics2D; |
|
4 |
import java.io.ByteArrayInputStream; |
|
5 |
import java.io.File; |
|
6 |
import java.io.FileInputStream; |
|
7 |
import java.io.FileNotFoundException; |
|
8 |
import java.io.IOException; |
|
9 |
import java.io.InputStream; |
|
10 |
import java.net.URL; |
|
11 |
import java.util.List; |
|
12 |
import java.util.Locale; |
|
13 |
import org.gvsig.pdf.lib.api.PDFDocument; |
|
14 |
import org.slf4j.LoggerFactory; |
|
15 |
import org.apache.commons.codec.binary.Hex; |
|
16 |
import org.apache.commons.codec.DecoderException; |
|
17 |
import org.apache.commons.codec.binary.Base64; |
|
18 |
import org.apache.commons.io.IOUtils; |
|
19 |
import org.gvsig.ods.lib.api.ODSDocument; |
|
20 |
import org.gvsig.pdf.lib.api.PDFLocator; |
|
21 |
import org.gvsig.pdf.lib.api.PDFManager; |
|
22 |
import org.gvsig.pdf.lib.api.PDFWriter; |
|
23 |
import org.jopendocument.model.OpenDocument; |
|
24 |
import org.jopendocument.renderer.ODTRenderer; |
|
25 |
import org.slf4j.Logger; |
|
26 |
|
|
27 |
/** |
|
28 |
* |
|
29 |
* @author osc |
|
30 |
*/ |
|
31 |
public class DefaultODSDocument implements ODSDocument { |
|
32 |
|
|
33 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultODSDocument.class); |
|
34 |
|
|
35 |
private Object source; |
|
36 |
private Locale locale; |
|
37 |
private Spread spread; |
|
38 |
|
|
39 |
public DefaultODSDocument() { |
|
40 |
|
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public void setSource(File source) { |
|
45 |
this.setSource((Object)source); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public void setSource(Object source) { |
|
50 |
this.source = source; |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
public void setLocale(Locale locale) { |
|
55 |
this.locale = locale; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public void close() { |
|
60 |
this.source = null; |
|
61 |
this.locale = null; |
|
62 |
IOUtils.closeQuietly(this.spread); |
|
63 |
this.spread = null; |
|
64 |
} |
|
65 |
|
|
66 |
public File getFile() { |
|
67 |
if( this.source instanceof File) { |
|
68 |
return (File) this.source; |
|
69 |
} |
|
70 |
return null; |
|
71 |
} |
|
72 |
|
|
73 |
private Spread getSpread() { |
|
74 |
if( this.spread==null ) { |
|
75 |
if( this.getFile()!=null ) { |
|
76 |
try { |
|
77 |
this.spread = new SpreadJOpenDocument(); |
|
78 |
this.spread.open(this.getFile(), this.locale); |
|
79 |
} catch (Exception ex) { |
|
80 |
IOUtils.closeQuietly(this.spread); |
|
81 |
this.spread = null; |
|
82 |
throw new RuntimeException("Can't load spread.", ex); |
|
83 |
} |
|
84 |
} else { |
|
85 |
SpreadSODS theSpread = new SpreadSODS(); |
|
86 |
InputStream is = null; |
|
87 |
try { |
|
88 |
is = this.getInputStream(); |
|
89 |
theSpread.open(is, this.locale); |
|
90 |
} catch (Exception ex) { |
|
91 |
IOUtils.closeQuietly(is); |
|
92 |
IOUtils.closeQuietly(theSpread); |
|
93 |
throw new RuntimeException("Can't load spread.", ex); |
|
94 |
} |
|
95 |
this.spread = theSpread; |
|
96 |
} |
|
97 |
} |
|
98 |
return this.spread; |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
|
102 |
public InputStream getInputStream() throws IOException { |
|
103 |
InputStream is = null; |
|
104 |
if (source == null) { |
|
105 |
return null; |
|
106 |
} else if (source instanceof File) { |
|
107 |
File fileSource = (File) source; |
|
108 |
try { |
|
109 |
is = new FileInputStream(fileSource); |
|
110 |
} catch (IOException ex) { |
|
111 |
LOGGER.warn("Not been able to convert file to input stream", ex); |
|
112 |
throw new IOException(ex); |
|
113 |
} |
|
114 |
} else if (source instanceof URL) { |
|
115 |
URL urlSource = (URL) source; |
|
116 |
try { |
|
117 |
is = urlSource.openStream(); |
|
118 |
} catch (IOException ex) { |
|
119 |
LOGGER.warn("Not been able to open URL stream", ex); |
|
120 |
throw new IOException(ex); |
|
121 |
} |
|
122 |
} else if (source instanceof String) { |
|
123 |
String strSource = (String) source; |
|
124 |
File f = new File(strSource); |
|
125 |
if (f.exists()) { |
|
126 |
try { |
|
127 |
is = new FileInputStream(f); |
|
128 |
} catch (FileNotFoundException ex) { |
|
129 |
LOGGER.warn("Not been able to load existing file", ex); |
|
130 |
throw new IOException(ex); |
|
131 |
} |
|
132 |
} else { |
|
133 |
try { |
|
134 |
URL url = new URL(strSource); |
|
135 |
is = url.openStream(); |
|
136 |
is.available(); // Force exception if is null |
|
137 |
} catch (Exception ex) { |
|
138 |
try { |
|
139 |
byte[] data = Hex.decodeHex(strSource.toCharArray()); |
|
140 |
is = new ByteArrayInputStream(data); |
|
141 |
} catch (DecoderException ex2) { |
|
142 |
try { |
|
143 |
byte[] data = Base64.decodeBase64(strSource); |
|
144 |
is = new ByteArrayInputStream(data); |
|
145 |
} catch (Exception ex3) { |
|
146 |
throw new IOException(ex3); |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
} |
|
151 |
} else if (source instanceof byte[]) { |
|
152 |
byte[] byteSource = (byte[]) source; |
|
153 |
is = new ByteArrayInputStream(byteSource); |
|
154 |
} |
|
155 |
|
|
156 |
return is; |
|
157 |
} |
|
158 |
|
|
159 |
@Override |
|
160 |
public byte[] toByteArray() { |
|
161 |
if (this.source != null) { |
|
162 |
InputStream is= null; |
|
163 |
try { |
|
164 |
is = this.getInputStream(); |
|
165 |
byte[] bytes = new byte[is.available()]; |
|
166 |
is.read(bytes); |
|
167 |
return bytes; |
|
168 |
} catch (IOException ex) { |
|
169 |
LOGGER.warn("Not been able to convert to byte array", ex); |
|
170 |
} finally { |
|
171 |
IOUtils.closeQuietly(is); |
|
172 |
} |
|
173 |
} |
|
174 |
return null; |
|
175 |
|
|
176 |
} |
|
177 |
|
|
178 |
private String bytearray_hex(byte[] data) { |
|
179 |
StringBuilder builder = new StringBuilder(); |
|
180 |
for (byte abyte : data) { |
|
181 |
int v = abyte & 0xff; |
|
182 |
builder.append(String.format("%02x", v)); |
|
183 |
} |
|
184 |
return builder.toString(); |
|
185 |
} |
|
186 |
|
|
187 |
@Override |
|
188 |
public String toHexString() { |
|
189 |
byte[] data = this.toByteArray(); |
|
190 |
return bytearray_hex(data); |
|
191 |
} |
|
192 |
|
|
193 |
@Override |
|
194 |
public PDFDocument createPDF(int pageSize) { |
|
195 |
PDFManager pdfManager = PDFLocator.getPDFManager(); |
|
196 |
|
|
197 |
OpenDocument doc = new OpenDocument(); |
|
198 |
doc.loadFrom(this.getFile()); |
|
199 |
|
|
200 |
PDFWriter writer = pdfManager.createPDFWriter(); |
|
201 |
writer.open(pageSize); |
|
202 |
Graphics2D g = writer.getGraphics2D(); |
|
203 |
|
|
204 |
// Configure the renderer |
|
205 |
ODTRenderer renderer = new ODTRenderer(doc); |
|
206 |
renderer.setIgnoreMargins(true); |
|
207 |
renderer.setPaintMaxResolution(true); |
|
208 |
// Scale the renderer to fit width |
|
209 |
renderer.setResizeFactor(renderer.getPrintWidth() / writer.getWidth()); |
|
210 |
// Render |
|
211 |
renderer.paintComponent(g); |
|
212 |
|
|
213 |
writer.close(); |
|
214 |
|
|
215 |
return writer.toDocument(); |
|
216 |
} |
|
217 |
|
|
218 |
@Override |
|
219 |
public Sheet getSheet(int sheetIndex) { |
|
220 |
if( this.getSpread() == null || sheetIndex<0 ) { |
|
221 |
return null; |
|
222 |
} |
|
223 |
return this.getSpread().getSheet(sheetIndex); |
|
224 |
} |
|
225 |
|
|
226 |
@Override |
|
227 |
public List<String> getSheetNames() { |
|
228 |
if( this.getSpread() == null ) { |
|
229 |
return null; |
|
230 |
} |
|
231 |
return this.getSpread().getSheetNames(); |
|
232 |
} |
|
233 |
|
|
234 |
} |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.impl/src/main/java/org/gvsig/ods/lib/impl/SpreadJOpenDocument.java | ||
---|---|---|
1 |
package org.gvsig.ods.lib.impl; |
|
2 |
|
|
3 |
import java.awt.Rectangle; |
|
4 |
import java.io.File; |
|
5 |
import java.io.IOException; |
|
6 |
import java.util.ArrayList; |
|
7 |
import java.util.Collections; |
|
8 |
import java.util.List; |
|
9 |
import java.util.Locale; |
|
10 |
import java.util.Objects; |
|
11 |
import org.apache.commons.lang3.StringUtils; |
|
12 |
import org.gvsig.ods.lib.api.ODSDocument.Sheet; |
|
13 |
import org.jopendocument.dom.ODPackage; |
|
14 |
import org.jopendocument.dom.spreadsheet.SpreadSheet; |
|
15 |
import org.slf4j.Logger; |
|
16 |
import org.slf4j.LoggerFactory; |
|
17 |
|
|
18 |
/** |
|
19 |
* |
|
20 |
* @author jjdelcerro |
|
21 |
*/ |
|
22 |
public class SpreadJOpenDocument implements Spread { |
|
23 |
|
|
24 |
private static final Logger LOGGER = LoggerFactory.getLogger(SpreadJOpenDocument.class); |
|
25 |
|
|
26 |
private class JOpenDocumentSheet implements Sheet { |
|
27 |
|
|
28 |
private int sheetIndex; |
|
29 |
private org.jopendocument.dom.spreadsheet.Sheet ODSSheet; |
|
30 |
private Rectangle usedRange = null; |
|
31 |
|
|
32 |
public JOpenDocumentSheet(File ODSFile, int sheetIndex) throws IOException { |
|
33 |
SpreadSheet workbook = ODPackage.createFromFile(ODSFile).getSpreadSheet(); |
|
34 |
this.ODSSheet = workbook.getSheet(sheetIndex); |
|
35 |
this.sheetIndex = sheetIndex; |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public Rectangle getUsedRange() { |
|
40 |
if( this.usedRange == null ) { |
|
41 |
Spread spread = new SpreadSODS(); |
|
42 |
spread.open(ODSFile, locale); |
|
43 |
Sheet sheet = spread.getSheet(this.sheetIndex); |
|
44 |
this.usedRange = sheet.getUsedRange(); |
|
45 |
} |
|
46 |
return this.usedRange; |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public int getColumnCount() { |
|
51 |
// return this.ODSSheet.getColumnCount(); |
|
52 |
if( this.usedRange==null ) { |
|
53 |
this.usedRange = this.getUsedRange(); |
|
54 |
} |
|
55 |
return this.usedRange.width; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public List<String> getColumnNames(boolean isFirstLineHedaer) { |
|
60 |
int columns = this.getColumnCount(); |
|
61 |
List<String> columnNames = new ArrayList<>(columns); |
|
62 |
|
|
63 |
String abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
64 |
if (columns > abc.length()) { |
|
65 |
for (int i = 0; i < columns; i++) { |
|
66 |
columnNames.add( "C" + i); |
|
67 |
} |
|
68 |
} else { |
|
69 |
for (int i = 0; i < columns; i++) { |
|
70 |
columnNames.add(abc.substring(i, i + 1)); |
|
71 |
} |
|
72 |
} |
|
73 |
if (isFirstLineHedaer) { |
|
74 |
for (int col = 0; col < columns; col++) { |
|
75 |
Object value = this.getValueAt(col, 0); |
|
76 |
String s = Objects.toString(value); |
|
77 |
if (!StringUtils.isBlank(s)) { |
|
78 |
columnNames.set(col, s); |
|
79 |
} |
|
80 |
} |
|
81 |
} |
|
82 |
return columnNames; |
|
83 |
} |
|
84 |
|
|
85 |
@Override |
|
86 |
public String getName() { |
|
87 |
return this.ODSSheet.getName(); |
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public int getRowCount() { |
|
92 |
// return this.ODSSheet.getRowCount(); |
|
93 |
if( this.usedRange==null ) { |
|
94 |
this.usedRange = this.getUsedRange(); |
|
95 |
} |
|
96 |
return this.usedRange.height; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public int getSheetIndex() { |
|
101 |
return this.sheetIndex; |
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
public Object getValueAt(int col, int row) { |
|
106 |
return this.ODSSheet.getValueAt(col, row); |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public void close() { |
|
111 |
this.ODSSheet = null; |
|
112 |
this.sheetIndex = -1; |
|
113 |
this.usedRange = null; |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
private File ODSFile; |
|
118 |
private Locale locale; |
|
119 |
|
|
120 |
public SpreadJOpenDocument() { |
|
121 |
|
|
122 |
} |
|
123 |
|
|
124 |
@Override |
|
125 |
public void open(File ODSFile, Locale locale) { |
|
126 |
this.ODSFile = ODSFile; |
|
127 |
this.locale = locale; |
|
128 |
} |
|
129 |
|
|
130 |
@Override |
|
131 |
public File getFile() { |
|
132 |
return this.ODSFile; |
|
133 |
} |
|
134 |
|
|
135 |
@Override |
|
136 |
public Sheet getSheet(int sheetIndex) { |
|
137 |
try { |
|
138 |
if( ODSFile == null || sheetIndex<0 ) { |
|
139 |
return null; |
|
140 |
} |
|
141 |
return new JOpenDocumentSheet(ODSFile, sheetIndex); |
|
142 |
} catch (IOException ex) { |
|
143 |
return null; |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
147 |
@Override |
|
148 |
public List<String> getSheetNames() { |
|
149 |
try { |
|
150 |
SpreadSheet workbook = ODPackage.createFromFile(ODSFile).getSpreadSheet(); |
|
151 |
List<String> r = new ArrayList<>(); |
|
152 |
for( int n=0; n<workbook.getSheetCount(); n++ ) { |
|
153 |
r.add(workbook.getSheet(n).getName()); |
|
154 |
} |
|
155 |
return r; |
|
156 |
} catch (IOException ex) { |
|
157 |
return Collections.emptyList(); |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
@Override |
|
162 |
public void close() { |
|
163 |
this.ODSFile = null; |
|
164 |
this.locale = null; |
|
165 |
} |
|
166 |
|
|
167 |
} |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.impl/src/main/java/org/gvsig/ods/lib/impl/ODSImplLibrary.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.ods.lib.impl; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.DALLibrary; |
|
27 |
import org.gvsig.ods.lib.api.ODSLibrary; |
|
28 |
import org.gvsig.ods.lib.api.ODSLocator; |
|
29 |
import org.gvsig.tools.ToolsLibrary; |
|
30 |
import org.gvsig.tools.library.AbstractLibrary; |
|
31 |
import org.gvsig.tools.library.LibraryException; |
|
32 |
|
|
33 |
public class ODSImplLibrary extends AbstractLibrary { |
|
34 |
|
|
35 |
@Override |
|
36 |
public void doRegistration() { |
|
37 |
super.doRegistration(); |
|
38 |
registerAsImplementationOf(ODSLibrary.class); |
|
39 |
this.require(ToolsLibrary.class); |
|
40 |
this.require(DALLibrary.class); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
protected void doInitialize() throws LibraryException { |
|
45 |
ODSLocator.registerDefaultODSManager(DefaultODSManager.class); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void doPostInitialize() throws LibraryException { |
|
50 |
ODSProfile.selfRegister(); |
|
51 |
} |
|
52 |
|
|
53 |
} |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.impl/src/main/java/org/gvsig/ods/lib/impl/Spread.java | ||
---|---|---|
1 |
package org.gvsig.ods.lib.impl; |
|
2 |
|
|
3 |
import java.io.Closeable; |
|
4 |
import java.io.File; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Locale; |
|
7 |
import org.gvsig.ods.lib.api.ODSDocument.Sheet; |
|
8 |
|
|
9 |
/** |
|
10 |
* |
|
11 |
* @author jjdelcerro |
|
12 |
*/ |
|
13 |
public interface Spread extends Closeable { |
|
14 |
|
|
15 |
public void open(File ODSFile, Locale locale); |
|
16 |
|
|
17 |
public File getFile(); |
|
18 |
|
|
19 |
public Sheet getSheet(int sheetIndex); |
|
20 |
|
|
21 |
public List<String> getSheetNames(); |
|
22 |
} |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.impl/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.ods.lib</artifactId> |
|
6 |
<version>1.0.159</version> |
|
7 |
</parent> |
|
8 |
<artifactId>org.gvsig.ods.lib.impl</artifactId> |
|
9 |
<name>${project.artifactId}</name> |
|
10 |
<dependencies> |
|
11 |
<dependency> |
|
12 |
<groupId>org.gvsig</groupId> |
|
13 |
<artifactId>org.gvsig.ods.lib.api</artifactId> |
|
14 |
<scope>compile</scope> |
|
15 |
</dependency> |
|
16 |
<dependency> |
|
17 |
<groupId>org.gvsig</groupId> |
|
18 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
19 |
<scope>compile</scope> |
|
20 |
</dependency> |
|
21 |
<dependency> |
|
22 |
<groupId>org.gvsig</groupId> |
|
23 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
24 |
<scope>compile</scope> |
|
25 |
</dependency> |
|
26 |
<dependency> |
|
27 |
<groupId>commons-codec</groupId> |
|
28 |
<artifactId>commons-codec</artifactId> |
|
29 |
<scope>compile</scope> |
|
30 |
</dependency> |
|
31 |
<dependency> |
|
32 |
<groupId>org.gvsig</groupId> |
|
33 |
<artifactId>org.gvsig.pdf.lib.api</artifactId> |
|
34 |
<scope>compile</scope> |
|
35 |
</dependency> |
|
36 |
<dependency> |
|
37 |
<groupId>org.jopendocument</groupId> |
|
38 |
<artifactId>jOpenDocument</artifactId> |
|
39 |
<scope>compile</scope> |
|
40 |
</dependency> |
|
41 |
<dependency> |
|
42 |
<groupId>com.github.miachm.sods</groupId> |
|
43 |
<artifactId>SODS</artifactId> |
|
44 |
<scope>compile</scope> |
|
45 |
</dependency> |
|
46 |
</dependencies> |
|
47 |
</project> |
|
0 | 48 |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.ods.lib.api.ODSLibrary |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.api/src/main/java/org/gvsig/ods/lib/api/ODSManager.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.ods.lib.api; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
* @author jjdelcerro |
|
31 |
*/ |
|
32 |
public interface ODSManager { |
|
33 |
|
|
34 |
public ODSDocument createODSDocument(byte[] document); |
|
35 |
// public ODSDocument createODSDocument(String document); |
|
36 |
public ODSDocument createODSDocument(File document); |
|
37 |
public ODSDocument createODSDocument(); |
|
38 |
|
|
39 |
|
|
40 |
} |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.api/src/main/java/org/gvsig/ods/lib/api/ODSDocument.java | ||
---|---|---|
1 |
package org.gvsig.ods.lib.api; |
|
2 |
|
|
3 |
import java.awt.Rectangle; |
|
4 |
import java.io.Closeable; |
|
5 |
import java.io.File; |
|
6 |
import java.io.IOException; |
|
7 |
import java.io.InputStream; |
|
8 |
import java.util.List; |
|
9 |
import java.util.Locale; |
|
10 |
import org.gvsig.pdf.lib.api.PDFDocument; |
|
11 |
|
|
12 |
public interface ODSDocument extends Closeable { |
|
13 |
|
|
14 |
public File getFile(); |
|
15 |
|
|
16 |
public interface Sheet extends Closeable { |
|
17 |
|
|
18 |
int getColumnCount(); |
|
19 |
|
|
20 |
List<String> getColumnNames(boolean isFirstLineHedaer); |
|
21 |
|
|
22 |
String getName(); |
|
23 |
|
|
24 |
int getRowCount(); |
|
25 |
|
|
26 |
int getSheetIndex(); |
|
27 |
|
|
28 |
Object getValueAt(int col, int row); |
|
29 |
|
|
30 |
public Rectangle getUsedRange(); |
|
31 |
} |
|
32 |
|
|
33 |
public Sheet getSheet(int sheetIndex); |
|
34 |
|
|
35 |
public List<String> getSheetNames(); |
|
36 |
|
|
37 |
public InputStream getInputStream() throws IOException ; |
|
38 |
|
|
39 |
public void setLocale(Locale locale); |
|
40 |
|
|
41 |
public void setSource(File document); |
|
42 |
|
|
43 |
public void setSource(Object document); |
|
44 |
|
|
45 |
public byte[] toByteArray(); |
|
46 |
|
|
47 |
public String toHexString(); |
|
48 |
|
|
49 |
public PDFDocument createPDF(int pageSize); |
|
50 |
} |
|
51 |
|
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.api/src/main/java/org/gvsig/ods/lib/api/ODSLocator.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.ods.lib.api; |
|
25 |
|
|
26 |
import org.gvsig.tools.locator.AbstractLocator; |
|
27 |
import org.gvsig.tools.locator.Locator; |
|
28 |
import org.gvsig.tools.locator.LocatorException; |
|
29 |
|
|
30 |
@SuppressWarnings("rawtypes") |
|
31 |
public class ODSLocator extends AbstractLocator { |
|
32 |
|
|
33 |
private static final String LOCATOR_NAME = "ODSLocator"; |
|
34 |
|
|
35 |
public static final String ODS_MANAGER_NAME = |
|
36 |
"ODSManager"; |
|
37 |
|
|
38 |
private static final String ODS_MANAGER_DESCRIPTION = |
|
39 |
"ODS Manager of gvSIG"; |
|
40 |
|
|
41 |
private static final ODSLocator INSTANCE = new ODSLocator(); |
|
42 |
|
|
43 |
private ODSLocator() { |
|
44 |
|
|
45 |
} |
|
46 |
|
|
47 |
/** |
|
48 |
* Return the singleton instance. |
|
49 |
* |
|
50 |
* @return the singleton instance |
|
51 |
*/ |
|
52 |
public static ODSLocator getInstance() { |
|
53 |
return INSTANCE; |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public String getLocatorName() { |
|
58 |
return LOCATOR_NAME; |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Return a reference to ODSManager. |
|
63 |
* |
|
64 |
* @return a reference to ODSManager |
|
65 |
* @throws LocatorException |
|
66 |
* if there is no access to the class or the class cannot be |
|
67 |
* instantiated |
|
68 |
* @see Locator#get(String) |
|
69 |
*/ |
|
70 |
public static ODSManager getODSManager() |
|
71 |
throws LocatorException { |
|
72 |
return (ODSManager) getInstance().get(ODS_MANAGER_NAME); |
|
73 |
} |
|
74 |
|
|
75 |
public static ODSManager getManager() |
|
76 |
throws LocatorException { |
|
77 |
return getODSManager(); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Registers the Class implementing the ODSManager interface. |
|
82 |
* |
|
83 |
* @param clazz |
|
84 |
* implementing the ODSManager interface |
|
85 |
*/ |
|
86 |
public static void registerODSManager(Class clazz) { |
|
87 |
getInstance().register(ODS_MANAGER_NAME, |
|
88 |
ODS_MANAGER_DESCRIPTION, clazz); |
|
89 |
} |
|
90 |
|
|
91 |
public static void registerDefaultODSManager(Class clazz) { |
|
92 |
getInstance().registerDefault(ODS_MANAGER_NAME, |
|
93 |
ODS_MANAGER_DESCRIPTION, clazz); |
|
94 |
} |
|
95 |
|
|
96 |
|
|
97 |
} |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.api/src/main/java/org/gvsig/ods/lib/api/ODSLibrary.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.ods.lib.api; |
|
25 |
|
|
26 |
import org.gvsig.tools.ToolsLibrary; |
|
27 |
import org.gvsig.tools.library.AbstractLibrary; |
|
28 |
import org.gvsig.tools.library.LibraryException; |
|
29 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
|
30 |
|
|
31 |
/** |
|
32 |
* |
|
33 |
* @author jjdelcerro |
|
34 |
*/ |
|
35 |
public class ODSLibrary extends AbstractLibrary { |
|
36 |
|
|
37 |
@Override |
|
38 |
public void doRegistration() { |
|
39 |
super.doRegistration(); |
|
40 |
registerAsAPI(ODSLibrary.class); |
|
41 |
this.require(ToolsLibrary.class); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
protected void doInitialize() throws LibraryException { |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void doPostInitialize() throws LibraryException { |
|
50 |
if(! ODSLocator.getInstance().exists(ODSLocator.ODS_MANAGER_NAME)) { |
|
51 |
throw new ReferenceNotRegisteredException( |
|
52 |
ODSLocator.ODS_MANAGER_NAME, |
|
53 |
ODSLocator.getInstance()); |
|
54 |
} |
|
55 |
} |
|
56 |
|
|
57 |
} |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/org.gvsig.ods.lib.api/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.ods.lib</artifactId> |
|
6 |
<version>1.0.159</version> |
|
7 |
</parent> |
|
8 |
<artifactId>org.gvsig.ods.lib.api</artifactId> |
|
9 |
<name>${project.artifactId}</name> |
|
10 |
<dependencies> |
|
11 |
<dependency> |
|
12 |
<groupId>org.gvsig</groupId> |
|
13 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
14 |
<scope>compile</scope> |
|
15 |
</dependency> |
|
16 |
<dependency> |
|
17 |
<groupId>org.gvsig</groupId> |
|
18 |
<artifactId>org.gvsig.pdf.lib.api</artifactId> |
|
19 |
<scope>compile</scope> |
|
20 |
</dependency> |
|
21 |
</dependencies> |
|
22 |
|
|
23 |
</project> |
|
0 | 24 |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.lib/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.ods</artifactId> |
|
6 |
<version>1.0.159</version> |
|
7 |
</parent> |
|
8 |
<artifactId>org.gvsig.ods.lib</artifactId> |
|
9 |
<packaging>pom</packaging> |
|
10 |
<name>${project.artifactId}</name> |
|
11 |
<modules> |
|
12 |
<module>org.gvsig.ods.lib.api</module> |
|
13 |
<module>org.gvsig.ods.lib.impl</module> |
|
14 |
</modules> |
|
15 |
</project> |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.swing/org.gvsig.ods.swing.impl/src/main/java/org/gvsig/ods/swing/impl/ODSSwingImplLibrary.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.ods.swing.impl; |
|
25 |
|
|
26 |
import org.gvsig.ods.swing.impl.dynform.JDynFormFieldODSFileFactory; |
|
27 |
import org.gvsig.tools.ToolsLibrary; |
|
28 |
import org.gvsig.tools.library.AbstractLibrary; |
|
29 |
import org.gvsig.tools.library.LibraryException; |
|
30 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
31 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
|
32 |
import org.gvsig.ods.swing.api.ODSSwingLibrary; |
|
33 |
import org.gvsig.ods.swing.api.ODSSwingLocator; |
|
34 |
import org.gvsig.ods.swing.impl.dynform.JDynFormFieldODSBytearrayFactory; |
|
35 |
import org.gvsig.ods.swing.impl.dynform.JDynFormFieldODSURLFactory; |
|
36 |
import org.gvsig.pdf.lib.api.PDFLibrary; |
|
37 |
/** |
|
38 |
* |
|
39 |
* @author jjdelcerro |
|
40 |
*/ |
|
41 |
public class ODSSwingImplLibrary extends AbstractLibrary { |
|
42 |
|
|
43 |
@Override |
|
44 |
public void doRegistration() { |
|
45 |
registerAsImplementationOf(ODSSwingLibrary.class); |
|
46 |
this.require(ToolsLibrary.class); |
|
47 |
this.require(PDFLibrary.class); |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
protected void doInitialize() throws LibraryException { |
|
52 |
ODSSwingLocator.registerDefaultODSSwingManager(DefaultODSSwingManager.class); |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
protected void doPostInitialize() throws LibraryException { |
|
57 |
JDynFormFieldODSFileFactory.selfRegister(); |
|
58 |
JDynFormFieldODSURLFactory.selfRegister(); |
|
59 |
JDynFormFieldODSBytearrayFactory.selfRegister(); |
|
60 |
} |
|
61 |
|
|
62 |
} |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.swing/org.gvsig.ods.swing.impl/src/main/java/org/gvsig/ods/swing/impl/DefaultODSSwingManager.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.ods.swing.impl; |
|
3 |
|
|
4 |
import org.gvsig.ods.lib.api.ODSDocument; |
|
5 |
import org.gvsig.ods.swing.api.ODSSwingManager; |
|
6 |
import org.gvsig.ods.swing.api.ODSViewer; |
|
7 |
import org.gvsig.ods.swing.impl.viewer.DefaultODSViewer; |
|
8 |
import org.gvsig.ods.swing.impl.viewer.EmbeddedViewerODS; |
|
9 |
import org.gvsig.pdf.swing.api.EmbeddedViewer; |
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
/** |
|
15 |
* |
|
16 |
* @author jjdelcerro |
|
17 |
*/ |
|
18 |
public class DefaultODSSwingManager implements ODSSwingManager { |
|
19 |
|
|
20 |
@Override |
|
21 |
public ODSViewer createODSViewer() { |
|
22 |
return new DefaultODSViewer(); |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public EmbeddedViewer<ODSDocument> createEmbeddedODSViewer() { |
|
27 |
return new EmbeddedViewerODS(); |
|
28 |
} |
|
29 |
|
|
30 |
} |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.swing/org.gvsig.ods.swing.impl/src/main/java/org/gvsig/ods/swing/impl/dynform/JDynFormFieldODSBytearrayFactory.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.ods.swing.impl.dynform; |
|
25 |
|
|
26 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
27 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
28 |
import org.gvsig.tools.dynform.JDynFormField; |
|
29 |
import org.gvsig.tools.dynform.spi.DynFormSPILocator; |
|
30 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
31 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldFactory; |
|
32 |
|
|
33 |
public class JDynFormFieldODSBytearrayFactory extends AbstractJDynFormFieldFactory { |
|
34 |
|
|
35 |
public JDynFormFieldODSBytearrayFactory() { |
|
36 |
super("ODS_FILE", DataTypes.BYTEARRAY, "ODS"); |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public JDynFormField create( |
|
41 |
DynFormSPIManager serviceManager, |
|
42 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
|
43 |
DynFormFieldDefinition fieldDefinition, |
|
44 |
Object value |
|
45 |
) { |
|
46 |
return new JDynFormFieldODSBytearray(serviceManager, componentsFactory, this, fieldDefinition, value); |
|
47 |
} |
|
48 |
|
|
49 |
public static void selfRegister() { |
|
50 |
DynFormSPIManager manager = DynFormSPILocator.getDynFormSPIManager(); |
|
51 |
manager.registerDynFieldFactory(new JDynFormFieldODSBytearrayFactory()); |
|
52 |
} |
|
53 |
} |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.swing/org.gvsig.ods.swing.impl/src/main/java/org/gvsig/ods/swing/impl/dynform/JDynFormFieldODSURLFactory.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.ods.swing.impl.dynform; |
|
25 |
|
|
26 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
27 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
28 |
import org.gvsig.tools.dynform.JDynFormField; |
|
29 |
import org.gvsig.tools.dynform.spi.DynFormSPILocator; |
|
30 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
31 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldFactory; |
|
32 |
|
|
33 |
public class JDynFormFieldODSURLFactory extends AbstractJDynFormFieldFactory { |
|
34 |
|
|
35 |
public JDynFormFieldODSURLFactory() { |
|
36 |
super("ODS_FILE", DataTypes.URL, "ODS"); |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public JDynFormField create( |
|
41 |
DynFormSPIManager serviceManager, |
|
42 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
|
43 |
DynFormFieldDefinition fieldDefinition, |
|
44 |
Object value |
|
45 |
) { |
|
46 |
return new JDynFormFieldODSURL(serviceManager, componentsFactory, this, fieldDefinition, value); |
|
47 |
} |
|
48 |
|
|
49 |
public static void selfRegister() { |
|
50 |
DynFormSPIManager manager = DynFormSPILocator.getDynFormSPIManager(); |
|
51 |
manager.registerDynFieldFactory(new JDynFormFieldODSURLFactory()); |
|
52 |
} |
|
53 |
} |
org.gvsig.ods/tags/org.gvsig.ods-1.0.159/org.gvsig.ods.swing/org.gvsig.ods.swing.impl/src/main/java/org/gvsig/ods/swing/impl/dynform/JDynFormFieldODSFile.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 modify it under |
|
7 |
* the terms of the GNU General Public License as published by the Free Software |
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later |
|
9 |
* version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
14 |
* details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us at info AT |
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.ods.swing.impl.dynform; |
|
24 |
|
|
25 |
import org.gvsig.pdf.swing.api.EmbeddedViewer; |
|
26 |
import java.awt.BorderLayout; |
|
27 |
import java.io.File; |
|
28 |
import java.util.Objects; |
|
29 |
import javax.swing.JButton; |
|
30 |
import javax.swing.JComponent; |
|
31 |
import javax.swing.JPanel; |
|
32 |
import org.gvsig.ods.lib.api.ODSDocument; |
|
33 |
import org.gvsig.ods.lib.api.ODSLocator; |
|
34 |
import org.gvsig.ods.swing.impl.viewer.DefaultODSViewer; |
|
35 |
import org.gvsig.ods.swing.impl.viewer.EmbeddedViewerODS; |
|
36 |
import org.gvsig.tools.ToolsLocator; |
|
37 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
38 |
import org.gvsig.tools.dynform.services.dynformfield.File.JDynFormFieldFile; |
|
39 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
Also available in: Unified diff