Statistics
| Revision:

root / org.gvsig.hyperlink.app / trunk / org.gvsig.hyperlink.app / org.gvsig.hyperlink.app.extension / src / main / java / org / gvsig / hyperlink / app / extension / AbstractHyperLinkPanel.java @ 368

History | View | Annotate | Download (3.13 KB)

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
package org.gvsig.hyperlink.app.extension;
24

    
25
import java.io.File;
26
import java.io.IOException;
27
import java.net.URI;
28

    
29
import javax.swing.JPanel;
30

    
31
import org.gvsig.andami.PluginServices;
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

    
35
/**
36
 * This class extends JPanel and implements IExtensioBuilder. Provides the
37
 * methods that will be reimplemented by the descendant class. Creates a panel
38
 * that shows the content of a URI. The necessary code that allows to show the
39
 * content of the URI is provided by the descendant class. Implmenting
40
 * IExtenssionBuilder this class and its the descendant provides a point of
41
 * extension for other extensions.
42
 */
43
public abstract class AbstractHyperLinkPanel extends JPanel {
44

    
45
    protected static final Logger logger = LoggerFactory.getLogger(AbstractHyperLinkPanel.class);
46
    
47
    protected URI document;
48

    
49
    public AbstractHyperLinkPanel(URI doc) {
50
        super();
51
        document = doc;
52
    }
53

    
54
    public URI getURI() {
55
        return document;
56
    }
57

    
58
    /**
59
     * Tries to make an absolute url from a relative one,
60
     * and returns true if the URL is valid.
61
     * false otherwise
62
     * 
63
     * @return
64
     */
65
    protected boolean checkAndNormalizeURI() {
66
        if (document == null) {
67
            PluginServices.getLogger().warn(PluginServices.getText(this,
68
                "Hyperlink_linked_field_doesnot_exist"));
69
            return false;
70
        } else
71
            if (!document.isAbsolute()) {
72
                try {
73
                    // try as a relative path
74
                    File file =
75
                        new File(document.toString()).getCanonicalFile();
76
                    if (!file.exists()) {
77
                        PluginServices.getLogger()
78
                            .warn(PluginServices.getText(this,
79
                                "Hyperlink_linked_field_doesnot_exist"));
80
                        return false;
81
                    }
82
                    document = file.toURI();
83
                } catch (IOException e) {
84
                    PluginServices.getLogger()
85
                        .warn(PluginServices.getText(this,
86
                            "Hyperlink_linked_field_doesnot_exist"));
87
                    return false;
88
                }
89
            }
90
        return true;
91
    }
92
}