Search in sources :

Example 56 with Resource

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

the class Project method readLayers.

protected void readLayers(final Project rootProject, final Resource resource) {
    final Resource layerGroupResource = resource.newChildResource("rgLayerGroup.rgobject");
    if (!layerGroupResource.exists()) {
        Logs.error(this, "File not found: " + layerGroupResource);
    } else {
        final Resource oldResource = Resource.setBaseResource(resource);
        try {
            final Map<String, Object> properties = Json.toMap(layerGroupResource);
            loadLayers(rootProject, properties);
        } catch (final RuntimeException e) {
            Logs.error(this, "Unable to read: " + layerGroupResource, e);
        } finally {
            Resource.setBaseResource(oldResource);
        }
    }
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource)

Example 57 with Resource

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

the class Project method readProperties.

protected void readProperties(final Resource resource) {
    final Resource layerGroupResource = resource.newChildResource("rgLayerGroup.rgobject");
    if (!layerGroupResource.exists()) {
        Logs.error(this, "File not found: " + layerGroupResource);
    } else {
        final Resource oldResource = Resource.setBaseResource(resource);
        try {
            final Map<String, Object> properties = Json.toMap(layerGroupResource);
            setProperties(properties);
        } catch (final Throwable e) {
            Logs.error(this, "Unable to read: " + layerGroupResource, e);
        } finally {
            Resource.setBaseResource(oldResource);
        }
    }
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource)

Example 58 with Resource

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

the class Project method readProject.

public void readProject(final Project rootProject, final Resource resource) {
    this.resource = resource;
    if (this.resource.exists()) {
        String name;
        try (final BaseCloseable booleanValueCloseable = eventsDisabled()) {
            final RecordStoreConnectionRegistry oldRecordStoreConnections = RecordStoreConnectionRegistry.getForThread();
            try {
                final boolean readOnly = isReadOnly();
                final Resource folderConnectionsDirectory = this.resource.newChildResource("Folder Connections");
                this.folderConnections.clear(folderConnectionsDirectory, readOnly);
                final Resource recordStoresDirectory = this.resource.newChildResource("Record Stores");
                this.recordStores.clear(recordStoresDirectory, readOnly);
                final Resource webServicesDirectory = this.resource.newChildResource("Web Services");
                this.webServices.clear(webServicesDirectory, readOnly);
                if (rootProject == null) {
                    RecordStoreConnectionRegistry.setForThread(this.recordStores);
                } else {
                    final WebServiceConnectionRegistry rootWebServices = rootProject.getWebServices();
                    importConnections("Web Service", this, this.webServices, rootWebServices);
                    final RecordStoreConnectionRegistry rootRecordStores = rootProject.getRecordStores();
                    rootProject.importConnections("Record Store", this, this.recordStores, rootRecordStores);
                    final FolderConnectionRegistry rootFolderConnections = rootProject.getFolderConnections();
                    rootProject.importConnections("Folder Connection", this, this.folderConnections, rootFolderConnections);
                }
                final Resource layersDir = this.resource.newChildResource("Layers");
                final boolean hasLayers = layersDir.exists();
                if (hasLayers) {
                    readProperties(layersDir);
                }
                if (hasLayers) {
                    readLayers(rootProject, layersDir);
                }
                readBaseMapsLayers(rootProject, this.resource);
            } finally {
                RecordStoreConnectionRegistry.setForThread(oldRecordStoreConnections);
            }
            name = getName();
            setName(null);
        }
        setName(name);
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) FolderConnectionRegistry(com.revolsys.io.file.FolderConnectionRegistry) WebServiceConnectionRegistry(com.revolsys.webservice.WebServiceConnectionRegistry) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource) RecordStoreConnectionRegistry(com.revolsys.record.io.RecordStoreConnectionRegistry)

Example 59 with Resource

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

the class Project method saveAllSettingsAs.

public Path saveAllSettingsAs() {
    final Resource resource = this.resource;
    try {
        this.resource = null;
        final Path projectPath = getSaveAsDirectory();
        if (projectPath != null) {
            setName(Paths.getBaseName(projectPath));
            saveAllSettings();
        }
        return projectPath;
    } finally {
        if (this.resource == null) {
            this.resource = resource;
        }
    }
}
Also used : Path(java.nio.file.Path) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource)

Example 60 with Resource

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

the class OracleJdbcClobFieldDefinition method setPreparedStatementValue.

@Override
public int setPreparedStatementValue(final PreparedStatement statement, final int parameterIndex, final Object value) throws SQLException {
    if (value == null) {
        final int sqlType = getSqlType();
        statement.setNull(parameterIndex, sqlType);
    } else {
        if (value instanceof Clob) {
            final Clob clob = (Clob) value;
            statement.setClob(parameterIndex, clob);
        } else {
            Reader in;
            if (value instanceof Resource) {
                final Resource resource = (Resource) value;
                in = resource.newBufferedReader();
            } else if (value instanceof Clob) {
                final Clob clob = (Clob) value;
                in = clob.getCharacterStream();
            } else if (value instanceof String) {
                final String string = (String) value;
                in = new StringReader(string);
            } else if (value instanceof File) {
                final File file = (File) value;
                final PathResource resource = new PathResource(file);
                in = resource.newBufferedReader();
            } else {
                throw new IllegalArgumentException("Not valid for a clob column");
            }
            statement.setCharacterStream(parameterIndex, in);
        }
    }
    return parameterIndex + 1;
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource) PathResource(com.revolsys.spring.resource.PathResource) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) Clob(java.sql.Clob) File(java.io.File)

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