Revision 42013

View differences:

tags/org.gvsig.desktop-2.0.85/org.gvsig.desktop.library/org.gvsig.utils/src/main/config/xml-entity.xsd
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 3
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27

  
28
<xs:schema targetNamespace="http://www.gvsig.gva.es"
29
        xmlns:xs="http://www.w3.org/2001/XMLSchema">
30
  <xs:element name="xmlCastor">
31
    <xs:complexType>
32
    <xs:sequence>
33
        <xs:element ref="xml-tag" minOccurs="0" maxOccurs="unbounded" />
34
      </xs:sequence>
35
    </xs:complexType>
36
  </xs:element>
37
  
38
  <xs:element name="property">
39
    <xs:complexType>
40
      <xs:attribute name="key" type="xs:string" use="required" />
41
      <xs:attribute name="value" type="xs:string" use="optional" />
42
    </xs:complexType>
43
  </xs:element>
44

  
45
  <xs:element name="xml-tag">
46
    <xs:complexType>
47
      <xs:sequence>
48
        <xs:element ref="property" minOccurs="0" maxOccurs="unbounded" />
49
        <xs:element ref="xml-tag" minOccurs="0" maxOccurs="unbounded" />
50
      </xs:sequence>
51
      <xs:attribute name="name" type="xs:string" use="optional" />
52
    </xs:complexType>
53
  </xs:element>
54

  
55
</xs:schema>
0 56

  
tags/org.gvsig.desktop-2.0.85/org.gvsig.desktop.library/org.gvsig.utils/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.tools.IverUtilesLibrary
tags/org.gvsig.desktop-2.0.85/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/tools/backup/DefaultBackupGeneratorFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.backup;
25

  
26
/* gvSIG. Geographic Information System of the Valencian Government
27
 *
28
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
29
 * of the Valencian Government (CIT)
30
 * 
31
 * This program is free software; you can redistribute it and/or
32
 * modify it under the terms of the GNU General Public License
33
 * as published by the Free Software Foundation; either version 2
34
 * of the License, or (at your option) any later version.
35
 * 
36
 * This program is distributed in the hope that it will be useful,
37
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
 * GNU General Public License for more details.
40
 *  
41
 * You should have received a copy of the GNU General Public License
42
 * along with this program; if not, write to the Free Software
43
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
44
 * MA  02110-1301, USA.
45
 * 
46
 */
47

  
48
/**
49
 * <p>Factory that gets a {@link DefaultBackupGenerator DefaultBackupGenerator} as a particular version of
50
 *  backup generator.</p>
51
 *
52
 * @author Jose Ignacio Yarza (jiyarza@opensistemas.com)
53
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
54
 */
55
public class DefaultBackupGeneratorFactory extends BackupGeneratorFactory {
56
	/*
57
	 * (non-Javadoc)
58
	 * @see com.iver.utiles.backup.BackupGeneratorFactory#getBackupGenerator()
59
	 */
60
	public BackupGenerator getBackupGenerator() {		
61
		return new DefaultBackupGenerator();
62
	}
63
}
0 64

  
tags/org.gvsig.desktop-2.0.85/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/tools/backup/BackupGenerator.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.backup;
25

  
26
/* gvSIG. Geographic Information System of the Valencian Government
27
 *
28
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
29
 * of the Valencian Government (CIT)
30
 * 
31
 * This program is free software; you can redistribute it and/or
32
 * modify it under the terms of the GNU General Public License
33
 * as published by the Free Software Foundation; either version 2
34
 * of the License, or (at your option) any later version.
35
 * 
36
 * This program is distributed in the hope that it will be useful,
37
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
 * GNU General Public License for more details.
40
 *  
41
 * You should have received a copy of the GNU General Public License
42
 * along with this program; if not, write to the Free Software
43
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
44
 * MA  02110-1301, USA.
45
 * 
46
 */
47

  
48
import java.io.File;
49

  
50
import org.gvsig.tools.backup.exceptions.BackupException;
51

  
52

  
53
/**
54
 * <p>A tagging interface that all file backups must implement.</p>
55
 *
56
 * @author Jose Ignacio Yarza (jiyarza@opensistemas.com)
57
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
58
 */
59
public interface BackupGenerator {
60
	/**
61
	 * <p>Performs a backup of <code>source</code>.</p>
62
	 * 
63
	 * @param source the source file
64
	 */
65
	public void backup(File source) throws BackupException;
66
}
0 67

  
tags/org.gvsig.desktop-2.0.85/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/tools/backup/DefaultBackupGenerator.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.backup;
25

  
26
/* gvSIG. Geographic Information System of the Valencian Government
27
 *
28
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
29
 * of the Valencian Government (CIT)
30
 * 
31
 * This program is free software; you can redistribute it and/or
32
 * modify it under the terms of the GNU General Public License
33
 * as published by the Free Software Foundation; either version 2
34
 * of the License, or (at your option) any later version.
35
 * 
36
 * This program is distributed in the hope that it will be useful,
37
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
 * GNU General Public License for more details.
40
 *  
41
 * You should have received a copy of the GNU General Public License
42
 * along with this program; if not, write to the Free Software
43
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
44
 * MA  02110-1301, USA.
45
 * 
46
 */ 
47

  
48
import java.io.File;
49
import java.io.FileInputStream;
50
import java.io.FileOutputStream;
51
import java.nio.channels.FileChannel;
52

  
53
import org.gvsig.tools.backup.exceptions.BackupException;
54

  
55

  
56
/**
57
 * <p>Performs a backup of a file, into another file at the same path (directory), with the file extension 
58
 *  changed to <i>.bak</i>.</p>
59
 *
60
 * @author Jose Ignacio Yarza (jiyarza@opensistemas.com)
61
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
62
 */
63
public class DefaultBackupGenerator implements BackupGenerator {
64
	/*
65
	 * (non-Javadoc)
66
	 * @see com.iver.utiles.backup.BackupGenerator#backup(java.io.File)
67
	 */
68
	public void backup(File source) throws BackupException {
69
		try {
70
			int index = source.getAbsolutePath().lastIndexOf(".");
71

  
72
			if (index == -1)
73
				return;
74

  
75
			File dest = new File(source.getAbsolutePath().substring(0, index) + ".bak");
76

  
77
	        // Create channel on the source
78
	        FileChannel srcChannel = new FileInputStream(source).getChannel();
79

  
80
	        // Create channel on the destination
81
	        FileChannel dstChannel = new FileOutputStream(dest).getChannel();
82

  
83
	        // Copy file contents from source to destination
84
	        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
85

  
86
	        // Close the channels
87
	        srcChannel.close();
88
	        dstChannel.close();
89
	    } catch (Exception ex) {
90
	    	throw new BackupException(ex.getMessage(), ex, source);
91
	    }
92
	}
93
}
0 94

  
tags/org.gvsig.desktop-2.0.85/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/tools/backup/exceptions/BackupException.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.backup.exceptions;
25

  
26
/* gvSIG. Geographic Information System of the Valencian Government
27
 *
28
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
29
 * of the Valencian Government (CIT)
30
 * 
31
 * This program is free software; you can redistribute it and/or
32
 * modify it under the terms of the GNU General Public License
33
 * as published by the Free Software Foundation; either version 2
34
 * of the License, or (at your option) any later version.
35
 * 
36
 * This program is distributed in the hope that it will be useful,
37
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
 * GNU General Public License for more details.
40
 *  
41
 * You should have received a copy of the GNU General Public License
42
 * along with this program; if not, write to the Free Software
43
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
44
 * MA  02110-1301, USA.
45
 * 
46
 */
47

  
48
import java.io.File;
49

  
50
/**
51
 * <p>Exception to report that a backup process has failed.</p>
52
 *
53
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
54
 */
55
public class BackupException extends Exception {
56
	private static final long serialVersionUID = -2846421984617208883L;
57

  
58
	/**
59
	 * <p>The source file to be backup.</p>
60
	 */
61
	protected File source;
62

  
63
	/**
64
	 * <p>Constructs a new backup exception with the specified detail message and cause.</p>
65
	 * 
66
	 * @param message the detail message (which is saved for later retrieval by the <code>getMessage()</code> method).
67
	 * @param cause the cause (which is saved for later retrieval by the <code>getCause()</code> method). (A <code>null</code>
68
	 *  value is permitted, and indicates that the cause is nonexistent or unknown.)
69
	 * @param source the file from that was going to be done a backup
70
	 * 
71
	 * @see Exception#Exception(String, Throwable)
72
	 */
73
	public BackupException(String message, Throwable cause, File source) {
74
		super(message, cause);
75
		this.source = source;
76
	}
77

  
78
	/**
79
	 * <p>Gets the source file to be backup.</p> 
80
	 * 
81
	 * @return the source file
82
	 */
83
	public File getSource() {
84
		return source;
85
	}
86
}
0 87

  
tags/org.gvsig.desktop-2.0.85/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/tools/backup/BackupGeneratorFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.backup;
25

  
26
/* gvSIG. Geographic Information System of the Valencian Government
27
 *
28
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
29
 * of the Valencian Government (CIT)
30
 * 
31
 * This program is free software; you can redistribute it and/or
32
 * modify it under the terms of the GNU General Public License
33
 * as published by the Free Software Foundation; either version 2
34
 * of the License, or (at your option) any later version.
35
 * 
36
 * This program is distributed in the hope that it will be useful,
37
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
 * GNU General Public License for more details.
40
 *  
41
 * You should have received a copy of the GNU General Public License
42
 * along with this program; if not, write to the Free Software
43
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
44
 * MA  02110-1301, USA.
45
 * 
46
 */
47
 
48
/**
49
 * <p>Generic factory that creates a {@link BackupGenerator BackupGenerator} that performs a particular
50
 *  kind of backup.</p>
51
 *
52
 * @author Jose Ignacio Yarza (jiyarza@opensistemas.com)
53
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
54
 */
55
public abstract class BackupGeneratorFactory {
56
	/**
57
	 * <p>Gets an instance of a backup generator that performs a particular kind of backup.</p>
58
	 * 
59
	 * @return an instance of a backup generator that performs a particular kind of backup
60
	 */
61
	public abstract BackupGenerator getBackupGenerator();
62
}
0 63

  
tags/org.gvsig.desktop-2.0.85/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/tools/IverUtilesLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools;
25

  
26
import org.gvsig.tools.library.AbstractLibrary;
27
import org.gvsig.tools.library.LibraryException;
28
import org.gvsig.utils.swing.jcomboServer.ServerData;
29

  
30
public class IverUtilesLibrary extends AbstractLibrary {
31

  
32
    @Override
33
    public void doRegistration() {
34
        registerAsAPI(IverUtilesLibrary.class);
35
    }
36

  
37
	@Override
38
	protected void doInitialize() throws LibraryException {
39
		// Nothing to do
40
	}
41

  
42
	@Override
43
	protected void doPostInitialize() throws LibraryException {
44
		ServerData.registerPersistence();
45
	}
46
}
0 47

  
tags/org.gvsig.desktop-2.0.85/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/search/BinarySearchUsingFirstCharacters.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.utils.search;
25

  
26
import java.util.ArrayList;
27
import java.util.Arrays;
28
import java.util.Comparator;
29
import java.util.List;
30
import java.util.Vector;
31

  
32
import org.gvsig.utils.MathExtension;
33

  
34

  
35
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
36
 *
37
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
38
 *
39
 * This program is free software; you can redistribute it and/or
40
 * modify it under the terms of the GNU General Public License
41
 * as published by the Free Software Foundation; either version 2
42
 * of the License, or (at your option) any later version.
43
 *
44
 * This program is distributed in the hope that it will be useful,
45
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
47
 * GNU General Public License for more details.
48
 *
49
 * You should have received a copy of the GNU General Public License
50
 * along with this program; if not, write to the Free Software
51
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
52
 *
53
 * For more information, contact:
54
 *
55
 *  Generalitat Valenciana
56
 *   Conselleria d'Infraestructures i Transport
57
 *   Av. Blasco Ib??ez, 50
58
 *   46010 VALENCIA
59
 *   SPAIN
60
 *
61
 *      +34 963862235
62
 *   gvsig@gva.es
63
 *      www.gvsig.gva.es
64
 *
65
 *    or
66
 *
67
 *   IVER T.I. S.A
68
 *   Salamanca 50
69
 *   46005 Valencia
70
 *   Spain
71
 *
72
 *   +34 963163400
73
 *   dac@iver.es
74
 */
75

  
76
/**
77
 * This class has static methods that return items that their beginning text value matches with a text pattern. <br>
78
 * It's necessary that items of the parameter array (Vector) were sort ordered according to their text value. <br>
79
 * Supports Vectors with and without repeated items.
80
 * 
81
 * There are four methods, that are a modification of a binary search algorithm of search, getting a rank of items:
82
 * <ul>
83
 * <li>Considering case sensitive in the search.</li>
84
 * <li>Ignoring case sensitive in the search.</li>
85
 * <li>Considering case sensitive in the search and an object which implements the Comparable interface</li>
86
 * <li>Ignoring case sensitive in the search, but yes an objecth which implements the Comparable interface</li>
87
 * </ul>
88
 *
89
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
90
 */
91
public class BinarySearchUsingFirstCharacters {
92
	/**
93
	 * This method should be used when is wanted to distinguish small letters from capital letters during the search.
94
	 *
95
	 * It's necessary that all items of the array implement the {@link Comparable} interface.<br>
96
	 * And it's also necessary that the value returned by the <i>toString()</i> method of each item (supposing
97
	 *   they inherit from Object) would be the expected value user saw (that would be used to compare the items).
98
	 *
99
	 * @param text java.lang.String
100
	 * @param sortOrderedItems java.util.Vector
101
	 */
102
	public synchronized static List doSearchConsideringCaseSensitive(String text, Vector sortOrderedItems) {
103
		int currentIteration = 0;
104
		int size = sortOrderedItems.size();
105
		int maxNumberOfIterations = (int) MathExtension.log2(size);
106
		int lowIndex = 0;
107
		int highIndex = sortOrderedItems.size() - 1;
108
		int mIndx;
109

  
110
		while ((lowIndex <= highIndex) && (currentIteration <= maxNumberOfIterations)) {
111
			mIndx = ( lowIndex + highIndex ) / 2;
112

  
113
			if ( sortOrderedItems.get( mIndx ).toString().startsWith( text ) ) {
114
				lowIndex = highIndex = mIndx;
115
				highIndex ++;
116

  
117
				// Expand the rank to up
118
				while ( ( highIndex < size ) && ( sortOrderedItems.get( highIndex ).toString().startsWith( text ) ) ) {
119
					highIndex ++;
120
				}
121

  
122
				// Expand the rank to down
123
				while ( ( (lowIndex - 1) > -1 ) && ( sortOrderedItems.get( (lowIndex - 1) ).toString().startsWith( text ) ) ) {
124
					lowIndex --;
125
				}
126

  
127
				// It's possible that items with different case, should be between the same case, then this item will be added individually:
128
				List list = new Vector(sortOrderedItems.subList(lowIndex, highIndex));
129

  
130
				// Expand to down
131
				lowIndex --;
132
				while ( ( lowIndex > -1 ) && ( sortOrderedItems.get( (lowIndex ) ).toString().toLowerCase().startsWith( text.toLowerCase() ) ) ) {
133
					if (sortOrderedItems.get( lowIndex ).toString().startsWith( text )) {
134
						list.add(0, sortOrderedItems.get( lowIndex ));
135
					}
136

  
137
					lowIndex --;
138
				}
139

  
140
				// Expand to up
141
				while ( ( highIndex < size ) && ( sortOrderedItems.get( highIndex ).toString().toLowerCase().startsWith( text.toLowerCase() ) ) ) {
142
					if (sortOrderedItems.get( highIndex ).toString().startsWith( text )) {
143
						list.add(list.size(), sortOrderedItems.get( highIndex ));
144
					}
145

  
146
					highIndex ++;
147
				}
148

  
149
				// Returns all items in the rank
150
				return list; // Breaks the loop
151
			}
152
			else {
153
				if ( sortOrderedItems.get( mIndx ).toString().compareTo( text ) > 0 ) {
154
					highIndex = mIndx - 1;
155
				}
156
				else {
157
					lowIndex = mIndx + 1;
158
				}
159
			}
160

  
161
			currentIteration ++;
162
		}
163

  
164
		// If no item has been found -> return null
165
		return null;
166
	}
167

  
168
	/**
169
	 * This method should be used when is wanted not to distinguish small letters from capital letters during the search.
170
	 *
171
	 * It's necessary that all items of the array implement the {@link Comparable} interface.<br>
172
	 * And it's also necessary that the value returned by the <i>toString()</i> method of each item (supposing
173
	 *   they inherit from Object) would be the expected value user saw (that would be used to compare the items).
174
	 *
175
	 * In this particular situation, it's supposed that the vector is sort ordered according the default algorithm of Java; this has the problem that
176
	 *   it doesn't consideres the special characters and the orthographic rules of languages that aren't English, and then, for a particular
177
	 *   <i>text</i> search, an incorrect result could be obtained. The solution decided for this problem has been to modify the algorithm, for seach
178
	 *   into two ranks.
179
	 *
180
	 * @param text java.lang.String
181
	 * @param sortOrderedItems java.util.Vector
182
	 */
183
	public synchronized static List doSearchIgnoringCaseSensitive(String text, Vector sortOrderedItems) {
184
		int currentIteration = 0;
185
		int size = sortOrderedItems.size();
186
		int maxNumberOfIterations = (int) MathExtension.log2(size);
187
		int lowIndex = 0;
188
		int highIndex = sortOrderedItems.size() - 1;
189
		int mIndx;
190
		List list = null;
191
		List list2 = null;
192

  
193
		// FIRST RANK
194
		while ((lowIndex <= highIndex) && (currentIteration <= maxNumberOfIterations)) {
195
			mIndx = ( lowIndex + highIndex ) / 2;
196

  
197
			if ( sortOrderedItems.get( mIndx ).toString().toLowerCase().startsWith( text.toLowerCase() ) ) {
198
				lowIndex = highIndex = mIndx;
199
				highIndex ++;
200

  
201
				// Expand the rank to up
202
				while ( ( highIndex < size ) && ( sortOrderedItems.get( highIndex ).toString().toLowerCase().startsWith( text.toLowerCase() ) ) ) {
203
					highIndex ++;
204
				}
205

  
206
				// Expand the rank to down
207
				while ( ( (lowIndex - 1) > -1 ) && ( sortOrderedItems.get( (lowIndex - 1) ).toString().toLowerCase().startsWith( text.toLowerCase() ) ) ) {
208
					lowIndex --;
209
				}
210

  
211
				// Returns all items in the rank
212
				list = Arrays.asList((sortOrderedItems.subList(lowIndex, highIndex)).toArray());
213
				break;
214
			}
215
			else {
216
				if ( sortOrderedItems.get( mIndx ).toString().compareTo( text ) > 0 ) {
217
					highIndex = mIndx - 1;
218
				}
219
				else {
220
					lowIndex = mIndx + 1;
221
				}
222
			}
223

  
224
			currentIteration ++;
225
		}
226

  
227
		// SECOND RANK
228
		currentIteration = 0;
229
		lowIndex = 0;
230
		highIndex = sortOrderedItems.size() - 1;
231

  
232
		while ((lowIndex <= highIndex) && (currentIteration <= maxNumberOfIterations)) {
233
			mIndx = ( lowIndex + highIndex ) / 2;
234

  
235
			if ( sortOrderedItems.get( mIndx ).toString().toLowerCase().startsWith( text.toLowerCase() ) ) {
236
				lowIndex = highIndex = mIndx;
237
				highIndex ++;
238

  
239
				// Expand the rank to up
240
				while ( ( highIndex < size ) && ( sortOrderedItems.get( highIndex ).toString().toLowerCase().startsWith( text.toLowerCase() ) ) ) {
241
					highIndex ++;
242
				}
243

  
244
				// Expand the rank to down
245
				while ( ( (lowIndex - 1) > -1 ) && ( sortOrderedItems.get( (lowIndex - 1) ).toString().toLowerCase().startsWith( text.toLowerCase() ) ) ) {
246
					lowIndex --;
247
				}
248

  
249
				// Returns all items in the rank
250
				list2 = Arrays.asList((sortOrderedItems.subList(lowIndex, highIndex)).toArray()); // Breaks the loop
251

  
252
				if (list == null)
253
					return list2;
254
				else {
255
					if (list2 == null)
256
						return null;
257

  
258
					Object obj;
259
					int j;
260

  
261
					list = new ArrayList(list.subList(0, list.size()));
262

  
263
					for (int i = 0; i < list2.size(); i ++) {
264
						obj = list2.get(i);
265

  
266
						// Don't add items which are already in the list
267
						if (!list.contains(obj)) {
268
							// Adds in sort order the new item:
269
							for (j = 0; j < list.size(); j ++) {
270
								if (list.get(j).toString().compareTo(obj.toString()) > 0)
271
									break;
272
							}
273

  
274
							list.add(j, obj);
275
						}
276
					}
277

  
278
					// It's possible that some elements at the end wouldn't be found -> another small search
279
					size = list.size();
280
					if (size == 0) {
281
						j = 0;
282
					}
283
					else {
284
						j = sortOrderedItems.indexOf(list.get(size - 1));
285
					}
286

  
287
					j++;
288

  
289
					if (j < sortOrderedItems.size()) {
290
						do {
291
							obj = sortOrderedItems.get( j );
292

  
293
							if (obj.toString().toLowerCase().startsWith( text.toLowerCase())) {
294
								list.add(size, obj);
295
							}
296

  
297
							j++;
298
						}
299
						while (j < sortOrderedItems.size());
300
					}
301

  
302
					return list;
303
				}
304
			}
305
			else {
306
				if ( sortOrderedItems.get( mIndx ).toString().toLowerCase().compareTo( text.toLowerCase() ) > 0 ) {
307
					highIndex = mIndx - 1;
308
				}
309
				else {
310
					lowIndex = mIndx + 1;
311
				}
312
			}
313

  
314
			currentIteration ++;
315
		}
316

  
317
		return null;
318
	}
319

  
320
//	/** THIS VERSION FAILURES IN SOME PARTICULAR SITUATIONS
321
//	 * This method should be used when is wanted distinguish small letters from capital letters during the search, and the comparation of items
322
//	 *   done according an algorithm we define.
323
//	 *
324
//	 * And it's also necessary that the value returned by the <i>toString()</i> method of each item (supposing
325
//	 *   they inherit from Object) would be the expected value user saw (that would be used to compare the items).
326
//	 *
327
//	 * @param text java.lang.String
328
//	 * @param sortOrderedItems java.util.Vector
329
//	 * @param comp An Comparator object which implements the <i><b>compareTo()</b><i>  method.
330
//	 */
331
//	public synchronized static List doSearchConsideringCaseSensitive(String text, Vector sortOrderedItems, Comparator comp) {
332
//		int currentIteration = 0;
333
//		int size = sortOrderedItems.size();
334
//		int maxNumberOfIterations = (int) MathExtension.log2(size);
335
//		int lowIndex = 0;
336
//		int highIndex = sortOrderedItems.size() - 1;
337
//		int mIndx;
338
//
339
//
340
//		while ((lowIndex <= highIndex) && (currentIteration <= maxNumberOfIterations)) {
341
//			mIndx = ( lowIndex + highIndex ) / 2;
342
//
343
//			if ( sortOrderedItems.get( mIndx ).toString().startsWith( text ) ) {
344
//				lowIndex = highIndex = mIndx;
345
//				highIndex ++;
346
//
347
//				// Expand the rank to up
348
//				while ( ( highIndex < size ) && ( sortOrderedItems.get( highIndex ).toString().startsWith( text ) ) ) {
349
//					highIndex ++;
350
//				}
351
//
352
//				// Expand the rank to down
353
//				while ( ( (lowIndex - 1) > -1 ) && ( sortOrderedItems.get( (lowIndex - 1) ).toString().startsWith( text ) ) ) {
354
//					lowIndex --;
355
//				}
356
//
357
//				// It's possible that items with different case, should be between the same case, then this item will be added individually:
358
//				List list = new Vector(sortOrderedItems.subList(lowIndex, highIndex));
359
//
360
//
361
//				// Expand to down
362
//				lowIndex --;
363
//				while ( ( lowIndex > -1 ) && ( sortOrderedItems.get( (lowIndex ) ).toString().toLowerCase().startsWith( text.toLowerCase() ) ) ) {
364
//					if (sortOrderedItems.get( lowIndex ).toString().startsWith( text )) {
365
//						list.add(0, sortOrderedItems.get( lowIndex ));
366
//					}
367
//
368
//					lowIndex --;
369
//				}
370
//
371
//				// Expand to up
372
//				while ( ( highIndex < size ) && ( sortOrderedItems.get( highIndex ).toString().toLowerCase().startsWith( text.toLowerCase() ) ) ) {
373
//					if (sortOrderedItems.get( highIndex ).toString().startsWith( text )) {
374
//						list.add(list.size(), sortOrderedItems.get( highIndex ));
375
//					}
376
//
377
//					highIndex ++;
378
//				}
379
//
380
//				// Returns all items in the rank
381
//				return list; // Breaks the loop
382
//			}
383
//			else {
384
//				if ( comp.compare(sortOrderedItems.get( mIndx ), text ) > 0 ) {
385
//					highIndex = mIndx - 1;
386
//				}
387
//				else {
388
//					lowIndex = mIndx + 1;
389
//				}
390
//			}
391
//
392
//			currentIteration ++;
393
//		}
394
//
395
//		// If no item has been found -> return null
396
//		return null;
397
//	}
398

  
399
	/**
400
	 * This method should be used when is wanted distinguish small letters from capital letters during the search, and the comparation of items
401
	 *   done according an algorithm we define.
402
	 *
403
	 * And it's also necessary that the value returned by the <i>toString()</i> method of each item (supposing
404
	 *   they inherit from Object) would be the expected value user saw (that would be used to compare the items).
405
	 *
406
	 * @param text java.lang.String
407
	 * @param sortOrderedItems java.util.Vector
408
	 * @param comp An Comparator object which implements the <i><b>compareTo()</b><i>  method.
409
	 */
410
	public synchronized static List doSearchConsideringCaseSensitive(String text, Vector sortOrderedItems, Comparator comp) {
411
		List results_list = doSearchIgnoringCaseSensitive(text, sortOrderedItems, comp);
412

  
413
		if (results_list == null)
414
			return null;
415

  
416
		List results = new ArrayList();
417

  
418
		for (int i = 0; i < (results_list.size()); i++) {
419
			if (results_list.get(i).toString().startsWith(text)) {
420
				results.add(results_list.get(i));
421
			}
422
		}
423

  
424
		return results;
425
	}
426

  
427
	/**
428
	 * This method should be used when is wanted not to distinguish small letters from capital letters during the search, and the comparation of items
429
	 *   done according an algorithm we define.
430
	 *
431
	 * And it's also necessary that the value returned by the <i>toString()</i> method of each item (supposing
432
	 *   they inherit from Object) would be the expected value user saw (that would be used to compare the items).
433
	 *
434
	 * @param text java.lang.String
435
	 * @param sortOrderedItems java.util.Vector
436
	 * @param comp An Comparator object which implements the <i><b>compareTo()</b><i>  method.
437
	 */
438
	public synchronized static List doSearchIgnoringCaseSensitive(String text, Vector sortOrderedItems, Comparator comp) {
439
		int currentIteration = 0;
440
		int size = sortOrderedItems.size();
441
		int maxNumberOfIterations = (int) MathExtension.log2(size);
442
		int lowIndex = 0;
443
		int highIndex = sortOrderedItems.size() - 1;
444
		int mIndx;
445

  
446
		while ((lowIndex <= highIndex) && (currentIteration <= maxNumberOfIterations)) {
447
			mIndx = ( lowIndex + highIndex ) / 2;
448

  
449
			if ( sortOrderedItems.get( mIndx ).toString().toLowerCase().startsWith( text.toLowerCase() ) ) {
450
				lowIndex = highIndex = mIndx;
451
				highIndex ++;
452

  
453
				// Expand the rank to up
454
				while ( ( highIndex < size ) && ( sortOrderedItems.get( highIndex ).toString().toLowerCase().startsWith( text.toLowerCase() ) ) ) {
455
					highIndex ++;
456
				}
457

  
458
				// Expand the rank to down
459
				while ( ( (lowIndex - 1) > -1 ) && ( sortOrderedItems.get( (lowIndex - 1) ).toString().toLowerCase().startsWith( text.toLowerCase() ) ) ) {
460
					lowIndex --;
461
				}
462

  
463
				// Returns all items in the rank
464
				return Arrays.asList((sortOrderedItems.subList(lowIndex, highIndex)).toArray()); // Breaks the loop
465
			}
466
			else {
467
				if ( comp.compare(sortOrderedItems.get( mIndx ).toString().toLowerCase(), text.toLowerCase() ) > 0 ) {
468
					highIndex = mIndx - 1;
469
				}
470
				else {
471
					lowIndex = mIndx + 1;
472
				}
473
			}
474

  
475
			currentIteration ++;
476
		}
477

  
478
		return null;
479
	}
480
}
0 481

  
tags/org.gvsig.desktop-2.0.85/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/ImageFilter.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * Created on 19-oct-2004
26
 *
27
 * TODO To change the template for this generated file go to
28
 * Window - Preferences - Java - Code Generation - Code and Comments
29
 */
30
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
31
 *
32
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
33
 *
34
 * This program is free software; you can redistribute it and/or
35
 * modify it under the terms of the GNU General Public License
36
 * as published by the Free Software Foundation; either version 2
37
 * of the License, or (at your option) any later version.
38
 *
39
 * This program is distributed in the hope that it will be useful,
40
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42
 * GNU General Public License for more details.
43
 *
44
 * You should have received a copy of the GNU General Public License
45
 * along with this program; if not, write to the Free Software
46
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
47
 *
48
 * For more information, contact:
49
 *
50
 *  Generalitat Valenciana
51
 *   Conselleria d'Infraestructures i Transport
52
 *   Av. Blasco Ib??ez, 50
53
 *   46010 VALENCIA
54
 *   SPAIN
55
 *
56
 *      +34 963862235
57
 *   gvsig@gva.es
58
 *      www.gvsig.gva.es
59
 *
60
 *    or
61
 *
62
 *   IVER T.I. S.A
63
 *   Salamanca 50
64
 *   46005 Valencia
65
 *   Spain
66
 *
67
 *   +34 963163400
68
 *   dac@iver.es
69
 */
70
package org.gvsig.utils;
71

  
72
/**
73
 * @author FJP
74
 * 
75
 * TODO To change the template for this generated type comment go to Window -
76
 * Preferences - Java - Code Generation - Code and Comments
77
 */
78
import java.io.File;
79

  
80
import javax.swing.filechooser.FileFilter;
81
/*
82
 * ImageFilter.java
83
 * 
84
 */
85
public class ImageFilter extends FileFilter
86
{
87
	//Accept all directories and all gif, jpg, tiff, or png files.
88
	public boolean accept(File f)
89
	{
90
		if (f.isDirectory()) { 
91
			return true; }
92
		String extension = Utils.getExtension(f);
93
		if (extension != null) 
94
		{
95
			if (extension.equals(Utils.tiff) || extension.equals(Utils.tif) || 
96
					extension.equals(Utils.gif) || extension.equals(Utils.jpeg) || 
97
					extension.equals(Utils.jpg) || extension.equals(Utils.png))
98
			{
99
				return true;
100
			} 
101
			else
102
			{
103
				return false;
104
			}
105
		}
106
		return false; } //The description of this filter
107

  
108
	public String getDescription() { return "Just Images"; }
109
	} 
0 110

  
tags/org.gvsig.desktop-2.0.85/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/DateTime.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
26
*
27
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
28
*
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 2
32
* of the License, or (at your option) any later version.
33
*
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
*
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
42
*
43
* For more information, contact:
44
*
45
*  Generalitat Valenciana
46
*   Conselleria d'Infraestructures i Transport
47
*   Av. Blasco Ib??ez, 50
48
*   46010 VALENCIA
49
*   SPAIN
50
*
51
*      +34 963862235
52
*   gvsig@gva.es
53
*      www.gvsig.gva.es
54
*
55
*    or
56
*
57
*   IVER T.I. S.A
58
*   Salamanca 50
59
*   46005 Valencia
60
*   Spain
61
*
62
*   +34 963163400
63
*   dac@iver.es
64
*/
65
package org.gvsig.utils;
66
import java.util.Calendar;
67
import java.util.Date;
68
import java.util.GregorianCalendar;
69
import java.util.Locale;
70

  
71
/**
72
 * This class contains static methods to manage Dates. It was principally 
73
 * created because of some problems doing the "String do DateTime" 
74
 * and the "DateTime to String" conversions.  
75
 * 
76
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
77
 */
78
public class DateTime {
79

  
80
/**
81
 * returns the current date
82
 * 
83
 * 
84
 * @return java.util.Date
85
 */
86
    public static Date getCurrentDate() {        
87
        Calendar cal = new GregorianCalendar();
88
 
89
        return cal.getTime();
90
    } 
91

  
92
/**
93
 * It trnasforms one date in one String
94
 * 
95
 * 
96
 * @return A String
97
 * @param dtK Date
98
 * @param sFormat Date format. Example: "Y-m-d H:i:s.Z";
99
 */
100
    public static String dateToString(Date dtK, String sFormat) {        
101
        String sDate;
102
        int nYear;
103
        int nMonth;
104
        int nDay;
105
        int nHour;
106
        int nMinute;
107
        int nSecond;
108
        int nMS;
109
        Calendar clnK;
110
        String sf;
111
        int jc;
112
        clnK = Calendar.getInstance(Locale.US);
113
        clnK.setTime(dtK);
114
        nYear = clnK.get(Calendar.YEAR);
115
        nMonth = 1 + clnK.get(Calendar.MONTH);
116
        nDay = clnK.get(Calendar.DAY_OF_MONTH);
117
        nHour = clnK.get(Calendar.HOUR_OF_DAY);
118
        nMinute = clnK.get(Calendar.MINUTE);
119
        nSecond = clnK.get(Calendar.SECOND);
120
        nMS = clnK.get(Calendar.MILLISECOND);
121
        sDate = "";
122
        for (jc = 0; jc < sFormat.length(); jc++) {
123
            switch (sFormat.charAt(jc)) {
124
                case 'Y':
125
                    sDate += nYear;
126
                    break;
127
                case 'm':
128
                    sf = "" + nMonth;
129
                    if (nMonth < 10) {
130
                        sf = "0" + sf;
131
                    }
132
                    sDate += sf;
133
                    break;
134
                case 'd':
135
                    sf = "" + nDay;
136
                    if (nDay < 10) {
137
                        sf = "0" + sf;
138
                    }
139
                    sDate += sf;
140
                    break;
141
                case 'H':
142
                    sf = "" + nHour;
143
                    if (nHour < 10) {
144
                        sf = "0" + sf;
145
                    }
146
                    sDate += sf;
147
                    break;
148
                case 'i':
149
                    sf = "" + nMinute;
150
                    if (nMinute < 10) {
151
                        sf = "0" + sf;
152
                    }
153
                    sDate += sf;
154
                    break;
155
                case 's':
156
                    sf = "" + nSecond;
157
                    if (nSecond < 10) {
158
                        sf = "0" + sf;
159
                    }
160
                    sDate += sf;
161
                    break;
162
                case 'Z':
163
                    sf = "" + nMS;
164
                    if (nMS < 10) {
165
                        sf = "0" + sf;
166
                    }
167
                    sDate += sf;
168
                    break;
169
                default:
170
                    sDate += sFormat.substring(jc, jc + 1);
171
            }
172
        }
173
        return sDate;
174
    } 
175
   
176
/**
177
 * It transfoms one String in one Date
178
 * 
179
 * 
180
 * @return Date
181
 * @param sDate String
182
 */
183
    public static Date stringToDate(String sDate) {        
184
        Date dtRes;
185
        Calendar clnK;
186
        int nYear;
187
        int nMonth;
188
        int nDay;
189
        int nHour;
190
        int nMinute;
191
        int nSecond;
192
        int nMS;
193
        String sf;
194
        for (; sDate.length() < 23;)
195
            sDate += "0";
196
        sf = sDate.substring(0, 4);
197
        nYear = Integer.parseInt(sf);
198
        sf = sDate.substring(5, 7);
199
        nMonth = Integer.parseInt(sf) - 1;
200
        sf = sDate.substring(8, 10);
201
        nDay = Integer.parseInt(sf);
202
        sf = sDate.substring(11, 13);
203
        nHour = Integer.parseInt(sf);
204
        sf = sDate.substring(14, 16);
205
        nMinute = Integer.parseInt(sf);
206
        sf = sDate.substring(17, 19);
207
        nSecond = Integer.parseInt(sf);
208
        sf = sDate.substring(20, 23);
209
        nMS = Integer.parseInt(sf);
210
        clnK = Calendar.getInstance(Locale.US);
211
        clnK.set(nYear, nMonth, nDay, nHour, nMinute, nSecond);
212
        clnK.set(Calendar.MILLISECOND, nMS);
213
        dtRes = new Date();
214
        dtRes = clnK.getTime();
215
        //	    sf=dateToString(dtRes,"Y-m-d H:i:s.Z");
216
        return dtRes;
217
    } 
218
 }
0 219

  
tags/org.gvsig.desktop-2.0.85/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/IPersistence.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.utils;
25

  
26
/**
27
 * <p>Any object that needs store its data to restore it after, should implement <code>IPersistence</code>.</p>
28
 *
29
 * <p>The process of persisting (for instance in a file) the information of an object using XML is named <i>Marshall</i>,
30
 *  whereas the inverse process in named <i>Unmarshall</i>.</p>
31
 *
32
 * <p>It's necessary specify the name of the class that will be persisted or restored.</p>
33
 *
34
 * @author fjp
35
 */
36
public interface IPersistence {
37
	/**
38
	 * <p>Gets the class name of the object.</p>
39
	 *
40
	 * @return the class name of the object
41
	 */
42
    String getClassName();
43

  
44
    /**
45
     * <p>Returns an XML entity with all necessary information of the object to <i>marshall</i>.</p>
46
     *
47
     * @return the XML entity with all necessary information of the object
48
     */
49
    XMLEntity getXMLEntity() throws XMLException;
50

  
51
    /**
52
     * <p>Sets an XML entity with all necessary information of the object.</p>
53
     *
54
     * @param xml the XML entity with all necessary information of the object
55
     */
56
    void setXMLEntity(XMLEntity xml) throws XMLException;
57
}
0 58

  
tags/org.gvsig.desktop-2.0.85/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/DefaultCharSet.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
9
 * of the License, or (at your option) any later version.
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff