Revision 39941

View differences:

tags/libraries/org.gvsig.compat/2.0/resources-test/log4j.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
5

  
6
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
7
		<layout class="org.apache.log4j.PatternLayout">
8
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
9
		</layout>
10
	</appender>
11

  
12
	<category name="org.gvsig.tools">
13
		<priority value="DEBUG" />
14
	</category>
15
	<category name="org.gvsig.compat">
16
		<priority value="DEBUG" /> 
17
	</category>
18

  
19
	<root>
20
		<priority value="INFO" />
21
		<appender-ref ref="CONSOLE" />
22
	</root>
23
</log4j:configuration>
tags/libraries/org.gvsig.compat/2.0/src/org/gvsig/compat/print/PrintAttributes.java
1
package org.gvsig.compat.print;
2

  
3
/**
4
 * Multi-platform interface to store print attributes.
5
 * Currently ionly supports the printing quality attribute
6
 * 
7
 * @author Juan Lucas Dominguez Rubio jldominguez at prodevelop.es
8
 *
9
 */
10
public interface PrintAttributes {
11
	
12
	/**
13
	 * Constant to indicate a poor printing quality (useful for drafts, etc) 
14
	 */
15
    public static final int PRINT_QUALITY_DRAFT = 0;
16
	/**
17
	 * Constant to indicate a normal printing quality 
18
	 */
19
	public static final int PRINT_QUALITY_NORMAL = 1;
20
	/**
21
	 * Constant to indicate a high printing quality 
22
	 */
23
	public static final int PRINT_QUALITY_HIGH = 2;
24
	
25
	/**
26
	 * DPI standard values associated with indices
27
	 */
28
    public static final int[] PRINT_QUALITY_DPI = { 72, 300, 600 };
29
	
30
	/**
31
	 * Gets the print quality value for this object.
32
	 * @return the print quality value for this object.
33
	 */
34
	public int getPrintQuality();
35
	
36
	/**
37
	 * Sets the print quality value for this object.
38
	 * @param pq the new value for the print quality value
39
	 */
40
	public void setPrintQuality(int pq);
41

  
42
}
0 43

  
tags/libraries/org.gvsig.compat/2.0/src/org/gvsig/compat/lang/GraphicsUtils.java
1
package org.gvsig.compat.lang;
2

  
3
import java.awt.Font;
4
import java.awt.Graphics2D;
5
import java.awt.Image;
6
import java.awt.image.BufferedImage;
7

  
8
import org.gvsig.compat.print.PrintAttributes;
9

  
10
/**
11
 * Multi-platform graphic utils interface.
12
 * This allows platforms with poor java.awt.Graphics2D implementations to
13
 * share most of the application source code.
14
 *   
15
 * @author Juan Lucas Dominguez Rubio jldominguez at prodevelop.es
16
 *
17
 */
18
public interface GraphicsUtils {
19
	
20
	/**
21
	 * Create a buffered Image of the given size and type.
22
	 * In this context, buffered image means editable image (admits setRGB etc)
23
	 *  
24
	 * @param w width in pixels of the requested image
25
	 * @param h height in pixels of the requested image
26
	 * @param type image type (refers to bands, etc. see {@link Image}
27
	 * @return a buffered (editable) image of the desired size and type
28
	 */
29
	public BufferedImage createBufferedImage(int w, int h, int type);
30
	
31
	/**
32
	 * Produces a copy of a buffered image with the same graphic content (pixel color)
33
	 * @param img image to be copied
34
	 * @return new instance of a BufferedImage (editable) with same size, type and graphic content.
35
	 */
36
	public BufferedImage copyBufferedImage(BufferedImage img);
37
	
38
	/**
39
	 * Returns an istance of Font which is the same as the one provided except for the size.
40
	 * 
41
	 * @param srcfont provided font to be used as model
42
	 * @param newheight height in pixels of the new fonr 
43
	 * @return the new font, same properties as the provided font, but different size
44
	 */
45
	public Font deriveFont(Font srcfont, float newheight);
46
	
47
	/**
48
	 * Returns device screen DPI (dots per inch)
49
	 * 
50
	 * @return number of pixels per inch in the current screen
51
	 */
52
	public int getScreenDPI();
53

  
54
	/**
55
	 * Adds a translation operation to the Graphics2D object's transformation matrix.
56
	 *   
57
	 * @param g Object whose transformation matrix has to be modified
58
	 * @param x horizontal offset of the translation 
59
	 * @param y vertical offset of the translation
60
	 */
61
	public void translate(Graphics2D g, double x, double y);
62
	
63
	/**
64
	 * Creates an object that implements the PrintAttributes interface with default/trivial values.
65
	 * 
66
	 * @return an object that implements the PrintAttributes interface with default/trivial values.
67
	 */
68
	public PrintAttributes createPrintAttributes();
69
	
70
	/**
71
	 * Sets the rendering hints to the Graphics2D object in a way that is suitable for drawing.
72
	 *  
73
	 * @param g the Graphics2D object whose rendering hints have to be set for drawing
74
	 */
75
	public void setRenderingHintsForDrawing(Graphics2D g);
76
	
77
	/**
78
	 * Sets the rendering hints to the Graphics2D object in a way that is suitable for printing.
79
	 *  
80
	 * @param g the Graphics2D object whose rendering hints have to be set for printing
81
	 */
82
	public void setRenderingHintsForPrinting(Graphics2D g);
83
}
0 84

  
tags/libraries/org.gvsig.compat/2.0/src/org/gvsig/compat/lang/StringUtils.java
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

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 DiSiD Technologies   Extract interface for the StringUtils utility
26
 */
27
package org.gvsig.compat.lang;
28

  
29
/**
30
 * String Utilities used for Java SE-ME compatibility.
31
 * 
32
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
33
 */
34
public interface StringUtils {
35
    
36
    /**
37
     * Compatible implementation of the String.split(regexp) method.
38
     * @see String#split(String)
39
     */
40
    String[] split(String input, String regex);
41
    
42
    /**
43
     * Compatible implementation of the String.split(regexp, limit) method.
44
     * @see String#split(String, int)
45
     */
46
    String[] split(String input, String regex, int limit);
47
    
48
    /**
49
     * Compatible implementation of the String.replaceAll(regexp, replacement)
50
     * method.
51
     * 
52
     * @see String#replaceAll(String, String)
53
     */
54
    String replaceAll(String input, String regex,
55
            String replacement);
56
    
57
    /**
58
     * Compatible implementation of the String.replaceFirst(regexp, replacement)
59
     * method.
60
     * 
61
     * @see String#replaceFirst(String, String)
62
     */
63
    String replaceFirst(String input, String regex,
64
            String replacement);
65

  
66
	/**
67
	 * Compares two Strings, maybe taking into account the current locale.
68
	 * 
69
	 * @param source
70
	 *            the source text
71
	 * @param target
72
	 *            the target text to compare to
73
	 * @param localized
74
	 *            if the comparison must be made with the current locale (ex: if
75
	 *            making a difference between accented characters or not).
76
	 * @return Returns an integer value. Value is less than zero if source is
77
	 *         less than target, value is zero if source and target are equal,
78
	 *         value is greater than zero if source is greater than target.
79
	 */
80
	int compare(String source, String target, boolean localized);
81
}
tags/libraries/org.gvsig.compat/2.0/src/org/gvsig/compat/lang/MathUtils.java
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

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 PRODEVELOP S.L. Main Development
26
 */
27
package org.gvsig.compat.lang;
28

  
29
/**
30
 * Math Utilities used for Java SE-ME compatibility.
31
 * 
32
 * @author <a href="mailto:jcarrasco@prodevelop.es">Javier Carrasco</a>
33
 */
34
public interface MathUtils {
35
	/**
36
     * Compatible implementation of the Math.log10(double) method.
37
     * @see Math#log10(double)
38
     */
39
    double log10(double value);
40
}
tags/libraries/org.gvsig.compat/2.0/src/org/gvsig/compat/net/Downloader.java
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.compat.net;
23

  
24
import java.io.File;
25
import java.io.IOException;
26
import java.net.ConnectException;
27
import java.net.URL;
28
import java.net.UnknownHostException;
29

  
30

  
31

  
32
/**
33
 * @author gvSIG Team
34
 * @version $Id$
35
 *
36
 */
37
public interface Downloader {
38
    /**
39
     * Downloads an URL into a temporary file that is removed the next time the
40
     * tempFileManager class is called, which means the next time gvSIG is launched.
41
     *
42
     * @param url
43
     * @param name
44
     * @return
45
     * @throws IOException
46
     * @throws ServerErrorResponseException
47
     * @throws ConnectException
48
     * @throws UnknownHostException
49
     */
50
    public File downloadFile(URL url, String name, ICancellable cancel) throws IOException,ConnectException, UnknownHostException;
51
    
52

  
53
    /**
54
     * Downloads a URL using the HTTP Post protocol
55
     * @param url
56
     * The server URL
57
     * @param data
58
     * The data to send in the request
59
     * @param name
60
     * A common name for all the retrieved files
61
     * @param cancel
62
     * Used to cancel the downloads
63
     * @return
64
     * The retrieved file
65
     * @throws IOException
66
     * @throws ConnectException
67
     * @throws UnknownHostException
68
     */
69
    public File downloadFile(URL url, String data, String name, ICancellable cancel) throws IOException,ConnectException, UnknownHostException;
70
 
71
    public void removeURL(URL url);
72
    
73
    public void removeURL(Object url);
74
    
75
    /**
76
     * Cleans every temporal file previously downloaded.
77
     */
78
    public void cleanUpTempFiles();
79
       
80

  
81
}
0 82

  
tags/libraries/org.gvsig.compat/2.0/src/org/gvsig/compat/net/ICancellable.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

  
42
/* CVS MESSAGES:
43
 *
44
 * $Id: ICancellable.java 29658 2009-06-29 17:10:19Z jpiera $
45
 * $Log$
46
 * Revision 1.1  2006-05-24 16:37:34  jaume
47
 * *** empty log message ***
48
 *
49
 *
50
 */
51
package org.gvsig.compat.net;
52

  
53
/**
54
 * <p>When a task is accessing to remote data, takes an indeterminate time, and occasionally gets locked. That's
55
 * the reason a task should support to be cancelable.</p>
56
 * <p><code>ICancellable</code> interface is designed for getting information about the cancellation of a
57
 * task of downloading remote information.</p>
58
 */
59
public interface ICancellable {
60
	/**
61
	 * <p>Returns <code>true</code> if a download or a group of downloads tasks has been canceled.</p>
62
	 * 
63
	 * @return <code>true</code> if a download or a group of downloads tasks has been canceled, otherwise <code>false</code>
64
	 */
65
	public boolean isCanceled();
66
	
67
	/**
68
	 * <p>Used to cancel only a group of downloads tasks with the same identifier.</p>
69
	 * 
70
	 * @return the identifier
71
	 */
72
	public Object getID();
73
}
0 74

  
tags/libraries/org.gvsig.compat/2.0/src/org/gvsig/compat/CompatLocator.java
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

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 DiSiD Technologies   Create initial base implementation
26
 */
27
package org.gvsig.compat;
28

  
29
import org.gvsig.compat.lang.GraphicsUtils;
30
import org.gvsig.compat.lang.MathUtils;
31
import org.gvsig.compat.lang.StringUtils;
32
import org.gvsig.compat.net.Downloader;
33
import org.gvsig.tools.locator.BaseLocator;
34
import org.gvsig.tools.locator.Locator;
35
import org.gvsig.tools.locator.LocatorException;
36

  
37
/**
38
 * Locator for the libCompat Library. Returns references to the library's main
39
 * utilities.
40
 * 
41
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
42
 */
43
public class CompatLocator extends BaseLocator {
44
    
45
    /**
46
     * The name of the StringUtils reference.
47
     */
48
    public static final String STRINGUTILS_NAME = "StringUtils";
49
    
50
    /**
51
     * The name of the MathUtils reference.
52
     */
53
    public static final String MATHUTILS_NAME = "MathUtils";
54
    public static final String GRAPHICSUTILS_NAME = "GraphicsUtils";
55

  
56
    /**
57
     * The description of the StringUtils reference.
58
     */
59
    private static final String STRINGUTILS_DESCRIPTION = "Compatible implementation for String Utilities";
60
    
61
    /**
62
     * The description of the MathUtils reference.
63
     */
64
    private static final String MATHUTILS_DESCRIPTION = "Compatible implementation for Math Utilities";
65
    private static final String GRAPHICSUTILS_DESCRIPTION = "Compatible implementation for Graphics Utilities";
66
    
67
    /**
68
     * The name and the description for the {@link Downloader} reference.
69
     */
70
    public static final String DOWNLOADER_NAME = "Downloader";
71
    public static final String DOWNLOADER_DESCRIPTION = "Downloader descripction";
72

  
73
    /**
74
     * Unique instance.
75
     */
76
    private static final CompatLocator instance = new CompatLocator();
77

  
78
    /**
79
     * Return the singleton instance.
80
     * 
81
     * @return the singleton instance
82
     */
83
    public static CompatLocator getInstance() {
84
        return instance;
85
    }
86

  
87
    /**
88
     * Return a reference to StringUtils.
89
     * 
90
     * @return a reference to StringUtils
91
     * @throws LocatorException
92
     *             if there is no access to the class or the class cannot be
93
     *             instantiated
94
     * @see Locator#get(String)
95
     */
96
    public static StringUtils getStringUtils() throws LocatorException {
97
        return (StringUtils) getInstance().get(STRINGUTILS_NAME);
98
    }
99

  
100
    /**
101
     * Return a reference to MathUtils.
102
     * 
103
     * @return a reference to MathUtils
104
     * @throws LocatorException
105
     *             if there is no access to the class or the class cannot be
106
     *             instantiated
107
     * @see Locator#get(String)
108
     */
109
    public static MathUtils getMathUtils() throws LocatorException {
110
        return (MathUtils) getInstance().get(MATHUTILS_NAME);
111
    }
112

  
113
    
114
    /**
115
     * Registers the Class implementing the MathUtils interface.
116
     * 
117
     * @param clazz
118
     *            implementing the MathUtils interface
119
     */
120
    public static void registerMathUtils(Class clazz) {
121
        getInstance()
122
                .register(MATHUTILS_NAME, MATHUTILS_DESCRIPTION, clazz);
123
    }
124
    
125
    /**
126
     * Registers the Class implementing the StringUtils interface.
127
     * 
128
     * @param clazz
129
     *            implementing the StringUtils interface
130
     */
131
    public static void registerStringUtils(Class clazz) {
132
        getInstance()
133
                .register(STRINGUTILS_NAME, STRINGUTILS_DESCRIPTION, clazz);
134
    }
135
    
136
    // ============================================================
137
    // ============================================================
138
    // ============================================================
139
    
140
    /**
141
     * Return a reference to GraphicsUtils.
142
     * 
143
     * @return a reference to GraphicsUtils
144
     * @throws LocatorException
145
     *             if there is no access to the class or the class cannot be
146
     *             instantiated
147
     * @see Locator#get(String)
148
     */
149
    public static GraphicsUtils getGraphicsUtils() throws LocatorException {
150
        return (GraphicsUtils) getInstance().get(GRAPHICSUTILS_NAME);
151
    }
152

  
153
    
154
    /**
155
     * Registers the Class implementing the GraphicsUtils interface.
156
     * 
157
     * @param clazz
158
     *            implementing the GraphicsUtils interface
159
     */
160
    public static void registerGraphicsUtils(Class clazz) {
161
        getInstance()
162
                .register(GRAPHICSUTILS_NAME, GRAPHICSUTILS_DESCRIPTION, clazz);
163
    }
164
    
165
    /**
166
     * Return a reference to GraphicsUtils.
167
     * 
168
     * @return a reference to GraphicsUtils
169
     * @throws LocatorException
170
     *             if there is no access to the class or the class cannot be
171
     *             instantiated
172
     * @see Locator#get(String)
173
     */
174
    public static Downloader getDownloader() throws LocatorException {
175
        return (Downloader) getInstance().get(DOWNLOADER_NAME);
176
    }
177

  
178
    
179
    /**
180
     * Registers the Class implementing the GraphicsUtils interface.
181
     * 
182
     * @param clazz
183
     *            implementing the GraphicsUtils interface
184
     */
185
    public static void registerDownloader(Class clazz) {
186
        getInstance()
187
                .register(DOWNLOADER_NAME, DOWNLOADER_DESCRIPTION, clazz);
188
    }
189
    
190
    
191
}
tags/libraries/org.gvsig.compat/2.0/src/org/gvsig/compat/se/net/SEDownloader.java
1
package org.gvsig.compat.se.net;
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42

  
43
import java.io.BufferedOutputStream;
44
import java.io.DataInputStream;
45
import java.io.DataOutputStream;
46
import java.io.File;
47
import java.io.FileNotFoundException;
48
import java.io.FileOutputStream;
49
import java.io.IOException;
50
import java.io.OutputStreamWriter;
51
import java.net.ConnectException;
52
import java.net.HttpURLConnection;
53
import java.net.URL;
54
import java.net.UnknownHostException;
55
import java.security.KeyManagementException;
56
import java.security.NoSuchAlgorithmException;
57
import java.util.Hashtable;
58
import java.util.prefs.Preferences;
59

  
60
import javax.net.ssl.HttpsURLConnection;
61
import javax.net.ssl.SSLContext;
62
import javax.net.ssl.TrustManager;
63
import javax.net.ssl.X509TrustManager;
64

  
65
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
67

  
68
import org.gvsig.compat.net.ICancellable;
69

  
70

  
71
/**
72
 * Clase con m?todos de utilidad en el protocolo WMS
73
 *
74
 * @authors Laura D?az, jaume dominguez faus
75
 */
76
public class SEDownloader implements org.gvsig.compat.net.Downloader{
77
    String                  characters;
78
	boolean                 canceled;
79
	final long              latency    = 500;
80
	private static int      count      = 0;
81
	private static Logger   LOG     = LoggerFactory.getLogger(SEDownloader.class);
82
	
83
	/**
84
	 * Used to cancel a group of files
85
	 * <b>key</b>: Group id, <b>value</b>: Boolean (true if
86
	 * the group has to be canceled. Otherwise it is
87
	 * false)
88
	 */
89
	Hashtable canceledGroup = new Hashtable();
90
	/**
91
	 * <b>key</b>: URL, <b>value</b>: path to the downloaded file.
92
	 */
93
	Hashtable downloadedFiles;
94
	Exception downloadException;
95
	final String tempDirectoryPath = System.getProperty("java.io.tmpdir")+"/tmp-andami";
96
    
97
	public SEDownloader() {
98
        super();  
99
		characters = "";
100
		for (int j = 32; j<=127; j++){
101
			characters += (char) j;
102
		}
103
		characters += "?????????????????????????????????????????????????\n\r\f\t??";
104
	}
105
	
106
	/**
107
	 * Return the content of a file that has been created 
108
	 * from a URL using the HTTP GET protocol
109
	 * @param url
110
	 * The URL
111
	 * @return
112
	 * File containing this URL's content or null if no file was found.
113
	 */
114
	private File getPreviousDownloadedURL(URL url){
115
		return getPreviousDownloaded(url);
116
	}
117

  
118
	/**
119
	 * Return the content of a file that has been created 
120
	 * from a URL using the HTTP POST protocol
121
	 * @param url
122
	 * The URL
123
	 * @param data
124
	 * The data to send on the query
125
	 * @return
126
	 * File containing this URL's content or null if no file was found.
127
	 */
128
	private File getPreviousDownloadedURL(URL url, String data) {
129
		if(data == null)
130
			return getPreviousDownloaded(url);
131
		return getPreviousDownloaded(url + data);
132
	}
133

  
134
	/**
135
	 * Returns the content of a URL as a file from the file system.<br>
136
	 * <p>
137
	 * If the URL has been already downloaded in this session and notified
138
	 * to the system using the static <b>Utilities.addDownloadedURL(URL)</b>
139
	 * method, it can be restored faster from the file system avoiding to
140
	 * download it again.
141
	 * </p>
142
	 * @param url
143
	 * @return File containing this URL's content or null if no file was found.
144
	 */
145
	private File getPreviousDownloaded(Object object) {
146
		File f = null;
147
		if (downloadedFiles != null && downloadedFiles.containsKey(object)) {
148
			String filePath = (String) downloadedFiles.get(object);
149
			f = new File(filePath);
150
			if (!f.exists())
151
				return null;
152
		}
153
		return f;
154
	}
155

  
156
	/**
157
	 * Adds an URL to the table of downloaded files for further uses. If the URL
158
	 * already exists in the table its filePath value is updated to the new one and
159
	 * the old file itself is removed from the file system.
160
	 *
161
	 * @param url
162
	 * @param filePath
163
	 */
164
	void addDownloadedURL(URL url, String filePath) {
165
		if (downloadedFiles == null)
166
			downloadedFiles = new Hashtable();
167
		String fileName = (String) downloadedFiles.put(url, filePath);
168
		//JMV: No se puede eliminar el anterior porque puede que alguien lo
169
		// este usando
170
		/*
171
        if (fileName!=null){
172
            File f = new File(fileName);
173
            if (f.exists())
174
                f.delete();
175
        }
176
		 */
177
	}
178

  
179
	/**
180
	 * Downloads an URL into a temporary file that is removed the next time the
181
	 * tempFileManager class is called, which means the next time gvSIG is launched.
182
	 *
183
	 * @param url
184
	 * @param name
185
	 * @return
186
	 * @throws IOException
187
	 * @throws ServerErrorResponseException
188
	 * @throws ConnectException
189
	 * @throws UnknownHostException
190
	 */
191
	public synchronized File downloadFile(URL url, String name, ICancellable cancel) throws IOException,ConnectException, UnknownHostException {
192
		File f = null;
193

  
194
		if ((f = getPreviousDownloadedURL(url)) == null) {
195
			File tempDirectory = new File(tempDirectoryPath);
196
			if (!tempDirectory.exists())
197
				tempDirectory.mkdir();
198

  
199
			f = new File(calculateFileName(name));
200

  
201
			if (cancel == null) {
202
				cancel = new ICancellable() {
203
					public boolean isCanceled() {
204
						return false;
205
					}
206
					public Object getID(){
207
						return SEDownloader.class.getName();
208
					}
209
				};
210
			}
211
			
212
			Monitor monitorObj = new Monitor(this, cancel);
213
			Thread downloader = new Thread(new Downloader(this, url, f, cancel.getID()));
214
			Thread monitor = new Thread(monitorObj);
215
			
216
			monitor.start();
217
			downloader.start();
218
			while(!getCanceled(cancel.getID()) && downloader.isAlive()) {
219
				try {
220
					Thread.sleep(latency);
221
				} catch (InterruptedException e) {
222
					LOG.error("Error", e);
223
				}
224
			}
225

  
226
			try {
227
				monitorObj.setFinish(true);
228
				monitor.join();
229
				downloader.join();
230
			} catch (InterruptedException e1) {
231
				LOG.warn(e1.getMessage());
232
			}
233
			downloader = null;
234
			monitor = null;
235

  
236
			if (getCanceled(cancel.getID()))
237
				return null;
238
			downloader = null;
239
			monitor = null;
240
			if (this.downloadException != null) {
241
				Exception e = this.downloadException;
242
				if (e instanceof FileNotFoundException)
243
					throw (IOException) e;
244
				else if (e instanceof IOException)
245
					throw (IOException) e;
246
				else if (e instanceof ConnectException)
247
					throw (ConnectException) e;
248
				else if (e instanceof UnknownHostException)
249
					throw (UnknownHostException) e;
250
			}
251
		} else {
252
		    LOG.info(url.toString() + " cached at '" + f.getAbsolutePath() + "'");
253
		}
254

  
255
		return f;
256
	}
257
	
258
	private String calculateFileName(String name) {
259
		count ++;
260
		int index = name.lastIndexOf(".");
261
		if (index > 0){
262
			return tempDirectoryPath + "/" + name.substring(0,index) + System.currentTimeMillis() + count + 
263
				name.substring(index, name.length());
264
		}
265
		return tempDirectoryPath + "/" + name + System.currentTimeMillis() + count;
266
	}
267

  
268

  
269
	/**
270
	 * Downloads a URL using the HTTP Post protocol
271
	 * @param url
272
	 * The server URL
273
	 * @param data
274
	 * The data to send in the request
275
	 * @param name
276
	 * A common name for all the retrieved files
277
	 * @param cancel
278
	 * Used to cancel the downloads
279
	 * @return
280
	 * The retrieved file
281
	 * @throws IOException
282
	 * @throws ConnectException
283
	 * @throws UnknownHostException
284
	 */
285
	public synchronized File downloadFile(URL url, String data, String name, ICancellable cancel) throws IOException,ConnectException, UnknownHostException{
286
		File f = null;
287

  
288
		if ((f = getPreviousDownloadedURL(url,data)) == null) {
289
			File tempDirectory = new File(tempDirectoryPath);
290
			if (!tempDirectory.exists())
291
				tempDirectory.mkdir();
292

  
293
			f = new File(calculateFileName(name));
294

  
295
			if (cancel == null) {
296
				cancel = new ICancellable() {
297
					public boolean isCanceled() {
298
						return false;
299
					}
300
					public Object getID(){
301
						return SEDownloader.class.getName();
302
					}
303
				};
304
			}
305
			Monitor monitorObj = new Monitor(this, cancel);
306
			Thread downloader = new Thread(new Downloader(this, url, data, f, cancel.getID()));
307
			Thread monitor = new Thread(monitorObj);
308
			monitor.start();
309
			downloader.start();
310
			while(!getCanceled(cancel.getID()) && downloader.isAlive()) {
311
				try {
312
					Thread.sleep(latency);
313
				} catch (InterruptedException e) {
314
					LOG.error("Error", e);
315
				}
316
			}
317

  
318
			try {
319
				monitorObj.setFinish(true);
320
				monitor.join();
321
				downloader.join();
322
			} catch (InterruptedException e1) {
323
				LOG.warn(e1.getMessage());
324
			}
325
			downloader = null;
326
			monitor = null;
327

  
328
			if (getCanceled(cancel.getID()))
329
				return null;
330
			if (this.downloadException!=null) {
331
				Exception e = this.downloadException;
332
				if (e instanceof FileNotFoundException)
333
					throw (IOException) e;
334
				else if (e instanceof IOException)
335
					throw (IOException) e;
336
				else if (e instanceof ConnectException)
337
					throw (ConnectException) e;
338
				else if (e instanceof UnknownHostException)
339
					throw (UnknownHostException) e;
340
			}
341
		} else {
342
			LOG.info(url.toString() + " cached at '" + f.getAbsolutePath() + "'");
343
		}
344

  
345
		return f;
346
	}
347

  
348
	/**
349
	 * Try if a group of downloads has been canceled
350
	 * @param groupId
351
	 * Group id
352
	 * @return
353
	 * If the group has been canceled
354
	 */
355
	protected boolean getCanceled(Object groupId) {
356
		Object obj = canceledGroup.get(groupId);
357
		if (obj != null) {
358
			return ((Boolean)obj).booleanValue();
359
		}
360
		return false;
361
	}
362

  
363
	/**
364
	 * Cancel a group of downloads
365
	 * @param groupId
366
	 * Group id
367
	 * @param isCanceled
368
	 * if the group has to be canceled
369
	 */
370
	protected void setCanceled(Object groupId, boolean isCanceled) {
371
		if (groupId == null) {
372
			groupId = SEDownloader.class.getName();
373
		}
374
		canceledGroup.put(groupId,new Boolean(isCanceled));
375
	}
376

  
377
	/**
378
	 * Cleans every temporal file previously downloaded.
379
	 */
380
	public void cleanUpTempFiles() {
381
		try{
382
			File tempDirectory = new File(tempDirectoryPath);
383

  
384
			File[] files = tempDirectory.listFiles();
385
			if (files!=null) {
386
				for (int i = 0; i < files.length; i++) {
387
					// s?lo por si en un futuro se necesitan crear directorios temporales
388
					if (files[i].isDirectory())	deleteDirectory(files[i]);
389
					files[i].delete();
390
				}
391
			}
392
			tempDirectory.delete();
393
		} catch (Exception e) {	}
394

  
395
	}
396
	/**
397
	 * Recursive directory delete.
398
	 * @param f
399
	 */
400
	private void deleteDirectory(File f) {
401
		File[] files = f.listFiles();
402
		for (int i = 0; i < files.length; i++) {
403
			if (files[i].isDirectory()) 
404
				deleteDirectory(files[i]);
405
			files[i].delete();
406
		}
407

  
408
	}
409

  
410

  
411
	/**
412
	 * Remove an URL from the system cache. The file will remain in the file
413
	 * system for further eventual uses.
414
	 * @param request
415
	 */
416
	public void removeURL(URL url) {
417
		if (downloadedFiles != null && downloadedFiles.containsKey(url))
418
			downloadedFiles.remove(url);
419
	}
420

  
421
	/**
422
	 * Remove an URL from the system cache. The file will remain in the file
423
	 * system for further eventual uses.
424
	 * @param request
425
	 */
426
	public void removeURL(Object url) {
427
		if (downloadedFiles != null && downloadedFiles.containsKey(url))
428
			downloadedFiles.remove(url);
429
	}
430
}
431

  
432
final class Monitor implements Runnable {
433
	ICancellable c;
434
	private volatile boolean finish = false;
435
	SEDownloader downloader;
436
	private static Logger LOG = LoggerFactory.getLogger(Monitor.class);
437
	
438
	public Monitor(SEDownloader downloader, ICancellable cancel) {
439
	    downloader.setCanceled(cancel.getID(),false);
440
		this.c = cancel;
441
		this.downloader = downloader;
442
	}
443
	
444
	public void run() {
445
		while (!c.isCanceled() && !getFinish()) {
446
			try {
447
				Thread.sleep(downloader.latency);
448
			} catch (InterruptedException e) {
449
				LOG.error("Error", e);
450
			}
451
		}
452

  
453
		/*  WARNING!! This works because only one download is being processed at once.
454
		 *  You could prefer to start several transfers simultaneously. If so, you
455
		 *  should consideer using a non-static variable such is Utilities.canceled to
456
		 *  control when and which transfer in particular has been canceled.
457
		 *
458
		 *  The feature of transfer several files is at the moment under study. We are
459
		 *  planning to add an intelligent system that will give you a lot of services
460
		 *  and ease-of-use. So, we encourage you to wait for it instead of write your
461
		 *  own code.
462
		 */
463
		if(c.isCanceled())
464
			downloader.setCanceled(c.getID(), true);
465
	}
466
	
467
	public synchronized void setFinish(boolean value) { 
468
		finish = value; 
469
	}
470
	
471
	public synchronized boolean getFinish() { 
472
		return finish; 
473
	}
474
}
475

  
476
final class Downloader implements Runnable {
477
	private URL url                    = null;
478
	private File dstFile               = null;
479
	private Object groupID             = null;
480
	private String data                = null;
481
	private SEDownloader downloader    = null;
482
	private static Logger LOG       = LoggerFactory.getLogger(Downloader.class);
483
	
484
	public Downloader(SEDownloader downloader, URL url, File dstFile, Object groupID) {
485
		this.url = url;
486
		this.dstFile = dstFile;
487
		this.groupID = groupID;
488
		this.downloader = downloader;
489
		downloader.downloadException = null;
490
	}
491

  
492
	public Downloader(SEDownloader downloader, URL url, String data, File dstFile, Object groupID) {
493
		this.url = url;
494
		this.data = data;
495
		this.dstFile = dstFile;
496
		this.groupID = groupID;	
497
		this.downloader = downloader;
498
		downloader.downloadException = null;
499
	}
500

  
501
	public void run() {
502
		LOG.info("downloading '" + url.toString() + "' to: " + dstFile.getAbsolutePath());
503
		if (data != null){
504
		    LOG.info("using POST, request = " + data);
505
		}
506
		// getting timeout from preferences in milliseconds.
507
		Preferences prefs = Preferences.userRoot().node( "gvsig.downloader" );
508
		// by default 1 minute (60000 milliseconds.
509
		int timeout = prefs.getInt("timeout", 60000);
510

  
511
		DataOutputStream dos;
512
		try {
513
			DataInputStream is;
514
			OutputStreamWriter os = null;
515
			HttpURLConnection connection = null;
516
			//If the used protocol is HTTPS
517
			if (url.getProtocol().equals("https")) {
518
				disableHttsValidation();
519
			}
520
			connection = (HttpURLConnection)url.openConnection();
521
			connection.setUseCaches(false);
522
			connection.setConnectTimeout(timeout);
523
			//If it uses a HTTP POST
524
			if (data != null) {
525
				connection.setRequestProperty("SOAPAction", "post");
526
				connection.setRequestMethod("POST");
527
				connection.setDoOutput(true);
528
				connection.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
529
				os = new OutputStreamWriter(connection.getOutputStream());
530
				os.write(data);
531
				os.flush();	
532
				is = new DataInputStream(connection.getInputStream());
533
			}else{
534
				is = new DataInputStream(url.openStream());
535
			}
536
			
537
			dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(dstFile)));
538
			byte[] buffer = new byte[1024 * 4];
539

  
540

  
541
			long readed = 0;
542
			for (int i = is.read(buffer); !downloader.getCanceled(groupID) && i>0; i = is.read(buffer)){
543
				dos.write(buffer, 0, i);
544
				readed += i;
545

  
546
			}
547
			if(os != null) {
548
				os.close();
549
			}
550
			dos.close();
551
			is.close();
552
			is = null;
553
			dos = null;
554
			if (downloader.getCanceled(groupID)) {
555
				LOG.info("[RemoteServices] '" + url + "' CANCELED.");
556
				dstFile.delete();
557
				dstFile = null;
558
			} else {
559
			    downloader.addDownloadedURL(url, dstFile.getAbsolutePath());
560
			}
561
		} catch (Exception e) {
562
			LOG.info("Error downloading", e);
563
			downloader.downloadException = e;
564
		}		
565
	}
566

  
567
	/**
568
	 * This method disables the Https certificate validation.
569
	 * @throws KeyManagementException
570
	 * @throws NoSuchAlgorithmException
571
	 */
572
	private void disableHttsValidation() throws KeyManagementException, NoSuchAlgorithmException{
573
		// Create a trust manager that does not validate certificate chains
574
		TrustManager[] trustAllCerts = new TrustManager[] {
575
				new X509TrustManager() {
576
					public java.security.cert.X509Certificate[] getAcceptedIssuers() {
577
						return null;
578
					}
579
					public void checkClientTrusted(
580
							java.security.cert.X509Certificate[] certs, String authType) {
581
					}
582
					public void checkServerTrusted(
583
							java.security.cert.X509Certificate[] certs, String authType) {
584
					}
585
				}
586
		};
587

  
588
		// Install the all-trusting trust manager
589
		SSLContext sc = SSLContext.getInstance("SSL");
590
		sc.init(null, trustAllCerts, new java.security.SecureRandom());
591
		HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
592
	}
593
}
0 594

  
tags/libraries/org.gvsig.compat/2.0/src/org/gvsig/compat/se/print/SePrintAttributes.java
1
package org.gvsig.compat.se.print;
2

  
3
import org.gvsig.compat.print.PrintAttributes;
4

  
5
/**
6
 * JSE (Desktop Java) implementation of {@link PrintAttributes}
7
 * 
8
 * @author Juan Lucas Dominguez Rubio jldominguez at prodevelop.es
9
 * 
10
 * @see PrintAttributes
11
 *
12
 */
13
public class SePrintAttributes implements PrintAttributes{
14

  
15
	int pq = 0;
16
	
17
	public int getPrintQuality() {
18
		return pq;
19
	}
20

  
21
	public void setPrintQuality(int pq) {
22
		this.pq=pq;
23
		
24
	}
25

  
26
}
tags/libraries/org.gvsig.compat/2.0/src/org/gvsig/compat/se/SECompatLibrary.java
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

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 DiSiD Technologies   Create initial base implementation
26
 */
27
package org.gvsig.compat.se;
28

  
29
import org.gvsig.compat.CompatLibrary;
30
import org.gvsig.compat.CompatLocator;
31
import org.gvsig.compat.se.lang.SEGraphUtils;
32
import org.gvsig.compat.se.lang.SEMathUtils;
33
import org.gvsig.compat.se.lang.StandardStringUtils;
34
import org.gvsig.compat.se.net.SEDownloader;
35
import org.gvsig.tools.library.AbstractLibrary;
36
import org.gvsig.tools.library.LibraryException;
37

  
38
/**
39
 * Initialization of the libCompat library, Java Standard Edition
40
 * implementation.
41
 * 
42
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
43
 */
44
public class SECompatLibrary extends AbstractLibrary {
45
	
46
    public void doRegistration() {
47
        registerAsImplementationOf(CompatLibrary.class);
48
    }
49

  
50
	protected void doInitialize() throws LibraryException {
51
		CompatLocator.registerStringUtils(StandardStringUtils.class);
52
		CompatLocator.registerMathUtils(SEMathUtils.class);
53
		CompatLocator.registerGraphicsUtils(SEGraphUtils.class);
54
		CompatLocator.registerDownloader(SEDownloader.class);
55
	}
56

  
57
	protected void doPostInitialize() throws LibraryException {
58
	}
59
}
tags/libraries/org.gvsig.compat/2.0/src/org/gvsig/compat/se/lang/SEMathUtils.java
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

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 PRODEVELOP S.L. Main Development
26
 */
27
package org.gvsig.compat.se.lang;
28

  
29
import org.gvsig.compat.lang.MathUtils;
30

  
31
/**
32
 * JSE (Desktop Java) implementation of {@link MathUtils}
33
 * 
34
 * @author Juan Lucas Dominguez Rubio jldominguez at prodevelop.es
35
 * 
36
 * @see MathUtils
37
 *
38
 */
39
public class SEMathUtils implements MathUtils{
40

  
41
	public double log10(double value) {
42
		return Math.log10(value);
43
	}
44

  
45
}
tags/libraries/org.gvsig.compat/2.0/src/org/gvsig/compat/se/lang/StandardStringUtils.java
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

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 DiSiD Technologies   Create initial implementation of StringUtils for Java SE.
26
 */
27
package org.gvsig.compat.se.lang;
28

  
29
import java.text.Collator;
30

  
31
import org.gvsig.compat.lang.StringUtils;
32

  
33
/**
34
 * String utilities implementation for Java Standard Edition.
35
 * 
36
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
37
 */
38
public class StandardStringUtils implements StringUtils {
39

  
40
	public String[] split(String input, String regex) {
41
		return input == null ? null : input.split(regex);
42
	}
43

  
44
	public String[] split(String input, String regex, int limit) {
45
		return input == null ? null : input.split(regex, limit);
46
	}
47

  
48
	public String replaceAll(String input, String regex, String replacement) {
49
		return input == null ? null : input.replaceAll(regex, replacement);
50
	}
51

  
52
	public String replaceFirst(String input, String regex, String replacement) {
53
		return input == null ? null : input.replaceFirst(regex, replacement);
54
	}
55

  
56
	public int compare(String source, String target, boolean localized) {
57
		if (localized) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff