Coverage Report - org.apache.maven.plugin.changes.ChangesXML
 
Classes in this File Line Coverage Branch Coverage Complexity
ChangesXML
0%
0/57
0%
0/18
1,833
 
 1  
 package org.apache.maven.plugin.changes;
 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 org.apache.maven.plugin.logging.Log;
 23  
 import org.xml.sax.Attributes;
 24  
 import org.xml.sax.SAXException;
 25  
 import org.xml.sax.helpers.DefaultHandler;
 26  
 
 27  
 import javax.xml.parsers.SAXParser;
 28  
 import javax.xml.parsers.SAXParserFactory;
 29  
 import java.io.File;
 30  
 import java.util.ArrayList;
 31  
 import java.util.List;
 32  
 
 33  
 /**
 34  
  * XML Parser for changes.xml files.
 35  
  *
 36  
  * @version $Id: org.apache.maven.plugin.changes.ChangesXML.html 816584 2012-05-08 12:33:35Z hboutemy $
 37  
  */
 38  
 public class ChangesXML
 39  
     extends DefaultHandler
 40  
 {
 41  
     private Action action;
 42  
 
 43  
     private List actionList;
 44  
 
 45  
     private Release release;
 46  
 
 47  0
     private StringBuffer currentElement = new StringBuffer( 1024 );
 48  
 
 49  
     private String currentName;
 50  
 
 51  
     private List releaseList;
 52  
 
 53  
     private String author;
 54  
 
 55  
     private String authorEmail;
 56  
 
 57  
     private String title;
 58  
 
 59  
     public ChangesXML( File xmlPath, Log log )
 60  0
     {
 61  0
         SAXParserFactory factory = SAXParserFactory.newInstance();
 62  
 
 63  
         try
 64  
         {
 65  0
             SAXParser saxParser = factory.newSAXParser();
 66  
 
 67  0
             saxParser.parse( xmlPath, this );
 68  
         }
 69  0
         catch ( Throwable t )
 70  
         {
 71  0
             log.error( "An error occured when parsing the changes.xml file:", t );
 72  0
         }
 73  0
     }
 74  
 
 75  
     public void setAuthor( String author )
 76  
     {
 77  0
         this.author = author;
 78  0
     }
 79  
 
 80  
     public String getAuthor()
 81  
     {
 82  0
         return author;
 83  
     }
 84  
 
 85  
     public void setAuthorEmail( String authorEmail )
 86  
     {
 87  0
         this.authorEmail = authorEmail;
 88  0
     }
 89  
 
 90  
     public String getAuthorEmail()
 91  
     {
 92  0
         return authorEmail;
 93  
     }
 94  
 
 95  
     public void setReleaseList( List releaseList )
 96  
     {
 97  0
         this.releaseList = releaseList;
 98  0
     }
 99  
 
 100  
     public List getReleaseList()
 101  
     {
 102  0
         return releaseList;
 103  
     }
 104  
 
 105  
     public void setTitle( String title )
 106  
     {
 107  0
         this.title = title;
 108  0
     }
 109  
 
 110  
     public String getTitle()
 111  
     {
 112  0
         return title;
 113  
     }
 114  
 
 115  
     public void characters( char[] buf, int offset, int len )
 116  
         throws SAXException
 117  
     {
 118  0
         currentElement.append( buf, offset, len );
 119  0
     }
 120  
 
 121  
     public void endElement( String namespaceURI, String sName, String qName )
 122  
         throws SAXException
 123  
     {
 124  0
         if ( qName.equals( "title" ) )
 125  
         {
 126  0
             this.title = currentElement.toString().trim();
 127  
         }
 128  0
         else if ( qName.equals( "author" ) )
 129  
         {
 130  0
             this.author = currentElement.toString().trim();
 131  
         }
 132  0
         else if ( qName.equals( "action" ) )
 133  
         {
 134  0
             action.setAction( currentElement.toString().trim() );
 135  
 
 136  0
             actionList.add( action );
 137  
         }
 138  0
         else if ( qName.equals( "release" ) )
 139  
         {
 140  0
             release.setAction( actionList );
 141  
 
 142  0
             releaseList.add( release );
 143  
         }
 144  
 
 145  0
         currentElement.setLength( 0 );
 146  0
     }
 147  
 
 148  
     public void startElement( String namespaceURI, String sName, String qName, Attributes attrs )
 149  
         throws SAXException
 150  
     {
 151  0
         if ( qName.equals( "title" ) )
 152  
         {
 153  0
             this.title = "";
 154  
         }
 155  0
         else if ( qName.equals( "author" ) )
 156  
         {
 157  0
             this.authorEmail = attrs.getValue( "email" );
 158  
 
 159  0
             this.author = "";
 160  
         }
 161  0
         else if ( qName.equals( "body" ) )
 162  
         {
 163  0
             releaseList = new ArrayList();
 164  
         }
 165  0
         else if ( qName.equals( "release" ) )
 166  
         {
 167  0
             release = new Release();
 168  
 
 169  0
             release.setDateRelease( attrs.getValue( "date" ) );
 170  
 
 171  0
             release.setVersion( attrs.getValue( "version" ) );
 172  
 
 173  0
             release.setDescription( attrs.getValue( "description" ) );
 174  
 
 175  0
             actionList = new ArrayList();
 176  
         }
 177  0
         else if ( qName.equals( "action" ) )
 178  
         {
 179  0
             action = new Action();
 180  
 
 181  0
             action.setDev( attrs.getValue( "dev" ) );
 182  
 
 183  0
             action.setDueTo( attrs.getValue( "due-to" ) );
 184  
 
 185  0
             action.setDueToEmail( attrs.getValue( "due-to-email" ) );
 186  
 
 187  0
             action.setType( attrs.getValue( "type" ) );
 188  
 
 189  0
             action.setIssue( attrs.getValue( "issue" ) );
 190  
         }
 191  
 
 192  0
         currentName = qName;
 193  0
     }
 194  
 }