use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class AbstractConnection method writeToFile.
@Override
public void writeToFile(final Object target) {
final Resource resource = Resource.getResource(target);
try {
this.connectionFile = resource.getPath();
} catch (final Throwable e) {
}
Connection.super.writeToFile(resource);
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class MapObjectFactory method toObject.
static <V> V toObject(final Object source) {
final Resource resource = Resource.getResource(source);
final Resource oldResource = Resource.setBaseResource(resource.getParent());
try {
final MapEx properties = Json.toMap(resource);
return toObject(properties);
} catch (final Throwable t) {
Logs.error(MapObjectFactoryRegistry.class, "Cannot load object from " + resource, t);
return null;
} finally {
Resource.setBaseResource(oldResource);
}
}
use of com.revolsys.spring.resource.Resource 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.Resource in project com.revolsys.open by revolsys.
the class MavenRepository method getPom.
public MavenPom getPom(final String groupId, final String artifactId, final String version) {
final String groupArtifactVersion = groupId + ":" + artifactId + ":" + version;
MavenPom pom = this.pomCache.get(groupArtifactVersion);
if (pom == null) {
final Resource resource = getResource(groupId, artifactId, "pom", version);
if (resource.exists()) {
final MapEx map = Xml.toMap(resource);
pom = new MavenPom(this, map);
this.pomCache.put(groupArtifactVersion, pom);
} else {
return null;
}
}
return pom;
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class CsvRecordWriter method write.
@Override
public void write(final Record record) {
Writer out = this.out;
if (this.paused) {
this.paused = false;
final Resource resource = getResource();
out = this.out = resource.newWriterAppend();
}
if (out != null) {
try {
final RecordDefinition recordDefinition = this.recordDefinition;
final char fieldSeparator = this.fieldSeparator;
boolean first = true;
for (final FieldDefinition field : recordDefinition.getFields()) {
if (first) {
first = false;
} else {
out.write(fieldSeparator);
}
final String fieldName = field.getName();
final Object value;
if (isWriteCodeValues()) {
value = record.getCodeValue(fieldName);
} else {
value = record.getValue(fieldName);
}
if (value instanceof Geometry) {
final Geometry geometry = (Geometry) value;
if (this.useQuotes) {
out.write('"');
EWktWriter.write(out, geometry, this.ewkt);
out.write('"');
} else {
EWktWriter.write(out, geometry, this.ewkt);
}
} else if (value != null) {
final DataType dataType = field.getDataType();
final String stringValue = dataType.toString(value);
if (dataType.isRequiresQuotes()) {
string(stringValue);
} else {
out.write(stringValue, 0, stringValue.length());
}
}
}
out.write('\n');
} catch (final IOException e) {
throw Exceptions.wrap(e);
}
}
}
Aggregations