Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.api / src / main / java / org / gvsig / fmap / dal / coverage / exception / RasterException.java @ 1367

History | View | Annotate | Download (2.99 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.fmap.dal.coverage.exception;
23

    
24
/**
25
 * Base exception for raster problems
26
 *
27
 * @author Nacho Brodin (nachobrodin@gmail.com)
28
 */
29
public class RasterException extends Exception {
30
        private static final long serialVersionUID = 1L;
31
        
32
        public RasterException() {
33
                super();
34
        }
35

    
36
        /**
37
         * Crea RemoteServiceException.
38
         *
39
         * @param message
40
         */
41
        public RasterException(String message) {
42
        super(message);
43
        }
44

    
45
        /**
46
         * Crea RemoteServiceException.
47
         *
48
         * @param message
49
         * @param cause
50
         */
51
        public RasterException(String message, Throwable cause) {
52
                super(format(message, 200), cause);
53
        }
54

    
55
        /**
56
          * Crea RemoteServiceException.
57
         *
58
         * @param cause
59
         */
60
        public RasterException(Throwable cause) {
61
                super(cause);
62
        }
63
    
64
    /**
65
     * Cuts the message text to force its lines to be shorter or equal to 
66
     * lineLength.
67
     * @param message, the message.
68
     * @param lineLength, the max line length in number of characters.
69
     * @return the formated message.
70
     */
71
    private static String format(String message, int lineLength){
72
        if (message.length() <= lineLength) return message;
73
        String[] lines = message.split("\n");
74
        String theMessage = "";
75
        for (int i = 0; i < lines.length; i++) {
76
            String line = lines[i].trim();
77
            if (line.length()<lineLength)
78
                theMessage += line+"\n";
79
            else {
80
                String[] chunks = line.split(" ");
81
                String newLine = "";
82
                for (int j = 0; j < chunks.length; j++) {
83
                    int currentLength = newLine.length();
84
                    chunks[j] = chunks[j].trim();
85
                    if (chunks[j].length()==0)
86
                        continue;
87
                    if ((currentLength + chunks[j].length() + " ".length()) <= lineLength)
88
                        newLine += chunks[j] + " ";
89
                    else {
90
                        newLine += "\n"+chunks[j]+" ";
91
                        theMessage += newLine;
92
                        newLine = "";
93
                    }
94
                }
95
                
96
            }
97
        }
98
        return theMessage;
99
    }
100
}