Coverage Report - org.apache.maven.changes.ChangesXML
 
Classes in this File Line Coverage Branch Coverage Complexity
ChangesXML
0% 
0% 
1,917
 
 1  
 package org.apache.maven.changes;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2006 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *      http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import org.apache.maven.plugin.logging.Log;
 20  
 import org.xml.sax.Attributes;
 21  
 import org.xml.sax.SAXException;
 22  
 import org.xml.sax.helpers.DefaultHandler;
 23  
 
 24  
 import javax.xml.parsers.SAXParser;
 25  
 import javax.xml.parsers.SAXParserFactory;
 26  
 import java.io.File;
 27  
 import java.util.ArrayList;
 28  
 import java.util.List;
 29  
 
 30  
 /**
 31  
  * XML Parser for changes.xml files.
 32  
  *
 33  
  * @version $Id: org.apache.maven.changes.ChangesXML.html 816584 2012-05-08 12:33:35Z hboutemy $
 34  
  */
 35  
 public class ChangesXML
 36  
     extends DefaultHandler
 37  
 {
 38  
     private Action action;
 39  
 
 40  
     private List actionList;
 41  
 
 42  
     private Release release;
 43  
 
 44  
     private String currentElement;
 45  
 
 46  
     private String currentName;
 47  
 
 48  
     private List releaseList;
 49  
 
 50  
     private String author;
 51  0
 
 52  0
     private String authorEmail;
 53  0
 
 54  
     private String title;
 55  0
 
 56  0
     public ChangesXML( String xmlPath, Log log )
 57  0
     {
 58  0
         SAXParserFactory factory = SAXParserFactory.newInstance();
 59  0
 
 60  0
         try
 61  0
         {
 62  0
             SAXParser saxParser = factory.newSAXParser();
 63  0
 
 64  0
             saxParser.parse( new File( xmlPath ), this );
 65  0
         }
 66  0
         catch ( Throwable t )
 67  0
         {
 68  0
             log.error( "An error occured when parsing the changes.xml file:", t );
 69  0
         }
 70  0
     }
 71  
 
 72  0
     public void setAuthor( String author )
 73  0
     {
 74  0
         this.author = author;
 75  0
     }
 76  
 
 77  0
     public String getAuthor()
 78  0
     {
 79  0
         return author;
 80  0
     }
 81  
 
 82  0
     public void setAuthorEmail( String authorEmail )
 83  0
     {
 84  0
         this.authorEmail = authorEmail;
 85  0
     }
 86  
 
 87  0
     public String getAuthorEmail()
 88  0
     {
 89  0
         return authorEmail;
 90  0
     }
 91  
 
 92  0
     public void setReleaseList( List releaseList )
 93  0
     {
 94  0
         this.releaseList = releaseList;
 95  0
     }
 96  
 
 97  0
     public List getReleaseList()
 98  0
     {
 99  0
         return releaseList;
 100  0
     }
 101  
 
 102  0
     public void setTitle( String title )
 103  0
     {
 104  0
         this.title = title;
 105  0
     }
 106  
 
 107  0
     public String getTitle()
 108  
     {
 109  0
         return title;
 110  0
     }
 111  0
 
 112  0
     public void characters( char[] buf, int offset, int len )
 113  0
         throws SAXException
 114  0
     {
 115  0
         String s = new String( buf, offset, len );
 116  0
 
 117  0
         if ( !s.trim().equals( "" ) )
 118  
         {
 119  0
             currentElement = currentElement + s.trim() + "\n";
 120  0
         }
 121  0
     }
 122  0
 
 123  0
     public void endElement( String namespaceURI, String sName, String qName )
 124  0
         throws SAXException
 125  0
     {
 126  0
         if ( qName.equals( "title" ) )
 127  0
         {
 128  0
             this.title = currentElement;
 129  0
         }
 130  0
         else if ( qName.equals( "author" ) )
 131  0
         {
 132  0
             this.title = currentElement;
 133  0
         }
 134  0
         else if ( qName.equals( "action" ) )
 135  0
         {
 136  0
             action.setAction( currentElement.trim() );
 137  0
 
 138  0
             actionList.add( action );
 139  0
         }
 140  0
         else if ( qName.equals( "release" ) )
 141  0
         {
 142  0
             release.setAction( actionList );
 143  0
 
 144  0
             releaseList.add( release );
 145  0
         }
 146  0
 
 147  0
         currentElement = "";
 148  0
     }
 149  0
 
 150  0
     public void startElement( String namespaceURI, String sName, String qName, Attributes attrs )
 151  0
         throws SAXException
 152  0
     {
 153  0
         if ( qName.equals( "title" ) )
 154  0
         {
 155  0
             this.title = "";
 156  0
         }
 157  0
         else if ( qName.equals( "author" ) )
 158  0
         {
 159  0
             this.authorEmail = attrs.getValue( "email" );
 160  0
 
 161  0
             this.author = "";
 162  0
         }
 163  0
         else if ( qName.equals( "body" ) )
 164  0
         {
 165  0
             releaseList = new ArrayList();
 166  0
         }
 167  0
         else if ( qName.equals( "release" ) )
 168  0
         {
 169  0
             release = new Release();
 170  0
 
 171  0
             release.setDateRelease( attrs.getValue( "date" ) );
 172  0
 
 173  0
             release.setVersion( attrs.getValue( "version" ) );
 174  0
 
 175  0
             release.setDescription( attrs.getValue( "description" ) );
 176  0
 
 177  0
             actionList = new ArrayList();
 178  0
         }
 179  0
         else if ( qName.equals( "action" ) )
 180  0
         {
 181  0
             action = new Action();
 182  0
 
 183  0
             action.setDev( attrs.getValue( "dev" ) );
 184  0
 
 185  0
             action.setDueTo( attrs.getValue( "due-to" ) );
 186  0
 
 187  0
             action.setDueToEmail( attrs.getValue( "due-to-email" ) );
 188  0
 
 189  0
             action.setType( attrs.getValue( "type" ) );
 190  0
 
 191  0
             action.setIssue( attrs.getValue( "issue" ) );
 192  0
         }
 193  0
 
 194  0
         currentName = qName;
 195  0
     }
 196  
 }