Revision 33729 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/InstallerInfoFileReader.java

View differences:

InstallerInfoFileReader.java
37 37
import org.gvsig.installer.lib.api.PackageInfo;
38 38
import org.gvsig.installer.lib.spi.InstallerInfoFileException;
39 39

  
40

  
41 40
/**
42 41
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
43 42
 */
44 43
public class InstallerInfoFileReader {
45 44

  
46
	public InstallerInfoFileReader()
47
	{
45
    public InstallerInfoFileReader() {
48 46

  
49
	}
47
    }
50 48

  
51
	/**
52
	 * Reads and parses the install.info file and creates one object that contains
53
	 * the information.
54
	 * @param fileName
55
	 * The file name that contains the install.info information. 
56
	 * @return
57
	 * An object with the information about the installation
58
	 * @throws InstallerInfoFileException
59
	 */
60
	public void read(PackageInfo installerInfoResource, String fileName) throws InstallerInfoFileException{
61
		read(installerInfoResource, new File(fileName));
62
	}
49
    /**
50
     * Reads and parses the install.info file and creates one object that
51
     * contains
52
     * the information.
53
     * 
54
     * @param fileName
55
     *            The file name that contains the install.info information.
56
     * @return
57
     *         An object with the information about the installation
58
     * @throws InstallerInfoFileException
59
     */
60
    public void read(PackageInfo installerInfoResource, String fileName)
61
        throws InstallerInfoFileException {
62
        read(installerInfoResource, new File(fileName));
63
    }
63 64

  
64
	/**
65
	 * Reads and parses the install.info file and creates one object that contains
66
	 * the information.
67
	 * @param file
68
	 * The file that contains the install.info information. 
69
	 * @return
70
	 * An object with the information about the installation
71
	 * @throws InstallerInfoFileException 
72
	 */
73
	public void read(PackageInfo installerInfoResource, File file) throws InstallerInfoFileException{
74
		if (!file.exists()){
75
			throw new InstallerInfoFileException("install_infofile_not_found");
76
		}		
77
		try {
78
			read(installerInfoResource, new FileInputStream(file));
79
		} catch (FileNotFoundException e) {
80
			throw new InstallerInfoFileException("install_infofile_not_found", e);
81
		}
82
	}
83
		
84
	/**
85
	 * Reads and parses the install.info file and creates one object that contains
86
	 * the information.
87
	 * @param is
88
	 * The input stream that contains the install.info information. 
89
	 * @return
90
	 * An object with the information about the installation
91
	 * @throws InstallerInfoFileException 
92
	 */
93
	public void read(PackageInfo installerInfoResource, InputStream is) throws InstallerInfoFileException{
94
		Properties properties = new Properties();
95
		try {			
96
			properties.load(is);
97
			is.close();
98
		} catch (IOException e) {
99
			throw new InstallerInfoFileException("install_infofile_reading_error", e);
100
		}
101
		//Checks if the file contains the minumum attributes
102
		if (!properties.containsKey(InstallerInfoTags.CODE)){
103
			throw new NotPropertyFoundException(InstallerInfoTags.CODE);
104
		}
105
		
106
		if (!properties.containsKey(InstallerInfoTags.NAME)){
107
			throw new NotPropertyFoundException(InstallerInfoTags.NAME);
108
		}
65
    /**
66
     * Reads and parses the install.info file and creates one object that
67
     * contains
68
     * the information.
69
     * 
70
     * @param file
71
     *            The file that contains the install.info information.
72
     * @return
73
     *         An object with the information about the installation
74
     * @throws InstallerInfoFileException
75
     */
76
    public void read(PackageInfo installerInfoResource, File file)
77
        throws InstallerInfoFileException {
78
        if (!file.exists()) {
79
            throw new InstallerInfoFileException("install_infofile_not_found");
80
        }
81
        try {
82
            read(installerInfoResource, new FileInputStream(file));
83
        } catch (FileNotFoundException e) {
84
            throw new InstallerInfoFileException("install_infofile_not_found",
85
                e);
86
        }
87
    }
109 88

  
110
		installerInfoResource.setCode(properties.getProperty(InstallerInfoTags.CODE));
111
		installerInfoResource.setName(properties.getProperty(InstallerInfoTags.NAME));
112
		installerInfoResource.setDescription(properties.getProperty(InstallerInfoTags.DESCRIPCTION));
113
		installerInfoResource.setVersion(properties.getProperty(InstallerInfoTags.VERSION));
114
		installerInfoResource.setType(properties.getProperty(InstallerInfoTags.TYPE));
115
		String build = properties.getProperty(InstallerInfoTags.BUILD);
116
		try{
89
    /**
90
     * Reads and parses the install.info file and creates one object that
91
     * contains
92
     * the information.
93
     * 
94
     * @param is
95
     *            The input stream that contains the install.info information.
96
     * @return
97
     *         An object with the information about the installation
98
     * @throws InstallerInfoFileException
99
     */
100
    public void read(PackageInfo installerInfoResource, InputStream is)
101
        throws InstallerInfoFileException {
102
        Properties properties = new Properties();
103
        try {
104
            properties.load(is);
105
            is.close();
106
        } catch (IOException e) {
107
            throw new InstallerInfoFileException(
108
                "install_infofile_reading_error", e);
109
        }
110
        // Checks if the file contains the minumum attributes
111
        if (!properties.containsKey(InstallerInfoTags.CODE)) {
112
            throw new NotPropertyFoundException(InstallerInfoTags.CODE);
113
        }
114

  
115
        if (!properties.containsKey(InstallerInfoTags.NAME)) {
116
            throw new NotPropertyFoundException(InstallerInfoTags.NAME);
117
        }
118

  
119
        installerInfoResource.setCode(properties
120
            .getProperty(InstallerInfoTags.CODE));
121
        installerInfoResource.setName(properties
122
            .getProperty(InstallerInfoTags.NAME));
123
        installerInfoResource.setDescription(properties
124
            .getProperty(InstallerInfoTags.DESCRIPCTION));
125
        installerInfoResource.setVersion(properties
126
            .getProperty(InstallerInfoTags.VERSION));
127
        installerInfoResource.setType(properties
128
            .getProperty(InstallerInfoTags.TYPE));
129
        String build = properties.getProperty(InstallerInfoTags.BUILD);
130
        try {
117 131
            installerInfoResource.setBuild(Integer.parseInt(build));
118
		}catch(Exception e){
119
			installerInfoResource.setBuild(0);
120
		}		
121
		installerInfoResource.setState(properties.getProperty(InstallerInfoTags.STATE));
122
		try{
132
        } catch (Exception e) {
133
            installerInfoResource.setBuild(0);
134
        }
135
        installerInfoResource.setState(properties
136
            .getProperty(InstallerInfoTags.STATE));
137
        try {
123 138
            installerInfoResource.setOfficial(Boolean.parseBoolean(properties
124 139
                .getProperty(InstallerInfoTags.OFFICIAL)));
125
		}catch(Exception e){
126
			installerInfoResource.setOfficial(false);
140
        } catch (Exception e) {
141
            installerInfoResource.setOfficial(false);
127 142
        }
128 143

  
129 144
        String os = properties.getProperty(InstallerInfoTags.OS);
......
143 158

  
144 159
        installerInfoResource.setGvSIGVersion(properties
145 160
            .getProperty(InstallerInfoTags.GVSIG_VERSION));
146
	}
161
    }
147 162

  
148 163
}
149

  

Also available in: Unified diff