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.program.xff; 023 024import org.biojava.bio.seq.io.ParseException; 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 xff:prop detail elements. prop details are simple 033 * tag-value text, and they are added directly as properties of the feature. 034 * 035 * @author Thomas Down 036 * @since 1.2 037 */ 038 039public class PropDetailHandler extends StringElementHandlerBase { 040 public static final XFFPartHandlerFactory PROPDETAIL_HANDLER_FACTORY = new XFFPartHandlerFactory() { 041 public StAXContentHandler getPartHandler(XFFFeatureSetHandler xffenv) { 042 return new PropDetailHandler(xffenv); 043 } 044 } ; 045 046 private String key; 047 private XFFFeatureSetHandler xffenv; 048 049 public PropDetailHandler(XFFFeatureSetHandler xffenv) { 050 super(); 051 this.xffenv = xffenv; 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 key = attrs.getValue("key"); 062 if (key == null) { 063 throw new SAXException("No key attribute for xff:prop"); 064 } 065 super.startElement(nsURI, localName, qName, attrs, dm); 066 } 067 068 protected void setStringValue(String s) 069 throws SAXException 070 { 071 try { 072 xffenv.getFeatureListener().addFeatureProperty(key, s); 073 } catch (ParseException pex) { 074 throw new SAXException(pex); 075 } 076 } 077}