use of digilib.meta.MetadataMap in project digilib by robcast.
the class MetaAccessAuthzOps method rolesForPath.
/**
* Return authorization roles needed for request.
*
* Returns the list of authorization roles that are needed to access the
* specified path. No list means the path is free.
*
* The location information of the request is also considered.
*
* @param request
* ServletRequest with address information.
* @throws AuthOpException
* Exception thrown on error.
* @return List of Strings with role names.
*/
@Override
public List<String> rolesForPath(DigilibServletRequest dlRequest) throws AuthOpException {
DocuDirent imgs;
try {
// try to get image file from JobDescription
ImageJobDescription ticket = dlRequest.getJobDescription();
if (ticket != null) {
imgs = (DocuDirent) ticket.getImageSet();
} else {
// try to get image file from DirCache
DigilibConfiguration config = dlRequest.getDigilibConfig();
DocuDirCache cache = (DocuDirCache) config.getValue(DigilibServletConfiguration.DIR_CACHE_KEY);
imgs = cache.getFile(dlRequest.getFilePath(), dlRequest.getAsInt("pn"));
}
} catch (FileOpException e) {
throw new AuthOpException("No file for auth check!");
}
/*
* get access restrictions from metadata
*/
String access = null;
try {
imgs.checkMeta();
MetadataMap meta = imgs.getMeta().getFileMeta();
if (meta != null) {
access = meta.get("access");
}
} catch (Exception e) {
logger.error("Error getting access meta for file!");
}
if (access == null) {
// no access tag - use default
logger.debug("Roles required for " + imgs.getName() + ": " + defaultRoles + "(default)");
return defaultRoles;
} else if (access.equalsIgnoreCase("free")) {
// access free
logger.debug("Roles required for " + imgs.getName() + ": (free)");
return null;
}
// get required roles
if (rolesMap.containsKey(access)) {
List<String> required = rolesMap.get(access);
logger.debug("Roles required for " + imgs.getName() + ": " + required);
return required;
} else {
// no mapping to role
logger.error("Error: no role for access type '" + access + "'");
// use default
logger.debug("Roles required for " + imgs.getName() + ": " + defaultRoles + "(substituted default)");
return defaultRoles;
}
}
use of digilib.meta.MetadataMap in project digilib by robcast.
the class ImageFileSet method checkMeta.
/**
* Checks metadata and sets resolution in resX and resY.
*/
public void checkMeta() {
if (metaChecked) {
return;
}
// have the FileMeta class load and check
meta.checkMeta(this);
metaChecked = true;
// take the metadata
MetadataMap fileMeta = meta.getFileMeta();
if (fileMeta == null)
return;
// process the metadata
float dpi = 0;
float dpix = 0;
float dpiy = 0;
float sizex = 0;
float sizey = 0;
float pixx = 0;
float pixy = 0;
// DPI is valid for X and Y
if (fileMeta.containsKey("original-dpi")) {
try {
dpi = Float.parseFloat((String) fileMeta.get("original-dpi"));
} catch (NumberFormatException e) {
}
if (dpi != 0) {
resX = dpi;
resY = dpi;
return;
}
}
// DPI-X and DPI-Y
if (fileMeta.containsKey("original-dpi-x") && fileMeta.containsKey("original-dpi-y")) {
try {
dpix = Float.parseFloat((String) fileMeta.get("original-dpi-x"));
dpiy = Float.parseFloat((String) fileMeta.get("original-dpi-y"));
} catch (NumberFormatException e) {
}
if ((dpix != 0) && (dpiy != 0)) {
resX = dpix;
resY = dpiy;
return;
}
}
// SIZE-X and SIZE-Y and PIXEL-X and PIXEL-Y
if (fileMeta.containsKey("original-size-x") && fileMeta.containsKey("original-size-y") && fileMeta.containsKey("original-pixel-x") && fileMeta.containsKey("original-pixel-y")) {
try {
sizex = Float.parseFloat((String) fileMeta.get("original-size-x"));
sizey = Float.parseFloat((String) fileMeta.get("original-size-y"));
pixx = Float.parseFloat((String) fileMeta.get("original-pixel-x"));
pixy = Float.parseFloat((String) fileMeta.get("original-pixel-y"));
} catch (NumberFormatException e) {
}
if ((sizex != 0) && (sizey != 0) && (pixx != 0) && (pixy != 0)) {
resX = pixx / (sizex * 100 / 2.54f);
resY = pixy / (sizey * 100 / 2.54f);
return;
}
}
}
Aggregations