Class SessionReader
- java.lang.Object
-
- org.openstreetmap.josm.io.session.SessionReader
-
public class SessionReader extends java.lang.Object
Reads a .jos session file and loads the layers in the process.- Since:
- 4668
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SessionReader.CancelOrContinueDialog
Show Dialog when there is an error for one layer.class
SessionReader.ImportSupport
A class that provides some context for the individualSessionLayerImporter
when doing the import.static class
SessionReader.LayerDependency
A dependency of another layerstatic class
SessionReader.SessionProjectionChoiceData
Data class for projection saved in the session file.static class
SessionReader.SessionViewportData
Data class for viewport saved in the session file.
-
Field Summary
Fields Modifier and Type Field Description private int
active
private java.util.List<Layer>
layers
private boolean
pluginData
private java.util.List<java.lang.Runnable>
postLoadTasks
private SessionReader.SessionProjectionChoiceData
projectionChoice
private java.net.URI
sessionFileURI
private static java.util.Map<java.lang.String,java.lang.Class<? extends SessionLayerImporter>>
sessionLayerImporters
private SessionReader.SessionViewportData
viewport
private boolean
zip
private java.util.zip.ZipFile
zipFile
-
Constructor Summary
Constructors Constructor Description SessionReader()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.io.InputStream
createInputStream(java.io.File sessionFile, boolean zip)
private static void
error(java.lang.String msg)
Layer
getActive()
Returns active layer.private static org.w3c.dom.Element
getElementByTagName(org.w3c.dom.Element root, java.lang.String name)
java.util.List<Layer>
getLayers()
Returns list of layers that are later added to the mapview.java.util.List<java.lang.Runnable>
getPostLoadTasks()
Returns actions executed in EDT after layers have been added.SessionReader.SessionProjectionChoiceData
getProjectionChoice()
Returns the projection choice data.static SessionLayerImporter
getSessionLayerImporter(java.lang.String layerType)
Returns the session layer importer for the given layer type.SessionReader.SessionViewportData
getViewport()
Returns the viewport (map position and scale).private static java.io.InputStream
getZipInputStream(java.util.zip.ZipFile zipFile)
boolean
loadedPluginData()
Returns whether plugins loaded additonal dataprivate void
loadPluginData()
void
loadSession(java.io.File sessionFile, boolean zip, ProgressMonitor progressMonitor)
Loads session from the given file.void
loadSession(java.io.InputStream josIS, java.net.URI sessionFileURI, boolean zip, ProgressMonitor progressMonitor)
Loads session from the given input stream.private void
parseJos(org.w3c.dom.Document doc, ProgressMonitor progressMonitor)
private static SessionReader.SessionProjectionChoiceData
readProjectionChoiceData(org.w3c.dom.Element root)
private static SessionReader.SessionViewportData
readViewportData(org.w3c.dom.Element root)
static void
registerSessionLayerImporter(java.lang.String layerType, java.lang.Class<? extends SessionLayerImporter> importer)
Register a session layer importer.private static void
setLayerAttributes(Layer layer, org.w3c.dom.Element e)
-
-
-
Field Detail
-
sessionLayerImporters
private static final java.util.Map<java.lang.String,java.lang.Class<? extends SessionLayerImporter>> sessionLayerImporters
-
sessionFileURI
private java.net.URI sessionFileURI
-
zip
private boolean zip
-
pluginData
private boolean pluginData
-
zipFile
private java.util.zip.ZipFile zipFile
-
active
private int active
-
postLoadTasks
private final java.util.List<java.lang.Runnable> postLoadTasks
-
viewport
private SessionReader.SessionViewportData viewport
-
projectionChoice
private SessionReader.SessionProjectionChoiceData projectionChoice
-
-
Constructor Detail
-
SessionReader
public SessionReader()
-
-
Method Detail
-
registerSessionLayerImporter
public static void registerSessionLayerImporter(java.lang.String layerType, java.lang.Class<? extends SessionLayerImporter> importer)
Register a session layer importer.- Parameters:
layerType
- layer typeimporter
- importer for this layer class
-
getSessionLayerImporter
public static SessionLayerImporter getSessionLayerImporter(java.lang.String layerType)
Returns the session layer importer for the given layer type.- Parameters:
layerType
- layer type to import- Returns:
- session layer importer for the given layer
-
getLayers
public java.util.List<Layer> getLayers()
Returns list of layers that are later added to the mapview.- Returns:
- list of layers that are later added to the mapview
-
getActive
public Layer getActive()
Returns active layer.- Returns:
- active layer, or
null
if not set - Since:
- 6271
-
getPostLoadTasks
public java.util.List<java.lang.Runnable> getPostLoadTasks()
Returns actions executed in EDT after layers have been added.- Returns:
- actions executed in EDT after layers have been added (message dialog, etc.)
-
getViewport
public SessionReader.SessionViewportData getViewport()
Returns the viewport (map position and scale).- Returns:
- the viewport; can be null when no viewport info is found in the file
-
getProjectionChoice
public SessionReader.SessionProjectionChoiceData getProjectionChoice()
Returns the projection choice data.- Returns:
- the projection; can be null when no projection info is found in the file
-
loadedPluginData
public boolean loadedPluginData()
Returns whether plugins loaded additonal data- Returns:
true
if at least one plugin loaded additional data- Since:
- 18833
-
error
private static void error(java.lang.String msg) throws IllegalDataException
- Throws:
IllegalDataException
-
parseJos
private void parseJos(org.w3c.dom.Document doc, ProgressMonitor progressMonitor) throws IllegalDataException
- Throws:
IllegalDataException
-
setLayerAttributes
private static void setLayerAttributes(Layer layer, org.w3c.dom.Element e)
-
readViewportData
private static SessionReader.SessionViewportData readViewportData(org.w3c.dom.Element root)
-
readProjectionChoiceData
private static SessionReader.SessionProjectionChoiceData readProjectionChoiceData(org.w3c.dom.Element root)
-
loadPluginData
private void loadPluginData()
-
loadSession
public void loadSession(java.io.File sessionFile, boolean zip, ProgressMonitor progressMonitor) throws IllegalDataException, java.io.IOException
Loads session from the given file.- Parameters:
sessionFile
- session file to loadzip
-true
if it's a zipped session (.joz)progressMonitor
- progress monitor- Throws:
IllegalDataException
- if invalid data is detectedjava.io.IOException
- if any I/O error occurs
-
createInputStream
private java.io.InputStream createInputStream(java.io.File sessionFile, boolean zip) throws java.io.IOException, IllegalDataException
- Throws:
java.io.IOException
IllegalDataException
-
getZipInputStream
private static java.io.InputStream getZipInputStream(java.util.zip.ZipFile zipFile) throws java.io.IOException, IllegalDataException
- Throws:
java.io.IOException
IllegalDataException
-
loadSession
public void loadSession(java.io.InputStream josIS, java.net.URI sessionFileURI, boolean zip, ProgressMonitor progressMonitor) throws java.io.IOException, IllegalDataException
Loads session from the given input stream.- Parameters:
josIS
- session stream to loadzip
-true
if it's a zipped session (.joz)sessionFileURI
- URI of the underlying session fileprogressMonitor
- progress monitor- Throws:
IllegalDataException
- if invalid data is detectedjava.io.IOException
- if any I/O error occurs- Since:
- 15070
-
getElementByTagName
private static org.w3c.dom.Element getElementByTagName(org.w3c.dom.Element root, java.lang.String name)
-
-