use of com.dexels.navajo.document.Selection in project navajo by Dexels.
the class MessageMap method getSelections.
public OptionMap[] getSelections() throws UserException {
if (selectionPointer == null) {
throw new UserException(-1, "Set selectionPointer first.");
}
Property p = getPropertyObject(selectionPointer);
if (!p.getType().equals(Property.SELECTION_PROPERTY)) {
throw new UserException(-1, "selections only supported for selection properties");
}
List<Selection> all = p.getAllSelections();
OptionMap[] om = new OptionMap[all.size()];
for (int i = 0; i < all.size(); i++) {
Selection s = all.get(i);
om[i] = new OptionMap();
om[i].setOptionName(s.getName());
om[i].setOptionValue(s.getValue());
om[i].setOptionSelected(s.isSelected());
}
return om;
}
use of com.dexels.navajo.document.Selection in project navajo by Dexels.
the class RestTmlServlet method constructFromRequest.
private 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);
}
}
}
}
return result;
}
use of com.dexels.navajo.document.Selection 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