Changeset 34396 in osm for applications/editors


Ignore:
Timestamp:
2018-07-06T01:23:01+02:00 (7 years ago)
Author:
donvip
Message:

move deprecated JOSM core methods to osmarender plugin (sole plugin using them)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/osmarender/src/org/openstreetmap/josm/plugins/osmarender/OsmarenderPlugin.java

    r33916 r34396  
    99import java.io.File;
    1010import java.io.FileInputStream;
     11import java.io.FileNotFoundException;
    1112import java.io.FileOutputStream;
    1213import java.io.IOException;
     14import java.io.InputStream;
    1315import java.io.InputStreamReader;
    1416import java.io.OutputStreamWriter;
    1517import java.io.PrintWriter;
    1618import java.nio.charset.StandardCharsets;
     19import java.nio.file.Files;
     20import java.nio.file.StandardCopyOption;
    1721import java.util.HashSet;
    1822import java.util.Set;
     
    5054import org.openstreetmap.josm.tools.Logging;
    5155import org.openstreetmap.josm.tools.PlatformHookWindows;
     56import org.openstreetmap.josm.tools.Utils;
    5257
    5358public class OsmarenderPlugin extends Plugin {
     
    151156
    152157        // install the xsl and xml file
    153         copy("/osmarender.xsl", "osmarender.xsl");
    154         copy("/osm-map-features.xml", "osm-map-features.xml");
     158        _copy("/osmarender.xsl", "osmarender.xsl");
     159        _copy("/osm-map-features.xml", "osm-map-features.xml");
     160    }
     161
     162    /**
     163     * @return The directory for the plugin to store all kind of stuff.
     164     * @deprecated (since 13007) to get the same directory as this method, use {@code getPluginDirs().getUserDataDirectory(false)}.
     165     * However, for files that can be characterized as cache or preferences, you are encouraged to use the appropriate
     166     * {@link org.openstreetmap.josm.spi.preferences.IBaseDirectories} method from {@link #getPluginDirs()}.
     167     */
     168    @Deprecated
     169    public String _getPluginDir() {
     170        return new File(Main.pref.getPluginsDirectory(), getPluginInformation().name).getPath();
     171    }
     172
     173    /**
     174     * Copies the resource 'from' to the file in the plugin directory named 'to'.
     175     * @param from source file
     176     * @param to target file
     177     * @throws FileNotFoundException if the file exists but is a directory rather than a regular file,
     178     * does not exist but cannot be created, or cannot be opened for any other reason
     179     * @throws IOException if any other I/O error occurs
     180     * @deprecated without replacement
     181     */
     182    @Deprecated
     183    public void _copy(String from, String to) throws IOException {
     184        String pluginDirName = _getPluginDir();
     185        File pluginDir = new File(pluginDirName);
     186        if (!pluginDir.exists()) {
     187            Utils.mkDirs(pluginDir);
     188        }
     189        try (InputStream in = getClass().getResourceAsStream(from)) {
     190            if (in == null) {
     191                throw new IOException("Resource not found: "+from);
     192            }
     193            Files.copy(in, new File(pluginDirName, to).toPath(), StandardCopyOption.REPLACE_EXISTING);
     194        }
    155195    }
    156196
Note: See TracChangeset for help on using the changeset viewer.