001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021 022package org.biojava.bio.seq.io.game; 023 024import org.biojava.utils.ChangeVetoException; 025import org.biojava.utils.stax.DelegationManager; 026import org.biojava.utils.stax.StAXContentHandler; 027import org.biojava.utils.stax.StringElementHandlerBase; 028import org.xml.sax.Attributes; 029import org.xml.sax.SAXException; 030 031/** 032 * StAX handler for GAME <description> elements. 033 * derived from Thomas Down's PropDetailHandler 034 * 035 * @author David Huen 036 * @author Thomas Down 037 * @since 1.8 038 */ 039public class GAMEDescriptionPropHandler extends StringElementHandlerBase { 040 // this just sets up a proprty named "description" in the annotation bundle. 041 public static final StAXHandlerFactory GAME_DESCRIPTION_PROP_HANDLER_FACTORY = new StAXHandlerFactory() { 042 public StAXContentHandler getHandler(StAXFeatureHandler staxenv) { 043 return new GAMEDescriptionPropHandler(staxenv); 044 } 045 } ; 046 047 private StAXFeatureHandler staxenv; 048 049 public GAMEDescriptionPropHandler(StAXFeatureHandler staxenv) { 050 super(); 051 this.staxenv = staxenv; 052 } 053 054 public void startElement(String nsURI, 055 String localName, 056 String qName, 057 Attributes attrs, 058 DelegationManager dm) 059 throws SAXException 060 { 061// System.out.println("desc: " + localName); 062 super.startElement(nsURI, localName, qName, attrs, dm); 063 } 064 065 protected void setStringValue(String s) 066 throws SAXException 067 { 068// System.out.println("GAMEDescriptionPropHandler: string is " + s); 069 String trimmed = s.trim(); 070 071 try { 072 staxenv.featureTemplate.annotation.setProperty("description", trimmed); 073 } 074 catch (ChangeVetoException cve) { 075 System.err.println("GAMEDescriptionPropHandler: veto exception caught."); 076 } 077 } 078 079}