作者:手机用户2502905845 | 来源:互联网 | 2024-12-02 17:02
本文详细介绍了Java中`org.sakaiproject.site.api.Site.addPage()`方法的功能和使用方法,并提供了多个实际项目中的代码示例。
在Java开发中,特别是在使用Sakai框架时,`org.sakaiproject.site.api.Site.addPage()`方法是一个非常实用的功能,用于在站点中动态创建新的页面。本文不仅解释了该方法的基本功能,还通过具体的代码示例展示了其在不同场景下的应用。
方法概述
该方法属于`Site`类,位于`org.sakaiproject.site.api`包下。其主要作用是在现有的站点中创建一个新的页面,并将该页面添加到站点中。
方法描述
英文描述:Create a new site page and add it to this site.
中文描述:创建新站点页面并将其添加到当前站点。
代码示例
以下是几个从GitHub、StackOverflow等平台收集的实际项目中的代码片段,这些示例可以帮助开发者更好地理解和应用`Site.addPage()`方法。
示例1(来源:org.sakaiproject/sakai-web-impl):
SitePage page = site.addPage();
page.setTitle(pageTitle);
ToolConfiguration tool = page.addTool();
示例2(来源:org.sakaiproject/sakai-news-impl):
SitePage page = site.addPage();
page.setTitle(pageTitle);
ToolConfiguration tool = page.addTool();
示例3(来源:org.sakaiproject.profile2/profile2-impl):
SitePage toolPage = site.addPage();
toolPage.addTool(toolId);
// 重复创建工具页面
SitePage toolPage2 = site.addPage();
toolPage2.addTool(toolId);
示例4(来源:org.sakaiproject.basiclti/basiclti-impl):
SitePage sitePage = site.addPage();
示例5(来源:org.sakaiproject.basiclti/basiclti-impl):
results.append(", merging basicLTI tool " + basicLTI.getPageTitle());
SitePage sitePage = site.addPage();
sitePage.setTitle(basicLTI.getPageTitle());
示例6(来源:org.sakaiproject/sakai-news-impl):
SitePage page = toSite.addPage();
page.setTitle(pageTitle);
ToolConfiguration tool = page.addTool();
示例7(来源:org.sakaiproject/sakai-web-impl):
SitePage page = toSite.addPage();
page.setTitle(pageTitle);
ToolConfiguration tool = page.addTool();
示例8(来源:sakaiproject/sakai):
protected boolean updateSite(JobExecutionContext context, Site site) throws JobExecutionException {
String toolId = context.getMergedJobDataMap().getString("tool");
if (toolId == null || toolId.isEmpty()) {
throw new JobExecutionException("tool isn't set in job data.");
}
Tool tool = toolManager.getTool(toolId);
if (tool == null) {
throw new JobExecutionException("Failed to find tool with id: " + toolId);
}
ToolConfiguration toolCOnfiguration= site.getToolForCommonId(toolId);
if (toolCOnfiguration== null) {
SitePage page = site.addPage();
page.setTitle(tool.getTitle());
page.addTool(tool);
try {
siteService.save(site);
return true;
} catch (IdUnusedException | PermissionException e) {
log.warn("Failed to save site: " + site.getId(), e);
}
} else {
log.debug(String.format("Site: %s already has tool: %s on page: %s",
site.getId(), toolId, toolConfiguration.getContainingPage().getId()));
}
return false;
}
示例9(来源:org.sakaiproject.scheduler/scheduler-component-shared):
protected boolean updateSite(JobExecutionContext context, Site site) throws JobExecutionException {
String toolId = context.getMergedJobDataMap().getString("tool");
if (toolId == null || toolId.isEmpty()) {
throw new JobExecutionException("tool isn't set in job data.");
}
Tool tool = toolManager.getTool(toolId);
if (tool == null) {
throw new JobExecutionException("Failed to find tool with id: " + toolId);
}
ToolConfiguration toolCOnfiguration= site.getToolForCommonId(toolId);
if (toolCOnfiguration== null) {
SitePage page = site.addPage();
page.setTitle(tool.getTitle());
page.addTool(tool);
try {
siteService.save(site);
return true;
} catch (IdUnusedException | PermissionException e) {
log.warn("Failed to save site: " + site.getId(), e);
}
} else {
log.debug(String.format("Site: %s already has tool: %s on page: %s",
site.getId(), toolId, toolConfiguration.getContainingPage().getId()));
}
return false;
}
示例10(来源:org.sakaiproject/sakai-citations-impl):
SitePage page = adminSite.addPage();
page.setTitle("Resources");
page.addTool("sakai.resources");
示例11(来源:org.sakaiproject.profile2/profile2-impl):
private void addHomePageAndTools(final Site site) {
SitePage homePage = site.addPage();
homePage.getPropertiesEdit().addProperty(SitePage.IS_HOME_PAGE, Boolean.TRUE.toString());
Tool homeTool = sakaiProxy.getTool(HOME_TOOL);
ToolConfiguration homeToolCOnfig= homePage.addTool();
homeToolConfig.setTool(TOOL_ID_HOME, homeTool);
homeToolConfig.setTitle(homeTool.getTitle());
List toolIds = sakaiProxy.getToolsRequired(SITE_TYPE_PROJECT);
int synopticToolIndex = addRequiredToolsForWorksite(site, homePage, toolIds);
if (synopticToolIndex > 0) {
homePage.setLayout(SitePage.LAYOUT_DOUBLE_COL);
}
addRequiredHomeTools(homePage, toolIds, synopticToolIndex);
}