S-Link-S Calculator API

The Java Documentation is available.
The BibDataFrame Class demonstrates how to use the Calculator API

import org.xml.sax.*;
import org.xml.sax.helpers.ParserFactory;
import com.ibm.xml.parsers.SAXParser;

	static final String parserClass = "com.ibm.xml.parsers.ValidatingSAXParser";

			String xmlFile = template.getText();
			
			//string to hold the result of the calculation
			String pr="";
			
			//string to hold the null token report
			String nt="";
			
			//instantiate a S-Link-S event handler for the SAX parser 
			SLinkSHandler sh= new SLinkSHandler();
			
			try{
				
				//make a SAX parser of the chosen class
				Parser parser = ParserFactory.makeParser(parserClass);
				
				//make the SLinkSHandler into a document handler (doesn't do much)
			    DocumentHandler handler =sh;
			    
			    //attach the document handler to the parser
			 	parser.setDocumentHandler(handler);
			 	
			 	//instantiate a BibData object to package bibliographic data
				BibData newBib = new BibData();
				
				//load the BibData object with data
				for (int i=0; i<bdItemCount ; i++){
					newBib.put(bdChoices[i].getSelectedItem() ,bdTextFields[i].getText() );
				}
				
				//attach the BibData object to the document handler
				sh.registerBibData(newBib);
				
				//tell the parser to use the BibData to resolve external entities
			 	parser.setEntityResolver((EntityResolver) newBib);
				try {
				
					//start the parser
					parser.parse(new InputSource(new StringReader(xmlFile) ));
				} catch (SAXException se) {
				  se.printStackTrace();
				} catch (IOException ioe) {
				    ioe.printStackTrace();
				}
				
				//examine the results
				pr=sh.parseResult().url ;
				nt="not found:"+ sh.parseResult().nullData.toString();
			} catch (Exception pe){
				pe.printStackTrace();
			}

©1999, OCLC Openly Informatics. All rights reserved. S-Link-S is a service mark of OCLC, Inc. Java is a registered trademark of Sun Microsystems, Inc.