use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class DirectoryRecordStore method getRecords.
@Override
public RecordReader getRecords(final PathName path) {
final RecordDefinition recordDefinition = getRecordDefinition(path);
final Resource resource = getResource(path.toString(), recordDefinition);
final RecordReader reader = RecordReader.newRecordReader(resource);
if (reader == null) {
throw new IllegalArgumentException("Cannot find reader for: " + path);
} else {
final String typePath = this.typePathByResource.get(resource);
reader.setProperty("schema", recordDefinition.getSchema());
reader.setProperty("typePath", typePath);
return reader;
}
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class DirectoryRecordStore method insertRecord.
@Override
public synchronized void insertRecord(final Record record) {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final String typePath = recordDefinition.getPath();
RecordWriter writer = this.writers.get(typePath);
if (writer == null) {
final String schemaName = PathUtil.getPath(typePath);
final File subDirectory = FileUtil.getDirectory(getDirectory(), schemaName);
final String fileExtension = getFileExtension();
final File file = new File(subDirectory, recordDefinition.getName() + "." + fileExtension);
final Resource resource = new PathResource(file);
writer = RecordWriter.newRecordWriter(recordDefinition, resource);
if (writer == null) {
throw new RuntimeException("Cannot create writer for: " + typePath);
} else if (writer instanceof ObjectWithProperties) {
final ObjectWithProperties properties = writer;
properties.setProperties(getProperties());
}
this.writers.put(typePath, writer);
}
writer.write(record);
addStatistic("Insert", record);
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class PdfImage method newBufferedImage.
protected BufferedImage newBufferedImage() {
final Resource imageResource = getImageResource();
try {
final File file = Resource.getOrDownloadFile(imageResource);
// TODO password support
final PDDocument document = PDDocument.loadNonSeq(file, null, null);
@SuppressWarnings("unchecked") final List<PDPage> pages = document.getDocumentCatalog().getAllPages();
if (pages.isEmpty()) {
throw new RuntimeException("PDF file " + imageResource + " doesn't contain any pages");
} else {
if (pages.size() > 1) {
Logs.warn(this, "PDF file " + imageResource + " doesn't contais more than 1 page");
}
final PDPage page = pages.get(0);
final COSDictionary pageDictionary = page.getCOSDictionary();
final Rectangle2D mediaBox = PdfUtil.findRectangle(pageDictionary, COSName.MEDIA_BOX);
final int resolution = 72;
BufferedImage image = page.convertToImage(BufferedImage.TYPE_INT_ARGB, resolution);
final COSDictionary viewport = PdfUtil.getPageViewport(pageDictionary);
if (viewport != null) {
final Rectangle2D bbox = PdfUtil.findRectangle(viewport, COSName.BBOX);
if (bbox != null) {
final double boxX = bbox.getX();
final double boxY = bbox.getY();
final int boxWidth = (int) bbox.getWidth();
final int boxHeight = (int) bbox.getHeight();
final BufferedImage viewportImage = new BufferedImage(boxWidth, boxHeight, BufferedImage.TYPE_INT_ARGB);
final Graphics2D graphics = (Graphics2D) viewportImage.getGraphics();
final double translateY = -(mediaBox.getHeight() - (boxHeight + boxY));
graphics.translate(-boxX, translateY);
graphics.scale(1, 1);
graphics.drawImage(image, 0, 0, null);
graphics.dispose();
image = viewportImage;
}
final BoundingBox boundingBox = PdfUtil.getViewportBoundingBox(viewport);
setBoundingBox(boundingBox);
setResolution(boundingBox.getWidth() / image.getWidth());
}
return image;
}
} catch (final IOException e) {
throw new RuntimeException("Error loading PDF file " + imageResource, e);
}
}
Aggregations