获取 ItemRequestForm.java 的修改版本以在 DSpace 版本 6x 中工作

Getting a modified version of ItemRequestForm.java to work in DSpace version 6x

我有一个修改过的 ItemRequestForm.java 版本,它以前在 5x 版本中工作过。在 item-view.xsl 中,我创建了一个 link,当单击它时,会将用户重定向到这个修改后的表单。这个 link 的 URL 模式是 http://example.com/documentdelivery/123456789/1234。当我将我的 DSpace 版本升级到 6x 时,我很难让它工作。由于版本 5 和 6 之间的主要代码重构,我发现很难将我的代码迁移到最新版本。

下面是在版本 5x (DocumentDeliveryForm.java)

中工作的部分代码

代码主要基于这个答案:How can I get the title of the referring page (item) from a modified version of feedback page in DSpace?

    String handle=parameters.getParameter("handle","unknown");
    DSpaceObject dso = HandleManager.resolveToObject(context, handle);
    if (!(dso instanceof Item)) {
        return;
    }
    Request request = ObjectModelHelper.getRequest(objectModel);
    boolean firstVisit=Boolean.valueOf(request.getParameter("firstVisit"));

    Item item = (Item) dso;

    // Build the item viewer division.
    Division documentdelivery = body.addInteractiveDivision("DocumentDelivery-form",
            contextPath+"/documentdelivery/"+parameters.getParameter("handle","unknown"),Division.METHOD_POST,"primary");

当我升级到版本 6 时,我发现 DSpaceObject dso = HandleManager.resolveToObject(context, handle) 不再有效,所以我将其替换为 DSpaceObject dso = handleService.resolveToObject(context, handle)

下面是我尝试将我的 5x 代码迁移到 6x(结果:java.lang.NullPointerException)

    String handle=parameters.getParameter("handle","unknown");
    DSpaceObject dso = handleService.resolveToObject(context, handle);
    if (!(dso instanceof Item)) {
        return;
    }
    Request request = ObjectModelHelper.getRequest(objectModel);
    Item item = (Item) dso;

    // Build the item viewer division.
    Division documentdelivery = body.addInteractiveDivision("DocumentDelivery-form",
            request.getRequestURI() + "/documentdelivery/" + item.getHandle(), Division.METHOD_POST,"primary");

下面是另一个导致 Handle is null 的尝试

    Request request = ObjectModelHelper.getRequest(objectModel);
    String handle = request.getParameter("handle");
    DSpaceObject dso = handleService.resolveToObject(context, handle);
    if (!(dso instanceof Item)) {
        return;
    }
    boolean firstVisit=Boolean.valueOf(request.getParameter("firstVisit"));

    Item item = (Item) dso;

    // Build the item viewer division.
    Division documentdelivery = body.addInteractiveDivision("DocumentDelivery-form",
            contextPath+"/documentdelivery/"+parameters.getParameter("handle","unknown"),Division.METHOD_POST,"primary");

查看 java 堆栈跟踪,它指向这行代码:DSpaceObject dso = handleService.resolveToObject(context, handle)handle 的值似乎没有被加载。

我应该修改我的代码的哪一部分,以便我可以成功地将用户从 http://example.com/handle/123456789/1234 重定向到 http://example.com/documentdelivery/123456789/1234

哪个项目查看器划分的结构是正确的?

    Division documentdelivery = body.addInteractiveDivision("DocumentDelivery-form",
            request.getRequestURI() + "/documentdelivery/" + item.getHandle(), Division.METHOD_POST,"primary");

    Division documentdelivery = body.addInteractiveDivision("DocumentDelivery-form",
            contextPath+"/documentdelivery/"+parameters.getParameter("handle","unknown"),Division.METHOD_POST,"primary");

提前致谢。

最后,我设法让它工作了。我还根据我之前的 post 在这里显示了其他元数据字段:

public void addBody(Body body) throws SAXException, WingException,
        UIException, SQLException, IOException, AuthorizeException
{
    Request request = ObjectModelHelper.getRequest(objectModel);

    // Build the item viewer division.
    Division documentdelivery = body.addInteractiveDivision("documentdelivery-form",
            contextPath+"/documentdelivery/"+parameters.getParameter("handle", "unknown"),Division.METHOD_POST,"primary");

    documentdelivery.setHead(T_head);

    String handle = parameters.getParameter("handle","unknown");
    DSpaceObject dso = handleService.resolveToObject(context, handle);
    Item item = (Item) dso;

    String citationDC = itemService.getMetadataFirstValue(item, "dc", "identifier", "citation", org.dspace.content.Item.ANY);
    String titleDC = item.getName();
    String title = "";
    if (citationDC != null && citationDC.length() > 0) {
        title = citationDC;
    } else {
        if (titleDC != null && titleDC.length() > 0)
            title = titleDC;
    }
    documentdelivery.addPara(title);

我还添加了必要的导入:

import org.dspace.content.service.ItemService;
import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService;

我还添加了这些:

    private final transient ItemService itemService = ContentServiceFactory.getInstance().getItemService();
    private final transient HandleService handleService = HandleServiceFactory.getInstance().getHandleService();