import java.net.*; import java.io.*; import java.util.*; import java.text.*; import org.w3c.dom.*; import org.xml.sax.InputSource; import javax.xml.parsers.*; import javax.xml.xpath.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; public class classifySample { private static String classifyURL = "http://classify.oclc.org/classify2/Classify?"; private void go(String args[]) { String paramType=null, paramValue=null, summaryInd="false"; if (args.length >= 2) { paramType = args[0]; paramValue = args[1]; if (args.length > 2) summaryInd = args[2]; } else { System.out.println("improper usage"); usage(); System.exit(-1); } System.out.println("Searching for: " + paramType + "=" + paramValue); Document doc = null; String nextURL = null; try { if (summaryInd.equals("true")) nextURL = classifyURL + paramType + "=" + java.net.URLEncoder.encode(paramValue, "UTF-8") + "&summary=true"; else nextURL = classifyURL + paramType + "=" + java.net.URLEncoder.encode(paramValue, "UTF-8"); URL url = new URL(nextURL); InputStream in = url.openStream(); doc = parseXML(in, false, false); in.close(); } catch (Exception e) { System.err.println(e); e.printStackTrace(); } XPath xpath = XPathFactory.newInstance().newXPath(); Node respNode = getNode(xpath, doc, "//response"); if (respNode != null) { String respCode = getAttribute(xpath, respNode, "@code"); System.out.println("response code=" + respCode); if (respCode.equals("0") || respCode.equals("2")) printRecommendations(doc, xpath); else if (respCode.equals("4")) printEditions(doc, xpath); } } private void printRecommendations(Document doc, XPath xpath) { try { System.out.println("DDC"); String expression = "//recommendations/ddc/mostPopular"; NodeList list = (NodeList) xpath.evaluate(expression, doc, XPathConstants.NODESET); if (list.getLength() > 0) System.out.println(" Most Popular"); for (int i=0; i 0) System.out.println(" Most Popular"); for (int i=0; i [summary ind]"); System.out.println("example: java classifySample oclc 166382351 true"); } public static void main(String[] args) { new classifySample().go(args); } }