View Javadoc

1   package org.apache.maven.doxia.module.fml;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.regex.Matcher;
24  import java.util.regex.Pattern;
25  
26  import org.apache.maven.doxia.markup.XmlMarkup;
27  import org.apache.maven.doxia.xsd.AbstractXmlValidatorTest;
28  import org.codehaus.plexus.util.StringUtils;
29  
30  /**
31   * Test FML files with namespace.
32   *
33   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
34   * @version $Id: FmlValidatorTest.java 1091053 2011-04-11 12:55:07Z ltheussl $
35   * @since 1.0
36   */
37  public class FmlValidatorTest
38      extends AbstractXmlValidatorTest
39  {
40      /** The xsd to use */
41      private static final File FML_XSD = new File( getBasedir(), "/src/main/resources/fml-1.0.1.xsd" );
42  
43      /** {@inheritDoc} */
44      protected String[] getIncludes()
45      {
46          return new String[] { "**/*.fml" };
47      }
48  
49      /** {@inheritDoc} */
50      protected String addNamespaces( String content )
51      {
52          Pattern pattern = Pattern.compile( ".*<([A-Za-z][A-Za-z0-9:_.-]*)([^>]*)>.*" );
53          Matcher matcher = pattern.matcher( content );
54          if ( matcher.find() )
55          {
56              String root = matcher.group( 1 );
57              String value = matcher.group( 2 );
58  
59              if ( value.indexOf( FML_XSD.getName() ) == -1 )
60              {
61                  String faqs =
62                      "<" + root + " xmlns=\"" + FmlMarkup.FML_NAMESPACE + "\""
63                          + "  xmlns:xsi=\"" + XmlMarkup.XML_NAMESPACE + "\""
64                          + "  xsi:schemaLocation=\"" + FmlMarkup.FML_NAMESPACE + " " + FML_XSD.toURI() + "\" ";
65  
66                  return StringUtils.replace( content, "<" + root, faqs );
67              }
68          }
69  
70          return content;
71      }
72  
73      public void testValidateFiles()
74          throws Exception
75      {
76          // TODO: super.testValidateFiles() only validates files from doxia-test-docs, what's the point?
77      }
78  }