Search in sources :

Example 76 with Selection

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;
}
Also used : Selection(com.dexels.navajo.document.Selection) OptionMap(com.dexels.navajo.adapter.OptionMap) UserException(com.dexels.navajo.script.api.UserException) Property(com.dexels.navajo.document.Property)

Example 77 with Selection

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) Message(com.dexels.navajo.document.Message) Selection(com.dexels.navajo.document.Selection) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property)

Example 78 with Selection

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) Message(com.dexels.navajo.document.Message) Header(com.dexels.navajo.document.Header) Selection(com.dexels.navajo.document.Selection) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) FatalException(com.dexels.navajo.script.api.FatalException) ServletException(javax.servlet.ServletException) NavajoException(com.dexels.navajo.document.NavajoException) IOException(java.io.IOException)

Aggregations

Selection (com.dexels.navajo.document.Selection)78 Property (com.dexels.navajo.document.Property)36 Test (org.junit.Test)32 Message (com.dexels.navajo.document.Message)24 Navajo (com.dexels.navajo.document.Navajo)21 Access (com.dexels.navajo.script.api.Access)14 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)13 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)12 TipiLink (com.dexels.navajo.expression.api.TipiLink)12 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)12 ArrayList (java.util.ArrayList)12 Optional (java.util.Optional)12 Operand (com.dexels.navajo.document.Operand)11 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)11 List (java.util.List)8 NavajoException (com.dexels.navajo.document.NavajoException)6 UserException (com.dexels.navajo.script.api.UserException)4 Binary (com.dexels.navajo.document.types.Binary)3 FunctionClassification (com.dexels.navajo.expression.api.FunctionClassification)3 StringTokenizer (java.util.StringTokenizer)3