-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,14 @@ | |
import java.awt.GridBagLayout; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.jar.JarFile; | ||
import java.util.logging.FileHandler; | ||
import java.util.logging.SimpleFormatter; | ||
import java.util.zip.ZipEntry; | ||
|
||
import javax.swing.JButton; | ||
import javax.swing.JFrame; | ||
|
@@ -23,6 +28,7 @@ | |
import javax.swing.border.EtchedBorder; | ||
|
||
import org.openstreetmap.josm.actions.JosmAction; | ||
import org.openstreetmap.josm.data.Preferences; | ||
import org.openstreetmap.josm.data.osm.Node; | ||
import org.openstreetmap.josm.data.osm.Way; | ||
import org.openstreetmap.josm.gui.MainApplication; | ||
|
@@ -72,6 +78,13 @@ public ImportDataController() { | |
} catch (SecurityException | IOException e) { | ||
Logging.info(e.getMessage()); | ||
} | ||
|
||
// export resource files from jar to file system used by BuildingSMARTLibrary | ||
try { | ||
exportPluginResource(); | ||
} catch (Exception e) { | ||
Logging.info(e.getMessage()); | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -100,7 +113,6 @@ public void run() { | |
@Override | ||
public void onDataParsed(ArrayList<Way> ways, ArrayList<Node> nodes) { | ||
model.setImportData(ways, nodes); | ||
|
||
String layerName = String.format("BIMObject%2d", MainApplication.getLayerManager().getLayers().size()); | ||
if(importedFilepath != null) { | ||
String[] parts = importedFilepath.split(File.separator.equals ("\\")? "\\\\": "/"); | ||
|
@@ -160,4 +172,25 @@ private void addInfoLabel() { | |
if(map != null) map.addTopPanel(infoPanel); | ||
} | ||
|
||
/** | ||
* Export resources embedded in jar into file system | ||
* @throws Exception | ||
*/ | ||
private void exportPluginResource() throws Exception{ | ||
File jarFile = new File(ImportDataController.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); | ||
String jarPath = Preferences.main().getPluginsDirectory().toString(); | ||
if(jarFile.isFile()) { | ||
Logging.info("Copying resource files from jar to file system"); | ||
JarFile jar = new JarFile(jarFile); | ||
ZipEntry ze1 = jar.getEntry("resources/IFC2X3_TC1.exp"); | ||
ZipEntry ze2 = jar.getEntry("resources/IFC4.exp"); | ||
InputStream is1 = jar.getInputStream(ze1); | ||
InputStream is2 = jar.getInputStream(ze2); | ||
new File(jarPath + "/indoorhelper/resources").mkdirs(); | ||
Files.copy(is1, Paths.get(jarPath + "/indoorhelper/resources/IFC2X3_TC1.exp")); | ||
Files.copy(is2, Paths.get(jarPath + "/indoorhelper/resources/IFC4.exp")); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rebeccasc
Author
Member
|
||
jar.close(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A cleaner way would be to use the resources directly without writing them to the filesystem. JOSM provides the
CachedFile
class, see https://josm.openstreetmap.de/browser/josm/trunk/src/org/openstreetmap/josm/data/preferences/PreferencesReader.java#L96 for an example.