gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 12:06:00 25 4
gpt4 key购买 nike

我有一个修改过的 ItemRequestForm.java 版本,以前在版本 5x 中工作过。在 item-view.xsl 中,我创建了一个链接,单击该链接后,会将用户重定向到此修改后的表单。此链接的 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");

下面是另一个导致句柄为空的尝试
    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 stacktrace,它指向这行代码: DSpaceObject dso = handleService.resolveToObject(context, handle) 。似乎未加载 句柄 的值。

我应该修改代码的哪一部分,以便我可以成功地将用户从 http://example.com/documentdelivery/123456789/1234 重定向到 http://example.com/handle/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");

提前致谢。

最佳答案

最后,我设法让它工作。我还根据我之前的帖子显示了其他元数据字段:Getting other metadata in ItemRequestForm in DSpace 6x

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();

关于java - 获取 ItemRequestForm.java 的修改版本以在 DSpace 版本 6x 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61585459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com