public String getFileName() { return StringUtils.trimToEmpty(bitstream.getName()); }
@Override public Bitstream getBitstreamByName(Bundle bundle, String name) { Bitstream target = null; for (Bitstream bitstream : bundle.getBitstreams()) { if (name.equals(bitstream.getName())) { target = bitstream; break; } } return target; }
/** * Tests bitstream by matching the regular expression in the * properties against the bitstream name * * @param bitstream Bitstream * @return whether bitstream name matches the regular expression * @throws BitstreamFilterException if filter error */ @Override public boolean accept(Bitstream bitstream) throws BitstreamFilterException { if (filenameRegex == null) { filenameRegex = props.getProperty("filename"); if (filenameRegex == null) { throw new BitstreamFilterException("BitstreamFilter property 'filename' not found."); } pattern = Pattern.compile(filenameRegex); } Matcher m = pattern.matcher(bitstream.getName()); return m.matches(); }
@Override public Bitstream getBitstreamByName(Item item, String bundleName, String bitstreamName) throws SQLException { List<Bundle> bundles = itemService.getBundles(item, bundleName); for (int i = 0; i < bundles.size(); i++) { Bundle bundle = bundles.get(i); List<Bitstream> bitstreams = bundle.getBitstreams(); for (int j = 0; j < bitstreams.size(); j++) { Bitstream bitstream = bitstreams.get(j); if (StringUtils.equals(bitstream.getName(), bitstreamName)) { return bitstream; } } } return null; }
protected String urlOfBitstream(HttpServletRequest request, Bitstream logo) { String name = logo.getName(); return resolveURL(request, null) + (uiType.equalsIgnoreCase(UITYPE_XMLUI) ? "/bitstream/id/" : "/retrieve/") + logo.getID() + "/" + (name == null ? "" : name); }
@Override public BitstreamFormat guessFormat(Context context, Bitstream bitstream) throws SQLException { String filename = bitstream.getName();
@Override public String getBitstreamProvenanceMessage(Context context, Item myitem) throws SQLException { // Get non-internal format bitstreams List<Bitstream> bitstreams = itemService.getNonInternalBitstreams(context, myitem); // Create provenance description StringBuilder myMessage = new StringBuilder(); myMessage.append("No. of bitstreams: ").append(bitstreams.size()).append("\n"); // Add sizes and checksums of bitstreams for (Bitstream bitstream : bitstreams) { myMessage.append(bitstream.getName()).append(": ") .append(bitstream.getSizeBytes()).append(" bytes, checksum: ") .append(bitstream.getChecksum()).append(" (") .append(bitstream.getChecksumAlgorithm()).append(")\n"); } return myMessage.toString(); } }
public String getActionableBitstreamUrl(Bitstream bitstream) throws DSpaceSwordException { return this.getSwordBaseUrl() + "/edit-media/bitstream/" + bitstream.getID() + "/" + bitstream.getName(); }
static List<String> getBitstreamNames(BundleName bundleName, Item item) { ArrayList<String> names = new ArrayList<String>(); for (Bundle bundle : item.getBundles()) { if (!bundle.getName().equals(bundleName.name())) { continue; } for (Bitstream bit : bundle.getBitstreams()) { names.add(bit.getName()); } } return names; }
private static Bitstream getItemBitstreamByName(Item item, String bsName) throws SQLException { Bundle[] bundles = item.getBundles(); for (int i = 0; i < bundles.length; i++) { Bitstream[] bitstreams = bundles[i].getBitstreams(); for (int k = 0; k < bitstreams.length; k++) { if (bsName.equals(bitstreams[k].getName())) { return bitstreams[k]; } } } return null; }
/** * Add the title from the bibliographic metadata */ protected void addTitle() { Title title = new Title(); title.setContent(this.bitstream.getName()); title.setType(ContentType.TEXT); entry.setTitle(title); log.debug("Added title to entry"); }
/** * Add the title from the bibliographic metadata * */ protected void addTitle() { Title title = new Title(); title.setContent(this.bitstream.getName()); title.setType(ContentType.TEXT); entry.setTitle(title); log.debug("Added title to entry"); }
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; }
/** * Find bitstream by its Name, looking in specific named bundle. * * @param item - dspace item whose bundles to search. * @param bsName - name of bitstream to match. * @param bnName - bundle name to match, or null for all. * @return the format found or null if none found. * @throws SQLException if database error */ public static Bitstream getBitstreamByName(Item item, String bsName, String bnName) throws SQLException { List<Bundle> bundles; if (bnName == null) { bundles = item.getBundles(); } else { bundles = itemService.getBundles(item, bnName); } for (Bundle bundle : bundles) { List<Bitstream> bitstreams = bundle.getBitstreams(); for (Bitstream bitstream : bitstreams) { if (bsName.equals(bitstream.getName())) { return bitstream; } } } return null; }
private void buildFullTextList(Item parentItem) { // now get full text of any bitstreams in the TEXT bundle // trundle through the bundles List<Bundle> myBundles = parentItem.getBundles(); for (Bundle myBundle : emptyIfNull(myBundles)) { if (StringUtils.equals(FULLTEXT_BUNDLE, myBundle.getName())) { // a-ha! grab the text out of the bitstreams List<Bitstream> bitstreams = myBundle.getBitstreams(); for (Bitstream fulltextBitstream : emptyIfNull(bitstreams)) { fullTextStreams.add(new FullTextBitstream(sourceInfo, fulltextBitstream)); log.debug("Added BitStream: " + fulltextBitstream.getStoreNumber() + " " + fulltextBitstream.getSequenceID() + " " + fulltextBitstream.getName()); } } } }
@Override public void additionalIndex(Context context, DSpaceObject dso, SolrInputDocument document) { if (dso instanceof Item) { Item item = (Item) dso; List<Bundle> bundles = item.getBundles(); if (bundles != null) { for (Bundle bundle : bundles) { String bundleName = bundle.getName(); if ((bundleName != null) && bundleName.equals(BUNDLE_NAME)) { List<Bitstream> bitstreams = bundle.getBitstreams(); if (bitstreams != null) { for (Bitstream bitstream : bitstreams) { document.addField(SOLR_FIELD_NAME_FOR_FILENAMES, bitstream.getName()); String description = bitstream.getDescription(); if ((description != null) && (!description.isEmpty())) { document.addField(SOLR_FIELD_NAME_FOR_DESCRIPTIONS, description); } } } } } } } } }
@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; }
/** * 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); } }