Statistics
| Revision:

root / trunk / extensions / extHyperlink / src / org / gvsig / hyperlink / AbstractHyperLinkPanel.java @ 28132

History | View | Annotate | Download (1.61 KB)

1
package org.gvsig.hyperlink;
2

    
3
import java.io.File;
4
import java.io.IOException;
5
import java.net.URI;
6

    
7
import javax.swing.JPanel;
8

    
9
import com.iver.andami.PluginServices;
10

    
11
/**
12
 * This class extends JPanel and implements IExtensioBuilder. Provides the methods that will
13
 * be reimplemented by the descendant class. Creates a panel that shows the content of a
14
 * URI. The necessary code that allows to show the content of the URI is provided by the
15
 * descendant class. Implmenting IExtenssionBuilder this class and its the descendant
16
 *  provides a point of extension for other extensions.
17
 */
18
public abstract class AbstractHyperLinkPanel extends JPanel {
19
        protected URI document;
20
        public AbstractHyperLinkPanel(URI doc) {
21
                super();
22
                document = doc;
23
        }
24

    
25
        public URI getURI() {
26
                return document;
27
        }
28
        
29
        /**
30
         * Tries to make an absolute url from a relative one, 
31
         * and returns true if the URL is valid.
32
         * false otherwise
33
         * @return
34
         */
35
        protected boolean checkAndNormalizeURI() {
36
                if (document==null) {
37
                        PluginServices.getLogger().warn(PluginServices.getText(this, "Hyperlink_linked_field_doesnot_exist"));
38
                        return false;
39
                }
40
                else if (!document.isAbsolute()) {
41
                        try {
42
                                // try as a relative path
43
                                File file = new File(document.toString()).getCanonicalFile();
44
                                if (!file.exists()) {
45
                                        PluginServices.getLogger().warn(PluginServices.getText(this, "Hyperlink_linked_field_doesnot_exist"));
46
                                        return false;
47
                                }
48
                                document = file.toURI();
49
                        } catch (IOException e) {
50
                                PluginServices.getLogger().warn(PluginServices.getText(this, "Hyperlink_linked_field_doesnot_exist"));
51
                                return false;
52
                        }
53
                }
54
                return true;
55
        }
56
}