?? multimediameta.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.xml.*;
import dli2fe.DLI2FEException;
import dli2fe.DAV;
import dli2fe.helpers.*;
import java.util.*;
import org.w3c.dom.*;
import java.io.*;
import java.net.*;
/**
* This is the internal implmentation class of integrated source of Multimedia and
* metadata.
* This class will access highway servlet to query the integrated source.
* The highway servlet application will access MultimediaSearch and
*/
public class MultimediaMeta {
public static final String shortNamespace = "mm";
public static final String Namespace = "http://www.cs.fudan.edu.cn/multimedia/#";
public static final String image = "image";
public static final String pfeedback = "pfeedback";
public static final String nfeedback = "nfeedback";
public static final String idmm = "idmm";
//public static final String queryURL = "http://localhost:8080/highway/highway?";
public static final String SELECT = "select";
public static final String FROM = "from";
public static final String WHERE = "where";
public static final String serviceType = "SearchImageBySample";
public static final String serviceTypeDID = "SearchImageByDocumentID";
// 輸入參數
XMLObject xmlQuery;
XMLObject xmlPropList;
String sMetaNamespace;
String metaNamespace;
String mmQueryURL;
String metaQueryURL;
String strFromClause;
String dummyAttr; // 用于做空查詢返回文檔標志符的集合
// parsed query
XMLObject metaQuery = null;
String strSampleImage = "";
String strPFeedback = "";
String strNFeedback = "";
String strSelect = "";
String strWhere = "";
String strMetaQuery = "";
String[] propArray; // this array stores names of all of the properties
int numProp; // this is the total number of properties
XMLObject resultDocs; // store the whole result set generated from string
Vector elements; // store the pointers to each element in the result, the key is DID
int numDocs = 0;
Hashtable attrTransTable; // store the translations for attributes
/**
* Sample XMLQuery
<?xml version="1.0" encoding="GB2312" ?>
<basicsearch xmlns="http://www.cs.fudan.edu.cn/DLI2FE/1.0#"
xmlns:dc="http://purl.org/metadata/dublin_core#"
xmlns:mm="http://www.cs.fudan.edu.cn/multimedia/#">
<where>
<and>
<eq>
<prop><dc:Contributor><dc:Performer/></dc:Contributor></prop>
<literal>施伯樂</literal>
</eq>
<not>
<like>
<prop><dc:Publisher/></prop>
<literal>復旦</literal>
</like>
</not>
</and>
</where>
</basicsearch>
* Sample xmlPropList
<?xml version="1.0" encoding="GB2312" ?>
<proplist xmlns="http://www.cs.fudan.edu.cn/DLI2FE/1.0#"
xmlns:dc="http://purl.org/metadata/dublin_core#"
xmlns:mm="http://www.cs.fudan.edu.cn/multimedia/#">
<dc:Contributor>
<dc:Performer/>
<dc:Translator/>
</dc:Contributor>
<dc:Language/>
<mm:Image/>
</proplist>
*/
public MultimediaMeta(String strSNamespace, String strLNamespace, String strMmURL, String strMetaURL, String inXMLQuery, String inXMLPropList, String fromClause, String dummyAttribute ) throws DLI2FEException {
attrTransTable = new Hashtable();
sMetaNamespace = strSNamespace;
metaNamespace = strLNamespace;
mmQueryURL = strMmURL;
metaQueryURL = strMetaURL;
xmlQuery = new XMLObject(inXMLQuery);
xmlPropList = new XMLObject(inXMLPropList);
strFromClause = fromClause;
dummyAttr = dummyAttribute;
}
public String getShortMetaNamespace() {
return sMetaNamespace;
}
public String getMetaNamespace() {
return metaNamespace;
}
public String getMMQueryURL() {
return mmQueryURL;
}
public void addAttrTranlation(String attrOrig, String attrTranslated) {
attrTransTable.put(attrOrig, attrTranslated);
}
// Issue the search then buffer the result.
public void searchMultimediaMeta() throws DLI2FEException {
//輸入參數有:
// xmlQuery;
// xmlPropList;
// sMetaNamespace;
// metaNamespace;
// mmQueryURL;
// metaQueryURL;
// strFromClause
//其中:xmlQuery包含XML查詢語句,xmlPropList包含返回屬性列表,strFromClause指定元數據查詢的庫名
//第一步先分解XML查詢
MMQueryDecomposer qd = new MMQueryDecomposer(xmlQuery);
//并緩存參數
metaQuery = qd.getMetaQuery();
MetaQueryTranslator mqtran = new MetaQueryTranslator(metaQuery, attrTransTable, xmlPropList, strFromClause, dummyAttr);
strSampleImage = qd.getQueryImage(); // 多媒體查詢的SampleImage的URL
strPFeedback = qd.getQueryPFeedback(); // 多媒體查詢的正反饋參數
strNFeedback = qd.getQueryNFeedback(); // 多媒體查詢的負反饋參數
strSelect = mqtran.getSelectClause(); // 元數據查詢的Select子句(用于后續的流程判斷)
strWhere = mqtran.getWhereClause(); // 元數據查詢的Where子句(用于后續的流程判斷)
strMetaQuery = mqtran.getMetaQuery(); // 元數據查詢的整個查詢串
// 先處理極端情況
// 如果查詢與多媒體庫無關,則直接從元數據庫返回結果
if (isNull(strSampleImage) && !mqtran.returnImage()) {
MetaQueryHelper mqh = new MetaQueryHelper(metaQueryURL, strMetaQuery);
ResultMerger rm = new ResultMerger(this, xmlPropList, null, mqh);
elements = rm.getElementsTable();
resultDocs = rm.getXMLResult();
numDocs = rm.getNumDocs();
return;
}
// 如果查詢與元數據庫無關,則直接從多媒體庫查詢返回結果
if (isNull(strWhere) && isNull(strSelect)) {
MMQueryHelper mmqh = new MMQueryHelper(mmQueryURL);
mmqh.searchMultimedia(strSampleImage, strPFeedback, strNFeedback);
ResultMerger rm = new ResultMerger(this, xmlPropList, mmqh, null);
elements = rm.getElementsTable();
resultDocs = rm.getXMLResult();
numDocs = rm.getNumDocs();
return;
}
// 如果頂層邏輯是或,并且元數據查詢的條件非空,則強行置為空
if (!qd.isAnd() && !"".equalsIgnoreCase(strWhere.trim()) && !isNull(strSampleImage)) {
strMetaQuery = strMetaQuery.substring(0, strMetaQuery.lastIndexOf(" where "));
strWhere = "";
}
MMQueryHelper mmqh = null;
MetaQueryHelper mqh = null;
if (!isNull(strSampleImage)) {
mmqh = new MMQueryHelper(mmQueryURL);
mmqh.searchMultimedia(strSampleImage, strPFeedback, strNFeedback);
}
if (!isNull(strMetaQuery))
mqh = new MetaQueryHelper(metaQueryURL, strMetaQuery);
ResultMerger rm = new ResultMerger(this, xmlPropList, mmqh, mqh);
elements = rm.getElementsTable();
resultDocs = rm.getXMLResult();
numDocs = rm.getNumDocs();
}
public int getNumDocs() {
return numDocs;
}
public String getDoc(int idx) throws DLI2FEException {
if (idx < 0 || idx>=elements.size())
throw new DLI2FEException(DLI2FEException.INVALID_REQUEST_EXC, "Specified document not found: " + idx);
return ((Element)elements.elementAt(idx)).toString();
}
public XMLObject getXMLResult() {
return resultDocs;
}
boolean isNull(String s) {
if (s == null)
return true;
else if ("".equalsIgnoreCase(s.trim()))
return true;
else
return false;
}
public static void main(String[] args) {
try {
MultimediaMeta mm = new MultimediaMeta("ts", "http://cs.fudan.edu.cn/travel/#", "http://localhost:8080/multimediasearch/MultimediaSearch?", "http://localhost:8080/SqlSocket/SqlSocket",
//"<basicsearch xmlns='http://www.cs.fudan.edu.cn/DLI2FE/1.0#' xmlns:mm='http://www.cs.fudan.edu.cn/multimedia/#' xmlns:ts='http://cs.fudan.edu.cn/travel/#'><where><and><like><prop><mm:image/></prop><literal>http://localhost:8080/query/upload/q158liyjv2[3].jpg</literal></like><eq><prop><mm:pfeedback/></prop><literal>003_5+003_6+</literal></eq><eq><prop><mm:nfeedback/></prop><literal>004_3+004_2+</literal></eq></and></where></basicsearch>",
"<basicsearch xmlns='http://www.cs.fudan.edu.cn/DLI2FE/1.0#' xmlns:mm='http://www.cs.fudan.edu.cn/multimedia/#' xmlns:ts='http://cs.fudan.edu.cn/travel/#'><where><and><like><prop><mm:image/></prop><literal>http://localhost:8080/query/upload/q158liyjv2[3].jpg</literal></like></and></where></basicsearch>",
//"<basicsearch xmlns='http://www.cs.fudan.edu.cn/DLI2FE/1.0#' xmlns:dc='http://purl.org/metadata/dublin_core#' xmlns:mm='http://www.cs.fudan.edu.cn/multimedia/#'><where><and><like><prop><mm:image/></prop><literal>http://localhost:8080/query/upload/158ag7p2b1[3].JPEG</literal></like><eq><prop><mm:pfeedback/></prop><literal></literal></eq><eq><prop><mm:nfeedback/></prop><literal></literal></eq></and></where></basicsearch>",
//"<?xml version='1.0' encoding='GB2312' ?><basicsearch xmlns='http://www.cs.fudan.edu.cn/DLI2FE/1.0#' xmlns:mm='http://www.cs.fudan.edu.cn/multimedia/#' xmlns:ts='http://cs.fudan.edu.cn/travel/#'><where><like><prop><mm:image/></prop><literal>http://localhost:8080/multimediasearch/tempsample/first.jpg</literal></like></where></basicsearch>",
//"<?xml version='1.0' encoding='GB2312' ?><basicsearch xmlns='http://www.cs.fudan.edu.cn/DLI2FE/1.0#' xmlns:ts='http://cs.fudan.edu.cn/travel/#' xmlns:mm='http://www.cs.fudan.edu.cn/multimedia/#'><where><and> <or> <eq> <prop><ts:Scene.Location.Province/></prop> <literal>河北</literal> </eq> <eq> <prop><ts:Scene.Location.Province/></prop> <literal>山西</literal> </eq> </or> <eq> <prop><Scene.Culture.Figures.Figure/></prop> <literal>廉頗</literal> </eq> </and> </where> </basicsearch>",
//"<?xml version='1.0' encoding='GB2312' ?><basicsearch xmlns='http://www.cs.fudan.edu.cn/DLI2FE/1.0#' xmlns:ts='http://cs.fudan.edu.cn/travel/#' xmlns:mm='http://www.cs.fudan.edu.cn/multimedia/#'><where><and> <or> <eq> <prop><ts:Scene.Location.Province/></prop> <literal>河北</literal> </eq> <eq> <prop><ts:Scene.Location.Province/></prop> <literal>山西</literal> </eq> </or> <eq> <prop><Scene.Culture.Figures.Figure/></prop> <literal>廉頗</literal> </eq> <like><prop><mm:image/></prop><literal>http://localhost:8080/multimediasearch/tempsample/first.jpg</literal></like></and> </where> </basicsearch>",
//"<?xml version='1.0' encoding='GB2312' ?><basicsearch xmlns='http://www.cs.fudan.edu.cn/DLI2FE/1.0#' xmlns:ts='http://cs.fudan.edu.cn/travel/#' xmlns:mm='http://www.cs.fudan.edu.cn/multimedia/#'><where><or> <eq> <prop><Scene.Culture.Figures.Figure/></prop> <literal>廉頗</literal> </eq> <like><prop><mm:image/></prop><literal>http://localhost:8080/multimediasearch/tempsample/first.jpg</literal></like></or> </where> </basicsearch>",
"<?xml version='1.0' encoding='GB2312' ?><proplist xmlns='http://www.cs.fudan.edu.cn/DLI2FE/1.0#' xmlns:mm='http://www.cs.fudan.edu.cn/multimedia/#' xmlns:ts='http://cs.fudan.edu.cn/travel/#'> <mm:idmm/> <ts:Scene.Name/> <ts:Scene.Alias/> <ts:Scene.Location.Province/> <ts:Scene.SubSights.SubSight/> <ts:Scene.Location.DetailLoc/></proplist>",
//"<?xml version='1.0' encoding='GB2312' ?><proplist xmlns='http://www.cs.fudan.edu.cn/DLI2FE/1.0#' xmlns:mm='http://www.cs.fudan.edu.cn/multimedia/#' xmlns:ts='http://cs.fudan.edu.cn/travel/#'> <mm:image/></proplist>",
//"<?xml version='1.0' encoding='GB2312' ?><proplist xmlns='http://www.cs.fudan.edu.cn/DLI2FE/1.0#' xmlns:mm='http://www.cs.fudan.edu.cn/multimedia/#' xmlns:ts='http://cs.fudan.edu.cn/travel/#'> <ts:Scene.Name/> <ts:Scene.SubSights.SubSight/> <ts:Scene.Location.DetailLoc/></proplist>",
"Sight", "Scene.Name");
mm.searchMultimediaMeta();
System.out.println(mm.getXMLResult().getString());
} catch (DLI2FEException ex) {
System.out.println(ex.getReason());
ex.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -