use of org.cytoscape.io.write.CyWriter in project cytoscape-impl by cytoscape.
the class ViewWriterTest method setUp.
@Before
@SuppressWarnings("rawtypes")
public void setUp() throws Exception {
final PresentationWriterManager viewWriterMgr = mock(PresentationWriterManager.class);
final CyApplicationManager applicationManager = mock(CyApplicationManager.class);
final RenderingEngineManager engineManager = mock(RenderingEngineManager.class);
final CyNetworkView view = mock(CyNetworkView.class);
final CyNetwork network = mock(CyNetwork.class);
final CyRow row = mock(CyRow.class);
final RenderingEngine re = mock(RenderingEngine.class);
final CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
when(serviceRegistrar.getService(CyApplicationManager.class)).thenReturn(applicationManager);
when(serviceRegistrar.getService(RenderingEngineManager.class)).thenReturn(engineManager);
when(serviceRegistrar.getService(PresentationWriterManager.class)).thenReturn(viewWriterMgr);
fileFilter = mock(CyFileFilter.class);
when(fileFilter.getDescription()).thenReturn("A dummy filter");
when(fileFilter.getExtensions()).thenReturn(Collections.singleton("dummy"));
final List<CyFileFilter> filters = new ArrayList<>();
filters.add(fileFilter);
when(viewWriterMgr.getAvailableWriterFilters()).thenReturn(filters);
when(view.getModel()).thenReturn(network);
when(network.getRow(network)).thenReturn(row);
cyWriter = new ViewWriter(view, re, serviceRegistrar);
final CyWriter aWriter = mock(CyWriter.class);
when(viewWriterMgr.getWriter(eq(view), eq(re), eq(fileFilter), argThat(new AnyOutputStreamMatcher()))).thenReturn(aWriter);
}
use of org.cytoscape.io.write.CyWriter in project cytoscape-impl by cytoscape.
the class SessionWriterImpl method zipProperties.
/**
* Writes the cytoscape.props file to the session zip.
*/
private void zipProperties() throws Exception {
for (CyProperty<?> cyProps : session.getProperties()) {
if (cancelled)
return;
String filename = null;
CyFileFilter filter = null;
Class<?> type = cyProps.getPropertyType();
if (Bookmarks.class.isAssignableFrom(type)) {
filename = BOOKMARKS_FILE;
filter = bookmarksFilter;
} else if (Properties.class.isAssignableFrom(type)) {
filename = cyProps.getName() + PROPERTIES_EXT;
filter = propertiesFilter;
} else {
// filename = cyProps.getName();
// TODO: how to get the file extension and the file filter for unknown CyProperty types?
logger.error("Cannot save CyProperty \"" + cyProps.getName() + "\": type \"" + type + "\" is not supported");
continue;
}
zos.putNextEntry(new ZipEntry(sessionDir + PROPERTIES_FOLDER + filename));
CyWriter propertiesWriter = propertyWriterMgr.getWriter(cyProps.getProperties(), filter, zos);
propertiesWriter.run(taskMonitor);
zos.closeEntry();
propertiesWriter = null;
}
}
use of org.cytoscape.io.write.CyWriter in project cytoscape-impl by cytoscape.
the class SessionWriterImpl method zipNetworks.
/**
* Writes network files to the session zip.
* @throws Exception
*/
private void zipNetworks() throws Exception {
final CyRootNetworkManager rootNetworkManager = serviceRegistrar.getService(CyRootNetworkManager.class);
final Set<CyNetwork> networks = session.getNetworks();
final Set<CyRootNetwork> rootNetworks = new HashSet<>();
// Zip only root-networks, because sub-networks should be automatically saved with them.
for (final CyNetwork n : networks) {
final CyRootNetwork rn = rootNetworkManager.getRootNetwork(n);
if (rn.getSavePolicy() == SavePolicy.SESSION_FILE)
rootNetworks.add(rn);
}
for (CyRootNetwork rn : rootNetworks) {
if (cancelled)
return;
String xgmmlFile = SessionUtil.getXGMMLFilename(rn);
if (xgmmlFile.contains("_ERROR"))
throw new Exception("Simulating exception...");
zos.putNextEntry(new ZipEntry(sessionDir + NETWORKS_FOLDER + xgmmlFile));
CyWriter writer = networkViewWriterFactory.createWriter(zos, rn);
writer.run(taskMonitor);
zos.closeEntry();
writer = null;
}
}
use of org.cytoscape.io.write.CyWriter in project cytoscape-impl by cytoscape.
the class MakeVisualStylesDefaultTask method run.
@Override
public void run(final TaskMonitor monitor) throws Exception {
if (!confirm)
return;
final VisualMappingManager vmMgr = servicesUtil.get(VisualMappingManager.class);
final Set<VisualStyle> currentStyles = vmMgr.getAllVisualStyles();
if (!currentStyles.isEmpty()) {
final VizmapWriterFactory vizmapWriterFactory = servicesUtil.get(VizmapWriterFactory.class);
final CyApplicationConfiguration config = servicesUtil.get(CyApplicationConfiguration.class);
final FileOutputStream os = new FileOutputStream(new File(config.getConfigurationDirectoryLocation(), VizMapperProxy.PRESET_VIZMAP_FILE));
final CyWriter vizmapWriter = vizmapWriterFactory.createWriter(os, currentStyles);
if (!cancelled)
vizmapWriter.run(monitor);
}
}
use of org.cytoscape.io.write.CyWriter in project cytoscape-impl by cytoscape.
the class ExportAsWebArchiveTask method run.
/**
* Archive the data into a zip file.
*/
@Override
public void run(TaskMonitor taskMonitor) throws Exception {
if (file == null) {
return;
}
// Get export type
final String exportType = this.outputFormat.getSelectedValue();
taskMonitor.setProgress(0.05);
// Add extension if missing.
if (!file.getName().endsWith(FILE_EXTENSION))
file = new File(file.getPath() + FILE_EXTENSION);
// Compress everything as a zip archive.
final FileOutputStream os = new FileOutputStream(file);
CyWriter writer = null;
if (exportType.equals(AS_SPA)) {
writer = fullWriterFactory.createWriter(os, null);
} else if (exportType.equals(AS_SIMPLE_PAGE)) {
writer = simpleWriterFactory.createWriter(os, null);
} else if (exportType.equals(AS_ZIPPED_ARCHIVE)) {
writer = zippedWriterFactory.createWriter(os, null);
} else {
os.close();
throw new NullPointerException("Could not find web session writer.");
}
writer.run(taskMonitor);
os.close();
taskMonitor.setProgress(1.0);
}
Aggregations