要导入内容,您可以尝试两个选项:
要创建门户页面/组件(如图像、文件、html),您还可以使用 Portal/WCM api。但在导入内容之前,请确保您了解内容和组件之间的差异,并决定您要创建的内容 - 内容源等内容或组件。此外,关于以编程方式创建页面的信息也较少,但有可能。
如果您打算使用 JSR 286 portlet 来显示 contnet,请查看 XML Import tool。通过这种方式,您可以自动化配置并避免对每个页面进行手动配置。页面配置 - 它只是 xml 文件,您始终可以使用 java 修改此文件并为特定页面应用更新的文件。
更新
以编程方式创建门户页面
import com.ibm.portal.ModifiableMetaDataProvider;
import com.ibm.portal.content.*;
import com.ibm.portal.model.ContentModelHome;
import com.ibm.portal.model.ContentModelProvider;
import com.ibm.portal.model.controller.ContentModelControllerHome;
import com.ibm.portal.model.controller.CreationContextBuilderFactory;
import com.ibm.portal.model.controller.exceptions.CannotInstantiateControllerException;
import com.ibm.workplace.wcm.services.addressability.FriendlyURLFactoryImpl;
import com.ibm.wps.pe.pc.std.core.PortletUtils;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.portlet.*;
/**
* @author : Georgy Gobozov
* @created : 12.03.13
*/
public class PageUtil {
private static final String PREF_PARENT_PAGE = "parent.page.unique.name";
private static final String PREF_UNIQUE_PREFIX = "pages.unique.name.prefix";
public static boolean createPortalPage(String title, ActionRequest request, ActionResponse response) {
PortletPreferences prefs = request.getPreferences();
String parentPageUniqueName = prefs.getValue(PREF_PARENT_PAGE, "wps.content.root");
String uniqueNamePrefix = prefs.getValue(PREF_UNIQUE_PREFIX, "study.portal.pages.");
ContentModelController ctrl = null;
CreationContextBuilderFactory factory = null;
ContentPageCreationContext ctx = null;
ModifiableContentPage newPage = null;
ContentNode parent = null;
try {
ctrl = getController(request, response);
factory = CreationContextBuilderFactory.getInstance();
// Use the context to create the private page
ctx = factory.newContentPageCreationContext(true);
newPage = (ModifiableContentPage) ctrl.create(ContentPage.class, ctx);
newPage.setTitle(request.getLocale(), title);
// set page unique name
newPage.getModifiableObjectID().setUniqueName(uniqueNamePrefix + title);
parent = (ContentNode) ctrl.getLocator().findByUniqueName(parentPageUniqueName);
if (parent != null) {
ctrl.insert(newPage, parent, null);
// set friendly name
ModifiableMetaDataProvider mmdp = (ModifiableMetaDataProvider)ctrl.getModifiableNode(newPage);
mmdp.getModifiableMetaData().setValue("com.ibm.portal.friendly.name", title);
// Commit, i. e. persist the changes.
ctrl.commit();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != ctrl)
// Dispose the Controller.
ctrl.dispose();
}
return true;
}
public static ContentModelController getController(PortletRequest request, PortletResponse response) {
ContentModel aContentmodel = null;
ContentModelController ctrl = null;
ContentModelControllerHome home = null;
try {
Context ictx = new InitialContext();
ContentModelHome homea = (ContentModelHome) ictx.lookup("portal:service/model/ContentModel");
if (homea != null) {
ContentModelProvider provider = homea.getContentModelProvider();
PortletUtils.getInternalRequest(request).getHttpServletRequest();
//aContentmodel = provider.getContentModel((ServletRequest) request, (ServletResponse) response);
aContentmodel = provider.getContentModel(PortletUtils.getInternalRequest(request).getHttpServletRequest(), PortletUtils.getInternalResponse(response).getHttpServletResponse());
}
home = (ContentModelControllerHome) ictx.lookup(ContentModelControllerHome.JNDI_NAME);
if (home != null) {
try {
ctrl = home.getContentModelControllerProvider().createContentModelController(aContentmodel);
} catch (CannotInstantiateControllerException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return ctrl;
}
}
更有用的课程在这里