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

📄 multimediameta.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.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 + -