Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.lib / org.gvsig.installer.lib.impl / src / main / java / org / gvsig / installer / lib / impl / info / InstallerInfoFileWriter.java @ 37882

History | View | Annotate | Download (5.57 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
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2010 {Prodevelop}   {Task}
26
 */
27

    
28
package org.gvsig.installer.lib.impl.info;
29

    
30
import java.io.File;
31
import java.io.FileNotFoundException;
32
import java.io.FileOutputStream;
33
import java.io.IOException;
34
import java.io.OutputStream;
35
import java.net.URL;
36
import java.util.Properties;
37

    
38
import org.gvsig.installer.lib.api.PackageInfo;
39
import org.gvsig.installer.lib.api.PackageInfoWriter;
40
import org.gvsig.installer.lib.impl.utils.SignUtil;
41
import org.gvsig.installer.lib.spi.InstallerInfoFileException;
42

    
43
/**
44
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
45
 */
46
public class InstallerInfoFileWriter implements PackageInfoWriter {
47

    
48
        /**
49
         * Writes the install.info file
50
         * 
51
         * @param fileName
52
         *            The file name to write the installation information
53
         * @param installInfo
54
         *            The installation information
55
         * @throws InstallerInfoFileException
56
         */
57
        public void write(PackageInfo installInfo, String fileName)
58
                        throws InstallerInfoFileException {
59
                write(installInfo, new File(fileName));
60
        }
61

    
62
        /**
63
         * Writes the install.info file
64
         * 
65
         * @param file
66
         *            The file to write the installation information
67
         * @param installInfo
68
         *            The installation information
69
         * @throws InstallerInfoFileException
70
         */
71
        public void write(PackageInfo installInfo, File file)
72
                        throws InstallerInfoFileException {
73
                try {
74
                        write(installInfo, new FileOutputStream(file));
75
                } catch (FileNotFoundException e) {
76
                        throw new InstallerInfoFileException("install_infofile_not_found",
77
                                        e);
78
                }
79
                SignUtil signutil = new SignUtil();
80
                if( signutil.canSign() ) {
81
                        signutil.sign(file);
82
                }
83
        }
84

    
85
        /**
86
         * Writes the install.info file
87
         * 
88
         * @param os
89
         *            The file to write the installation information
90
         * @param installInfo
91
         *            The installation information
92
         * @throws InstallerInfoFileException
93
         */
94
        public void write(PackageInfo installInfo, OutputStream os)
95
                        throws InstallerInfoFileException {
96
                try {
97
                        // Fill the properties
98
                        Properties properties = new Properties();
99
                        properties.setProperty(InstallerInfoTags.CODE, installInfo
100
                                        .getCode());
101
                        properties.setProperty(InstallerInfoTags.NAME, installInfo
102
                                        .getName());
103
                        properties.setProperty(InstallerInfoTags.DESCRIPTION, installInfo
104
                                        .getDescription());
105
                        properties.setProperty(InstallerInfoTags.VERSION, installInfo
106
                                        .getVersion().toString());
107
                        properties.setProperty(InstallerInfoTags.BUILD, Integer
108
                                        .toString(installInfo.getBuild()));
109
                        properties.setProperty(InstallerInfoTags.STATE, installInfo
110
                                        .getState());
111
                        properties.setProperty(InstallerInfoTags.OFFICIAL, Boolean
112
                                        .toString(installInfo.isOfficial()));
113
                        properties.setProperty(InstallerInfoTags.TYPE, installInfo
114
                                        .getType());
115
                        properties.setProperty(InstallerInfoTags.OS, installInfo
116
                                        .getOperatingSystem());
117
                        properties.setProperty(InstallerInfoTags.ARCHITECTURE, installInfo
118
                                        .getArchitecture());
119
                        properties.setProperty(InstallerInfoTags.JVM, installInfo
120
                                        .getJavaVM());
121
                        properties.setProperty(InstallerInfoTags.GVSIG_VERSION, installInfo
122
                                        .getGvSIGVersion());
123
                        String owner = installInfo.getOwner();
124
                        properties.setProperty(InstallerInfoTags.OWNER, owner == null ? ""
125
                                        : owner);
126
                        String categories = installInfo.getCategoriesAsString();
127
                        properties.setProperty(InstallerInfoTags.CATEGORIES,
128
                                        categories == null ? "" : categories);
129
                        if (installInfo.getDependencies() == null) {
130
                                properties.setProperty(InstallerInfoTags.DEPENDENCIES, "");
131
                        } else {
132
                                properties.setProperty(InstallerInfoTags.DEPENDENCIES,
133
                                                installInfo.getDependencies().toString());
134
                        }
135

    
136
                        URL sourcesURL = installInfo.getSourcesURL();
137
                        if (sourcesURL != null) {
138
                                properties.setProperty(InstallerInfoTags.SOURCES_URL,
139
                                                sourcesURL.toString());
140
                        } else {
141
                                properties.setProperty(InstallerInfoTags.SOURCES_URL, "");
142
                        }
143

    
144
                        URL webURL = installInfo.getWebURL();
145
                        if (webURL != null) {
146
                                properties.setProperty(InstallerInfoTags.WEB_URL, webURL
147
                                                .toString());
148
                        } else {
149
                                properties.setProperty(InstallerInfoTags.WEB_URL, "");
150
                        }
151

    
152
            String downloadURL = installInfo.getDownloadURLAsString();
153
                        if (downloadURL != null) {
154
                                properties.setProperty(InstallerInfoTags.DOWNLOAD_URL,
155
                    downloadURL);
156
                        }
157
                        URL ownerURL = installInfo.getOwnerURL();
158
                        if (ownerURL != null) {
159
                                properties.setProperty(InstallerInfoTags.OWNER_URL, ownerURL
160
                                                .toString());
161
                        }
162
                        properties.setProperty(InstallerInfoTags.MODEL_VERSION, installInfo
163
                                        .getModelVersion());
164
                        properties.store(os, "");
165
                        os.close();
166
                } catch (IOException e) {
167
                        throw new InstallerInfoFileException(
168
                                        "install_infofile_writing_error", e);
169
                }
170
        }
171
}