public String getContentType(final Context context) throws SQLException { BitstreamFormat format = bitstream.getFormat(context); return format == null ? null : StringUtils.trimToEmpty(format.getMIMEType()); }
@Override public boolean canGenerateCitationVersion(Context context, Bitstream bitstream) throws SQLException { return VALID_TYPES.contains(bitstream.getFormat(context).getMIMEType()); }
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; } } }
protected void setFormatToMIMEType(Context context, Bitstream bs, String mimeType) throws SQLException { List<BitstreamFormat> bf = bitstreamFormatService.findNonInternal(context); for (BitstreamFormat aBf : bf) { if (aBf.getMIMEType().equalsIgnoreCase(mimeType)) { bs.setFormat(context, aBf); break; } } }
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; }
/** * Get the list of MIME types that the given DSpace object will * accept as packages. * * @param context The relevant DSpace Context. * @param dso target DSpace object * @return the list of MIME types that the given DSpace object will * accept as packages. * @throws DSpaceSWORDException can be thrown by the internals of the DSpace SWORD implementation */ public List<String> getAccepts(Context context, DSpaceObject dso) throws DSpaceSWORDException { try { List<String> accepts = new ArrayList<String>(); if (dso instanceof Collection) { for (String format : swordaccepts) { accepts.add(format); } } else if (dso instanceof Item) { List<BitstreamFormat> bfs = bitstreamFormatService .findNonInternal(context); for (BitstreamFormat bf : bfs) { accepts.add(bf.getMIMEType()); } } return accepts; } catch (SQLException e) { throw new DSpaceSWORDException(e); } }
public GoogleBitstreamComparator(Context context, Map<String, String> googleScholarSettings) { this.context = context; String[] shortDescriptions; if (googleScholarSettings.containsKey("citation.prioritized_types")) { shortDescriptions = splitAndTrim(googleScholarSettings.get("citation.prioritized_types")); } else { log.warn("Please define citation.prioritized_types in google-metadata.properties"); shortDescriptions = new String[0]; } int priority = 1; for (String s : shortDescriptions) { try { BitstreamFormat format = ContentServiceFactory.getInstance().getBitstreamFormatService() .findByShortDescription(context, s); if (format != null) { priorityMap.put(format.getMIMEType(), priority); } else { log.warn(s + " is not a valid short description, please add it to bitstream-formats.xml"); } priority++; } catch (SQLException e) { log.error(e.getMessage()); } } }
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; }
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; }
@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; }
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); } }
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); } }
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; }
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; }
/** * 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); }
/** * 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); }
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); } }
String fileID = gensym("logo"); file.setID(fileID); file.setMIMETYPE(logoBs.getFormat(context).getMIMEType()); file.setSIZE(logoBs.getSizeBytes());
/** * 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); } }
contentType = format.getMIMEType();