Revision 38333

View differences:

tags/v2_0_0_Build_2047/libraries/libCompat/libCompat/src-test/org/gvsig/compat/se/SECompatLibraryTest.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}  {{Task}}
26
 */
27
package org.gvsig.compat.se;
28

  
29
import junit.framework.TestCase;
30

  
31
import org.gvsig.compat.CompatLocator;
32
import org.gvsig.compat.se.lang.StandardStringUtils;
33
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
34

  
35
/**
36
 * Unit tests for the {@link SECompatLibrary} class.
37
 * 
38
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
39
 */
40
public class SECompatLibraryTest extends TestCase {
41

  
42
    /**
43
     * Test method for {@link org.gvsig.compat.se.SECompatLibrary#initialize()}.
44
     */
45
    public void testInitialize() {
46
        new DefaultLibrariesInitializer().fullInitialize();
47

  
48
        // Check if the correct implementation is returned
49
        assertEquals(StandardStringUtils.class, CompatLocator.getStringUtils()
50
                .getClass());
51
    }
52

  
53
}
tags/v2_0_0_Build_2047/libraries/libCompat/libCompat/src-test/org/gvsig/compat/se/lang/SEMathUtilsTest.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
import org.gvsig.compat.lang.MathUtilsTestParent;
31

  
32
public class SEMathUtilsTest extends MathUtilsTestParent{
33

  
34
	protected MathUtils createUtils() {
35
		return new SEMathUtils();
36
	}
37

  
38
}
tags/v2_0_0_Build_2047/libraries/libCompat/libCompat/src-test/org/gvsig/compat/se/lang/StandardStringUtilsTest.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 {{Company}}   {{Task}}
26
 */
27
package org.gvsig.compat.se.lang;
28

  
29
import org.gvsig.compat.lang.StringUtils;
30
import org.gvsig.compat.lang.StringUtilsTestParent;
31

  
32
/**
33
 * Unit tests for the {@link org.gvsig.compat.se.lang.StandardStringUtils}
34
 * class.
35
 * 
36
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
37
 */
38
public class StandardStringUtilsTest extends StringUtilsTestParent {
39

  
40
    protected StringUtils createUtils() {
41
        return new StandardStringUtils();
42
    }
43

  
44
}
tags/v2_0_0_Build_2047/libraries/libCompat/libCompat/src-test/org/gvsig/compat/CompatLibraryTest.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}  {{Task}}
26
 */
27
package org.gvsig.compat;
28

  
29
import junit.framework.TestCase;
30

  
31
import org.gvsig.tools.library.Library;
32

  
33
/**
34
 * Unit tests for the {@link CompatLibrary} class.
35
 * 
36
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
37
 */
38
public class CompatLibraryTest extends TestCase {
39

  
40
    /**
41
     * Test method for {@link org.gvsig.compat.se.SECompatLibrary#initialize()}.
42
     */
43
    public void testInitialize() {
44
        Library api = new CompatLibrary();
45

  
46
        // 1: Initialize the Library
47
        api.initialize();
48

  
49
        // 2: postInitialize them
50
        // as we don't initialize an implementation library,
51
        // the postInitialization must throw an Exception
52
        try {
53
            api.postInitialize();
54
            fail("Library postInitialization is not checking "
55
                    + "for implementation availability");
56
        } catch (Exception ex) {
57
            // Good
58
        }
59
    }
60

  
61
}
tags/v2_0_0_Build_2047/libraries/libCompat/libCompat/src-test/org/gvsig/compat/lang/StringUtilsTestParent.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 {{Company}}   {{Task}}
26
 */
27
package org.gvsig.compat.lang;
28

  
29
import java.util.Arrays;
30
import java.util.List;
31

  
32
import junit.framework.TestCase;
33

  
34
/**
35
 * Parent class for Unit tests for {@link org.gvsig.compat.lang.StringUtils}
36
 * implementations.
37
 * 
38
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
39
 */
40
public abstract class StringUtilsTestParent extends TestCase {
41

  
42
	private StringUtils utils;
43

  
44
	protected void setUp() throws Exception {
45
		super.setUp();
46
		utils = createUtils();
47
	}
48

  
49
	/**
50
	 * Return a new instance of an implementation of the StringUtils interface.
51
	 * 
52
	 * @return a new StringUtils instance
53
	 */
54
	protected abstract StringUtils createUtils();
55

  
56
	/**
57
	 * Test method for
58
	 * {@link org.gvsig.compat.se.lang.StandardStringUtils#split(java.lang.String, java.lang.String)}
59
	 * .
60
	 */
61
	public void testSplitString() {
62
		// Check the result is the same as the returned with the String.split
63
		// method.
64
		List list1;
65
		List list2;
66

  
67
		String testString = "En un lugar de la Mancha";
68
		String regex = " ";
69

  
70
		list1 = Arrays.asList(new String[] { "En", "un", "lugar", "de", "la",
71
				"Mancha" });
72

  
73
		list2 = Arrays.asList(utils.split(testString, regex));
74

  
75
		assertEquals(list1, list2);
76

  
77
		list1 = Arrays.asList(new String[] { "En", "un lugar de la Mancha" });
78

  
79
		list2 = Arrays.asList(utils.split(testString, regex, 2));
80

  
81
		assertEquals(list1, list2);
82
	}
83

  
84
	/**
85
	 * Test method for
86
	 * {@link org.gvsig.compat.se.lang.StandardStringUtils#replaceAll(java.lang.String, java.lang.String, java.lang.String)}
87
	 * .
88
	 */
89
	public void testReplaceAll() {
90
		// Check the result is the same as the returned with the
91
		// String.replaceAll method.
92
		String testString = "En un lugar de la Mancha";
93
		String regex = " ";
94
		String replacement = "_";
95

  
96
		assertEquals("En_un_lugar_de_la_Mancha",
97
				utils.replaceAll(testString, regex, replacement));
98

  
99
		// Check replaceFirst
100
		assertEquals("En_un lugar de la Mancha",
101
				utils.replaceFirst(testString, regex, replacement));
102
	}
103

  
104
	/**
105
	 * Test method for
106
	 * {@link org.gvsig.compat.se.lang.StandardStringUtils#compare(String, String, boolean)}
107
	 * .
108
	 */
109
	public void testCompare() {
110
		String avion = "Avi?n";
111
		String avionaccent = "Avion";
112
		String barco = "Barco";
113

  
114
		// Same value
115
		assertEquals(avion + " is not equal to " + avion, 0,
116
				utils.compare(avion, avion, false));
117
		assertEquals(avion + " is not equal to " + avion, 0,
118
				utils.compare(avion, avion, true));
119

  
120
		// Non localized comparison
121
		assertTrue(utils.compare(avion, barco, false) < 0);
122
		assertTrue(utils.compare(avion, avionaccent, false) > 0);
123
		assertTrue(utils.compare(barco, avion, false) > 0);
124
		assertTrue(utils.compare(avionaccent, avion, false) < 0);
125

  
126
		// Localized comparison, so accents must not be taken into account
127
		assertTrue(utils.compare(avion, barco, true) < 0);
128
		assertEquals(0, utils.compare(avion, avionaccent, true));
129
		assertTrue(utils.compare(barco, avion, true) > 0);
130
		assertEquals(0, utils.compare(avionaccent, avion, true));
131
	}
132
}
tags/v2_0_0_Build_2047/libraries/libCompat/libCompat/src-test/org/gvsig/compat/lang/MathUtilsTestParent.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
import junit.framework.TestCase;
30

  
31
/**
32
 * Parent class for Unit tests for {@link org.gvsig.compat.lang.MathUtils}
33
 * implementations.
34
 * 
35
 * @author <a href="mailto:jcarrasco@prodevelop.es">Javier Carrasco</a>
36
 */
37
public abstract class MathUtilsTestParent extends TestCase{
38
	
39
	private MathUtils utils;
40

  
41
    protected void setUp() throws Exception {
42
        super.setUp();
43
        utils = createUtils();
44
    }
45

  
46
    /**
47
     * Return a new instance of an implementation of the MathUtils interface.
48
     * 
49
     * @return a new MathUtils instance
50
     */
51
    protected abstract MathUtils createUtils();
52
    
53
    /**
54
     * Test method for
55
     * {@link org.gvsig.compat.se.lang.MathUtils#log10(double)}
56
     * .
57
     */
58
    public void testLog10() {
59
    	assertEquals(utils.log10(1000),3.0,0.00000000001);
60
    }
61
}
tags/v2_0_0_Build_2047/libraries/libCompat/libCompat/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/v2_0_0_Build_2047/libraries/libCompat/libCompat/src/org/gvsig/compat/CompatLibrary.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.library.AbstractLibrary;
34
import org.gvsig.tools.library.LibraryException;
35
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
36

  
37
/**
38
 * Initialization of the libCompat library.
39
 * 
40
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
41
 */
42
public class CompatLibrary extends AbstractLibrary {
43

  
44
    public void doRegistration() {
45
        registerAsAPI(CompatLibrary.class);
46
    }
47

  
48
	protected void doInitialize() throws LibraryException {
49
		// Nothing to do
50
	}
51

  
52
	protected void doPostInitialize() throws LibraryException {
53
		// Validate there is any implementation registered.
54
		StringUtils stringUtils = CompatLocator.getStringUtils();
55
		
56
		if (stringUtils == null) {
57
			throw new ReferenceNotRegisteredException(
58
					CompatLocator.STRINGUTILS_NAME, CompatLocator.getInstance());
59
		}
60
		
61
		// Validate there is any implementation registered.
62
		MathUtils mathUtils = CompatLocator.getMathUtils();
63
		
64
		if (mathUtils == null) {
65
			throw new ReferenceNotRegisteredException(
66
					CompatLocator.MATHUTILS_NAME, CompatLocator.getInstance());
67
		}
68
		
69
		// Validate there is any implementation registered.
70
		GraphicsUtils gUtils = CompatLocator.getGraphicsUtils();
71
		
72
		if (gUtils == null) {
73
			throw new ReferenceNotRegisteredException(
74
					CompatLocator.GRAPHICSUTILS_NAME, CompatLocator.getInstance());
75
		}
76
		
77
		  // Validate there is any implementation registered for the Downloader.
78
        Downloader downloader = CompatLocator.getDownloader();
79
        
80
        if (downloader == null) {
81
            throw new ReferenceNotRegisteredException(
82
                    CompatLocator.DOWNLOADER_NAME, CompatLocator.getInstance());
83
        }
84
	}
85

  
86
}
tags/v2_0_0_Build_2047/libraries/libCompat/libCompat/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
	 * Gets the print quality value for this object.
27
	 * @return the print quality value for this object.
28
	 */
29
	public int getPrintQuality();
30
	
31
	/**
32
	 * Sets the print quality value for this object.
33
	 * @param pq the new value for the print quality value
34
	 */
35
	public void setPrintQuality(int pq);
36

  
37
}
0 38

  
tags/v2_0_0_Build_2047/libraries/libCompat/libCompat/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/v2_0_0_Build_2047/libraries/libCompat/libCompat/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/v2_0_0_Build_2047/libraries/libCompat/libCompat/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/v2_0_0_Build_2047/libraries/libCompat/libCompat/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/v2_0_0_Build_2047/libraries/libCompat/libCompat/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/v2_0_0_Build_2047/libraries/libCompat/libCompat/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/v2_0_0_Build_2047/libraries/libCompat/libCompat/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(){
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff