List of usage examples for java.io File.Builder File.Builder
File.Builder
From source file:eu.scape_project.service.ConnectorService.java
/** * Retrieve a {@link File} from Fedora//from www . j a v a2 s . co m * * @param session * the {@link Session} to use for the operation * @param fileUri * the {@link File}'s URI * @return the {@link File} object as saved in Fedora * @throws RepositoryException * if an error ocurred while retrieving the {@link File} from * Fedora */ public File fetchFile(final Session session, final String fileUri) throws RepositoryException { final File.Builder f = new File.Builder(); final FedoraObject fileObject = this.objectService.getObject(session, fileUri); final IdentifierTranslator subjects = new DefaultIdentifierTranslator(); final Model fileModel = SerializationUtils.unifyDatasetModel(fileObject.getPropertiesDataset(subjects)); final Resource parent = fileModel.createResource(subjects.getSubject(fileObject.getPath()).getURI()); /* fetch and add the properties and metadata from the repo */ f.technical(fetchMetadata(session, fileUri + "/TECHNICAL")); String fileId = fileUri.substring(fileUri.lastIndexOf('/') + 1); f.identifier(new Identifier(fileId)); f.filename(getFirstLiteralString(fileModel, parent, HAS_FILENAME)); f.mimetype(getFirstLiteralString(fileModel, parent, HAS_MIMETYPE)); String[] ids = fileUri.split("/"); if (this.referencedContent) { f.uri(URI.create(getFirstLiteralString(fileModel, parent, HAS_REFERENCED_CONTENT))); } else { f.uri(URI.create(fedoraUrl + "/scape/file/" + ids[ids.length - 4] + "/" + ids[ids.length - 2] + "/" + ids[ids.length - 1])); } /* discover all the Bistreams and add them to the file */ final List<BitStream> streams = new ArrayList<>(); for (String bsUri : getLiteralStrings(fileModel, parent, HAS_BITSTREAM)) { streams.add(fetchBitStream(session, bsUri.substring(bsUri.indexOf('/')))); } f.bitStreams(streams); return f.build(); }