/** * Compares two bitstreams based on their mimetypes, if mimetypes are the same,then the largest bitstream comes * first * See google-metadata.properties to define the order * * @param b1 first bitstream * @param b2 second bitstream * @return */ public int compare(Bitstream b1, Bitstream b2) { int priority1 = getPriorityFromBitstream(b1); int priority2 = getPriorityFromBitstream(b2); if (priority1 > priority2) { return 1; } else if (priority1 == priority2) { if (b1.getSizeBytes() <= b2.getSizeBytes()) { return 1; } else { return -1; } } else { return -1; } }
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()); } } }
/** * Wrap the item, parse all configured fields and generate metadata field * values. * * @param context context * @param item The item being viewed to extract metadata from * @throws SQLException if database error */ public GoogleMetadata(Context context, Item item) throws SQLException { // Hold onto the item in case we need to refresh a stale parse this.item = item; this.itemService = ContentServiceFactory.getInstance().getItemService(); itemURL = HandleServiceFactory.getInstance().getHandleService().resolveToURL(context, item.getHandle()); googleBitstreamComparator = new GoogleBitstreamComparator(context, googleScholarSettings); parseItem(); }