1

我正在尝试通过 Fedora Commons 网络服务进行搜索。我对findObjects方法很感兴趣。如何在 Java 中进行与findObjects 语法文档中描述的示例相同的搜索。

我对这种类型的请求特别感兴趣:

http://localhost:8080/fedora/search?terms=fedora&pid=true&title=true

我会附上一些代码,我有一个可以调用我的 Fedora 服务的类。

package test.fedora;

import info.fedora.definitions._1._0.types.DatastreamDef;
import info.fedora.definitions._1._0.types.MIMETypedStream;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;
import javax.xml.ws.BindingProvider;
import org.w3c.dom.Document;

public class FedoraAccessor {
    info.fedora.definitions._1._0.api.FedoraAPIAService service;
    info.fedora.definitions._1._0.api.FedoraAPIA port;
    final String username = "xxxx";
    final String password = "yyyy";

    public FedoraAClient() {
        service = new info.fedora.definitions._1._0.api.FedoraAPIAService();
        port = service.getFedoraAPIAServiceHTTPPort();
        ((BindingProvider) port.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
        ((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
    }

    public List findObjects() {
        //how?
    }

    public List<DatastreamDef> listDatastreams(String pid, String asOfTime) {
        List<DatastreamDef> result = null;
        try { 
            result = port.listDatastreams(pid, asOfTime);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return result;
    }
}
4

1 回答 1

1

从 mediashelf (http://mediashelf.github.com/fedora-client/) 使用客户端更容易。这是一个搜索标题中包含字符串 foobar 的对象的示例:

@Test
 public void doTest() throws FedoraClientException {
    connect();
    FindObjectsResponse response = null;

    response = findObjects().pid().title().query("title~foobar").execute(fedoraClient);
    List<String> pids = response.getPids();

    List<String> titles = new ArrayList<String>();
    for (String pid : pids) {
        titles.add(response.getObjectField(pid, "title").get(0));
    }
    assertEquals(7, titles.size());
  }
于 2012-02-10T14:52:00.363 回答