Skip to content

Commit

Permalink
[josm_plugins] fix java 7 warnings / global usage of try-with-resource
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.openstreetmap.org/applications/editors/josm/plugins@30738 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4
  • Loading branch information
don-vip committed Oct 18, 2014
1 parent ccd46ed commit 11a5f62
Show file tree
Hide file tree
Showing 113 changed files with 4,019 additions and 4,115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,12 @@ protected void saveDto(Dto dto)

try {
path.mkdirs();

FileOutputStream file = new FileOutputStream(fileName);
ObjectOutputStream o = new ObjectOutputStream(file);
o.writeObject(dto);
o.close();
try (
FileOutputStream file = new FileOutputStream(fileName);
ObjectOutputStream o = new ObjectOutputStream(file)
) {
o.writeObject(dto);
}
} catch (Exception ex) {
logger.log(Level.SEVERE, ex.getMessage());
fileName.delete();
Expand Down Expand Up @@ -533,36 +534,34 @@ private Collection<String> getPossibleStreets() {
return names;
}

private Dto loadDto() {
Dto dto = new Dto();
File fileName = new File(pluginDir + TagDialog.TEMPLATE_DATA);

try {

if (fileName.exists()) {
FileInputStream file = new FileInputStream(fileName);
ObjectInputStream o = new ObjectInputStream(file);

dto = (Dto) o.readObject();
o.close();
} else {
dto.setCity(selection.get(TagDialog.TAG_ADDR_CITY));
dto.setCountry(selection.get(TagDialog.TAG_ADDR_COUNTRY));
dto.setHousenumber(selection.get(TagDialog.TAG_ADDR_HOUSENUMBER));
dto.setPostcode(selection.get(TagDialog.TAG_ADDR_POSTCODE));
dto.setStreet(selection.get(TagDialog.TAG_ADDR_STREET));
dto.setState(selection.get(TagDialog.TAG_ADDR_STATE));
}
} catch (Exception ex) {
private Dto loadDto() {
Dto dto = new Dto();
File fileName = new File(pluginDir + TagDialog.TEMPLATE_DATA);

try {
if (fileName.exists()) {
try (
FileInputStream file = new FileInputStream(fileName);
ObjectInputStream o = new ObjectInputStream(file);
) {
dto = (Dto) o.readObject();
}
} else {
dto.setCity(selection.get(TagDialog.TAG_ADDR_CITY));
dto.setCountry(selection.get(TagDialog.TAG_ADDR_COUNTRY));
dto.setHousenumber(selection.get(TagDialog.TAG_ADDR_HOUSENUMBER));
dto.setPostcode(selection.get(TagDialog.TAG_ADDR_POSTCODE));
dto.setStreet(selection.get(TagDialog.TAG_ADDR_STREET));
dto.setState(selection.get(TagDialog.TAG_ADDR_STATE));
}
} catch (Exception ex) {
logger.log(Level.SEVERE, ex.getMessage());
fileName.delete();
}
return dto;

}
}
return dto;
}

class RadioChangeListener implements ItemListener
{
class RadioChangeListener implements ItemListener {

@Override
public void itemStateChanged(ItemEvent e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public ImportImagePlugin(PluginInformation info){

// add menu entries
//Main.main.menu.fileMenu.insert(loadFileAction, 8);

//Main.main.menu.fileMenu.insertSeparator(9);

ExtensionFileFilter.importers.add(new ImportImageFileImporter());

} catch (Exception e) {
Expand Down Expand Up @@ -128,8 +128,7 @@ private void checkInstallation() throws IOException


// if properties file doesn't exist, install plugin
if(!isInstalled)
{
if (!isInstalled) {

/*----------- Begin installation ---------------*/

Expand All @@ -146,33 +145,30 @@ private void checkInstallation() throws IOException
}

// create local properties file
if(pluginProps == null || pluginProps.isEmpty()){

FileWriter fw = new FileWriter(new File(PLUGINPROPERTIES_PATH));
URL propertiesURL = pluginClassLoader.getResource("resources/" + PLUGINPROPERTIES_FILENAME);
pluginProps = new Properties();
pluginProps.load(propertiesURL.openStream());
pluginProps.store(fw, null);
fw.close();
if (pluginProps == null || pluginProps.isEmpty()) {
try (FileWriter fw = new FileWriter(new File(PLUGINPROPERTIES_PATH))) {
URL propertiesURL = pluginClassLoader.getResource("resources/" + PLUGINPROPERTIES_FILENAME);
pluginProps = new Properties();
pluginProps.load(propertiesURL.openStream());
pluginProps.store(fw, null);
}
logger.debug("Plugin properties loaded");
}

if(!new File(LOGGING_PROPERTIES_FILEPATH).exists())
{
FileWriter fw = new FileWriter(new File(LOGGING_PROPERTIES_FILEPATH));
URL propertiesURL = pluginClassLoader.getResource("resources/log4j.properties");
Properties loggingProps = new Properties();
loggingProps.load(propertiesURL.openStream());
loggingProps.store(fw, null);
fw.close();
if (!new File(LOGGING_PROPERTIES_FILEPATH).exists()) {
try (FileWriter fw = new FileWriter(new File(LOGGING_PROPERTIES_FILEPATH))) {
URL propertiesURL = pluginClassLoader.getResource("resources/log4j.properties");
Properties loggingProps = new Properties();
loggingProps.load(propertiesURL.openStream());
loggingProps.store(fw, null);
}
logger.debug("Logging properties created");
}

logger.debug("Plugin successfully installed");
}
}


/**
* Initialize logger using plugin classloader.
*
Expand Down
Loading

0 comments on commit 11a5f62

Please sign in to comment.