Skip to content

Instantly share code, notes, and snippets.

@xmorave2
Last active July 19, 2017 07:26
Show Gist options
  • Select an option

  • Save xmorave2/4de52fcd54e3a4216bce41c9e98cc1c8 to your computer and use it in GitHub Desktop.

Select an option

Save xmorave2/4de52fcd54e3a4216bce41c9e98cc1c8 to your computer and use it in GitHub Desktop.
format.bsh
/**
* Get and normalize EAN code (from ISBN)
*
* @param Record record
* @return String EAN code
*/
private String getEAN(Record record) {
DataField isbn = (DataField) record.getVariableField("020");
if(isbn != null) {
Subfield isbn2 = isbn.getSubfield('a');
if(isbn2 != null) {
String ean = isbn2.getData();
ean = ean.replaceAll("[^0-9]*","");
if(ean.isEmpty()) {
return null;
}
else {
return ean;
}
}
}
return null;
}
/**
* Determine Record Format(s)
*
* @param Record record
* @return Set format of record
*/
public Set getFormat(Record record){
Set result = new LinkedHashSet();
List items = record.getVariableFields("993");
for (VariableField item : items) {
DataField i = (DataField) item;
String itype = i.getSubfield('y').getData();
if(itype.equals("KN")) {
// Zjištění jestli je dostupná kniha přes ereading
String ean = getEAN(record);
String xmlfilename = "data/ereading/" + ean + ".xml";
File xmlfile = new File(xmlfilename);
if(xmlfile.exists() && !xmlfile.isDirectory()) {
result.add("eBook");
}
}
result.add(itype);
}
// Nothing worked!
if (result.isEmpty()) {
result.add("Unknown");
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment