Package org.apache.sling.servlets.post.impl.helper

Examples of org.apache.sling.servlets.post.impl.helper.RequestProperty


            // @TypeHint example
            // <input type="text" name="./age" />
            // <input type="hidden" name="./age@TypeHint" value="long" />
            // causes the setProperty using the 'long' property type
            if (propPath.endsWith(SlingPostConstants.TYPE_HINT_SUFFIX)) {
                RequestProperty prop = getOrCreateRequestProperty(
                    reqProperties, propPath,
                    SlingPostConstants.TYPE_HINT_SUFFIX);

                String typeHintValue = convertToString(e.getValue());
                if (typeHintValue != null) {
                    prop.setTypeHintValue(typeHintValue);
                }

                continue;
            }

            // @DefaultValue
            if (propPath.endsWith(SlingPostConstants.DEFAULT_VALUE_SUFFIX)) {
                RequestProperty prop = getOrCreateRequestProperty(
                    reqProperties, propPath,
                    SlingPostConstants.DEFAULT_VALUE_SUFFIX);

                prop.setDefaultValues(convertToRequestParameterArray(e.getValue()));

                continue;
            }

            // SLING-130: VALUE_FROM_SUFFIX means take the value of this
            // property from a different field
            // @ValueFrom example:
            // <input name="./Text@ValueFrom" type="hidden" value="fulltext" />
            // causes the JCR Text property to be set to the value of the
            // fulltext form field.
            if (propPath.endsWith(SlingPostConstants.VALUE_FROM_SUFFIX)) {
                RequestProperty prop = getOrCreateRequestProperty(
                    reqProperties, propPath,
                    SlingPostConstants.VALUE_FROM_SUFFIX);

                // @ValueFrom params must have exactly one value, else ignored
                String [] valueFrom = convertToStringArray(e.getValue());
                if (valueFrom.length == 1) {
                    String refName = valueFrom[0];
                    RequestParameter[] refValues = convertToRequestParameterArray(refName);
                    if (refValues != null) {
                        prop.setValues(refValues);
                    }
                }

                continue;
            }

            // SLING-458: Allow Removal of properties prior to update
            // @Delete example:
            // <input name="./Text@Delete" type="hidden" />
            // causes the JCR Text property to be deleted before update
            if (propPath.endsWith(SlingPostConstants.SUFFIX_DELETE)) {
                RequestProperty prop = getOrCreateRequestProperty(
                    reqProperties, propPath, SlingPostConstants.SUFFIX_DELETE);

                prop.setDelete(true);

                continue;
            }

            // SLING-455: @MoveFrom means moving content to another location
            // @MoveFrom example:
            // <input name="./Text@MoveFrom" type="hidden" value="/tmp/path" />
            // causes the JCR Text property to be set by moving the /tmp/path
            // property to Text.
            if (propPath.endsWith(SlingPostConstants.SUFFIX_MOVE_FROM)) {
                // don't support @MoveFrom here
                continue;
            }

            // SLING-455: @CopyFrom means moving content to another location
            // @CopyFrom example:
            // <input name="./Text@CopyFrom" type="hidden" value="/tmp/path" />
            // causes the JCR Text property to be set by copying the /tmp/path
            // property to Text.
            if (propPath.endsWith(SlingPostConstants.SUFFIX_COPY_FROM)) {
                // don't support @CopyFrom here
                continue;
            }

            // plain property, create from values
            RequestProperty prop = getOrCreateRequestProperty(reqProperties,
                propPath, null);
            prop.setValues(convertToRequestParameterArray(e.getValue()));
        }

        return reqProperties;
    }
View Full Code Here


        if (suffix != null && paramPath.endsWith(suffix)) {
            paramPath = paramPath.substring(0, paramPath.length()
                - suffix.length());
        }

        RequestProperty prop = props.get(paramPath);
        if (prop == null) {
            prop = new RequestProperty(paramPath);
            props.put(paramPath, prop);
        }

        return prop;
    }
View Full Code Here

    @Test
    public void testSingleValueWithBlank() throws Throwable {
        Map<String, RequestProperty> props = collectContent(p("./param", ""));

        assertEquals(1, props.size());
        RequestProperty prop = props.get("/test/path/param");
        assertTrue(prop.hasValues());
        assertFalse(prop.providesValue());
        assertEquals(1, prop.getStringValues().length);
        assertEquals("", prop.getStringValues()[0]);
    }
View Full Code Here

    @Test
    public void testNullSingleValueWithDefaultToIgnore() throws Throwable {
        Map<String, RequestProperty> props = collectContent(p("./param@DefaultValue", ":ignore"));

        assertEquals(1, props.size());
        RequestProperty prop = props.get("/test/path/param");
        assertFalse(prop.hasValues());
    }
View Full Code Here

    @Test
    public void testSingleValueWithDefaultToIgnore() throws Throwable {
        Map<String, RequestProperty> props = collectContent(p("./param", ""), p("./param@DefaultValue", ":ignore"));

        assertEquals(1, props.size());
        RequestProperty prop = props.get("/test/path/param");
        assertTrue(prop.hasValues());
        assertFalse(prop.providesValue());
        assertEquals(0, prop.getStringValues().length);
    }
View Full Code Here

    @Test
    public void testSingleValueWithDefaultToNull() throws Throwable {
        Map<String, RequestProperty> props = collectContent(p("./param", ""), p("./param@DefaultValue", ":null"));

        assertEquals(1, props.size());
        RequestProperty prop = props.get("/test/path/param");
        assertTrue(prop.hasValues());
        assertTrue(prop.providesValue());
        assertNull(prop.getStringValues());
    }
View Full Code Here

    @Test
    public void testSingleValueIgnoringBlanks() throws Throwable {
        Map<String, RequestProperty> props = collectContent(p("./param", ""), p("./param@IgnoreBlanks", "true"));

        assertEquals(1, props.size());
        RequestProperty prop = props.get("/test/path/param");
        assertFalse(prop.hasValues());
    }
View Full Code Here

    @Test
    public void testMultiValue() throws Throwable {
        Map<String, RequestProperty> props = collectContent(p("./param", "true", "false"));

        assertEquals(1, props.size());
        RequestProperty prop = props.get("/test/path/param");
        assertTrue(prop.hasValues());
        assertTrue(prop.providesValue());
        assertEquals(2, prop.getStringValues().length);
        assertEquals("true", prop.getStringValues()[0]);
        assertEquals("false", prop.getStringValues()[1]);
    }
View Full Code Here

    @Test
    public void testMultiValueWithBlank() throws Throwable {
        Map<String, RequestProperty> props = collectContent(p("./param", "true", ""));

        assertEquals(1, props.size());
        RequestProperty prop = props.get("/test/path/param");
        assertTrue(prop.hasValues());
        assertTrue(prop.providesValue());
        assertEquals(2, prop.getStringValues().length);
        assertEquals("true", prop.getStringValues()[0]);
        assertEquals("", prop.getStringValues()[1]);
    }
View Full Code Here

    @Test
    public void testMultiValueWithBlanks() throws Throwable {
        Map<String, RequestProperty> props = collectContent(p("./param", "true", "", ""));

        assertEquals(1, props.size());
        RequestProperty prop = props.get("/test/path/param");
        assertTrue(prop.hasValues());
        assertTrue(prop.providesValue());
        assertEquals(3, prop.getStringValues().length);
        assertEquals("true", prop.getStringValues()[0]);
        assertEquals("", prop.getStringValues()[1]);
        assertEquals("", prop.getStringValues()[2]);
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.servlets.post.impl.helper.RequestProperty

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.