wurfl.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="net.sourceforge.wurfl.*"/>




    <!--<bean id="wurfl.resource.zip" class="net.sourceforge.wurfl.core.resource.XMLResource">-->
        <!--<constructor-arg index="0" value="classpath:/wurfl-2.2.zip" />-->
    <!--</bean>-->
    <!--<bean id="wurfl.resource.patch1" class="net.sourceforge.wurfl.core.resource.XMLResource">-->
        <!--<constructor-arg index="0" value="classpath:/web_browsers_patch.xml" />-->
    <!--</bean>-->

    <!--<bean id="wurfl.resource.patches" class="net.sourceforge.wurfl.core.resource.WURFLResources">-->

         <!--<constructor-arg>-->
             <!--<list>-->
                 <!--<ref bean="wurfl.resource.patch1" />-->
             <!--</list>-->
         <!--</constructor-arg>-->
        <!--&lt;!&ndash; <constructor-arg index="2" value="<< more patches here >>"/> &ndash;&gt;-->
    <!--</bean>-->



    <bean id="wurfl.model" class="net.sourceforge.wurfl.spring.SpringWURFLModel">
        <property name="wurfl" value="WEB-INF/wurfl-2.2.zip"/>
        <property name="wurflPatch"  value="WEB-INF/web_browsers_patch.xml"   />
    </bean>

    <bean id="wurfl.manager" class="net.sourceforge.wurfl.spring.SpringWurflManager">
         <property name="wurflModel" ref="wurfl.model" />
    </bean>



    <!--<bean id="wurfl.matcherManager" class="net.sourceforge.wurfl.core.matchers.MatcherManager">-->
        <!--<constructor-arg ref="wurfl.model"/>-->
    <!--</bean>-->

    <!--<bean id="wurfl.deviceProvider" class="net.sourceforge.wurfl.core.DefaultDeviceProvider">-->
        <!--<constructor-arg ref="wurfl.model"/>-->
    <!--</bean>-->

    <!--<bean id="wurfl.service" class="net.sourceforge.wurfl.core.DefaultWURFLService" >-->
        <!--<constructor-arg index="0" ref="wurfl.matcherManager"/>-->
        <!--<constructor-arg index="1" ref="wurfl.deviceProvider"/>-->
    <!--</bean>-->

    <!--<bean id="wurfl.manager" class="net.sourceforge.wurfl.core.DefaultWURFLManager" >-->
        <!--<constructor-arg ref="wurfl.service"/>-->
    <!--</bean>-->
    <!--<bean id="wurfl.utils" class="net.sourceforge.wurfl.core.WURFLUtils">-->
        <!--<constructor-arg ref="wurfl.model"/>-->
    <!--</bean>-->
    <!--<bean id="wurfl.holder" class="net.sourceforge.wurfl.core.DefaultWURFLHolder">-->
        <!--<constructor-arg index="0" ref="wurfl.manager"/>-->
        <!--<constructor-arg index="1" ref="wurfl.utils"/>-->
    <!--</bean>-->
    
    <bean id="mDecoratorMapper" class="com.bla.bla.web.decoratormapper.MDecoratorMapper">
        <!--<property name="wurflManager" ref="wurfl.manager"/>-->
    </bean>


</beans>

sitemesh.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<sitemesh>
    <property name="decorators-file" value="/WEB-INF/decorators.xml"/>
    <excludes file="${decorators-file}"/>

    <page-parsers>
        <parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser"/>
    </page-parsers>

    <page-parsers>
        <parser content-type="text/html" class="com.opensymphony.module.sitemesh.multipass.DivExtractingPageParser"/>
    </page-parsers>

    <!--<decorator-mappers>-->
        <!--<mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">-->
            <!--<param name="config" value="${decorators-file}"/>-->
        <!--</mapper>-->
    <!--</decorator-mappers> -->

    <decorator-mappers>
        <mapper class="com.bla.bla.web.decoratormapper.MDecoratorMapper">
        <!--<mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">-->
            <param name="config" value="${decorators-file}"/>
        </mapper>
    </decorator-mappers>
</sitemesh>

MDecoratorMapper.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

public class MDecoratorMapper extends ConfigDecoratorMapper{
    private String decoratorName = null;
    @Resource //changed from @Autowired to @Resource
    WURFLManager wurflManager;
    private Properties prop;

    public void init(Config config, Properties properties, DecoratorMapper parent) throws InstantiationException {
        super.init(config, properties, parent);
        this.prop = properties;
//        decoratorName = properties.getProperty("decorator.name", "mobile");
    }

    public Decorator getDecorator(final HttpServletRequest request, final Page page) {
        Device device = wurflManager.getDeviceForRequest(request);
        MarkUp markUp = device.getMarkUp();
//        if (MarkUp.XHTML_ADVANCED.equals(markUp)) {
//            decoratorName = prop.getProperty("decorator.name","");
//        } else
        if (MarkUp.XHTML_SIMPLE.equals(markUp)) {
            decoratorName = prop.getProperty("decorator.name","mobile");
            return getNamedDecorator(request,decoratorName);
        } else if (MarkUp.CHTML.equals(markUp)) {
            decoratorName = prop.getProperty("decorator.name","wap");
            return getNamedDecorator(request,decoratorName);
        } else if (MarkUp.WML.equals(markUp)) {
            decoratorName = prop.getProperty("decorator.name","wap");
            return getNamedDecorator(request,decoratorName);
        } else {
            return super.getDecorator(request, page);
        }

    }

    public WURFLManager getWurflManager() {
        return wurflManager;
    }

    public void setWurflManager(WURFLManager wurflManager) {
        this.wurflManager = wurflManager;
    }

    public Properties getProp() {
        return prop;
    }

    public void setProp(Properties prop) {
        this.prop = prop;
    }
}