⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 photolsp.java

📁 数字图书馆的互操作接口
💻 JAVA
字号:
package dli2fe.sample;/** * Title:        Digial Library Interoperable Interface Fudan Edition * Description:  This project contains all the classes required for DLI2FE interface. Developers use these classes to implement the wrapper and client side codes. The basic functions of DLI2FE is as follows: * Search: Search a digital library source site. * Metadata: Fetch metadata for a site. * ResultAccess: Get results for a given query. * DLI2FE uses Dublin Core as the basic attribute model, DAV/DASL as the general XML-based query language and CORBA as distributed object transportation mechanism. * Copyright:    Copyright (c) 2001 * Company:      Fudan University * @author Carl Tao * @version 1.0 */import dli2fe.*;import javax.swing.Timer;import java.util.*;import java.awt.event.*;import dli2fe.helpers.*;public class PhotoLSP implements Metadata, Searcher, ResultAccess {  public static final String SHORT_NAME = "Photo";  static final String COLL_NAME = "图片收藏";  static final String FROM_CLAUSE = "Photo";  static final String Namespace = "http://cs.fudan.edu.cn/photo/#";  static final String shortNamespace = "photo";  static final String mmQueryURL = "http://localhost:8080/multimediasearch/MultimediaSearch?";  static final String metaQueryURL = "http://localhost:8080/SqlSocket/SqlSocket";  static int SIDGenerator = 0;  Hashtable sessions = new Hashtable();  public PhotoLSP() {  }  class Session implements ActionListener {    int SID;    MultimediaMeta mmphoto;    Timer timer;    PhotoLSP container;    boolean done;    long endTime;    Session(PhotoLSP plsp, XMLObject xmlQuery, XMLObject xmlPropList) throws DLI2FEException {      container = plsp;      SID = container.getNextSID();      mmphoto = new MultimediaMeta(container.shortNamespace, container.Namespace, container.mmQueryURL, container.metaQueryURL,        xmlQuery.getString(), xmlPropList.getString(), container.FROM_CLAUSE, "PhotoGroup.SightZone");      // No attribute translation needed for this LSP      endTime = System.currentTimeMillis() + DLI2FE.DEFAULT_TIMEOUT*1000;      timer = new Timer(DLI2FE.DEFAULT_TIMEOUT*1000, this);      timer.setRepeats(false);      timer.start();      done = false;      mmphoto.searchMultimediaMeta();      done = true;    }    public void extendTimeout(int seconds) {      endTime = System.currentTimeMillis() + seconds * 1000;      timer.stop();      timer.setDelay(seconds*1000);      timer.setRepeats(false);      timer.start();    }    public int getTimeout() {      return (int)((endTime - System.currentTimeMillis())/1000);    }    // for interface ActionListener to receive timer's message    public void actionPerformed(ActionEvent e) {      if (!done) {        timer.stop();        timer.setDelay(10000);        timer.setRepeats(false);        timer.start();      } else        container.removeSession(this);    }    public String createResult(String selection) throws DLI2FEException {      RangeEnumerator re = new RangeEnumerator(selection);      String result = "<SearchResult xmlns='" + DLI2FE.Namespace +"' xmlns:" + container.shortNamespace + "='" +        container.Namespace + "' xmlns:"+ MultimediaMeta.shortNamespace + "='" + MultimediaMeta.Namespace + "'>\n";      while (re.next()) {        result += mmphoto.getDoc(re.get() - 1) + "\n";      }      result += "</SearchResult>";      return result;    }    public MultimediaMeta getMultimediaMeta() {      return mmphoto;    }    public int getSessionID() {      return SID;    }    public String toString() {      return "[ SID : " + SID + "]";    }  }  public int getNextSID() {    return ++SIDGenerator;  }  public String toString() {    return "PhotoLSP";  }  public void addSession(Session session) {    sessions.put(new Integer(session.getSessionID()), session);  }  public void removeSession(Object handle) {    Session session = (Session)handle;    System.out.println("Session " + session + " timed out!");    sessions.remove(new Integer(session.getSessionID()));  }  String notNull(String str) {    return str == null ? "" : str;  }  // parse query XML String and stores arguments to temporary storage.  // XML query String example:  /*  */  public void getSiteMetadata (XMLObject theSiteMetadata) throws DLI2FEException{    theSiteMetadata.setString("<SiteMetadata xmlns='" + DLI2FE.Namespace +"'>\n<version>1.0</version> " +      "<collectionName>" + COLL_NAME + "</collectionName> <baseURI>dli2fens:http://localhost:9524/photo</baseURI> <ctgrName>Photo</ctgrName>\n" +      "<contentConstraint/> <boolOp>and</boolOp> <boolOp>or</boolOp> <language>zh_CN</language>\n</SiteMetadata>");  }  public void getAttributeInfo (String ctgrName,                                XMLObject attributeInfo) throws DLI2FEException {    if ("Photo".equals(ctgrName)) {      attributeInfo.setString("<AttributeInfo collectionName='" + COLL_NAME + "' xmlns='" + DLI2FE.Namespace + "' xmlns:" +        shortNamespace + "='" + Namespace + "' xmlns:mm='" + MultimediaMeta.Namespace + "'> \n" +        "<attr attrName='mm:image'><searchable/><operator>like</operator></attr>\n" +        "<attr attrName='mm:pfeedback'><searchable/><operator>eq</operator></attr>\n" +        "<attr attrName='mm:nfeedback'><searchable/><operator>eq</operator></attr>\n" +        "<attr attrName='mm:idmm'><retrievable/></attr>\n" +        "<attr attrName='" + shortNamespace + ":PhotoGroup.SightZone'><searchable/><retrievable/><operator>eq</operator></attr>" +        "<attr attrName='" + shortNamespace + ":PhotoGroup.SightLoc'><searchable/><retrievable/><operator>eq</operator></attr>" +        "<attr attrName='" + shortNamespace + ":PhotoGroup.Photographer.FirstName'><searchable/><retrievable/><operator>eq</operator></attr>" +        "<attr attrName='" + shortNamespace + ":PhotoGroup.Photographer.LastName'><searchable/><retrievable/><operator>eq</operator></attr>" +        "<attr attrName='" + shortNamespace + ":PhotoGroup.Description'><searchable/><retrievable/><operator>eq</operator></attr>" +        "<attr attrName='" + shortNamespace + ":PhotoGroup.Context'><searchable/><retrievable/><operator>eq</operator></attr>" +        "<attr attrName='" + shortNamespace + ":PhotoGroup.Photos.Photo'><searchable/><retrievable/><operator>eq</operator></attr>" +      "</AttributeInfo>");    }    else      throw new DLI2FEException(DLI2FEException.INVALID_REQUEST_EXC, "Category " + notNull(ctgrName) + " not supported.");  }  public void search (int clientSID,                      XMLObject subcols,                      XMLObject query,                      int numDocs,                      XMLObject docPropList,                      XMLObject queryOptions,                      org.omg.CORBA.IntHolder expectedTotal,                      org.omg.CORBA.IntHolder serverSID,                      XMLObject result) throws DLI2FEException {    //System.out.println("PhotoLSP:" + query.getString());    expectedTotal.value = Searcher.UNKNOWABLE;    // ignores clientSID, subcols, docPropList and queryOptions arguments    Session session = new Session(this, query, docPropList);    sessions.put(new Integer(session.getSessionID()), session);    serverSID.value = session.getSessionID();    if ((expectedTotal.value = session.getMultimediaMeta().getNumDocs()) == 0) {      return;    }    String selection = "1-";    if ( numDocs == Searcher.RETURN_ALL_DOCS || numDocs > expectedTotal.value)      selection += String.valueOf(expectedTotal.value);    else      selection += String.valueOf(numDocs);    String dbg = session.createResult(selection);    System.out.println(dbg);    result.setString(dbg);  }  public void getSessionInfo (int serverSID,                              org.omg.CORBA.IntHolder expectedTotal,                              org.omg.CORBA.IntHolder stateTimeout) throws DLI2FEException {    Session session = (Session)sessions.get(new Integer(serverSID));    if (session == null)      throw new DLI2FEException(DLI2FEException.INVALID_SESSIONID_EXC, "Invalid session ID.");    expectedTotal.value = session.getMultimediaMeta().getNumDocs();    stateTimeout.value = session.getTimeout();  }  public void getDocs (int serverSID,                       int reqID,                       XMLObject docPropList,                       String docsToGet,                       XMLObject res) throws DLI2FEException {    // ignores reqID, docPropList    Session session = (Session)sessions.get(new Integer(serverSID));    if (session == null)      throw new DLI2FEException(DLI2FEException.INVALID_SESSIONID_EXC, "Invalid session ID.");    res.setString(session.createResult(docsToGet));    //System.out.println("Carl wrote: " + docsToGet + "\n" + res.getString());  }  public void extendStateTimeout (int serverSID,                                  int secondsToExtend) throws DLI2FEException {    Session session = (Session)sessions.get(new Integer(serverSID));    if (session == null)      throw new DLI2FEException(DLI2FEException.INVALID_SESSIONID_EXC, "Invalid session ID.");    session.extendTimeout(secondsToExtend);  }  // Do nothing  public void cancelRequest (int serverSID,                             int reqID) throws DLI2FEException {    return;  }  public static void main(String[] args) throws Exception {  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -