Search in sources :

Example 41 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class ResourceEditor method setAsText.

@Override
public void setAsText(final String text) throws IllegalArgumentException {
    final Resource resource = Resource.getResource(text);
    setValue(resource);
}
Also used : Resource(com.revolsys.spring.resource.Resource)

Example 42 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class AttributeMap method setProperties.

public void setProperties(final String resourceUrl) {
    final Resource resource = Resource.getResource(resourceUrl);
    final Properties properties = new Properties();
    try {
        properties.load(resource.getInputStream());
        setProps(properties);
    } catch (final Throwable e) {
        Logs.warn(this, "Cannot load properties from " + resource, e);
    }
}
Also used : Resource(com.revolsys.spring.resource.Resource) Properties(java.util.Properties)

Example 43 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class AttributeMap method setPropertyResources.

public void setPropertyResources(final Resource[] resources) {
    final Properties properties = new Properties();
    for (final Resource resource : resources) {
        try {
            properties.load(resource.getInputStream());
        } catch (final Throwable e) {
            Logs.warn(this, "Cannot load properties from " + resource, e);
        }
    }
    setProps(properties);
}
Also used : Resource(com.revolsys.spring.resource.Resource) Properties(java.util.Properties)

Example 44 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class MapObjectFactory method toObject.

/**
 * Convert the resource specified in the source parameter to an object. The properties parameter
 * will override those specific properties.
 *
 * @param source
 * @param properties
 * @return
 */
static <V> V toObject(final Object source, final Map<String, ? extends Object> properties) {
    final Resource resource = Resource.getResource(source);
    final Resource oldResource = Resource.setBaseResource(resource.getParent());
    try {
        final MapEx resourceProperties = Json.toMap(resource);
        resourceProperties.putAll(properties);
        return toObject(resourceProperties);
    } 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 45 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class MapObjectFactory method toObject.

/**
 * Convert the resource specified in the source parameter to an object. The properties parameter
 * will override those specific properties.
 *
 * @param source
 * @param properties
 * @return
 */
static <V> V toObject(final Object source, final Map<String, ? extends Object> properties, final BiConsumer<Resource, Throwable> errorHandler) {
    final Resource resource = Resource.getResource(source);
    final Resource oldResource = Resource.setBaseResource(resource.getParent());
    try {
        final MapEx resourceProperties = Json.toMap(resource);
        resourceProperties.putAll(properties);
        return toObject(resourceProperties);
    } catch (final Throwable t) {
        errorHandler.accept(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)

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