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 classSessionReader.CancelOrContinueDialogShow Dialog when there is an error for one layer.classSessionReader.ImportSupportA class that provides some context for the individualSessionLayerImporterwhen doing the import.static classSessionReader.LayerDependencyA dependency of another layerstatic classSessionReader.SessionProjectionChoiceDataData class for projection saved in the session file.static classSessionReader.SessionViewportDataData class for viewport saved in the session file.
-
Field Summary
Fields Modifier and Type Field Description private intactiveprivate java.util.List<Layer>layersprivate booleanpluginDataprivate java.util.List<java.lang.Runnable>postLoadTasksprivate SessionReader.SessionProjectionChoiceDataprojectionChoiceprivate java.net.URIsessionFileURIprivate static java.util.Map<java.lang.String,java.lang.Class<? extends SessionLayerImporter>>sessionLayerImportersprivate SessionReader.SessionViewportDataviewportprivate booleanzipprivate java.util.zip.ZipFilezipFile
-
Constructor Summary
Constructors Constructor Description SessionReader()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.io.InputStreamcreateInputStream(java.io.File sessionFile, boolean zip)private static voiderror(java.lang.String msg)LayergetActive()Returns active layer.private static org.w3c.dom.ElementgetElementByTagName(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.SessionProjectionChoiceDatagetProjectionChoice()Returns the projection choice data.static SessionLayerImportergetSessionLayerImporter(java.lang.String layerType)Returns the session layer importer for the given layer type.SessionReader.SessionViewportDatagetViewport()Returns the viewport (map position and scale).private static java.io.InputStreamgetZipInputStream(java.util.zip.ZipFile zipFile)booleanloadedPluginData()Returns whether plugins loaded additonal dataprivate voidloadPluginData()voidloadSession(java.io.File sessionFile, boolean zip, ProgressMonitor progressMonitor)Loads session from the given file.voidloadSession(java.io.InputStream josIS, java.net.URI sessionFileURI, boolean zip, ProgressMonitor progressMonitor)Loads session from the given input stream.private voidparseJos(org.w3c.dom.Document doc, ProgressMonitor progressMonitor)private static SessionReader.SessionProjectionChoiceDatareadProjectionChoiceData(org.w3c.dom.Element root)private static SessionReader.SessionViewportDatareadViewportData(org.w3c.dom.Element root)static voidregisterSessionLayerImporter(java.lang.String layerType, java.lang.Class<? extends SessionLayerImporter> importer)Register a session layer importer.private static voidsetLayerAttributes(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
nullif 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:
trueif 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-trueif 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.IOExceptionIllegalDataException
-
getZipInputStream
private static java.io.InputStream getZipInputStream(java.util.zip.ZipFile zipFile) throws java.io.IOException, IllegalDataException
- Throws:
java.io.IOExceptionIllegalDataException
-
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-trueif 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)
-
-