Search in sources :

Example 46 with NavajoException

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;
}
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

NavajoException (com.dexels.navajo.document.NavajoException)46 Message (com.dexels.navajo.document.Message)28 Property (com.dexels.navajo.document.Property)25 Navajo (com.dexels.navajo.document.Navajo)21 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)12 SystemException (com.dexels.navajo.script.api.SystemException)9 Operand (com.dexels.navajo.document.Operand)8 UserException (com.dexels.navajo.script.api.UserException)8 IOException (java.io.IOException)8 StringWriter (java.io.StringWriter)6 Selection (com.dexels.navajo.document.Selection)5 MappableException (com.dexels.navajo.script.api.MappableException)5 ArrayList (java.util.ArrayList)4 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)3 ManualAsyncClient (com.dexels.navajo.client.async.ManualAsyncClient)3 FatalException (com.dexels.navajo.script.api.FatalException)3 File (java.io.File)3 ClientException (com.dexels.navajo.client.ClientException)2 NavajoResponseHandler (com.dexels.navajo.client.NavajoResponseHandler)2 Header (com.dexels.navajo.document.Header)2