Revision 68

View differences:

org.gvsig.toolbox/tags/v1.3.0/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<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/maven-v4_0_0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	
5
	<groupId>org.gvsig</groupId>
6
	<artifactId>org.gvsig.toolbox</artifactId>
7
	<packaging>pom</packaging>
8
	<name>Algorithms</name>
9
	<version>1.3.0</version>
10
	
11
	<parent>
12
		<groupId>org.gvsig</groupId>
13
		<artifactId>org.gvsig.desktop</artifactId>
14
		<version>2.0.25</version>
15
	</parent>
16
	
17
	<scm>
18
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-toolbox/org.gvsig.toolbox/tags/v1.3.0</connection>
19
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-toolbox/org.gvsig.toolbox/tags/v1.3.0</developerConnection>
20
        <url>https://devel.gvsig.org/redmine/projects/gvsig-toolbox/repository/show/org.gvsig.toolbox/tags/v1.3.0</url>
21
    </scm>
22
	
23
	<repositories>
24
      <repository>
25
        <id>gvsig-public-http-repository</id>
26
        <name>gvSIG maven public HTTP repository</name>
27
        <url>http://devel.gvsig.org/m2repo/j2se</url>
28
        <releases>
29
          <enabled>true</enabled>
30
          <updatePolicy>daily</updatePolicy>
31
          <checksumPolicy>warn</checksumPolicy>
32
        </releases>
33
        <snapshots>
34
          <enabled>true</enabled>
35
          <updatePolicy>daily</updatePolicy>
36
          <checksumPolicy>warn</checksumPolicy>
37
        </snapshots>
38
      </repository>
39
    </repositories> 
40
    
41
	<properties>
42
    	<maven.compiler.source>1.6</maven.compiler.source>
43
    	<maven.compiler.target>1.6</maven.compiler.target>
44
	</properties>
45
	
46
	 <build>
47
	
48
	    <pluginManagement>
49
	       <plugins>
50
	          <plugin>
51
                <groupId>org.codehaus.mojo</groupId>
52
                <artifactId>animal-sniffer-maven-plugin</artifactId>
53
                <version>1.7</version>
54
              </plugin>
55
	       </plugins>
56
	    </pluginManagement>
57
	    
58
	    <plugins>
59
        	<plugin>
60
            	<groupId>org.apache.maven.plugins</groupId>
61
            	<artifactId>maven-compiler-plugin</artifactId>
62
            	<version>2.0.2</version>
63
            	<configuration>
64
                	<source>1.6</source>
65
                	<target>1.6</target>
66
                	<encoding>ISO-8859-1</encoding>
67
            	</configuration>
68
        	</plugin>
69
        	
70
        	<plugin>
71
              <groupId>org.codehaus.mojo</groupId>
72
              <artifactId>animal-sniffer-maven-plugin</artifactId>
73
              <executions>
74
                <execution>
75
                    <id>check-java-api</id>
76
                    <phase>test</phase>
77
                    <goals>
78
                        <goal>check</goal>
79
                    </goals>
80
                    <configuration>
81
                        <signature>
82
                            <groupId>org.codehaus.mojo.signature
83
                            </groupId>
84
                            <artifactId>java16</artifactId>
85
                            <version>1.0</version>
86
                        </signature>
87
                    </configuration>
88
                </execution>
89
              </executions>
90
             </plugin>
91
             
92
             <plugin>
93
                <groupId>org.apache.maven.plugins</groupId>
94
                <artifactId>maven-release-plugin</artifactId>
95
                <configuration>
96
                    <tagBase>https://devel.gvsig.org/svn/gvsig-toolbox/org.gvsig.toolbox/tags/</tagBase>
97
                    <goals>deploy</goals>
98
                </configuration>
99
            </plugin>
100
            
101
    	  </plugins>
102
    </build>
103
	
104
	<dependencyManagement>
105
      <dependencies>
106
		<dependency>
107
			<groupId>gishur</groupId>
108
			<artifactId>gishur_x</artifactId>
109
			<version>unknown</version>
110
		</dependency>
111
		<dependency>
112
			<groupId>gishur</groupId>
113
			<artifactId>gishur_core</artifactId>
114
			<version>unknown</version>
115
		</dependency>
116
		<dependency>
117
			<groupId>com.vividsolutions</groupId>
118
			<artifactId>jts</artifactId>
119
			<version>1.13</version>
120
		</dependency>
121
		<dependency>
122
			<groupId>org.gvsig</groupId>
123
			<artifactId>org.gvsig.toolbox.core</artifactId>
124
			<version>1.3.0</version>
125
		</dependency>
126
		<dependency>
127
			<groupId>org.gvsig</groupId>
128
			<artifactId>org.gvsig.toolbox.gui</artifactId>
129
			<version>1.3.0</version>
130
		</dependency>
131
		<dependency>
132
			<groupId>org.gvsig</groupId>
133
			<artifactId>org.gvsig.toolbox.math</artifactId>
134
			<version>1.3.0</version>
135
		</dependency>
136
		<dependency>
137
			<groupId>gnu.trove</groupId>
138
			<artifactId>trove</artifactId>
139
			<version>0.1.8</version>
140
		</dependency>
141
		<dependency>
142
			  <groupId>org.gvsig.legacy</groupId>
143
			  <artifactId>jama</artifactId>
144
			  <version>1.0.2</version>
145
		</dependency>
146
        <dependency>
147
			<groupId>org.nfunk</groupId>
148
			<artifactId>jep</artifactId>
149
			<version>2.4.0</version>
150
		</dependency>
151
		<dependency>
152
			<groupId>commons-codec</groupId>
153
			<artifactId>commons-codec</artifactId>
154
			<version>1.8</version>
155
		</dependency>
156
		<dependency>
157
            <groupId>es.unex</groupId>
158
            <artifactId>sextante_wps</artifactId>
159
            <version>0.6.0</version>
160
        </dependency>
161
        <dependency>
162
			<groupId>es.unex</groupId>
163
			<artifactId>libDocEngines</artifactId>
164
			<version>0.6.0</version>
165
		</dependency>
166
		<dependency>
167
			<groupId>org.beanshell</groupId>
168
			<artifactId>bsh</artifactId>
169
			<version>2.0b4</version>
170
		</dependency>
171
        <dependency>
172
            <groupId>org.japura</groupId>
173
            <artifactId>org.japura</artifactId>
174
            <version>1.14.0</version>
175
        </dependency>
176
		<dependency>
177
			<groupId>commons-codec</groupId>
178
			<artifactId>commons-codec</artifactId>
179
			<version>1.8</version>
180
		</dependency>
181
	  </dependencies>
182
	</dependencyManagement>
183
	
184
	 <modules>
185
		<module>org.gvsig.toolbox.math</module>
186
		<module>org.gvsig.toolbox.gui</module>
187
		<module>org.gvsig.toolbox.core</module>
188
		<module>org.gvsig.toolbox.algorithm</module>
189
	</modules>
190
</project>
0 191

  
org.gvsig.toolbox/tags/v1.3.0/org.gvsig.toolbox.gui/MANIFEST.MF
1
Manifest-Version: 1.0
2
Ant-Version: Apache Ant 1.7.1
3
Created-By: 20.1-b02 (Sun Microsystems Inc.)
4
Implementation-Version: 0.7
5
Built-Date: 2013-03-04 16:06:37
6

  
0 7

  
org.gvsig.toolbox/tags/v1.3.0/org.gvsig.toolbox.gui/src/main/java/jsh/shell/Utils.java
1
/*
2
 * 20:25:20 20/05/99
3
 *
4
 * The Java Shell: Utilities.
5
 * (C)1999 Romain Guy, Osvaldo Pinali Doederlein.
6
 *
7
 * LICENSE
8
 * =======
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 *
23
 * CHANGES
24
 * =======
25
 * 1.0.8 - Filled the listRoots method                   (Romain & Osvaldo)
26
 * 1.0.7 - Several bug fixes in constructPath            (Romain)
27
 * 1.0.6 - Split JDK1.1/1.2                              (Osvaldo)
28
 * 1.0.5 - Important bug fix in constructPath(String)    (Romain)
29
 * 1.0.4 - Added getSize(Enumeration)                    (Osvaldo)
30
 * 1.0.3 - Changed sortStrings bubble-sort algorithm to  (Romain)
31
 *         quick-sort (James Gosling)
32
 * 1.0.2 - Fixed two little bug in constructPath(String) (Romain)
33
 * 1.0.1 - Added listFiles(String[], boolean)            (Romain)
34
 *       - Removed unecessary createWhiteSpace(int)      (Romain)
35
 *       - Modified getWildCardMatches(String, boolean)  (Romain)
36
 *       - Slighty improved javadoc comments             (Romain)
37
 * 1.0.0 - Initial release.                              (Romain & Osvaldo)
38
 *
39
 * LINKS
40
 * =====
41
 * Contact: mailto@osvaldo.visionnaire.com.br
42
 * Site #1: http://www.geocities.com/ResearchTriangle/Node/2005/
43
 * Site #2: http://student.vub.ac.be/~opinalid/
44
 */
45

  
46
package jsh.shell;
47

  
48
import java.io.File;
49
import java.util.Enumeration;
50
import java.util.Vector;
51

  
52
import es.unex.sextante.gui.core.SextanteGUI;
53

  
54
/**
55
 * The Java Shell: Utility pack.
56
 *
57
 * @author Romain Guy.
58
 * @author Osvaldo Pinali Doederlein.
59
 */
60

  
61
public class Utils {
62

  
63
   /**
64
    * Removes some elements from a String array.
65
    *
66
    * @param arr
67
    *                The array.
68
    * @param first
69
    *                First element to keep (new 0-index).
70
    * @param last
71
    *                Last element to keep.
72
    * @return Copy of arr[first..]
73
    */
74
   public static String[] subarray(final String[] arr,
75
                                   int first,
76
                                   final int last) {
77
      final String[] newArr = new String[last - first + 1];
78

  
79
      for (int i = 0; i < newArr.length; ++i, ++first) {
80
         newArr[i] = arr[first];
81
      }
82

  
83
      return newArr;
84
   }
85

  
86

  
87
   /**
88
    * Removes some leading elements from a String array.
89
    *
90
    * @param arr
91
    *                The array.
92
    * @param first
93
    *                First element to keep (new 0-index).
94
    * @return Copy of arr[first..]
95
    */
96
   public static String[] subarray(final String[] arr,
97
                                   final int first) {
98
      return subarray(arr, first, arr.length - 1);
99
   }
100

  
101

  
102
   /**
103
    * Formats a number of bytes for output.
104
    *
105
    * @param bytes
106
    *                Number of bytes.
107
    * @return "xxxxK" form.
108
    */
109
   public static String fmtBytes(final long bytes) {
110
      return Long.toString(bytes / 1024) + "K";
111
   }
112

  
113

  
114
   /**
115
    * Formats time for output.
116
    *
117
    * @param bytes
118
    *                Number of milliseconds.
119
    * @return "x,yyys" form.
120
    */
121
   public static String fmtTime(final long ms) {
122
      return Float.toString(ms / 1000.0f) + "s";
123
   }
124

  
125

  
126
   /**
127
    * Return a String made of spaces.
128
    *
129
    * @param len
130
    *                Number of spaces
131
    */
132
   public static String getSpaces(final int len) {
133
      final StringBuffer buf = new StringBuffer();
134

  
135
      for (int i = 0; i < len; i++) {
136
         buf.append(' ');
137
      }
138

  
139
      return buf.toString();
140
   }
141

  
142

  
143
   public static String[] toArray(final Vector strings) {
144
      final String[] arr = new String[strings.size()];
145

  
146
      for (int i = 0; i < strings.size(); ++i) {
147
         arr[i] = (String) strings.elementAt(i);
148
      }
149

  
150
      return arr;
151
   }
152

  
153

  
154
   /**
155
    * When the user has to specify file names, he can use wildcards (*, ?). This methods handles the usage of these wildcards.
156
    *
157
    * @param s
158
    *                Wilcards
159
    * @param sort
160
    *                Set to true will sort file names
161
    * @return An array of String which contains all files matching <code>s</code> in current directory.
162
    * @see Utils#match(String, String)
163
    */
164

  
165
   public static String[] getWildCardMatches(final String s,
166
                                             final boolean sort) {
167
      final String args = new String(s.trim());
168
      String files[];
169
      final Vector filesThatMatchVector = new Vector();
170
      String filesThatMatch[];
171

  
172
      files = (new File(getUserDirectory())).list();
173

  
174
      for (int i = 0; i < files.length; i++) {
175
         if (match(args, files[i])) {
176
            final File temp = new File(getUserDirectory(), files[i]);
177
            filesThatMatchVector.addElement(new String(temp.getName()));
178
         }
179
      }
180

  
181
      filesThatMatch = new String[filesThatMatchVector.size()];
182
      filesThatMatchVector.copyInto(filesThatMatch);
183

  
184
      if (sort) {
185
         sortStrings(filesThatMatch);
186
      }
187

  
188
      return filesThatMatch;
189
   }
190

  
191

  
192
   /**
193
    * This method can determine if a String matches a pattern of wildcards
194
    *
195
    * @param pattern
196
    *                The pattern used for comparison
197
    * @param string
198
    *                The String to be checked
199
    * @return true if <code>string</code> matches <code>pattern</code>
200
    * @see Utils#getWildCardMatches(String)
201
    */
202

  
203
   public static boolean match(final String pattern,
204
                               final String string) {
205
      for (int p = 0;; p++) {
206
         for (int s = 0;; p++, s++) {
207
            final boolean sEnd = (s >= string.length());
208
            final boolean pEnd = (p >= pattern.length() || pattern.charAt(p) == '|');
209

  
210
            if (sEnd && pEnd) {
211
               return true;
212
            }
213
            if (sEnd || pEnd) {
214
               break;
215
            }
216
            if (pattern.charAt(p) == '?') {
217
               continue;
218
            }
219

  
220
            if (pattern.charAt(p) == '*') {
221
               int i;
222
               p++;
223

  
224
               for (i = string.length(); i >= s; --i) {
225
                  if (match(pattern.substring(p), string.substring(i))) {
226
                     return true;
227
                  }
228
               }
229

  
230
               break;
231
            }
232

  
233
            if (pattern.charAt(p) != string.charAt(s)) {
234
               break;
235
            }
236
         }
237

  
238
         p = pattern.indexOf('|', p);
239

  
240
         if (p == -1) {
241
            return false;
242
         }
243
      }
244
   }
245

  
246

  
247
   /**
248
    * Quick sort an array of Strings.
249
    *
250
    * @param string
251
    *                Strings to be sorted
252
    */
253

  
254
   public static void sortStrings(final String[] strings) {
255
      sortStrings(strings, 0, strings.length - 1);
256
   }
257

  
258

  
259
   /**
260
    * Quick sort an array of Strings.
261
    *
262
    * @param a
263
    *                Strings to be sorted
264
    * @param lo0
265
    *                Lower bound
266
    * @param hi0
267
    *                Higher bound
268
    */
269

  
270
   public static void sortStrings(final String a[],
271
                                  final int lo0,
272
                                  final int hi0) {
273
      int lo = lo0;
274
      int hi = hi0;
275
      String mid;
276

  
277
      if (hi0 > lo0) {
278
         mid = a[(lo0 + hi0) / 2];
279

  
280
         while (lo <= hi) {
281
            while (lo < hi0 && a[lo].compareTo(mid) < 0) {
282
               ++lo;
283
            }
284

  
285
            while (hi > lo0 && a[hi].compareTo(mid) > 0) {
286
               --hi;
287
            }
288

  
289
            if (lo <= hi) {
290
               swap(a, lo, hi);
291
               ++lo;
292
               --hi;
293
            }
294
         }
295

  
296
         if (lo0 < hi) {
297
            sortStrings(a, lo0, hi);
298
         }
299

  
300
         if (lo < hi0) {
301
            sortStrings(a, lo, hi0);
302
         }
303
      }
304
   }
305

  
306

  
307
   /**
308
    * Swaps two Strings.
309
    *
310
    * @param a
311
    *                The array to be swapped
312
    * @param i
313
    *                First String index
314
    * @param j
315
    *                Second String index
316
    */
317

  
318
   public static void swap(final String a[],
319
                           final int i,
320
                           final int j) {
321
      String T;
322
      T = a[i];
323
      a[i] = a[j];
324
      a[j] = T;
325
   }
326

  
327

  
328
   /**
329
    * Returns the user current directory.
330
    */
331
   public static String getUserDirectory() {
332

  
333
      String folder = SextanteGUI.getOutputFolder();
334
      if (folder == null) {
335
         folder = System.getProperty("user.home");
336
      }
337

  
338
      return folder;
339

  
340
   }
341

  
342

  
343
   /**
344
    * Sometimes, Strings are too long to be correctly displayed. This method will reduce a String, keeping first and last
345
    * characters.
346
    *
347
    * @param longString
348
    *                The String to be modified
349
    * @param maxLength
350
    *                The maximum length of the String
351
    * @return A shorter String
352
    */
353

  
354
   public static String getShortStringOf(final String longString,
355
                                         final int maxLength) {
356
      final int len = longString.length();
357

  
358
      if (len < maxLength) {
359
         return longString;
360
      }
361
      else {
362
         return longString.substring(0, maxLength / 2) + "..." + longString.substring(len - (maxLength / 2));
363
      }
364
   }
365

  
366

  
367
   /**
368
    * Because a lot of people still use JDK 1.1, we need this method to create an array of Files from an array of String.
369
    *
370
    * @param names
371
    *                Names of the files
372
    * @param construct
373
    *                Set it to true if names does not contain full paths
374
    * @return An array of Files
375
    */
376
   public static File[] listFiles(final String[] names,
377
                                  final boolean construct) {
378
      final File[] files = new File[names.length];
379

  
380
      String path = Utils.getUserDirectory();
381

  
382
      if (construct) {
383
         if (!path.endsWith(File.separator)) {
384
            path += File.separator;
385
         }
386
      }
387

  
388
      for (int i = 0; i < files.length; i++) {
389
         if (construct) {
390
            files[i] = new File(path + names[i]);
391
         }
392
         else {
393
            files[i] = new File(names[i]);
394
         }
395
      }
396

  
397
      return files;
398
   }
399

  
400

  
401
   /**
402
    * Counts things in an Enumeration (and destroys it as a side effect).
403
    *
404
    * @param enum
405
    *                The enumeration, in the start position.
406
    * @return Elements found.
407
    */
408
   public static int getSize(final Enumeration enu) {
409
      int size = 0;
410

  
411
      while (enu.hasMoreElements()) {
412
         ++size;
413
         enu.nextElement();
414
      }
415

  
416
      return size;
417
   }
418

  
419

  
420
   /**
421
    * Constructs a new path from current user path. This is an easy way to get a path if the user specified, for example,
422
    * "..\Java" as new path. This method will return the argument if this one is a path to a root (i.e, if <code>change</code>
423
    * is equal to C:\Jdk, constructPath will return C:\Jdk).
424
    *
425
    * @param change
426
    *                The modification to apply to the path
427
    * @see Utils#beginsWithRoot(String), Utils#getRoot(String)
428
    */
429

  
430
   public static String constructPath(final String change) {
431
      if (change == null || beginsWithRoot(change)) {
432
         return change;
433
      }
434

  
435
      String newPath = getUserDirectory();
436

  
437
      char current;
438
      char lastChar = '\0';
439
      boolean toAdd = false;
440
      StringBuffer buf = new StringBuffer(change.length());
441

  
442
      for (int i = 0; i < change.length(); i++) {
443
         switch ((current = change.charAt(i))) {
444
            case '.':
445
               if (lastChar == '.') {
446
                  final String parent = (new File(newPath)).getParent();
447
                  if (parent != null) {
448
                     newPath = parent;
449
                  }
450
               }
451
               else if (lastChar != '\0' && lastChar != '\\' && lastChar != '/') {
452
                  buf.append('.');
453
               }
454
               lastChar = '.';
455
               break;
456
            case '\\':
457
            case '/':
458
               if (lastChar == '\0') {
459
                  newPath = getRoot(newPath);
460
               }
461
               else {
462
                  if (!newPath.endsWith("\\")) {
463
                     newPath += File.separator + buf.toString();
464
                  }
465
                  else {
466
                     newPath += buf.toString();
467
                  }
468
                  buf = new StringBuffer();
469
                  toAdd = false;
470
               }
471
               lastChar = '\\';
472
               break;
473
            case '~':
474
               if (i < change.length() - 1) {
475
                  if (change.charAt(i + 1) == '\\' || change.charAt(i + 1) == '/') {
476
                     newPath = System.getProperties().getProperty("user.home");
477
                  }
478
                  else {
479
                     buf.append('~');
480
                  }
481
               }
482
               else if (i == 0) {
483
                  newPath = System.getProperties().getProperty("user.home");
484
               }
485
               else {
486
                  buf.append('~');
487
               }
488
               lastChar = '~';
489
               break;
490
            default:
491
               lastChar = current;
492
               buf.append(current);
493
               toAdd = true;
494
               break;
495
         }
496
      }
497

  
498
      if (toAdd) {
499
         if (!newPath.endsWith(File.separator)) {
500
            newPath += File.separator + buf.toString();
501
         }
502
         else {
503
            newPath += buf.toString();
504
         }
505
      }
506

  
507
      return newPath;
508
   }
509

  
510

  
511
   /**
512
    * It can be necessary to determine which is the root of a path. For example, the root of D:\Projects\Java is D:\.
513
    *
514
    * @param path
515
    *                The path used to get a root
516
    * @return The root which contais the specified path
517
    */
518

  
519
   public static String getRoot(final String path) {
520
      final File roots[] = listRoots(new File(path));
521

  
522
      for (int i = 0; i < roots.length; i++) {
523
         if (path.startsWith(roots[i].getPath())) {
524
            return roots[i].getPath();
525
         }
526
      }
527

  
528
      return path;
529
   }
530

  
531

  
532
   /**
533
    * It can be necessary to determine if a path begins with a root.
534
    *
535
    * @param path
536
    *                The path to check
537
    * @return True if path begins with a root, false otherwise
538
    */
539

  
540
   public static boolean beginsWithRoot(final String path) {
541
      final File roots[] = listRoots(new File(path));
542

  
543
      for (int i = 0; i < roots.length; i++) {
544
         if (path.regionMatches(true, 0, roots[i].getPath(), 0, roots[i].getPath().length())) {
545
            return true;
546
         }
547
      }
548

  
549
      return false;
550
   }
551

  
552

  
553
   /**
554
    * We override a Java2 specific method.
555
    *
556
    * @param f
557
    *                A File
558
    * @return A list of standards roots
559
    */
560

  
561
   public static File[] listRoots(final File f) {
562
      if (System.getProperty("os.name").startsWith("Windows")) {
563
         return new File[] { new File("A:\\"), new File("B:\\"), new File("C:\\"), new File("D:\\"), new File("E:\\"),
564
                  new File("F:\\"), new File("G:\\"), new File("H:\\"), new File("I:\\") };
565
         //return new File[]{new File(System.getProperty("java.home").substring(0, 3))};
566
      }
567
      else {
568
         return new File[] { new File("/") };
569
      }
570
   }
571

  
572

  
573
   /**
574
    * We override a Java2 spcific method.
575
    *
576
    * @param file
577
    *                Determine if this file is hidden or not
578
    * @return Always false
579
    */
580

  
581
   public boolean isHidden(final File file) {
582
      return false;
583
   }
584

  
585
}
586

  
587
// End of Utils.java
0 588

  
org.gvsig.toolbox/tags/v1.3.0/org.gvsig.toolbox.gui/src/main/java/es/unex/sextante/gui/grass/UnwrappableGrassProcessException.java
1
package es.unex.sextante.gui.grass;
2

  
3
public class UnwrappableGrassProcessException
4
         extends
5
            Exception {
6

  
7
}
0 8

  
org.gvsig.toolbox/tags/v1.3.0/org.gvsig.toolbox.gui/src/main/java/es/unex/sextante/gui/grass/GrassModelerBlackList.java
1
package es.unex.sextante.gui.grass;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import es.unex.sextante.core.Sextante;
7

  
8

  
9
/**
10
 * A hard-coded list of those GRASS algorithms not compatible with the SEXTANTE modeler
11
 * 
12
 * @author volaya
13
 * 
14
 */
15
public class GrassModelerBlackList {
16

  
17
   private static List           m_List;
18
   private static final String[] ALGS = {};
19

  
20
   static {
21

  
22
      m_List = new ArrayList();
23
      for (int i = 0; i < ALGS.length; i++) {
24
         m_List.add(ALGS[i]);
25
      }
26

  
27
   }
28

  
29

  
30
   public static boolean isInBlackList(final GrassAlgorithm alg) {
31

  
32
      return (isInBlackList(alg.getName()));
33

  
34
   }
35

  
36

  
37
   public static boolean isInBlackList(final String sName) {
38
      if (m_List.contains(sName)) {
39
         Sextante.addWarningToLog("SEXTANTE GRASS interface: Module " + sName + " disabled: blacklisted.");
40
         return (true);
41
      }
42
      return (false);
43
   }
44

  
45

  
46
}
0 47

  
org.gvsig.toolbox/tags/v1.3.0/org.gvsig.toolbox.gui/src/main/java/es/unex/sextante/gui/grass/GrassUtils.java
1
package es.unex.sextante.gui.grass;
2

  
3
import java.io.BufferedReader;
4
import java.io.BufferedWriter;
5
import java.io.DataInputStream;
6
import java.io.File;
7
import java.io.FileInputStream;
8
import java.io.FileReader;
9
import java.io.FileWriter;
10
import java.io.IOException;
11
import java.io.InputStream;
12
import java.io.InputStreamReader;
13
import java.io.Writer;
14
import java.util.ArrayList;
15
import java.util.List;
16
import java.util.Map;
17
import java.util.UUID;
18

  
19
import javax.swing.JOptionPane;
20

  
21
import es.unex.sextante.core.Sextante;
22
import es.unex.sextante.gui.core.SextanteGUI;
23
import es.unex.sextante.gui.settings.SextanteGrassSettings;
24
import es.unex.sextante.outputs.FileOutputChannel;
25
import es.unex.sextante.outputs.Output;
26

  
27

  
28
public class GrassUtils {
29

  
30

  
31
   //For parsing of GRASS message blocks
32
   private static boolean        lastWasInfoEnd       = false;
33
   private static boolean        lastWasEmpty         = false;
34
   private static boolean        insideRegPrimitives  = false;
35

  
36
   //Link to the currently running GRASS algorithm (need this for status updates)
37
   private static GrassAlgorithm m_Alg;
38

  
39
   //The currently running GRASS process;
40
   private static Process        m_Proc               = null;
41
   private static boolean        m_bProcCanceled      = false;
42
   private static boolean        m_bProcInterruptible = true;
43

  
44
   //A file for process communication (on Windows)
45
   //private static File           m_ComFile            = null;
46

  
47
   //Char array size for raw input stream processing
48
   private static final int      MAX_CHARS            = 8192;
49

  
50
   //Temporary color table file constants
51
   public static final String    colorTableExt        = "colortable";
52
   public static final String    colorTableIdentifier = "SEXTANTE GRASS Interface Color Table";
53
   public static final String    colorTableVersion    = "1.0";
54

  
55
   //The default prefix for temporary files and folders
56
   public static final String    TEMP_PREFIX          = "SGI";
57

  
58
   private static String         m_sGrassTempMapsetFolder;
59

  
60
   static {
61

  
62
      //      readGroupNames();
63

  
64
   }
65

  
66

  
67
   //private static HashMap<String, String> m_Groups;
68

  
69

  
70
   /*
71
    * Returns the running GRASS process or null.
72
    */
73
   public static Process getProcess() {
74
      return (m_Proc);
75
   }
76

  
77

  
78
   /*
79
    * Returns the status of the running process.
80
    */
81
   public static boolean isProcessCanceled() {
82
      return (m_bProcCanceled);
83
   }
84

  
85

  
86
   /*
87
    * Sets interruptible status of current and future processes.
88
    */
89
   public static void setInterruptible(final boolean choice) {
90
      m_bProcInterruptible = choice;
91
   }
92

  
93

  
94
   /*
95
    * Cancels the running process.
96
    * But only if it is interruptible (it is by default).
97
    */
98
   public static void cancelProcess() {
99

  
100
      if (m_Proc != null) {
101
         if (m_bProcInterruptible) {
102
            m_Proc.destroy();
103
            m_Proc = null;
104
            m_bProcCanceled = true;
105
         }
106
      }
107

  
108
   }
109

  
110

  
111
   /**
112
    * Creates a compact startup script for GRASS. The script code created may vary, depending on the operating system. This also
113
    * creates a temporary GRASS settings file (GISCR).
114
    * 
115
    * @param cmdline
116
    * 
117
    * @return The file handler for the created script, NULL on failure.
118
    * 
119
    */
120
   public static File createStartupScript(final String cmdline) {
121
      BufferedWriter output = null;
122

  
123
      File script = null;
124
      File gisrc = null;
125

  
126
      UUID id;
127
      String tmpPrefix;
128
      String tmpSuffix;
129
      String tmpExtension;
130
      String tmpBase;
131
      String tmpName;
132

  
133
      final String sFolder = SextanteGUI.getSettingParameterValue(SextanteGrassSettings.GRASS_FOLDER);
134
      final String sWinShell = SextanteGUI.getSettingParameterValue(SextanteGrassSettings.GRASS_WIN_SHELL);
135

  
136
      //Create temporary script file in system's temp dir
137
      id = UUID.randomUUID();
138
      tmpPrefix = new String(GrassUtils.TEMP_PREFIX);
139
      tmpSuffix = new String("_" + id);
140
      tmpBase = new String(System.getProperty("java.io.tmpdir"));
141
      if (Sextante.isWindows()) {
142
         tmpExtension = new String("bat");
143
      }
144
      else {
145
         tmpExtension = new String("sh");
146
      }
147
      if (tmpBase.endsWith(File.separator)) {
148
         tmpName = new String(tmpBase + File.separator + tmpPrefix + tmpSuffix.replace('-', '_') + "." + tmpExtension);
149
      }
150
      else {
151
         tmpName = new String(tmpBase + File.separator + tmpPrefix + tmpSuffix.replace('-', '_') + "." + tmpExtension);
152
      }
153
      script = new File(tmpName);
154
      script.deleteOnExit();
155

  
156
      //Create a temporary GISRC file in system's temp dir
157
      id = UUID.randomUUID();
158
      tmpPrefix = new String(GrassUtils.TEMP_PREFIX);
159
      tmpSuffix = new String("_" + id);
160
      tmpBase = new String(System.getProperty("java.io.tmpdir"));
161
      if (tmpBase.endsWith(File.separator)) {
162
         tmpName = new String(tmpBase + File.separator + tmpPrefix + tmpSuffix.replace('-', '_') + ".gisrc");
163
      }
164
      else {
165
         tmpName = new String(tmpBase + File.separator + tmpPrefix + tmpSuffix.replace('-', '_') + ".gisrc");
166
      }
167
      gisrc = new File(tmpName);
168
      gisrc.deleteOnExit();
169

  
170
      //Get GISDBASE, LOCATION and MAPSET from String parameter
171
      final String mapset = new String(getGrassMapsetFolder().substring(getGrassMapsetFolder().lastIndexOf(File.separator) + 1,
172
               getGrassMapsetFolder().length()));
173
      final String path = new String(getGrassMapsetFolder().substring(0, getGrassMapsetFolder().lastIndexOf(File.separator)));
174
      final String location = new String(path.substring(path.lastIndexOf(File.separator) + 1, path.length()));
175
      final String gisdbase = new String(path.substring(0, path.lastIndexOf(File.separator)));
176

  
177
      //Write the temporary GISRC file to use in this session
178
      try {
179
         output = new BufferedWriter(new FileWriter(gisrc));
180
         output.write("GISDBASE: " + gisdbase + "\n");
181
         output.write("LOCATION_NAME: " + location + "\n");
182
         output.write("MAPSET: " + mapset + "\n");
183
         output.write("GRASS_GUI: text\n");
184
         output.close();
185
      }
186
      catch (final Exception e) {
187
         return (null);
188
      }
189

  
190
      //Write the startup script
191
      if (Sextante.isUnix() || Sextante.isMacOSX()) {
192
         //Startup script for *nix like systems with built-in shell interpreter
193
         final String grassfolder = new String(sFolder);
194
         try {
195
            output = new BufferedWriter(new FileWriter(script));
196
            output.write("#!/bin/sh\n");
197
            output.write("export GISRC=\"" + gisrc.getAbsolutePath() + "\"\n");
198
            output.write("export GISBASE=\"" + grassfolder + "\"\n");
199
            output.write("export GRASS_PROJSHARE=\"" + grassfolder + File.separator + "share" + File.separator + "proj" + "\"\n");
200
            output.write("export GRASS_MESSAGE_FORMAT=gui\n");
201
            output.write("export GRASS_SH=/bin/sh\n");
202
            output.write("export GRASS_PERL=/usr/bin/perl\n");
203
            output.write("export GRASS_VERSION=\"" + getGrassVersion() + "\"\n");
204
            output.write("export GIS_LOCK=$$\n");
205
            output.write("\n");
206
            output.write("if [ \"$LC_ALL\" ] ; then\n");
207
            output.write("\tLCL=`echo \"$LC_ALL\" | sed 's/\\(..\\)\\(.*\\)/\\1/'`\n");
208
            output.write("elif [ \"$LC_MESSAGES\" ] ; then\n");
209
            output.write("\tLCL=`echo \"$LC_MESSAGES\" | sed 's/\\(..\\)\\(.*\\)/\\1/'`\n");
210
            output.write("else\n");
211
            output.write("\tLCL=`echo \"$LANG\" | sed 's/\\(..\\)\\(.*\\)/\\1/'`\n");
212
            output.write("fi\n");
213
            output.write("\n");
214
            output.write("if [ -n \"$GRASS_ADDON_PATH\" ] ; then\n");
215
            output.write("\tPATH=\"" + grassfolder + "/bin:" + grassfolder + "/scripts:$GRASS_ADDON_PATH:$PATH\"\n");
216
            output.write("else\n");
217
            output.write("\tPATH=\"" + grassfolder + "/bin:" + grassfolder + "/scripts:$PATH\"\n");
218
            output.write("fi\n");
219
            output.write("export PATH\n");
220
            output.write("\n");
221
            if (Sextante.isMacOSX()) {
222
               output.write("if [ ! \"$DYLD_LIBRARY_PATH\" ] ; then\n");
223
               output.write("\tDYLD_LIBRARY_PATH=\"$GISBASE/lib\"\n");
224
               output.write("else\n");
225
               output.write("\tDYLD_LIBRARY_PATH=\"$GISBASE/lib:$DYLD_LIBRARY_PATH\"\n");
226
               output.write("fi\n");
227
               output.write("export DYLD_LIBRARY_PATH\n");
228
            }
229
            else {
230
               output.write("if [ ! \"$LD_LIBRARY_PATH\" ] ; then\n");
231
               output.write("\tLD_LIBRARY_PATH=\"$GISBASE/lib\"\n");
232
               output.write("else\n");
233
               output.write("\tLD_LIBRARY_PATH=\"$GISBASE/lib:$LD_LIBRARY_PATH\"\n");
234
               output.write("fi\n");
235
               output.write("export LD_LIBRARY_PATH\n");
236
            }
237
            output.write("\n");
238
            output.write("if [ ! \"$GRASS_PYTHON\" ] ; then\n");
239
            output.write("\tGRASS_PYTHON=python\n");
240
            output.write("fi\n");
241
            output.write("export GRASS_PYTHON\n");
242
            output.write("if [ ! \"$PYTHONPATH\" ] ; then\n");
243
            output.write("\tPYTHONPATH=\"$GISBASE/etc/python\"\n");
244
            output.write("else\n");
245
            output.write("\tPYTHONPATH=\"$GISBASE/etc/python:$PYTHONPATH\"\n");
246
            output.write("fi\n");
247
            output.write("export PYTHONPATH\n");
248
            output.write("\n");
249
            output.write("if [ ! \"$GRASS_GNUPLOT\" ] ; then\n");
250
            output.write("\tGRASS_GNUPLOT=\"gnuplot -persist\"\n");
251
            output.write("\texport GRASS_GNUPLOT\n");
252
            output.write("fi\n");
253
            output.write("\n");
254
            output.write("if [ \"$GRASS_FONT_CAP\" ] && [ ! -f \"$GRASS_FONT_CAP\" ] ; then\n");
255
            output.write("\tg.mkfontcap\n");
256
            output.write("fi\n");
257
            output.write("\n");
258
            output.write("g.gisenv set=\"MAPSET=" + mapset + "\"\n");
259
            output.write("g.gisenv set=\"LOCATION=" + location + "\"\n");
260
            output.write("g.gisenv set=\"LOCATION_NAME=" + location + "\"\n");
261
            output.write("g.gisenv set=\"GISDBASE=" + gisdbase + "\"\n");
262
            output.write("g.gisenv set=\"GRASS_GUI=text\"\n");
263
            output.write("\n");
264
            output.write("\"" + grassfolder + File.separator + "etc" + File.separator + "run\" " + "\"$GRASS_BATCH_JOB\" 1>&2\n");
265
            output.write("\n");
266
            output.close();
267
            setExecutable(script.getAbsolutePath());
268
         }
269
         catch (final Exception e) {
270
            return (null);
271
         }
272
      }
273
      else {//Windows
274

  
275
         //Write windows startup script
276
         String shToolsPath = "";
277
         if ((sWinShell.length() < 2) || (sWinShell == null)) {
278
            return (null);
279
         }
280
         shToolsPath = sWinShell;
281
         shToolsPath = shToolsPath.substring(0, shToolsPath.lastIndexOf(File.separator));
282
         try {
283
            //m_ComFile.createNewFile();
284
            output = new BufferedWriter(new FileWriter(script));
285
            //Turn on/off verbose output
286
            output.write("@echo off\n");
287
            //Settings that would otherwise be done in grassXx.bat
288
            output.write("set HOME=" + System.getProperty("user.home") + "\n");
289
            output.write("set GISRC=" + gisrc.getAbsolutePath() + "\n");
290
            output.write("set GRASS_SH=" + sWinShell + "\n");
291
            output.write("set PATH=" + shToolsPath + File.separator + ";" + "%PATH%\n");
292
            output.write("set WINGISBASE=" + sFolder + "\n");
293
            output.write("set GISBASE=" + sFolder + "\n");
294
            output.write("set GRASS_PROJSHARE=" + sFolder + File.separator + "share" + File.separator + "proj" + "\n");
295
            output.write("set GRASS_MESSAGE_FORMAT=gui\n");
296
            //Replacement code for etc/Init.bat
297
            output.write("if \"%GRASS_ADDON_PATH%\"==\"\" set PATH=%WINGISBASE%\\bin;%WINGISBASE%\\scripts;%WINGISBASE%\\lib;%PATH%\n");
298
            output.write("if not \"%GRASS_ADDON_PATH%\"==\"\" set PATH=%WINGISBASE%\\bin;%WINGISBASE%\\scripts;%WINGISBASE%\\lib;%GRASS_ADDON_PATH%;%PATH%\n");
299
            output.write("\n");
300
            output.write("set GRASS_VERSION=" + getGrassVersion() + "\n");
301
            output.write("if not \"%LANG%\"==\"\" goto langset\n");
302
            output.write("FOR /F \"usebackq delims==\" %%i IN (`\"%WINGISBASE%\\etc\\winlocale\"`) DO @set LANG=%%i\n");
303
            output.write(":langset\n");
304
            output.write("\n");
305
            output.write("set PATHEXT=%PATHEXT%;.PY\n");
306
            output.write("set PYTHONPATH=%PYTHONPATH%;%WINGISBASE%\\etc\\python;%WINGISBASE%\\etc\\wxpython\\n");
307
            output.write("\n");
308
            output.write("g.gisenv.exe set=\"MAPSET=" + mapset + "\"\n");
309
            output.write("g.gisenv.exe set=\"LOCATION=" + location + "\"\n");
310
            output.write("g.gisenv.exe set=\"LOCATION_NAME=" + location + "\"\n");
311
            output.write("g.gisenv.exe set=\"GISDBASE=" + gisdbase + "\"\n");
312
            output.write("g.gisenv.exe set=\"GRASS_GUI=text\"\n");
313
            output.write(cmdline);
314
            output.write("\n");
315
            /*output.write("call \"%GRASS_BATCH_JOB%\"\n");
316
            output.write("call \"%GRASS_BATCH_JOB%\" > " + m_ComFile.getAbsolutePath() + " 2>&1\n\n");*/
317
            output.write("exit\n");
318
            output.close();
319
         }
320
         catch (final Exception e) {
321
            return (null);
322
         }
323
      }
324

  
325
      if (script != null) {
326
         return script;
327
      }
328
      return null;
329
   }
330

  
331

  
332
   /**
333
    * Returns a ProcesBuilder ready to execute grass.
334
    * 
335
    * @param cmdline
336
    * 
337
    * @return a ProcesBuilder ready to execute grass
338
    */
339
   static ProcessBuilder getGrassExecutable(final String cmdline) {
340

  
341
      final String sFolder = SextanteGUI.getSettingParameterValue(SextanteGrassSettings.GRASS_FOLDER);
342

  
343
      final List<String> list = new ArrayList<String>();
344
      ProcessBuilder pb;
345
      pb = new ProcessBuilder(list);
346
      final Map env = pb.environment();
347
      env.put("GRASS_BATCH_JOB", getBatchJobFile());
348
      if (Sextante.isUnix() || Sextante.isMacOSX()) {
349
         env.put("GRASS_MESSAGE_FORMAT", "gui");
350
         env.put("GISBASE", sFolder);
351
         final File script = (createStartupScript(cmdline));
352
         if (script != null) {
353
            list.add(script.getAbsolutePath());
354
         }
355
         else {
356
            //TODO: need to catch this one level higher!
357
            return null;
358
         }
359
      }
360
      else { //windows
361
         list.add("cmd.exe");
362
         list.add("/C");
363
         //list.add("start");
364
         //list.add("/max");
365
         final File script = (createStartupScript(cmdline));
366
         if (script != null) {
367
            list.add(script.getAbsolutePath());
368
         }
369
         else {
370
            //TODO: need to catch this one level higher!
371
            return null;
372
         }
373
      }
374
      return pb;
375
   }
376

  
377

  
378
   public static String getBatchJobFile() {
379

  
380
      String sFile;
381

  
382
      if (Sextante.isUnix() || Sextante.isMacOSX()) {
383
         sFile = "sextante_batch_job.sh";
384
      }
385
      else {//Windows
386
         sFile = "sextante_batch_job.bat";
387
      }
388

  
389
      sFile = SextanteGUI.getUserFolder() + File.separator + sFile;
390

  
391
      return sFile;
392

  
393
   }
394

  
395

  
396
   /**
397
    * Returns a GRASS map name which can be safely used to store an imported layer or any other GRASS element (a region setting, a
398
    * group) that is significant in our context. When using the name returned by this function, there is virtually no chance that
399
    * it will overwrite any existing data in the mapset.
400
    * 
401
    * Note: valid GRASS MAP names must not contain spaces or special characters, must start on a letter and should not include "-"
402
    * (minus)
403
    * 
404
    * @param sPrefix
405
    *                a prefix for the temp map name
406
    */
407
   public static String getTempMapName(final String sPrefix) {
408
      String tmpName;
409
      String sName;
410
      UUID id;
411
      boolean exists;
412

  
413
      do {
414
         exists = false;
415
         id = UUID.randomUUID();
416
         tmpName = new String(sPrefix + id);
417
         sName = new String(tmpName.replace('-', '_'));
418
         final File vectordir = new File(getGrassMapsetFolder() + File.separator + "vector" + File.separator + sName);
419
         final File rasterfile = new File(getGrassMapsetFolder() + File.separator + "cellhd" + File.separator + sName);
420
         final File regionfile = new File(getGrassMapsetFolder() + File.separator + "windows" + File.separator + sName);
421
         final File voxelfile = new File(getGrassMapsetFolder() + File.separator + "grid3d" + File.separator + sName);
422
         final File catfile = new File(getGrassMapsetFolder() + File.separator + "cats" + File.separator + sName);
423
         final File groupfile = new File(getGrassMapsetFolder() + File.separator + "group" + File.separator + sName);
424
         if (vectordir.exists() || rasterfile.exists() || regionfile.exists() || voxelfile.exists() || catfile.exists()
425
             || groupfile.exists()) {
426
            exists = true;
427
         }
428
      }
429
      while (exists);
430

  
431
      return (sName);
432
   }
433

  
434

  
435
   /**
436
    * Returns a GRASS map name which can be safely used to store an imported layer (i.e. there is no chance that it will overwrite
437
    * an existing map in the mapset).
438
    * 
439
    * Note: valid GRASS MAP names must not contain spaces or special characters, must start on a letter and should not include "-"
440
    * (minus)
441
    * 
442
    */
443
   public static String getTempMapName() {
444
      return (getTempMapName(GrassUtils.TEMP_PREFIX + "_"));
445
   }
446

  
447

  
448
   /**
449
    * Checks if the current GRASS mapset (rather: the location of which it is part) works in lat/lon degrees. We need this
450
    * information, because some GRASS modules do not work (well) with lat/lon input data.
451
    * 
452
    * @return "true" if the current mapset works in lat/lon, "false" otherwise.
453
    */
454
   public static boolean isLatLon() {
455
      String mapSetFolder;
456

  
457

  
458
      mapSetFolder = new String(getGrassMapsetFolder().substring(0, getGrassMapsetFolder().lastIndexOf(File.separator))
459
                                + File.separator + "PERMANENT/PROJ_UNITS");
460

  
461
      try {
462
         final FileInputStream fstream = new FileInputStream(mapSetFolder);
463
         final DataInputStream in = new DataInputStream(fstream);
464
         final BufferedReader br = new BufferedReader(new InputStreamReader(in));
465
         String line;
466
         while ((line = br.readLine()) != null) {
467
            if (line.contains("degree")) {
468
               in.close();
469
               return (true);
470
            }
471
         }
472
         in.close();
473
      }
474
      catch (final Exception e) {
475
         Sextante.addWarningToLog("GRASS Interface: could not determine coordinate system. Assuming X/Y(/Z) cartesian.\n");
476
      }
477
      return (false);
478
   }
479

  
480

  
481
   /*
482
    * Checks whether a GRASS map contains more than one type of geometry primitives.
483
    * We need to know this for shapefile export.
484
    *
485
    * @param sMapName
486
    * 				Name of GRASS map to query
487
    */
488
   public static boolean isMultiGeom(final String sMapName) throws GrassExecutionException {
489

  
490
      boolean is_multi_geom = false;
491

  
492
      //Get number of objects for each type of geometry in GRASS map
493
      final int num_points = GrassVInfoUtils.getNumPoints(sMapName);
494
      final int num_lines = GrassVInfoUtils.getNumLines(sMapName);
495
      final int num_polygons = GrassVInfoUtils.getNumPolygons(sMapName);
496
      final int num_faces = GrassVInfoUtils.getNumFaces(sMapName);
497
      final int num_kernels = GrassVInfoUtils.getNumKernels(sMapName);
498

  
499
      //Check for type combinations that would lead to multiple geometry types
500
      if (num_points > 0) {
501
         if ((num_kernels > 0) || (num_lines > 0) || (num_polygons > 0) || (num_faces > 0)) {
502
            is_multi_geom = true;
503
         }
504
      }
505
      if (num_kernels > 0) {
506
         if ((num_points > 0) || (num_lines > 0) || (num_polygons > 0) || (num_faces > 0)) {
507
            is_multi_geom = true;
508
         }
509
      }
510
      if (num_lines > 0) {
511
         if ((num_points > 0) || (num_kernels > 0) || (num_polygons > 0) || (num_faces > 0)) {
512
            is_multi_geom = true;
513
         }
514
      }
515
      if (num_polygons > 0) {
516
         if ((num_points > 0) || (num_kernels > 0) || (num_lines > 0) || (num_faces > 0)) {
517
            is_multi_geom = true;
518
         }
519
      }
520
      if (num_faces > 0) {
521
         if ((num_points > 0) || (num_kernels > 0) || (num_lines > 0) || (num_polygons > 0)) {
522
            is_multi_geom = true;
523
         }
524
      }
525

  
526
      if (num_points + num_lines + num_polygons + num_faces + num_kernels == 0) {
527
         //No valid geometries. Maybe a topology error?
528
         JOptionPane.showMessageDialog(null, Sextante.getText("grass_error_geometries_none_found"),
529
                  Sextante.getText("grass_error_title"), JOptionPane.WARNING_MESSAGE);
530
         throw new GrassExecutionException();
531
      }
532
      return (is_multi_geom);
533

  
534
   }
535

  
536

  
537
   /*
538
    * Helper function for runGRASS().
539
    *
540
    * Takes a line of GRASS output, analyzes it and decides whether to
541
    * send it to log and/or progress monitor.
542
    * May also do some reformatting before relaying the string for display.
543
    *
544
    */
545
   public static void filterGRASSOutput(String line) throws GrassExecutionException {
546

  
547
      boolean skip = false;
548

  
549
      //just process output if we are running grass form a sextante algorithm
550
      if (m_Alg == null) {
551
         return;
552
      }
553

  
554
      //Speedhack: if this is a progress info line, we can skip 99% of the remaining checks!
555
      if (!line.contains("GRASS_INFO_PERCENT")) {
556
         //All other lines need to be processed more elaborately
557
         if ((line.length() < 2)) {
558
            if ((lastWasEmpty == true) || (lastWasInfoEnd == true)) {
559
               skip = true;
560
            }
561
            lastWasEmpty = true;
562
         }
563
         else {
564
            lastWasEmpty = false;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff