0

我因以下问题而受阻:

我有一个文件 web.xml,其中包含几个信息、标签和过滤器。

如果过滤器名称'AdministratorGuardFilter'的参数名称'guard'具有参数值='true',我想停止处理

web.xml 的格式如下:

<filter>
<filter-name>Character encoding filter</filter-name>
<filter-class>ergonomics.filter.CharacterEncodingFilter</filter-class>
</filter>

<filter>
<filter-name>AdministratorGuardFilter</filter-name>
<filter-class>security.common.AdministratorGuard</filter-class>
<init-param>
    <param-name>guard</param-name>
    <param-value>true</param-value>
</init-param>
</filter>    

<filter-mapping>     
 <filter-name>AdministratorGuardFilter</filter-name>    
 <url-pattern>/administrator/*</url-pattern>     

任何想法 ?

非常感谢您的帮助或提示

迪迪埃。

4

1 回答 1

1

以下 Ant 脚本使用第三方<xmltask>. <xmltask>可以将 XPath 表达式选择的 XML 节点映射到 Ant 属性。

<project name="ant-xmltask-web-xml-extract" default="run" basedir=".">
    <!-- The elements of a web.xml file are in an XML namespace. To have -->
    <!-- <xmltask> ignore namespaces, we put a ':' in front of each element -->
    <!-- name. ':' tells the XPath mechanism to use the local name of the -->
    <!-- element. -->
    <property 
        name="xpath.expression"
        value="/:web-app/:filter[:filter-name/text() = 'AdministratorGuardFilter']/:init-param[:param-name/text() = 'guard']/:param-value/text()"
    />

    <target name="run">
        <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" />
        <xmltask>
            <fileset file="web.xml"/>
            <copy path="${xpath.expression}" property="guard.value"/>
        </xmltask>

        <fail message="guard param for AdministratorGuardFilter is true.">
            <condition>
                <equals arg1="${guard.value}" arg2="true"/>
            </condition>
        </fail>
    </target>
</project>
于 2013-10-16T14:21:43.587 回答