Search in sources :

Example 1 with ExtensionFilenameFilter

use of com.revolsys.io.filter.ExtensionFilenameFilter in project com.revolsys.open by revolsys.

the class DirectoryRecordStore method refreshSchemaElements.

@Override
protected Map<PathName, RecordStoreSchemaElement> refreshSchemaElements(final RecordStoreSchema schema) {
    final Map<PathName, RecordStoreSchemaElement> elements = new TreeMap<>();
    final String schemaPath = schema.getPath();
    final PathName schemaPathName = schema.getPathName();
    final File subDirectory;
    if (schemaPath.equals("/")) {
        subDirectory = this.directory;
    } else {
        subDirectory = new File(this.directory, schemaPath);
    }
    final FileFilter filter = new ExtensionFilenameFilter(this.fileExtensions);
    final File[] files = subDirectory.listFiles();
    if (files != null) {
        for (final File file : files) {
            if (filter.accept(file)) {
                final PathResource resource = new PathResource(file);
                final RecordDefinition recordDefinition = loadRecordDefinition(schema, schemaPath, resource);
                if (recordDefinition != null) {
                    final PathName path = recordDefinition.getPathName();
                    elements.put(path, recordDefinition);
                }
            } else if (file.isDirectory()) {
                final String name = file.getName();
                final PathName childSchemaPath = schemaPathName.newChild(name);
                RecordStoreSchema childSchema = schema.getSchema(childSchemaPath);
                if (childSchema == null) {
                    childSchema = new RecordStoreSchema(schema, childSchemaPath);
                } else {
                    if (!childSchema.isInitialized()) {
                        childSchema.refresh();
                    }
                }
                elements.put(childSchemaPath, childSchema);
            }
        }
    }
    return elements;
}
Also used : RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) PathResource(com.revolsys.spring.resource.PathResource) ExtensionFilenameFilter(com.revolsys.io.filter.ExtensionFilenameFilter) PathName(com.revolsys.io.PathName) TreeMap(java.util.TreeMap) FileFilter(java.io.FileFilter) File(java.io.File) RecordStoreSchemaElement(com.revolsys.record.schema.RecordStoreSchemaElement) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

PathName (com.revolsys.io.PathName)1 ExtensionFilenameFilter (com.revolsys.io.filter.ExtensionFilenameFilter)1 RecordDefinition (com.revolsys.record.schema.RecordDefinition)1 RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)1 RecordStoreSchemaElement (com.revolsys.record.schema.RecordStoreSchemaElement)1 PathResource (com.revolsys.spring.resource.PathResource)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 TreeMap (java.util.TreeMap)1