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 * 017 * http://www.biojava.org/ 018 019 * @author Andreas Prlic 020 * 021 */ 022package org.biojava.nbio.structure.align.webstart; 023 024 025import org.biojava.nbio.structure.align.util.UserConfiguration; 026import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; 027import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior; 028import org.xml.sax.Attributes; 029import org.xml.sax.helpers.DefaultHandler; 030 031 032 033/** 034 * XML content handler for serialisation of RegistryConfiguration class 035 */ 036public class ConfigXMLHandler extends DefaultHandler { 037 038 UserConfiguration config ; 039 040 /** 041 * 042 */ 043 public ConfigXMLHandler() { 044 super(); 045 046 config = new UserConfiguration(); 047 } 048 049 @Override 050 public void startElement (String uri, String name, String qName, Attributes atts){ 051 //System.out.println("new element >" + name + "< >" + qName+"<" + uri); 052 if ( qName.equals("PDBFILEPATH")){ 053 054 String path = atts.getValue("path"); 055 // default path is system tmp... 056 if ( path != null) 057 config.setPdbFilePath(path); 058 059 //Deprecated property; supported for backwards compatibility 060 String autoFetch = atts.getValue("autoFetch"); 061 if(autoFetch == null || !autoFetch.equals("false")) { 062 config.setFetchBehavior(FetchBehavior.DEFAULT); 063 } else { 064 config.setFetchBehavior(FetchBehavior.LOCAL_ONLY); 065 } 066 067 String fetchBehavior = atts.getValue("fetchBehavior"); 068 if(fetchBehavior == null) { 069 config.setFetchBehavior(FetchBehavior.DEFAULT); 070 } else { 071 config.setFetchBehavior(FetchBehavior.valueOf(fetchBehavior)); 072 } 073 String obsoleteBehavior = atts.getValue("obsoleteBehavior"); 074 if(obsoleteBehavior == null) { 075 config.setObsoleteBehavior(ObsoleteBehavior.DEFAULT); 076 } else { 077 config.setObsoleteBehavior(ObsoleteBehavior.valueOf(obsoleteBehavior)); 078 } 079 080 String fileFormat = atts.getValue("fileFormat"); 081 config.setFileFormat(UserConfiguration.PDB_FORMAT); 082 if ( fileFormat != null) { 083 if ( fileFormat.equals(UserConfiguration.MMCIF_FORMAT)) 084 config.setFileFormat(UserConfiguration.MMCIF_FORMAT); 085 } 086 087 } 088 } 089 090 091 092 093 094 095 096 public UserConfiguration getConfig() { 097 return config ; 098 } 099 100}