我遇到了以下问题:
我有一个文件web.xml,其中包含多个信息,标签和过滤器。
我想在过滤器名称'AdministratorGuardFilter'的参数名称'guard'的情况下停止处理param-value ='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>
有什么想法吗?
非常感谢您提供帮助或提示
迪迪埃。
答案 0 :(得分: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>