use of com.revolsys.record.io.RecordReaderFactory in project com.revolsys.open by revolsys.
the class FileRecordLayer method newPropertiesTabGeneralPanelSource.
@Override
protected ValueField newPropertiesTabGeneralPanelSource(final BasePanel parent) {
final ValueField panel = super.newPropertiesTabGeneralPanelSource(parent);
final String url = getUrl();
if (url.startsWith("file:")) {
final String fileName = url.replaceFirst("file:(//)?", "");
SwingUtil.addLabelledReadOnlyTextField(panel, "File", fileName);
} else {
SwingUtil.addLabelledReadOnlyTextField(panel, "URL", url);
}
final String fileNameExtension = FileUtil.getFileNameExtension(url);
if (Property.hasValue(fileNameExtension)) {
SwingUtil.addLabelledReadOnlyTextField(panel, "File Extension", fileNameExtension);
final RecordReaderFactory factory = IoFactory.factory(RecordReaderFactory.class, fileNameExtension);
if (factory != null) {
SwingUtil.addLabelledReadOnlyTextField(panel, "File Type", factory.getName());
}
}
GroupLayouts.makeColumns(panel, 2, true);
return panel;
}
use of com.revolsys.record.io.RecordReaderFactory in project com.revolsys.open by revolsys.
the class RecordReaderHttpMessageConverter method read.
@Override
public RecordReader read(final Class<? extends RecordReader> clazz, final HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
try {
final HttpHeaders headers = inputMessage.getHeaders();
final MediaType mediaType = headers.getContentType();
Charset charset = mediaType.getCharSet();
if (charset == null) {
charset = StandardCharsets.UTF_8;
}
final InputStream body = inputMessage.getBody();
final String mediaTypeString = mediaType.getType() + "/" + mediaType.getSubtype();
final RecordReaderFactory readerFactory = IoFactory.factoryByMediaType(RecordReaderFactory.class, mediaTypeString);
if (readerFactory == null) {
throw new HttpMessageNotReadableException("Cannot read data in format" + mediaType);
} else {
final Reader<Record> reader = readerFactory.newRecordReader(new InputStreamResource("recordInput", body));
GeometryFactory factory = this.geometryFactory;
final ServletWebRequest requestAttributes = (ServletWebRequest) RequestContextHolder.getRequestAttributes();
final String srid = requestAttributes.getParameter("srid");
if (srid != null && srid.trim().length() > 0) {
factory = GeometryFactory.floating3d(Integer.parseInt(srid));
}
reader.setProperty(IoConstants.GEOMETRY_FACTORY, factory);
return (RecordReader) reader;
}
} catch (final IOException e) {
throw new HttpMessageNotReadableException("Error reading data", e);
}
}
use of com.revolsys.record.io.RecordReaderFactory in project com.revolsys.open by revolsys.
the class RecordIoTestSuite method doRecordReadTest.
private static void doRecordReadTest(final PathResource resource, final ArrayRecord record) {
if (RecordReader.isReadable(resource)) {
final RecordReaderFactory recordReaderFactory = IoFactory.factory(RecordReaderFactory.class, resource);
try (RecordReader recordReader = RecordReader.newRecordReader(resource)) {
final ClockDirection polygonRingDirection = recordReader.getPolygonRingDirection();
final List<Record> records = recordReader.toList();
Assert.assertEquals("Record Count", 1, records.size());
final Record actualRecord = records.get(0);
if (recordReaderFactory.isCustomFieldsSupported() && !(recordReader instanceof GeometryRecordReader)) {
for (final String fieldName : record.getRecordDefinition().getFieldNames()) {
if (!fieldName.equals("GEOMETRY")) {
final Object expectedValue = record.getValue(fieldName);
final Object actualValue = actualRecord.getValue(fieldName);
final boolean equals = DataType.equal(expectedValue, actualValue);
com.revolsys.geometry.util.Assert.equals(fieldName, equals, expectedValue, actualValue);
}
}
}
if (recordReaderFactory.isGeometrySupported()) {
final Geometry expectedGeometry = record.getGeometry();
final Geometry actualGeometry = actualRecord.getGeometry();
assertGeometry(polygonRingDirection, expectedGeometry, actualGeometry);
}
}
} else {
Logs.debug(RecordIoTestSuite.class, "Reading geometry not supported for: " + resource.getFileNameExtension());
}
}
Aggregations