use of digilib.util.Parameter in project digilib by robcast.
the class DigilibServletRequest method getAsString.
/**
* Return the request parameters of a given type type as a String in the
* parameter form 'fn=/icons&pn=1'. Empty (undefined) fields are not
* included.
*
* @return String of request parameters in parameter form.
*/
public String getAsString(int type) {
StringBuffer s = new StringBuffer(50);
// go through all values
for (Parameter p : params.values()) {
if ((type > 0) && (p.getType() != type)) {
// skip the wrong types
continue;
}
String name = p.getName();
// request_path adds to fn
if (name.equals("fn")) {
s.append("&fn=" + getAsString("request.path") + getAsString("fn"));
continue;
}
// parameters that are not set or internal are not sent
if ((!p.hasValue()) || (p.getType() == 'i')) {
continue;
}
s.append("&" + name + "=" + p.getAsString());
}
// kill first "&"
s.deleteCharAt(0);
return s.toString();
}
use of digilib.util.Parameter in project digilib by robcast.
the class DigilibServletRequest method setWithParamRequest.
/**
* Set request parameters from javax.servlet.ServletRequest. Uses the
* Requests getParameter methods for 'fn=foo' style parameters.
*
* @param request
* ServletRequest to get parameters from.
*/
// @SuppressWarnings("unchecked") // ServletRequest.getParameterNames()
// returns naked Enumeration
public void setWithParamRequest(ServletRequest request) {
setValue("servlet.request", request);
// go through all request parameters
for (@SuppressWarnings("unchecked") Enumeration<String> i = request.getParameterNames(); i.hasMoreElements(); ) {
String name = (String) i.nextElement();
// is this a known parameter?
if (params.containsKey(name)) {
Parameter p = (Parameter) this.get(name);
// internal parameters are not set
if (p.getType() == 'i') {
continue;
}
p.setValueFromString(request.getParameter(name));
continue;
}
// unknown parameters are just added with type 'r'
newParameter(name, null, request.getParameter(name), 'r');
}
// add path from request
setValue("request.path", ((HttpServletRequest) request).getPathInfo());
}
use of digilib.util.Parameter in project digilib by robcast.
the class PDFStreamWorker method renderPDF.
/**
* @throws DocumentException
* @throws InterruptedException
* @throws ExecutionException
* @throws IOException
* @throws ImageOpException
*/
protected OutputStream renderPDF() throws InterruptedException, ExecutionException, IOException, ImageOpException {
long start_time = System.currentTimeMillis();
// create document object
PdfWriter writer = new PdfWriter(outstream);
PdfDocument pdfdoc = new PdfDocument(writer);
doc = new Document(pdfdoc, PageSize.A4);
logger.debug("PDF: {} doc.open()ed ({}ms)", outstream, (System.currentTimeMillis() - start_time));
// add title page
PDFTitlePage titlepage = new PDFTitlePage(job_info);
titlepage.createPage(doc);
// add pages
NumRange pgs = job_info.getPages();
for (int p : pgs) {
// start new page
doc.add(new AreaBreak());
logger.debug("PDF: adding Image {} to {}", p, outstream);
// copy request and set page number (as new Parameter)
DigilibRequest pageRequest = new DigilibRequest(dlConfig, job_info);
pageRequest.put("pn", new Parameter("pn", p, p));
// create ImageJobInformation
ImageJobDescription iji = ImageJobDescription.getRawInstance(pageRequest, job_info.getDlConfig());
iji.prepareScaleParams();
addImage(doc, iji);
logger.debug("PDF: done adding Image {} to {}", p, outstream);
}
logger.debug("PDF: done adding all Images to {}", outstream);
doc.close();
logger.debug("PDF: {} doc.close() ({}ms)", outstream, (System.currentTimeMillis() - start_time));
writer.flush();
writer.close();
return outstream;
}
use of digilib.util.Parameter in project digilib by robcast.
the class DigilibConfiguration method readConfig.
/**
* read parameters from properties file digilib.properties in class path.
*/
public void readConfig() {
Properties props = new Properties();
InputStream s = Thread.currentThread().getContextClassLoader().getResourceAsStream(propertiesFileName);
if (s != null) {
try {
props.load(s);
s.close();
for (Entry<Object, Object> confEntry : props.entrySet()) {
Parameter param = get((String) confEntry.getKey());
if (param != null) {
if (param.getType() == 's') {
// type 's' Parameters are not overwritten.
continue;
}
if (!param.setValueFromString((String) confEntry.getValue())) {
/*
* automatic conversion failed -- try special cases
*/
if (!setSpecialValueFromString(param, (String) confEntry.getValue())) {
logger.warn("Unable to parse config parameter: {}", param.getName());
}
}
} else {
// parameter unknown -- just add
newParameter((String) confEntry.getKey(), null, confEntry.getValue(), 'u');
}
}
// set config file path parameter
newParameter("digilib.config.file", Thread.currentThread().getContextClassLoader().getResource("digilib.properties").toString(), null, 's');
} catch (IOException e) {
logger.error("Error reading digilib properties file.", e);
}
}
}
use of digilib.util.Parameter in project digilib by robcast.
the class DigilibRequest method setWithParamString.
/**
* Set request parameters from query string. Uses the separator string qs to
* get 'fn=foo' style parameters.
*
* @param qs
* query string
* @param sep
* parameter-separator string
*/
public void setWithParamString(String qs, String sep) {
// go through all request parameters
String[] qa = qs.split(sep);
for (int i = 0; i < qa.length; i++) {
// split names and values on "="
String[] nv = qa[i].split("=");
try {
String name = URLDecoder.decode(nv[0], "UTF-8");
String val = URLDecoder.decode(nv[1], "UTF-8");
// is this a known parameter?
if (params.containsKey(name)) {
Parameter p = (Parameter) this.get(name);
// internal parameters are not set
if (p.getType() == 'i') {
continue;
}
p.setValueFromString(val);
continue;
}
// unknown parameters are just added with type 'r'
newParameter(name, null, val, 'r');
} catch (UnsupportedEncodingException e) {
// this shouldn't happen anyway
}
}
initOptions();
}
Aggregations