Coverage Report - org.apache.maven.jira.JiraXML
 
Classes in this File Line Coverage Branch Coverage Complexity
JiraXML
0% 
0% 
3
 
 1  
 package org.apache.maven.jira;
 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.xml.sax.Attributes;
 20  
 import org.xml.sax.SAXException;
 21  
 import org.xml.sax.helpers.DefaultHandler;
 22  
 
 23  
 import javax.xml.parsers.SAXParser;
 24  
 import javax.xml.parsers.SAXParserFactory;
 25  
 import java.io.File;
 26  
 import java.util.ArrayList;
 27  
 import java.util.List;
 28  
 
 29  
 /**
 30  
  * XML parser for <code>JiraIssue</code>s.
 31  
  *
 32  
  * @version $Id: org.apache.maven.jira.JiraXML.html 816584 2012-05-08 12:33:35Z hboutemy $
 33  
  */
 34  
 public class JiraXML
 35  
     extends DefaultHandler
 36  0
 {
 37  
     private List issueList;
 38  
 
 39  
     private String currentElement;
 40  
 
 41  0
     private String currentParent = "";
 42  0
 
 43  
     private JiraIssue issue;
 44  0
 
 45  
     public JiraXML( String xmlPath )
 46  0
     {
 47  0
         SAXParserFactory factory = SAXParserFactory.newInstance();
 48  0
 
 49  0
         issueList = new ArrayList();
 50  0
 
 51  
         try
 52  0
         {
 53  0
             SAXParser saxParser = factory.newSAXParser();
 54  0
 
 55  0
             saxParser.parse( new File( xmlPath ), this );
 56  0
         }
 57  0
         catch ( Throwable t )
 58  
         {
 59  0
             t.printStackTrace();
 60  0
         }
 61  0
     }
 62  
 
 63  0
     public void startElement( String namespaceURI, String sName, String qName, Attributes attrs )
 64  
         throws SAXException
 65  0
     {
 66  0
         if ( qName.equals( "item" ) )
 67  0
         {
 68  0
             issue = new JiraIssue();
 69  
 
 70  0
             currentParent = "item";
 71  
         }
 72  0
     }
 73  
 
 74  0
     public void endElement( String namespaceURI, String sName, String qName )
 75  
         throws SAXException
 76  0
     {
 77  0
         if ( qName.equals( "item" ) )
 78  0
         {
 79  0
             issueList.add( issue );
 80  0
 
 81  0
             currentParent = "";
 82  0
         }
 83  0
         else if ( qName.equals( "key" ) )
 84  0
         {
 85  0
             issue.setKey( currentElement );
 86  0
         }
 87  0
         else if ( qName.equals( "summary" ) )
 88  0
         {
 89  0
             issue.setSummary( currentElement );
 90  0
         }
 91  0
         else if ( qName.equals( "link" ) && currentParent.equals( "item" ) )
 92  0
         {
 93  0
             issue.setLink( currentElement );
 94  0
         }
 95  0
         else if ( qName.equals( "status" ) )
 96  0
         {
 97  0
             issue.setStatus( currentElement );
 98  0
         }
 99  0
         else if ( qName.equals( "resolution" ) )
 100  0
         {
 101  0
             issue.setResolution( currentElement );
 102  
         }
 103  0
         else if ( qName.equals( "assignee" ) )
 104  0
         {
 105  0
             issue.setAssignee( currentElement );
 106  
         }
 107  
 
 108  0
         currentElement = "";
 109  0
     }
 110  
 
 111  0
     public void characters( char[] buf, int offset, int len )
 112  
         throws SAXException
 113  0
     {
 114  0
         String s = new String( buf, offset, len );
 115  0
 
 116  0
         if ( !s.trim().equals( "" ) )
 117  
         {
 118  0
             currentElement = currentElement + s.trim() + "\n";
 119  0
         }
 120  0
     }
 121  
 
 122  
     public List getIssueList()
 123  
     {
 124  0
         return this.issueList;
 125  
     }
 126  
 }