📄 multimedialiblsp.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 MultimediaLibLSP /*implements Metadata, Searcher, ResultAccess*/ { static final String COLL_NAME = "多媒体数字图书馆"; static final String FROM_CLAUSE = "Book"; //static final String Namespace = "http://cs.fudan.edu.cn/mmlib/#"; //static final String shortNamespace = "mml"; static final String queryURL = "http://localhost:8080/MultimediaSearch/MultimediaSearch?"; static int SIDGenerator = 0; Hashtable sessions = new Hashtable(); public MultimediaLibLSP() { } /*class Session implements ActionListener { int SID; MultimediaMeta mmlib; Timer timer; MultimediaLibLSP container; boolean done; long endTime; Session(MultimediaLibLSP tlsp, XMLObject xmlQuery, XMLObject xmlPropList) throws DLI2FEException { container = tlsp; SID = container.getNextSID(); mmlib = new MultimediaMeta("dc", DublinCore.Namespace, container.queryURL, xmlQuery.getString(), xmlPropList.getString(), container.FROM_CLAUSE); // add translation rules for attributes mmlib.addAttrTranlation("Title", "Description.OneDescription.Title"); mmlib.addAttrTranlation("Creator", "Description.OneDescription.Creator"); mmlib.addAttrTranlation("Description.Abstract", "Description.OneDescription.Description.Abstract"); mmlib.addAttrTranlation("Publisher.Distributor", "Description.OneDescription.Publisher.Distributor"); mmlib.addAttrTranlation("Contributor.Translator", "Description.OneDescription.Contributor.Translator"); mmlib.addAttrTranlation("Identifier", "Description.OneDescription.ResourceIdentifier"); endTime = System.currentTimeMillis() + DLI2FE.DEFAULT_TIMEOUT*1000; timer = new Timer(DLI2FE.DEFAULT_TIMEOUT*1000, this); timer.setRepeats(false); timer.start(); done = false; mmlib.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:dc='" + DublinCore.Namespace + "' xmlns:mm='" + MultimediaMeta.Namespace + "'>\n"; while (re.next()) { result += mmlib.getDoc(re.get() - 1) + "\n"; } result += "</SearchResult>"; return result; } public MultimediaMeta getMultimediaMeta() { return mmlib; } public int getSessionID() { return SID; } public String toString() { return "[ SID : " + SID + "]"; } } public int getNextSID() { return ++SIDGenerator; } public String toString() { return "MultimediaLibLSP"; } 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/</baseURI> <ctgrName>MultimediaLib</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 ("MultimediaLib".equals(ctgrName)) { attributeInfo.setString("<AttributeInfo collectionName='" + COLL_NAME + "' xmlns='" + DLI2FE.Namespace + "' xmlns:dc='" + DublinCore.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='dc:Title'><searchable/><retrievable>/<operator>like</operator></attr>" + "<attr attrName='dc:Creator'><searchable/><retrievable>/<operator>eq</operator></attr>" + "<attr attrName='dc:Description.Abstract'><searchable/><retrievable>/<operator>like</operator></attr>" + "<attr attrName='dc:Publisher.Distributor'><searchable/><retrievable>/<operator>like</operator></attr>" + "<attr attrName='dc:Contributor.Translator'><searchable/><retrievable>/<operator>like</operator></attr>" + "<attr attrName='dc:Identifier'><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 { 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)); } 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 + -