Search in sources :

Example 6 with Resource

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);
}
Also used : Resource(com.revolsys.spring.resource.Resource)

Example 7 with 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);
    }
}
Also used : LinkedHashMapEx(com.revolsys.collection.map.LinkedHashMapEx) MapEx(com.revolsys.collection.map.MapEx) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource)

Example 8 with Resource

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;
    }
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource) File(java.io.File)

Example 9 with Resource

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;
}
Also used : MapEx(com.revolsys.collection.map.MapEx) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource)

Example 10 with Resource

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);
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) FieldDefinition(com.revolsys.record.schema.FieldDefinition) Resource(com.revolsys.spring.resource.Resource) DataType(com.revolsys.datatype.DataType) IOException(java.io.IOException) AbstractRecordWriter(com.revolsys.io.AbstractRecordWriter) EWktWriter(com.revolsys.record.io.format.wkt.EWktWriter) Writer(java.io.Writer) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

Resource (com.revolsys.spring.resource.Resource)78 PathResource (com.revolsys.spring.resource.PathResource)23 MapEx (com.revolsys.collection.map.MapEx)9 File (java.io.File)9 IOException (java.io.IOException)8 InputStream (java.io.InputStream)6 LinkedHashMapEx (com.revolsys.collection.map.LinkedHashMapEx)5 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 UrlResource (com.revolsys.spring.resource.UrlResource)5 Writer (java.io.Writer)5 Record (com.revolsys.record.Record)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)4 DataType (com.revolsys.datatype.DataType)3 BoundingBox (com.revolsys.geometry.model.BoundingBox)3 Geometry (com.revolsys.geometry.model.Geometry)3 AbstractRecordWriter (com.revolsys.io.AbstractRecordWriter)3 ArrayRecord (com.revolsys.record.ArrayRecord)3 RecordReader (com.revolsys.record.io.RecordReader)3 RecordWriter (com.revolsys.record.io.RecordWriter)3 Blob (java.sql.Blob)3