📄 parseacd.java
字号:
/********************************************************************** This library is free software; you can redistribute it and/or* modify it under the terms of the GNU Library General Public* License as published by the Free Software Foundation; either* version 2 of the License, or (at your option) any later version.** This library is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU* Library General Public License for more details.** You should have received a copy of the GNU Library General Public* License along with this library; if not, write to the* Free Software Foundation, Inc., 59 Temple Place - Suite 330,* Boston, MA 02111-1307, USA.** @author: Copyright (C) Tim Carver*********************************************************************/package org.emboss.jemboss.parser;import org.emboss.jemboss.parser.acd.*;import java.io.*;import java.util.StringTokenizer;import java.util.Vector;import java.util.Enumeration;/**** ACD (Ajax command line definition) file parser.**/public class ParseAcd{ /** number of ACD fields */ private int numofFields = 0; /** number of parameters in a field */ private int numofParams; /** vector containing the application fields */ private Vector vappF = new Vector(); /** string value of a parameter */ private String svalue; /** double value of a parameter */ private double nvalue; /** parameter data type */ private String attr; /** array of dependent variables */ private Dependent dep[]; /** number of dependent variables */ private int numOfDependents; /** String of the groups application belongs to */ private String groupList = ""; /** number of sections */ private int nsection = 0; /** number of subsections */ private int nsubsection = 0;// data types in ACD /** number of text fields */ private int ntextf; /** number of integer fields */ private int nint; /** number of float fields */ private int nfloat; /** number of checkbox fields */ private int nbool; /** number of sequence fields */ private int nseqs; /** number of filelist fields */ private int nflist; /** number of list & selection fields - single selection */ private int nlist; /** number of list & selection fields - multiple selection */ private int mlist; /** number of range fields */ private int nrange; /** default for list or select data type */ private Vector listdefault; private int nmultiTextField;// Groups the program belongs to /** true if primary group is defined */ private boolean isPrimaryGp; /** true if secondary group is defined */ private boolean isSecondaryGp; /** primary group */ private String primaryGp; /** secondary group */ private String secondaryGp; /** * * The constructor takes the ACD as a string. * @param acdText String representation of * the ACD file * @param groups boolean determing whether * just to retieve the groups * */ public ParseAcd(String acdText, boolean groups) { Vector variables = new Vector(); //for "variable:" fields ApplicationFields appF; int colonPos=0; int braketPos=0; int ttype; String param; String line; try { BufferedReader in = new BufferedReader(new StringReader(acdText)); line = new String(); in.mark(2500); line = in.readLine();// loop over all fields defined in the ACD do { line = line.trim(); // removes leading & trailing whitespace if(line.startsWith("#") || (line.length() ==0)) { in.mark(2500); continue; } colonPos = line.indexOf(':'); if(colonPos < 0) colonPos = line.indexOf('='); if(colonPos < 0) continue; String dataType = line.substring(0,colonPos).toLowerCase(); if(dataType.equals("toggle")) dataType = "boolean"; braketPos = line.indexOf('['); if(braketPos >= 0) param = line.substring(colonPos+1,braketPos).trim(); else param = line.substring(colonPos+1).trim(); if(line.startsWith("var:") || line.startsWith("variable")) { param = param.trim(); ApplicationFields var = new ApplicationFields(); var.setNumberOfParam(2); int ns = param.indexOf(" "); if(ns > -1) { String value = param.substring(0,ns); value = value.replace('"',' ').trim(); var.setParam(0,dataType,value); value = param.substring(ns); value = value.replace('"',' ').trim(); var.setParam(1, "value", value); } variables.add(var); in.mark(2500); continue; } else if(line.startsWith("endsection")) { appF = new ApplicationFields(); appF.setNumberOfParam(1); appF.setParam(0, dataType, param); numofFields++; vappF.add(appF); in.mark(2500); continue; } else if(line.startsWith("section")) { if(param.equals("input") || param.equals("required") || param.equals("output") || param.equals("advanced") || param.equals("additional") ) nsection++; else nsubsection++; } numofParams = 1; StreamTokenizer st = new StreamTokenizer(in); if(! line.endsWith("[")) { // rewind to start in.reset(); // tokeniser on same line st.nextToken(); st.nextToken(); st.nextToken(); st.nextToken(); } in.mark(2500); do { ttype = parseParam(in, st); } while(attr != null); appF = new ApplicationFields(); vappF.add(appF); appF.setNumberOfParam(numofParams); numofParams = 0; //set param name to lowercase as ACD is case insensitive appF.setParam(numofParams, dataType, param.toLowerCase()); in.reset(); do { ttype = parseParam(in, st); // is the value a number or string if( ttype != java.io.StreamTokenizer.TT_NUMBER && attr != null) { if(variables.size()>0) svalue = resolveVariables(variables,svalue); //set variables to lower case as ACD is case insensitive if(svalue.indexOf("$") > -1 || svalue.indexOf("@") > -1) svalue = svalue.toLowerCase(); appF.setParam(numofParams, attr, svalue);// System.out.println(" ATTR " + attr + " SVALUE " + // getParamValueStr(numofFields,numofParams)); } else if ( ttype == java.io.StreamTokenizer.TT_NUMBER) {// System.out.println(" ATTR " + attr + " NVALUE " + nvalue); appF.setParam(numofParams, attr, nvalue); } } while (attr != null);// set gui handle (based on data type) setGuiHandleNumber(dataType,appF); numofFields++; in.mark(2500); } while((line = in.readLine()) != null); } catch (IOException e) { System.out.println("PareAcd: Parsing acd file error" ); } } /** * * Used to replace the "variable:" or "var:" shorthand notation in * the ACD to the full expression it represent * @param variables ApplicationFields of var ACD fields * @param svalue value to be resolved if necessary * */ private String resolveVariables(Vector variables,String svalue) { String res=svalue; Enumeration enumer = variables.elements(); while(enumer.hasMoreElements()) { ApplicationFields var = (ApplicationFields)enumer.nextElement(); String vName = var.getParamValueStr(0); String vValue = var.getParamValueStr(1); //if we have something that might need resolving if((res.indexOf("$") >-1) || (res.indexOf("@") >-1)) { AcdVariableResolve avresolve = new AcdVariableResolve(res,vName,vValue); res = avresolve.getResult(); } }// if(!res.equals(svalue))// System.out.println("START VAL "+svalue+" END VAL "+res); return res; } /** * * Gets the handle for a gui component on the Jemboss form. * @param field field number in the ACD file * @return handle integer. * */ public int getGuiHandleNumber(int field) { ApplicationFields aF = (ApplicationFields)vappF.get(field); return aF.getGuiHandleNumber(); } /** * * Gets the number of float, string, seqout, outfile, * infile, regexp, codon & featout data types in the ACD. * These make up the number of JTextAreas in the Jemboss form. * @return number of TextArea's in the Jemboss form. * */ public int getNumTextf() { return ntextf; } /** * * Gets the number of int data types in the ACD. * @return number of TextFieldInt in the Jemboss form. * */ public int getNumNint() { return nint; } /** * * Gets the number of float data types in the ACD. * @return number of TextFieldFloat in the Jemboss form. * */ public int getNumNfloat() { return nfloat; } /** * * Gets the number of boolean data types in the ACD. * @return number of check boxes in the Jemboss form. * */ public int getNumBool() { return nbool; } /** * * Gets the number of seqset, seqall & sequence data types in the ACD * @return number of sequence inputs in the Jemboss form. * */ public int getNumSeq() { return nseqs; } /** * * Gets the number of filelist data types in the ACD * @return number of file lists in the Jemboss form. * */ public int getNumFileList() { return nflist; } /** * * Gets the number of list & selection data types in the ACD, * using single list selection * @return number of selection lists in the Jemboss form. * */ public int getNumList() { return nlist; } /** * * Gets the number of list & selection data types in the ACD, * using multiple list selection * @return number of selection lists in the Jemboss form. * */ public int getNumMList() { return mlist; } /** * * @return number of range data types in the Jemboss form. * */ public int getNumRange() { return nrange; } /** * * Gets the number of sections in the ACD * @return number of sections in the Jemboss form. * */ public int getNumSection() { return nsection; } /** * * Gets the number of nested sections in the ACD * @return number of subsections in the Jemboss form. * */ public int getNumSubsection() { return nsubsection; } /** * * Get a specified parameter attribute. * @param field field number in the ACD file * @param param parameter number in that field * @return string of the value. * */ public String getParameterAttribute(int field, int param) { ApplicationFields aF = (ApplicationFields)vappF.get(field); return aF.getParamAttribute(param); } /** * * Determine if the value of the parameter is a String. * @return true if the value of the parameter is a String. * */ public boolean isParamValueStr(int field, int param) { ApplicationFields aF = (ApplicationFields)vappF.get(field); return aF.isParamValueStr(param); } /** * * Gets the String value of a parameter. * @return String value of the parameter. * */ public String getParamValueStr(int field, int param) { ApplicationFields aF = (ApplicationFields)vappF.get(field); return aF.getParamValueStr(param).trim(); } /** * * Sets the gui handle depending on the data type. * @param dataType data type * @param appF application field *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -