use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class TmlHttpServlet method constructFromRequest.
public static final Navajo constructFromRequest(HttpServletRequest request) throws NavajoException {
Navajo result = NavajoFactory.getInstance().createNavajo();
Enumeration<String> all = request.getParameterNames();
// Construct TML document from request parameters.
while (all.hasMoreElements()) {
String parameter = all.nextElement().toString();
if (parameter.indexOf("/") != -1) {
StringTokenizer typedParameter = new StringTokenizer(parameter, "|");
String propertyName = typedParameter.nextToken();
String type = (typedParameter.hasMoreTokens() ? typedParameter.nextToken() : Property.STRING_PROPERTY);
String value = request.getParameter(parameter);
Message msg = com.dexels.navajo.mapping.MappingUtils.getMessageObject(parameter, null, false, result, false, "", -1);
String propName = com.dexels.navajo.mapping.MappingUtils.getStrippedPropertyName(propertyName);
Property prop = null;
if (propName.indexOf(":") == -1) {
prop = NavajoFactory.getInstance().createProperty(result, propName, type, value, 0, "", Property.DIR_IN);
msg.addProperty(prop);
} else {
StringTokenizer selProp = new StringTokenizer(propName, ":");
propertyName = selProp.nextToken();
selProp.nextToken();
prop = msg.getProperty(propertyName);
if (prop == null) {
prop = NavajoFactory.getInstance().createProperty(result, propertyName, "+", "", Property.DIR_IN);
msg.addProperty(prop);
} else {
prop.setType(Property.SELECTION_PROPERTY);
prop.setCardinality("+");
}
StringTokenizer allValues = new StringTokenizer(value, ",");
while (allValues.hasMoreTokens()) {
String val = allValues.nextToken();
Selection sel = NavajoFactory.getInstance().createSelection(result, val, val, true);
prop.addSelection(sel);
}
}
}
}
String service = request.getParameter("service");
String type = request.getParameter("type");
String username = request.getParameter("username");
String password = request.getParameter("password");
if (username == null) {
username = "empty";
password = "";
}
if ((type == null) || (type.equals(""))) {
type = "xml";
}
if (password == null) {
password = "";
}
long expirationInterval = -1;
String expiration = request.getParameter("expiration");
if ((expiration == null) || (expiration.equals(""))) {
expirationInterval = -1;
} else {
try {
expirationInterval = Long.parseLong(expiration);
} catch (Exception e) {
// System.out.println("invalid expiration interval: " +
// expiration);
}
}
Header h = NavajoFactory.getInstance().createHeader(result, service, username, password, expirationInterval);
result.addHeader(h);
return result;
}
Aggregations