Class SessionReader
- java.lang.Object
-
- org.openstreetmap.josm.io.session.SessionReader
-
public class SessionReader extends 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
static 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 List<Layer>
layers
private List<Runnable>
postLoadTasks
private SessionReader.SessionProjectionChoiceData
projectionChoice
private URI
sessionFileURI
private static Map<String,Class<? extends SessionLayerImporter>>
sessionLayerImporters
private SessionReader.SessionViewportData
viewport
private boolean
zip
private ZipFile
zipFile
-
Constructor Summary
Constructors Constructor Description SessionReader()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private InputStream
createInputStream(File sessionFile, boolean zip)
private static void
error(String msg)
Layer
getActive()
Returns active layer.private static Element
getElementByTagName(Element root, String name)
List<Layer>
getLayers()
Returns list of layers that are later added to the mapview.List<Runnable>
getPostLoadTasks()
Returns actions executed in EDT after layers have been added.SessionReader.SessionProjectionChoiceData
getProjectionChoice()
Returns the projection choice data.static SessionLayerImporter
getSessionLayerImporter(String layerType)
Returns the session layer importer for the given layer type.SessionReader.SessionViewportData
getViewport()
Returns the viewport (map position and scale).private static InputStream
getZipInputStream(ZipFile zipFile)
void
loadSession(File sessionFile, boolean zip, ProgressMonitor progressMonitor)
Loads session from the given file.void
loadSession(InputStream josIS, URI sessionFileURI, boolean zip, ProgressMonitor progressMonitor)
Loads session from the given input stream.private void
parseJos(Document doc, ProgressMonitor progressMonitor)
private static SessionReader.SessionProjectionChoiceData
readProjectionChoiceData(Element root)
private static SessionReader.SessionViewportData
readViewportData(Element root)
static void
registerSessionLayerImporter(String layerType, Class<? extends SessionLayerImporter> importer)
Register a session layer importer.
-
-
-
Field Detail
-
sessionLayerImporters
private static final Map<String,Class<? extends SessionLayerImporter>> sessionLayerImporters
-
sessionFileURI
private URI sessionFileURI
-
zip
private boolean zip
-
active
private int active
-
postLoadTasks
private final List<Runnable> postLoadTasks
-
viewport
private SessionReader.SessionViewportData viewport
-
projectionChoice
private SessionReader.SessionProjectionChoiceData projectionChoice
-
-
Constructor Detail
-
SessionReader
public SessionReader()
-
-
Method Detail
-
registerSessionLayerImporter
public static void registerSessionLayerImporter(String layerType, Class<? extends SessionLayerImporter> importer)
Register a session layer importer.- Parameters:
layerType
- layer typeimporter
- importer for this layer class
-
getSessionLayerImporter
public static SessionLayerImporter getSessionLayerImporter(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 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 List<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
-
error
private static void error(String msg) throws IllegalDataException
- Throws:
IllegalDataException
-
parseJos
private void parseJos(Document doc, ProgressMonitor progressMonitor) throws IllegalDataException
- Throws:
IllegalDataException
-
readViewportData
private static SessionReader.SessionViewportData readViewportData(Element root)
-
readProjectionChoiceData
private static SessionReader.SessionProjectionChoiceData readProjectionChoiceData(Element root)
-
loadSession
public void loadSession(File sessionFile, boolean zip, ProgressMonitor progressMonitor) throws IllegalDataException, 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 detectedIOException
- if any I/O error occurs
-
createInputStream
private InputStream createInputStream(File sessionFile, boolean zip) throws IOException, IllegalDataException
- Throws:
IOException
IllegalDataException
-
getZipInputStream
private static InputStream getZipInputStream(ZipFile zipFile) throws IOException, IllegalDataException
- Throws:
IOException
IllegalDataException
-
loadSession
public void loadSession(InputStream josIS, URI sessionFileURI, boolean zip, ProgressMonitor progressMonitor) throws 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 detectedIOException
- if any I/O error occurs- Since:
- 15070
-
getElementByTagName
private static Element getElementByTagName(Element root, String name)
-
-