本文整理了Java中org.dspace.content.Bitstream.getFormat()
方法的一些代码示例,展示了Bitstream.getFormat()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitstream.getFormat()
方法的具体详情如下:
包路径:org.dspace.content.Bitstream
类名称:Bitstream
方法名:getFormat
[英]Get the format of the bitstream
[中]获取位流的格式
代码示例来源:origin: DSpace/DSpace
private int getPriorityFromBitstream(Bitstream bitstream) {
try {
String check = bitstream.getFormat(context).getMIMEType();
if (priorityMap.containsKey(bitstream.getFormat(context).getMIMEType())) {
return priorityMap.get(bitstream.getFormat(context).getMIMEType());
} else {
return Integer.MAX_VALUE;
}
} catch (SQLException e) {
log.error(e.getMessage());
return Integer.MAX_VALUE;
}
}
}
代码示例来源:origin: DSpace/DSpace
public String getContentType(final Context context) throws SQLException {
BitstreamFormat format = bitstream.getFormat(context);
return format == null ? null : StringUtils.trimToEmpty(format.getMIMEType());
}
代码示例来源:origin: DSpace/DSpace
@Override
public boolean canGenerateCitationVersion(Context context, Bitstream bitstream) throws SQLException {
return VALID_TYPES.contains(bitstream.getFormat(context).getMIMEType());
}
代码示例来源:origin: DSpace/DSpace
@Override
public String getFormatDescription(Context context, Bitstream bitstream) throws SQLException {
if (bitstream.getFormat(context).getShortDescription().equals("Unknown")) {
// Get user description if there is one
String desc = bitstream.getUserFormatDescription();
if (desc == null) {
return "Unknown";
}
return desc;
}
// not null or Unknown
return bitstream.getFormat(context).getShortDescription();
}
代码示例来源:origin: DSpace/DSpace
private List<String> getFileFormats(Item item) {
List<String> formats = new ArrayList<>();
try {
for (Bundle b : itemService.getBundles(item, "ORIGINAL")) {
for (Bitstream bs : b.getBitstreams()) {
if (!formats.contains(bs.getFormat(context).getMIMEType())) {
formats.add(bs.getFormat(context).getMIMEType());
}
}
}
} catch (SQLException ex) {
log.error(ex.getMessage(), ex);
}
return formats;
}
代码示例来源:origin: DSpace/DSpace
@Override
public List<Bitstream> getNonInternalBitstreams(Context context, Item item) throws SQLException {
List<Bitstream> bitstreamList = new ArrayList<>();
// Go through the bundles and bitstreams picking out ones which aren't
// of internal formats
List<Bundle> bunds = item.getBundles();
for (Bundle bund : bunds) {
List<Bitstream> bitstreams = bund.getBitstreams();
for (Bitstream bitstream : bitstreams) {
if (!bitstream.getFormat(context).isInternal()) {
// Bitstream is not of an internal format
bitstreamList.add(bitstream);
}
}
}
return bitstreamList;
}
代码示例来源:origin: DSpace/DSpace
@Override
protected void performItem(Item item) throws SQLException, IOException {
for (Bundle bundle : item.getBundles()) {
for (Bitstream bs : bundle.getBitstreams()) {
String fmt = bs.getFormat(Curator.curationContext()).getShortDescription();
Integer count = fmtTable.get(fmt);
if (count == null) {
count = 1;
} else {
count += 1;
}
fmtTable.put(fmt, count);
}
}
}
代码示例来源:origin: DSpace/DSpace
static int countBitstreamMime(Context context, BundleName bundleName, Item item, String[] mimeList) {
int count = 0;
for (Bundle bundle : item.getBundles()) {
if (!bundle.getName().equals(bundleName.name())) {
continue;
}
for (Bitstream bit : bundle.getBitstreams()) {
for (String mime : mimeList) {
try {
if (bit.getFormat(context).getMIMEType().equals(mime.trim())) {
count++;
}
} catch (SQLException e) {
log.error("Get format error for bitstream " + bit.getName());
}
}
}
}
return count;
}
代码示例来源:origin: DSpace/DSpace
static int countBitstreamMimeStartsWith(Context context, BundleName bundleName, Item item, String prefix) {
int count = 0;
try {
for (Bundle bundle : item.getBundles()) {
if (!bundle.getName().equals(bundleName.name())) {
continue;
}
for (Bitstream bit : bundle.getBitstreams()) {
if (bit.getFormat(context).getMIMEType().startsWith(prefix)) {
count++;
}
}
}
} catch (SQLException e) {
// ignore
}
return count;
}
代码示例来源:origin: DSpace/DSpace
@Override
public Thumbnail getThumbnail(Context context, Item item, boolean requireOriginal) throws SQLException {
Bitstream thumbBitstream;
List<Bundle> originalBundles = getBundles(item, "ORIGINAL");
Bitstream primaryBitstream = null;
if (CollectionUtils.isNotEmpty(originalBundles)) {
primaryBitstream = originalBundles.get(0).getPrimaryBitstream();
}
if (primaryBitstream != null) {
if (primaryBitstream.getFormat(context).getMIMEType().equals("text/html")) {
return null;
}
thumbBitstream = bitstreamService
.getBitstreamByName(item, "THUMBNAIL", primaryBitstream.getName() + ".jpg");
} else {
if (requireOriginal) {
primaryBitstream = bitstreamService.getFirstBitstream(item, "ORIGINAL");
}
thumbBitstream = bitstreamService.getFirstBitstream(item, "THUMBNAIL");
}
if (thumbBitstream != null) {
return new Thumbnail(thumbBitstream, primaryBitstream);
}
return null;
}
代码示例来源:origin: DSpace/DSpace
protected List<OriginalDeposit> getOriginalDeposits(Context context,
Item item, String swordBundle)
throws DSpaceSwordException {
try {
// NOTE: DSpace does not store file metadata, so we can't access the information
// about who deposited what, when, on behalf of whoever.
List<OriginalDeposit> originalDeposits = new ArrayList<OriginalDeposit>();
// an original deposit is everything in the SWORD bundle
List<Bundle> bundles = item.getBundles();
for (Bundle bundle : bundles) {
if (swordBundle.equals(bundle.getName())) {
List<Bitstream> bitstreams = bundle
.getBitstreams();
for (Bitstream bitstream : bitstreams) {
// note that original deposits don't have actionable urls
OriginalDeposit deposit = new OriginalDeposit(
this.urlManager.getBitstreamUrl(
bitstream));
deposit.setMediaType(bitstream
.getFormat(context).getMIMEType());
originalDeposits.add(deposit);
}
}
}
return originalDeposits;
} catch (SQLException e) {
throw new DSpaceSwordException(e);
}
}
代码示例来源:origin: DSpace/DSpace
protected List<ResourcePart> getResourceParts(Context context, Item item,
List<String> includeBundles)
throws DSpaceSwordException {
try {
// the list of resource parts is everything in the bundles to be included
List<ResourcePart> resources = new ArrayList<ResourcePart>();
for (String bundleName : includeBundles) {
List<Bundle> bundles = item.getBundles();
for (Bundle bundle : bundles) {
if (bundleName.equals(bundle.getName())) {
List<Bitstream> bitstreams = bundle
.getBitstreams();
for (Bitstream bitstream : bitstreams) {
// note that individual bitstreams have actionable urls
ResourcePart part = new ResourcePart(this.urlManager
.getActionableBitstreamUrl(
bitstream));
part.setMediaType(bitstream
.getFormat(context).getMIMEType());
resources.add(part);
}
}
}
}
return resources;
} catch (SQLException e) {
throw new DSpaceSwordException(e);
}
}
代码示例来源:origin: DSpace/DSpace
static int countBitstreamLargerThanMaxSize(Context context, BundleName bundleName, Item item, String[] mimeList,
String prop) {
long size = DSpaceServicesFactory.getInstance().getConfigurationService().getLongProperty(prop);
int count = 0;
try {
for (Bundle bundle : item.getBundles()) {
if (!bundle.getName().equals(bundleName.name())) {
continue;
}
for (Bitstream bit : bundle.getBitstreams()) {
for (String mime : mimeList) {
if (bit.getFormat(context).getMIMEType().equals(mime.trim())) {
if (bit.getSizeBytes() > size) {
count++;
}
}
}
}
}
} catch (SQLException e) {
// ignore
}
return count;
}
代码示例来源:origin: DSpace/DSpace
static int countBitstreamSmallerThanMinSize(Context context, BundleName bundleName, Item item, String[] mimeList,
String prop) {
long size = DSpaceServicesFactory.getInstance().getConfigurationService().getLongProperty(prop);
int count = 0;
try {
for (Bundle bundle : item.getBundles()) {
if (!bundle.getName().equals(bundleName.name())) {
continue;
}
for (Bitstream bit : bundle.getBitstreams()) {
for (String mime : mimeList) {
if (bit.getFormat(context).getMIMEType().equals(mime.trim())) {
if (bit.getSizeBytes() < size) {
count++;
}
}
}
}
}
} catch (SQLException e) {
// ignore
}
return count;
}
代码示例来源:origin: DSpace/DSpace
if (bitstream.getFormat(context).getID() == fid) {
return bitstream;
代码示例来源:origin: DSpace/DSpace
@Override
public void removeLicenses(Context context, Item item) throws SQLException, AuthorizeException, IOException {
// Find the License format
BitstreamFormat bf = bitstreamFormatService.findByShortDescription(context, "License");
int licensetype = bf.getID();
// search through bundles, looking for bitstream type license
List<Bundle> bunds = item.getBundles();
for (Bundle bund : bunds) {
boolean removethisbundle = false;
List<Bitstream> bits = bund.getBitstreams();
for (Bitstream bit : bits) {
BitstreamFormat bft = bit.getFormat(context);
if (bft.getID() == licensetype) {
removethisbundle = true;
}
}
// probably serious troubles with Authorizations
// fix by telling system not to check authorization?
if (removethisbundle) {
removeBundle(context, item, bund);
}
}
}
代码示例来源:origin: DSpace/DSpace
/**
* Add links associated with this item.
*/
protected void addLinks()
throws DSpaceSWORDException {
// if this is a deposit which is no op we can't do anything here
if (this.deposit != null && this.deposit.isNoOp()) {
return;
}
// get the things we need out of the service
SWORDUrlManager urlManager = swordService.getUrlManager();
String bsurl = urlManager.getBitstreamUrl(this.bitstream);
BitstreamFormat bf;
try {
bf = this.bitstream.getFormat(swordService.getContext());
} catch (SQLException e) {
log.error("Exception caught: ", e);
throw new DSpaceSWORDException(e);
}
String format = "application/octet-stream";
if (bf != null) {
format = bf.getMIMEType();
}
Link link = new Link();
link.setType(format);
link.setHref(bsurl);
link.setRel("alternate");
entry.addLink(link);
log.debug("Added link entity to entry for url " + bsurl);
}
代码示例来源:origin: org.dspace/dspace-sword-api
/**
* Add links associated with this item.
*
*/
protected void addLinks()
throws DSpaceSWORDException
{
// if this is a deposit which is no op we can't do anything here
if (this.deposit != null && this.deposit.isNoOp())
{
return;
}
// get the things we need out of the service
SWORDUrlManager urlManager = swordService.getUrlManager();
String bsurl = urlManager.getBitstreamUrl(this.bitstream);
BitstreamFormat bf = this.bitstream.getFormat();
String format = "application/octet-stream";
if (bf != null)
{
format = bf.getMIMEType();
}
Link link = new Link();
link.setType(format);
link.setHref(bsurl);
link.setRel("alternate");
entry.addLink(link);
log.debug("Added link entity to entry for url " + bsurl);
}
代码示例来源:origin: DSpace/DSpace
private MediaResource getBitstreamResource(Context context,
Bitstream bitstream)
throws SwordServerException, SwordAuthException {
try {
InputStream stream = bitstreamService.retrieve(context, bitstream);
MediaResource mr = new MediaResource(stream,
bitstream.getFormat(context).getMIMEType(), null, true);
mr.setContentMD5(bitstream.getChecksum());
mr.setLastModified(this.getLastModified(context, bitstream));
return mr;
} catch (IOException | SQLException e) {
throw new SwordServerException(e);
} catch (AuthorizeException e) {
throw new SwordAuthException(e);
}
}
代码示例来源:origin: DSpace/DSpace
/**
* Add the bitstream metadata to the item
*
* @param item The item
* @param bitstream The bitstream
* @param type The type of bitstream
* @throws SQLException An exception that provides information on a database access error or other errors.
*/
protected void addMetadata(Item item, Bitstream bitstream, String type) throws SQLException {
String value = bitstream.getFormat(Curator.curationContext()).getMIMEType() + "##";
value += bitstream.getName() + "##";
value += bitstream.getSizeBytes() + "##";
value += item.getHandle() + "##";
value += bitstream.getSequenceID() + "##";
value += bitstream.getChecksum() + "##";
if (bitstream.getDescription() != null) {
value += bitstream.getDescription();
}
itemService.addMetadata(Curator.curationContext(), item, "dc", "format", type, "en", value);
}
}
内容来源于网络,如有侵权,请联系作者删除!