java without java casey durfee [email protected] [email protected] codi 2006

33
Java without Java Casey Durfee [email protected] CODI 2006

Upload: carmella-eaton

Post on 26-Dec-2015

223 views

Category:

Documents


0 download

TRANSCRIPT

  • Slide 1
  • Java without Java Casey Durfee [email protected] [email protected] CODI 2006
  • Slide 2
  • Why should I care? You want to get things done or you just want more time to goof off You know Horizon will never perfectly meet your librarys needs You dont have $$$ for custom work You want to understand why software isnt perfect You want the bragging rights of having seen the geekiest presentation at CODI.
  • Slide 3
  • But I cant Dont sell yourself short! Plenty of other people will be happy to do it for you Dont worry about what youre supposed to be able to do
  • Slide 4
  • Lack of Social Skills a Plus! Be lazy and easily annoyed; take it personally Lazy: always look for an easier way Easily annoyed: If something doesnt work right, dont just learn to ignore it! Take it personally: If you dont fix it, nobody will Dont take any guff: Its just a computer. Dont forget whos boss Laziness, impatience, hubris (the 3 Perl virtues)
  • Slide 5
  • Whats an API? Tools to interface with someone elses software Examples Flickr, Google, Amazon, etc. Horizon APIs will make it easier to extend Horizon without knowing too much about how it works behind the scenes
  • Slide 6
  • Foundations
  • Slide 7
  • Slide 8
  • Intro to Java The Platform (great) OS independent Fast Powerful 3 rd party support (good) Lots of stuff you can use Isnt going anywhere
  • Slide 9
  • Intro to Java (continued) The language (ehh) Wordy Fussy Complex Steep learning curve Good for engineers The programmers ($$$)
  • Slide 10
  • The Virtual Machine
  • Slide 11 >> from org.marc4j import * >>> from java.io import * >>> inStream = FileInputStream(">>> marcReader = MarcStreamReader( inStream )"> >> marcReader = MarcStreamReader( inStream ) >>> marcRecord = marcReader.next() >>> print marcRecord LEADER 01265nam 2200337 a 4500 001 ocm62127695 003 OCoLC 005 20060817030408.0 008 050921s2006 nyu c 000 1 eng 010 $a 2005027306 020 $a0316057533 (trade pbk.) 024 3 $a9780316057530 040 $aDLC$cDLC$dBAKER$dUOK 042 $alcac... Reading a MARC record (using marc4j) jruby require 'java' include_class ['org.marc4j.MarcStreamReader', 'java.io.FileInputStream'] inStream = FileInputStream.new "spl.marc" marcReader = MarcStreamReader.new inStream marcRecord = marcReader.next p marcRecord LEADER 01265nam 2200337 a 4500 001 ocm62127695 003 OCoLC 005 20060817030408.0 008 050921s2006 nyu c 000 1 eng 010 $a 2005027306 020 $a0316057533 (trade pbk.) 024 3 $a9780316057530 040 $aDLC$cDLC$dBAKER$dUOK 042 $alcac..."> >> marcReader = MarcStreamReader( inStream )" title="jython >>> from org.marc4j import * >>> from java.io import * >>> inStream = FileInputStream("spl.marc") >>> marcReader = MarcStreamReader( inStream )">
  • jython >>> from org.marc4j import * >>> from java.io import * >>> inStream = FileInputStream("spl.marc") >>> marcReader = MarcStreamReader( inStream ) >>> marcRecord = marcReader.next() >>> print marcRecord LEADER 01265nam 2200337 a 4500 001 ocm62127695 003 OCoLC 005 20060817030408.0 008 050921s2006 nyu c 000 1 eng 010 $a 2005027306 020 $a0316057533 (trade pbk.) 024 3 $a9780316057530 040 $aDLC$cDLC$dBAKER$dUOK 042 $alcac... Reading a MARC record (using marc4j) jruby require 'java' include_class ['org.marc4j.MarcStreamReader', 'java.io.FileInputStream'] inStream = FileInputStream.new "spl.marc" marcReader = MarcStreamReader.new inStream marcRecord = marcReader.next p marcRecord LEADER 01265nam 2200337 a 4500 001 ocm62127695 003 OCoLC 005 20060817030408.0 008 050921s2006 nyu c 000 1 eng 010 $a 2005027306 020 $a0316057533 (trade pbk.) 024 3 $a9780316057530 040 $aDLC$cDLC$dBAKER$dUOK 042 $alcac...
  • Slide 24
  • Z39.50 query w/Jython (using Jafer) Does a Z39.50 query and print out results as XML. from org.jafer.zclient import * from org.jafer.util.xml import DOMFactory, XMLSerializer from org.jafer.query import * from java.lang import * from java.io import StringWriter z = ZClient() z.setHost("z3950.loc.gov") z.setPort(7090) query = QueryBuilder() numHits = z.submitQuery( query.getNode("author", "Durfee")) z.setRecordCursor(1) sw = StringWriter() XMLSerializer.out( z.getCurrentRecord().getXML(), "xml", sw ) z.close() print sw
  • Slide 25
  • Z39.50 Query results Analytic philosophy and phenomenology / Durfee, Harold A.1920- text bibliography ne The Hague : Nijhoff, monographic 1976. eng viii, 277 p. ;24 cm. Includes index....
  • Slide 26
  • Less Quick Jython Example Lets create a report of circulation statistics and email it out as an Excel spreadsheet Well use a couple of java tools to make our lives easier Spring (http://www.springframework.org/ ) for database connectionhttp://www.springframework.org/ POI (http://jakarta.apache.org/poi/ ) to generate spreadsheethttp://jakarta.apache.org/poi/ SPL-developed convenience functions Same # of lines as Java email program
  • Slide 27
  • from spl.Horizon import DBWrapper from spl.misc import poi from spl.email import easyEmailSender import time conn = DBWrapper.DBWrapperFromProperties("horizon") checkoutsAndRenewalsQuery = """select sum(total) from stat_summary where location in ( '%(location)s' ) and stat_category = 'cko' and year = %(year)d and month = %(month)d and day = %(day)d""" checkinsQuery = """select sum(total) from stat_summary where location in ('%(location)s') and stat_category = 'cki' and year = %(year)d and month = %(month)d and day = %(day)d""" newBorrQuery = """select sum(total) from stat_summary where location in ('%(location)s') and stat_category = 'bordel' and year = %(year)d and month = %(month)d and day = %(day)d and stat_subcategory in ( '1', '3')""" LOCATIONS_TO_RUN_FOR = [ 'bea', 'bal', 'cen'] results = [ [ "Date", "Location", "Checkouts and Renewals", "Checkins", "New Borrowers"] ] date = time.strftime("%m-%d-%Y") month,day,year = date.split("-") for locationOn in LOCATIONS_TO_RUN_FOR: params = { 'location' : locationOn, 'year' : year, 'month' : month, 'day' : day } numCheckouts = conn.queryForInt( checkoutsAndRenewalsQuery % params ) numCheckins = conn.queryForInt( checkinsQuery % params ) numNewBorrowers = conn.queryForInt( newBorrQuery % params ) results.append( [ date, locationOn, numCheckouts, numCheckins, numNewBorrowers] ) fileName = "spl-circ-stats-%s.xls" % date poi.writeSpreadsheet( fileName, results ) sender = easyEmailSender.easyEmailSender("[email protected]", "Casey Durfee", "circ stats for %s" % date, "see attached spreadsheet" ) sender.setFileName( fileName, "statistics spreadsheet") sender.sendMessage()
  • Slide 28
  • Slide 29
  • Where do I go from here? Learn Python or Ruby first Even if you never use Jython/JRuby, it will be worth your time Learn a little bit about Java If only so you will know how good you have it Dont wait for the 8.0 APIs to be released
  • Slide 30
  • At my local Barnes and Noble, there is a huge wall of Java books just waiting to tip over and crush me one day. And one day it will. At the rate things are going, one day that bookcase will be tall enough to crush us all. It might even loop the world several times, crushing previous editions of the same Java books over and over again. --Why, Whys (poignant) Guide to Ruby
  • Slide 31
  • Getting Started with Python How to Think like a Computer Scientist Using Python (beginning) : http://www.ibiblio.org/obp/thinkCSpy/ http://www.ibiblio.org/obp/thinkCSpy/ Dive Into Python (advanced) http://www.diveintopython.org/ http://www.diveintopython.org/ Learning Python (ISBN 0596002815 ) Jython Essentials ( ISBN 0596002475 ) http://www.jython.org
  • Slide 32
  • Getting Started With Ruby Programming Ruby: The Pragmatic Programmers Guide : online at http://www.rubycentral.com/book/ (ISBN 0974514055 ) http://www.rubycentral.com/book/ Whys (poignant) guide to Ruby : http://poignantguide.net/ruby/ http://poignantguide.net/ruby/ http://www.jruby.org
  • Slide 33
  • Useful Java APIs Jafer (Z39.50): http://www.jafer.org Marc4j (MARC reader): http://marc4j.tigris.org POI (create MS Word/Excel files): http://jakarta.apache.org/poi