Package org.apache.tiles.request

Examples of org.apache.tiles.request.Request


    }

    @Override
    public String getSourceAccessor(OgnlContext context, Object target,
            Object index) {
        Request request = (Request) target;
        String attributeName = (String) index;
        for (String scopeName : request.getAvailableScopes()) {
            Map<String, Object> scope = request.getContext(scopeName);
            if (scope.containsKey(attributeName)) {
                return ".getContext(\"" + scopeName + "\").get(index)";
            }
        }
        return null;
View Full Code Here


    }

    @Override
    public String getSourceSetter(OgnlContext context, Object target,
            Object index) {
        Request request = (Request) target;
        String attributeName = (String) index;
        String[] availableScopes = request.getAvailableScopes().toArray(new String[0]);
        for (String scopeName : availableScopes) {
            Map<String, Object> scope = request.getContext(scopeName);
            if (scope.containsKey(attributeName)) {
                return ".getContext(\"" + scopeName + "\").put(index, target)";
            }
        }
        return ".getContext(\"" + availableScopes[0] + "\").put(index, target)";
View Full Code Here

    }

    @Override
    public void setProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name,
            Object value) {
        Request request = (Request) target;
        String attributeName = (String) name;
        String[] availableScopes = request.getAvailableScopes().toArray(new String[0]);
        for (String scopeName : availableScopes) {
            Map<String, Object> scope = request.getContext(scopeName);
            if (scope.containsKey(attributeName)) {
                scope.put(attributeName, value);
                return;
            }
        }
        if (availableScopes.length > 0) {
            request.getContext(availableScopes[0]).put(attributeName, value);
        }
    }
View Full Code Here

     */
    static final int SCOPE_SUFFIX_LENGTH = 5;

    @Override
    public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name) {
        Request request = (Request) target;
        String scope = (String) name;
        if (scope.endsWith("Scope")) {
            String scopeName = scope.substring(0, scope.length() - SCOPE_SUFFIX_LENGTH);
            return request.getContext(scopeName);
        }
        return null;
    }
View Full Code Here

     * @throws IOException If something goes wrong.
     */
    @Test
    public void testExecute() throws IOException {
        Deque<Object> composeStack = new ArrayDeque<Object>();
        Request request = createMock(Request.class);
        Map<String, Object> requestScope = new HashMap<String, Object>();
        ModelBody modelBody = createMock(ModelBody.class);

        modelBody.evaluateWithoutWriting();
        requestScope.put(ComposeStackUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack);
        expect(request.getContext("request")).andReturn(requestScope);

        replay(request, modelBody);
        ListAttribute parent = new ListAttribute();
        composeStack.push(parent);
        model.execute("myRole", request, modelBody);
View Full Code Here

     * @throws IOException If something goes wrong.
     */
    @Test
    public void testExecuteListAttribute() throws IOException {
        TilesContainer container = createMock(TilesContainer.class);
        Request request = createMock(Request.class);
        ModelBody modelBody = createMock(ModelBody.class);
        AttributeContext attributeContext = createMock(AttributeContext.class);
        Deque<Object> composeStack = new ArrayDeque<Object>();
        ListAttribute listAttribute = new ListAttribute();
        composeStack.push(listAttribute);
        Map<String, Object> requestScope = new HashMap<String, Object>();
        requestScope.put(ComposeStackUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack);
        requestScope.put(TilesAccess.CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
        ApplicationContext applicationContext = createMock(ApplicationContext.class);

        expect(request.getApplicationContext()).andReturn(applicationContext);
        expect(request.getContext("request")).andReturn(requestScope).anyTimes();
        expect(container.getAttributeContext(request)).andReturn(attributeContext);
        attributeContext.putAttribute(eq("myName"), (Attribute) notNull(), eq(false));
        expect(modelBody.evaluateAsString()).andReturn(null);

        replay(container, attributeContext, request, applicationContext, modelBody);
View Full Code Here

    /**
     * Tests {@link ComposeStackUtil#getComposeStack(org.apache.tiles.request.Request)}.
     */
    @Test
    public void testGetComposeStackNull() {
        Request request = createMock(Request.class);

        Map<String, Object> requestScope = new HashMap<String, Object>();
        expect(request.getContext("request")).andReturn(requestScope);

        replay(request);
        assertSame(ComposeStackUtil.getComposeStack(request),
                requestScope.get(ComposeStackUtil.COMPOSE_STACK_ATTRIBUTE_NAME));
        verify(request);
View Full Code Here

    /**
     * Tests {@link ComposeStackUtil#getComposeStack(org.apache.tiles.request.Request)}.
     */
    @Test
    public void testGetComposeStackNotNull() {
        Request request = createMock(Request.class);
        @SuppressWarnings("unchecked")
        Deque<Object> composeStack = createMock(Deque.class);

        Map<String, Object> requestScope = new HashMap<String, Object>();
        requestScope.put(ComposeStackUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack);
        expect(request.getContext("request")).andReturn(requestScope);

        replay(request, composeStack);
        assertSame(composeStack, ComposeStackUtil.getComposeStack(request));
        verify(request, composeStack);
    }
View Full Code Here

    /**
     * Tests {@link ComposeStackUtil#getComposeStack(org.apache.tiles.request.Request)}.
     */
    @Test
    public void testGetComposeStackNoNull() {
        Request request = createMock(Request.class);

        Map<String, Object> requestScope = new HashMap<String, Object>();
        expect(request.getContext("request")).andReturn(requestScope);

        replay(request);
        assertSame(ComposeStackUtil.getComposeStack(request),
                requestScope.get(ComposeStackUtil.COMPOSE_STACK_ATTRIBUTE_NAME));
        verify(request);
View Full Code Here

     * @throws IOException If something goes wrong.
     */
    @Test
    public void testExecute() throws IOException {
        TilesContainer container = createMock(TilesContainer.class);
        Request request = createMock(Request.class);
        AttributeContext attributeContext = createMock(AttributeContext.class);
        Map<String, Object> requestScope = new HashMap<String, Object>();
        requestScope.put(TilesAccess.CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
        ApplicationContext applicationContext = createMock(ApplicationContext.class);
        ModelBody modelBody = createMock(ModelBody.class);

        modelBody.evaluateWithoutWriting();
        expect(request.getApplicationContext()).andReturn(applicationContext).times(2);
        expect(request.getContext("request")).andReturn(requestScope).anyTimes();
        expect(container.startContext(request)).andReturn(attributeContext);
        expect(container.getAttributeContext(request)).andReturn(attributeContext);
        container.endContext(request);
        attributeContext.setPreparer("myPreparer");
        attributeContext.setTemplateAttribute((Attribute) notNull());
View Full Code Here

TOP

Related Classes of org.apache.tiles.request.Request

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.