gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.api / src / main / java / org / gvsig / raster / cache / tile / exception / TileBuildException.java @ 899
History | View | Annotate | Download (3.06 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
package org.gvsig.raster.cache.tile.exception; |
23 |
|
24 |
/**
|
25 |
* This exception is thrown when the pool of threads fails
|
26 |
*
|
27 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
28 |
*/
|
29 |
public class TileBuildException extends Exception { |
30 |
private static final long serialVersionUID = 1L; |
31 |
|
32 |
String message;
|
33 |
|
34 |
public TileBuildException() {
|
35 |
super();
|
36 |
} |
37 |
|
38 |
/**
|
39 |
* Crea TileGettingException.
|
40 |
*
|
41 |
* @param message
|
42 |
*/
|
43 |
public TileBuildException(String message) { |
44 |
super();
|
45 |
this.message = message;
|
46 |
} |
47 |
|
48 |
/**
|
49 |
* Crea TileGettingException.
|
50 |
*
|
51 |
* @param message
|
52 |
* @param cause
|
53 |
*/
|
54 |
public TileBuildException(String message, Throwable cause) { |
55 |
super(format(message, 200), cause); |
56 |
} |
57 |
|
58 |
/**
|
59 |
* Crea TileGettingException.
|
60 |
*
|
61 |
* @param cause
|
62 |
*/
|
63 |
public TileBuildException(Throwable cause) { |
64 |
super(cause);
|
65 |
} |
66 |
|
67 |
/**
|
68 |
* Cuts the message text to force its lines to be shorter or equal to
|
69 |
* lineLength.
|
70 |
* @param message, the message.
|
71 |
* @param lineLength, the max line length in number of characters.
|
72 |
* @return the formated message.
|
73 |
*/
|
74 |
private static String format(String message, int lineLength){ |
75 |
if (message.length() <= lineLength) return message; |
76 |
String[] lines = message.split("\n"); |
77 |
String theMessage = ""; |
78 |
for (int i = 0; i < lines.length; i++) { |
79 |
String line = lines[i].trim();
|
80 |
if (line.length()<lineLength)
|
81 |
theMessage += line+"\n";
|
82 |
else {
|
83 |
String[] chunks = line.split(" "); |
84 |
String newLine = ""; |
85 |
for (int j = 0; j < chunks.length; j++) { |
86 |
int currentLength = newLine.length();
|
87 |
chunks[j] = chunks[j].trim(); |
88 |
if (chunks[j].length()==0) |
89 |
continue;
|
90 |
if ((currentLength + chunks[j].length() + " ".length()) <= lineLength) |
91 |
newLine += chunks[j] + " ";
|
92 |
else {
|
93 |
newLine += "\n"+chunks[j]+" "; |
94 |
theMessage += newLine; |
95 |
newLine = "";
|
96 |
} |
97 |
} |
98 |
|
99 |
} |
100 |
} |
101 |
return theMessage;
|
102 |
} |
103 |
} |