0

Castor-Maven-Plugin で生成された Java クラスが XML 文字列のコンテンツの非整列化に失敗するという奇妙な問題があります。

検証しようとしている XML は次のようになります。

...
    <mediaType>audio/media</mediaType>
...

そして、次のパターンに対して検証しています。

(audio|video|document|application|example|image|message|model|multipart|text)/.+

Castor がクラスを生成する XSD の関連部分:

...  
<xs:simpleType name="mediaType">  
        <xs:annotation>   
            <xs:documentation>  
                The internet media type of the paired file. For example, a MP3 file would be audio/mpeg.  
            </xs:documentation>
        </xs:annotation>  
        <xs:restriction base="xs:string">  
            <xs:pattern value="(audio|video|document|application|example|image|message|model|multipart|text)/.+"/>  
        </xs:restriction>  
    </xs:simpleType>  
...

XML 文字列を非整列化しようとすると、次の例外がスローされます。

org.exolab.castor.xml.MarshalException: The following exception occured while validating field: _mediaType of class: my.domain.GeneratedClass: audio/mpegdoes not match the required regular expression: "(audio|video|document|application|example|image|message|model|multipart|text)/.+"{File: [not available]; line: 23; column: 12}...

現在、IntelliJ の XML 検証と、私が試した他のすべての正規表現ツールによると、これは問題にはなりません。キャスターがそう思うのはなぜですか?

4

1 に答える 1

1

Castor には (適切な) ネイティブ Regex バリデーターがありません。構成ファイルで指定する必要があります。http://castor.codehaus.org/conf-lib.htmlを参照してください。

以下を含むクラスパスに castor.properties という構成ファイルを追加します。

org.exolab.castor.regexp=org.exolab.castor.util.JakartaRegExpEvaluator

Jakarta Regex への依存関係を Maven にも追加する必要がある場合があります。

 <dependency>
        <groupId>jakarta-regexp</groupId>
        <artifactId>jakarta-regexp</artifactId>
        <version>1.4</version>
    </dependency>
于 2013-08-30T13:21:12.600 に答える