michael-o commented on code in PR #38:
URL: 
https://github.com/apache/maven-doxia-converter/pull/38#discussion_r1096807707


##########
src/main/java/org/apache/maven/doxia/DefaultConverter.java:
##########
@@ -78,57 +77,160 @@
 public class DefaultConverter
     implements Converter
 {
-    private static final String APT_PARSER = "apt";
-
-    private static final String CONFLUENCE_PARSER = "confluence";
-
-    private static final String DOCBOOK_PARSER = "docbook";
-
-    private static final String FML_PARSER = "fml";
-
-    private static final String TWIKI_PARSER = "twiki";
-
-    private static final String XDOC_PARSER = "xdoc";
-
-    private static final String XHTML_PARSER = "xhtml";
-
-    private static final String XHTML5_PARSER = "xhtml5";
-
-    private static final String MARKDOWN_PARSER = "markdown";
-
-    /** Supported input format, i.e. supported Doxia parser */
-    public static final String[] SUPPORTED_FROM_FORMAT =
-        { APT_PARSER, CONFLUENCE_PARSER, DOCBOOK_PARSER, FML_PARSER, 
MARKDOWN_PARSER, TWIKI_PARSER,
-            XDOC_PARSER, XHTML_PARSER, XHTML5_PARSER };
+    /**
+     * All supported Doxia formats (either only parser, only sink or both)
+     */
+    public enum DoxiaFormat
+    {
+        APT( "apt", "apt", true, true ),
+        CONFLUENCE( "confluence", "confluence", true, true ),
+        DOCBOOK( "docbook", "xml", "article", true, true ),
+        FML( "fml", "fml", "faqs", true, false ),
+        FO( "fo", "fo", false, true ),
+        ITEXT( "itext", "itext", false, true ),
+        LATEX( "latex", "tex", false, true ),
+        TWIKI( "twiki", "twiki", true, true ),
+        RTF( "rtf", "rtf", false, true ),
+        XDOC( "xdoc", "xml", "document", true, true ),
+        XHTML( "xhtml", "html", "html", true, true ),
+        XHTML5( "xhtml5", "html", true, true ), // no autodetect support
+        MARKDOWN( "markdown", "md", false, true );
 
-    private static final String APT_SINK = "apt";
+        /** Plexus role hint for Doxia sink/parser */
+        private final String roleHint;
+        private final String extension;
+        /** The name of the first element in case this is an XML format, 
otherwise {@code null} */
+        private final String firstElement;
+        private final boolean hasParser;
+        private final boolean hasSink;
 
-    private static final String CONFLUENCE_SINK = "confluence";
+        DoxiaFormat( String roleHint, String extension, boolean hasParser, 
boolean hasSink )
+        {
+            this( roleHint, extension, null, hasParser, hasSink );
+        }
 
-    private static final String DOCBOOK_SINK = "docbook";
+        DoxiaFormat( String roleHint, String extension, String firstElement, 
boolean hasParser, boolean hasSink )
+        {
+            this.roleHint = roleHint;
+            this.extension = extension;
+            this.firstElement = firstElement;
+            this.hasParser = hasParser;
+            this.hasSink = hasSink;
+        }
 
-    private static final String FO_SINK = "fo";
+        /**
+         * 
+         * @return the primary extension used with this format
+         */
+        public String getExtension()
+        {
+            return extension;
+        }
 
-    private static final String ITEXT_SINK = "itext";
+        public boolean hasParser()
+        {
+            return hasParser;
+        }
 
-    private static final String LATEX_SINK = "latex";
+        public boolean hasSink()
+        {
+            return hasSink;
+        }
 
-    private static final String RTF_SINK = "rtf";
+        /**
+         * 
+         * @return {@code true} in case this format is XML based
+         */
+        public boolean isXml()
+        {
+            return firstElement != null;
+        }
 
-    private static final String TWIKI_SINK = "twiki";
+        /**
+         * @param plexus not null
+         * @return an instance of <code>Parser</code> depending on the format.
+         * @throws ComponentLookupException if could not find the Parser for 
the given format.
+         * @throws IllegalArgumentException if any parameter is null
+         */
+        public Parser getParser( PlexusContainer plexus )
+            throws ComponentLookupException
+        {
+            if ( !hasParser )
+            {
+                throw new IllegalStateException( "The format " + 
this.toString() + " is not supported as parser!" );

Review Comment:
   toString() is redundant.



##########
src/main/java/org/apache/maven/doxia/DefaultConverter.java:
##########
@@ -78,57 +77,160 @@
 public class DefaultConverter
     implements Converter
 {
-    private static final String APT_PARSER = "apt";
-
-    private static final String CONFLUENCE_PARSER = "confluence";
-
-    private static final String DOCBOOK_PARSER = "docbook";
-
-    private static final String FML_PARSER = "fml";
-
-    private static final String TWIKI_PARSER = "twiki";
-
-    private static final String XDOC_PARSER = "xdoc";
-
-    private static final String XHTML_PARSER = "xhtml";
-
-    private static final String XHTML5_PARSER = "xhtml5";
-
-    private static final String MARKDOWN_PARSER = "markdown";
-
-    /** Supported input format, i.e. supported Doxia parser */
-    public static final String[] SUPPORTED_FROM_FORMAT =
-        { APT_PARSER, CONFLUENCE_PARSER, DOCBOOK_PARSER, FML_PARSER, 
MARKDOWN_PARSER, TWIKI_PARSER,
-            XDOC_PARSER, XHTML_PARSER, XHTML5_PARSER };
+    /**
+     * All supported Doxia formats (either only parser, only sink or both)
+     */
+    public enum DoxiaFormat
+    {
+        APT( "apt", "apt", true, true ),
+        CONFLUENCE( "confluence", "confluence", true, true ),
+        DOCBOOK( "docbook", "xml", "article", true, true ),
+        FML( "fml", "fml", "faqs", true, false ),
+        FO( "fo", "fo", false, true ),
+        ITEXT( "itext", "itext", false, true ),
+        LATEX( "latex", "tex", false, true ),
+        TWIKI( "twiki", "twiki", true, true ),
+        RTF( "rtf", "rtf", false, true ),
+        XDOC( "xdoc", "xml", "document", true, true ),
+        XHTML( "xhtml", "html", "html", true, true ),
+        XHTML5( "xhtml5", "html", true, true ), // no autodetect support
+        MARKDOWN( "markdown", "md", false, true );
 
-    private static final String APT_SINK = "apt";
+        /** Plexus role hint for Doxia sink/parser */
+        private final String roleHint;
+        private final String extension;
+        /** The name of the first element in case this is an XML format, 
otherwise {@code null} */
+        private final String firstElement;
+        private final boolean hasParser;
+        private final boolean hasSink;
 
-    private static final String CONFLUENCE_SINK = "confluence";
+        DoxiaFormat( String roleHint, String extension, boolean hasParser, 
boolean hasSink )
+        {
+            this( roleHint, extension, null, hasParser, hasSink );
+        }
 
-    private static final String DOCBOOK_SINK = "docbook";
+        DoxiaFormat( String roleHint, String extension, String firstElement, 
boolean hasParser, boolean hasSink )
+        {
+            this.roleHint = roleHint;
+            this.extension = extension;
+            this.firstElement = firstElement;
+            this.hasParser = hasParser;
+            this.hasSink = hasSink;
+        }
 
-    private static final String FO_SINK = "fo";
+        /**
+         * 
+         * @return the primary extension used with this format
+         */
+        public String getExtension()
+        {
+            return extension;
+        }
 
-    private static final String ITEXT_SINK = "itext";
+        public boolean hasParser()
+        {
+            return hasParser;
+        }
 
-    private static final String LATEX_SINK = "latex";
+        public boolean hasSink()
+        {
+            return hasSink;
+        }
 
-    private static final String RTF_SINK = "rtf";
+        /**
+         * 
+         * @return {@code true} in case this format is XML based
+         */
+        public boolean isXml()
+        {
+            return firstElement != null;
+        }
 
-    private static final String TWIKI_SINK = "twiki";
+        /**
+         * @param plexus not null
+         * @return an instance of <code>Parser</code> depending on the format.
+         * @throws ComponentLookupException if could not find the Parser for 
the given format.
+         * @throws IllegalArgumentException if any parameter is null
+         */
+        public Parser getParser( PlexusContainer plexus )
+            throws ComponentLookupException
+        {
+            if ( !hasParser )
+            {
+                throw new IllegalStateException( "The format " + 
this.toString() + " is not supported as parser!" );
+            }
+            Objects.requireNonNull( plexus, "plexus is required" );
 
-    private static final String XDOC_SINK = "xdoc";
+            return (Parser) plexus.lookup( Parser.ROLE, roleHint );
+        }
 
-    private static final String XHTML_SINK = "xhtml";
+        /**
+         * @param plexus not null
+         * @return an instance of <code>SinkFactory</code> depending on the 
given format.
+         * @throws ComponentLookupException if could not find the SinkFactory 
for the given format.
+         * @throws IllegalArgumentException if any parameter is null
+         */
+        public SinkFactory getSinkFactory( PlexusContainer plexus )
+            throws ComponentLookupException
+        {
+            if ( !hasSink )
+            {
+                throw new IllegalStateException( "The format " + 
this.toString() + " is not supported as sink!" );

Review Comment:
   same here



##########
src/main/java/org/apache/maven/doxia/DefaultConverter.java:
##########
@@ -357,23 +458,19 @@ private void parse( File inputFile, String inputEncoding, 
String inputFormat, Ou
         }
 
         File outputFile;
-        if ( output.getFile().isDirectory() )
+        if ( outputDirectoryOrFile.isDirectory() 
+             || !SelectorUtils.match( "**.*", output.getFile().getName() ) 

Review Comment:
   This pattern looks wrong. Shouldn't it be: `**/*`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to