Author: ltheussl Date: Fri Aug 17 02:55:05 2007 New Revision: 566992 URL: http://svn.apache.org/viewvc?view=rev&rev=566992 Log: Javadocs. Error handling.
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlParser.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Faq.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Faqs.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Part.java Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlParser.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlParser.java?view=diff&rev=566992&r1=566991&r2=566992 ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlParser.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlParser.java Fri Aug 17 02:55:05 2007 @@ -19,6 +19,7 @@ * under the License. */ +import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.util.Iterator; @@ -33,6 +34,7 @@ import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.pull.MXParser; import org.codehaus.plexus.util.xml.pull.XmlPullParser; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** * Parse a fml model and emit events into the specified doxia Sink. @@ -58,19 +60,27 @@ faqs = parseFml( parser, sink ); } - catch ( Exception ex ) + catch ( XmlPullParserException ex ) { throw new ParseException( "Error parsing the model: " + ex.getMessage(), ex ); } + catch ( IOException ex ) + { + throw new ParseException( "Error reading the model: " + ex.getMessage(), ex ); + } try { createSink( faqs, sink ); } - catch ( Exception e ) + catch ( XmlPullParserException e ) { throw new ParseException( "Error creating sink: " + e.getMessage(), e ); } + catch ( IOException e ) + { + throw new ParseException( "Error writing to sink: " + e.getMessage(), e ); + } } /** [EMAIL PROTECTED] */ @@ -80,13 +90,16 @@ } /** - * @param parser - * @param sink - * @return Faqs - * @throws Exception + * Parses an fml and emits the events into the given sink. + * + * @param parser The parser to use. + * @param sink The sink to consume the event. + * @return Faqs The parsed faqs model. + * @throws IOException if the model cannot be read. + * @throws XmlPullParserException if the model cannot be parsed. */ public Faqs parseFml( XmlPullParser parser, Sink sink ) - throws Exception + throws IOException, XmlPullParserException { Faqs faqs = new Faqs(); @@ -94,10 +107,6 @@ Faq currentFaq = null; - boolean inFaq = false; - - boolean inPart = false; - boolean inQuestion = false; boolean inAnswer = false; @@ -135,7 +144,6 @@ } else if ( parser.getName().equals( "part" ) ) { - inPart = true; currentPart = new Part(); currentPart.setId( parser.getAttributeValue( null, "id" ) ); } @@ -145,7 +153,6 @@ } else if ( parser.getName().equals( "faq" ) ) { - inFaq = true; currentFaq = new Faq(); currentFaq.setId( parser.getAttributeValue( null, "id" ) ); } @@ -196,16 +203,12 @@ faqs.addPart( currentPart ); currentPart = null; - - inPart = false; } else if ( parser.getName().equals( "faq" ) ) { currentPart.addFaq( currentFaq ); currentFaq = null; - - inFaq = false; } if ( parser.getName().equals( "question" ) ) { @@ -264,12 +267,15 @@ } /** - * @param faqs - * @param sink - * @throws Exception + * Writes the faqs to the specified sink. + * + * @param faqs The faqs to emit. + * @param sink The sink to consume the event. + * @throws IOException if something goes wrong. + * @throws XmlPullParserException if something goes wrong. */ private void createSink( Faqs faqs, Sink sink ) - throws Exception + throws IOException, XmlPullParserException { sink.head(); sink.title(); @@ -367,12 +373,15 @@ } /** - * @param sink - * @param answer - * @throws Exception + * Writes an answer to the sink. + * + * @param sink The sink to consume the event. + * @param answer The answer to be written. + * @throws IOException if something goes wrong. + * @throws XmlPullParserException if something goes wrong. */ private void writeAnswer( Sink sink, String answer ) - throws Exception + throws IOException, XmlPullParserException { int startSource = answer.indexOf( "<source>" ); if ( startSource != -1 ) @@ -386,7 +395,9 @@ } /** - * @param sink + * Writes a toplink element. + * + * @param sink The sink to consume the event. */ private void writeTopLink( Sink sink ) { @@ -402,12 +413,15 @@ } /** - * @param sink - * @param answer - * @throws Exception + * Writes an answer to the sink that contains a <source> element. + * + * @param sink The sink to consume the event. + * @param answer The answer to be written. + * @throws IOException if something goes wrong. + * @throws XmlPullParserException if something goes wrong. */ private void writeAnswerWithSource( Sink sink, String answer ) - throws Exception + throws IOException, XmlPullParserException { XmlPullParser parser = new MXParser(); parser.setInput( new StringReader( "<answer>" + answer + "</answer>" ) ); Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Faq.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Faq.java?view=diff&rev=566992&r1=566991&r2=566992 ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Faq.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Faq.java Fri Aug 17 02:55:05 2007 @@ -19,41 +19,75 @@ * under the License. */ +/** Encapsulates a model of a FAQ. */ public class Faq { + /** An id for the FAQ. */ private String id; + /** The question. */ private String question; + /** The answer. */ private String answer; + /** + * Returns the id of this FAQ. + * + * @return the id. + */ public String getId() { return id; } - public void setId( String id ) + /** + * Sets the id of this FAQ. + * + * @param newId the id to set. + */ + public void setId( String newId ) { - this.id = id; + this.id = newId; } + /** + * Returns the answer of this FAQ. + * + * @return the answer. + */ public String getAnswer() { return answer; } - public void setAnswer( String answer ) + /** + * Sets the answer of this FAQ. + * + * @param newAnswer the id to set. + */ + public void setAnswer( String newAnswer ) { - this.answer = answer; + this.answer = newAnswer; } + /** + * Returns the question of this FAQ. + * + * @return the question. + */ public String getQuestion() { return question; } - public void setQuestion( String question ) + /** + * Sets the question of this FAQ. + * + * @param newQuestion the id to set. + */ + public void setQuestion( String newQuestion ) { - this.question = question; + this.question = newQuestion; } } Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Faqs.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Faqs.java?view=diff&rev=566992&r1=566991&r2=566992 ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Faqs.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Faqs.java Fri Aug 17 02:55:05 2007 @@ -22,24 +22,43 @@ import java.util.ArrayList; import java.util.List; +/** Encapsulates a model of a collection of FAQs. */ public class Faqs { + /** Whether to create toplinks. */ private boolean toplink = true; + /** The FAQ title. */ private String title = "FAQ"; + /** The FAQ parts. */ private List parts; + /** + * Returns the parts of this FAQ. + * + * @return the parts. + */ public List getParts() { return parts; } - public void setParts( List parts ) - { - this.parts = parts; + /** + * Sets the parts of this FAQ. + * + * @param newParts the parts to set. + */ + public void setParts( List newParts ) + { + this.parts = newParts; } + /** + * Adds the given Part to the parts of this FAQ. + * + * @param part the part to add. + */ public void addPart( Part part ) { if ( parts == null ) @@ -50,21 +69,41 @@ parts.add( part ); } + /** + * Returns the title of this FAQ. Defaults to "FAQ". + * + * @return the title. + */ public String getTitle() { return title; } - public void setTitle( String title ) - { - this.title = title; - } - - public void setToplink( boolean toplink ) - { - this.toplink = toplink; - } - + /** + * Sets the title of this FAQ. + * + * @param newTitle the title to set. + */ + public void setTitle( String newTitle ) + { + this.title = newTitle; + } + + /** + * Sets the toplink of this FAQ. + * + * @param newToplink the toplink to set. + */ + public void setToplink( boolean newToplink ) + { + this.toplink = newToplink; + } + + /** + * Whether to create toplinks. Defaults to true. + * + * @return True if toplinks are created. + */ public boolean isToplink() { return toplink; Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Part.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Part.java?view=diff&rev=566992&r1=566991&r2=566992 ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Part.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/model/Part.java Fri Aug 17 02:55:05 2007 @@ -22,14 +22,23 @@ import java.util.ArrayList; import java.util.List; +/** Encapsulates a model of a part of a FAQ. */ public class Part { + /** An id for the part. */ private String id; + /** The title of the part. */ private String title; + /** The list of FAQs. */ private List faqs; + /** + * Adds the given Faq to the FAQs of this Part. + * + * @param faq the faq to add. + */ public void addFaq( Faq faq ) { if ( faqs == null ) @@ -40,33 +49,63 @@ faqs.add( faq ); } + /** + * Returns the faqs of this Part. + * + * @return the faqs. + */ public List getFaqs() { return faqs; } - public void setFaqs( List faqs ) - { - this.faqs = faqs; + /** + * Sets the list of FAQs of this Part. + * + * @param newFaqs the faqs to set. + */ + public void setFaqs( List newFaqs ) + { + this.faqs = newFaqs; } + /** + * Returns the id of this Part. + * + * @return the id. + */ public String getId() { return this.id; } - public void setId( String id ) - { - this.id = id; + /** + * Sets the id of this Part. + * + * @param newId the id to set. + */ + public void setId( String newId ) + { + this.id = newId; } + /** + * Returns the title of this Part. + * + * @return the title. + */ public String getTitle() { return title; } - public void setTitle( String title ) + /** + * Sets the title of this Part. + * + * @param newTitle the title to set. + */ + public void setTitle( String newTitle ) { - this.title = title; + this.title = newTitle; } }