use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.
the class MapObjectFactory method write.
static void write(final Path path, final MapSerializer serializer) {
final PathResource resource = new PathResource(path);
write(resource, serializer);
}
use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.
the class MavenRepositoryCache method setRoot.
@Override
public void setRoot(final Resource root) {
if (root != null) {
try {
final File file = root.getFile();
if (!file.exists()) {
if (!file.mkdirs()) {
throw new IllegalArgumentException("Cannot create maven cache directory " + file);
}
} else if (!file.isDirectory()) {
throw new IllegalArgumentException("Maven cache is not a directory directory " + file);
}
final PathResource fileResource = new PathResource(file);
super.setRoot(fileResource);
} catch (final Throwable e) {
throw new IllegalArgumentException("Maven cache must resolve to a local directory " + root);
}
}
}
use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.
the class MavenRepository method getMavenMetadata.
public MapEx getMavenMetadata(final String groupId, final String artifactId, final String version) {
final String mavenMetadataPath = "/" + Strings.toString("/", groupId.replace('.', '/'), artifactId, version, "maven-metadata.xml");
final Resource resource = this.root;
final Resource mavenMetadataResource = resource.newChildResource(mavenMetadataPath);
if (mavenMetadataResource.exists()) {
try {
return Xml.toMap(mavenMetadataResource);
} catch (final RuntimeException e) {
Logs.error(this, "Error loading maven resource" + mavenMetadataResource, e);
if (mavenMetadataResource instanceof PathResource) {
try {
final File file = mavenMetadataResource.getFile();
if (file.delete()) {
Logs.error(this, "Deleting corrupt maven resource" + mavenMetadataResource, e);
}
} catch (final Throwable ioe) {
}
}
throw e;
}
} else {
return MapEx.EMPTY;
}
}
use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.
the class DirectoryRecordWriter method getWriter.
private Writer<Record> getWriter(final Record record) {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final String path = recordDefinition.getPath();
Writer<Record> writer = this.writers.get(path);
if (writer == null) {
final File directory = getDirectory(recordDefinition);
directory.mkdirs();
final String fileName = getFileName(recordDefinition);
final File file = new File(directory, fileName + this.nameSuffix + "." + this.fileExtension);
final PathResource resource = new PathResource(file);
writer = RecordWriter.newRecordWriter(recordDefinition, resource);
if (writer == null) {
throw new IllegalArgumentException("Unable to create writer for " + resource);
} else {
final Map<String, Object> properties = getProperties();
writer.setProperties(properties);
final Geometry geometry = record.getGeometry();
if (geometry != null) {
final GeometryFactory geometryFactory = geometry.getGeometryFactory();
setProperty(IoConstants.GEOMETRY_FACTORY, geometryFactory);
}
this.writers.put(path, writer);
RecordDefinition writerRecordDefinition = recordDefinition;
if (writer instanceof AbstractRecordWriter) {
final AbstractRecordWriter recordWriter = (AbstractRecordWriter) writer;
writerRecordDefinition = recordWriter.getRecordDefinition();
if (writerRecordDefinition == null) {
writerRecordDefinition = recordDefinition;
}
}
this.recordDefinitionMap.put(path, writerRecordDefinition);
}
}
return writer;
}
use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.
the class ShapefileDirectoryWriter method getWriter.
private Writer<Record> getWriter(final Record object) {
final RecordDefinition recordDefinition = object.getRecordDefinition();
final String path = recordDefinition.getPath();
Writer<Record> writer = this.writers.get(path);
if (writer == null) {
final File directory = getDirectory(recordDefinition);
directory.mkdirs();
final File file = new File(directory, getFileName(recordDefinition) + this.nameSuffix + ".shp");
writer = RecordWriter.newRecordWriter(recordDefinition, new PathResource(file));
((XbaseRecordWriter) writer).setUseZeroForNull(this.useZeroForNull);
final Geometry geometry = object.getGeometry();
if (geometry != null) {
setProperty(IoConstants.GEOMETRY_FACTORY, geometry.getGeometryFactory());
}
this.writers.put(path, writer);
this.recordDefinitionMap.put(path, ((ShapefileRecordWriter) writer).getRecordDefinition());
}
return writer;
}
Aggregations