Sitemap customization within WebCenter Portal is a lot easier than it may seem.
Within web.xml the sitemap servlet is defined as per below.
Conveniently, there is also a method available to retrieve the default sitemap. This sitemap is generated from the default-navigation-model.xml.
import oracle.webcenter.portalframework.sitestructure.preference.PortalPreferences;
String siteMap = "";
siteMap = PortalPreferences.getInstance().getSiteMap();
As such all you need to do is perform a find and replace within the siteMap string in order to manipulate your result or return your own customized sitemap from the servlet.
A sample of the full servlet is below:
package test_portal.portal.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import oracle.webcenter.portalframework.sitestructure.preference.PortalPreferences;
public class SiteMapServlet extends HttpServlet {
transient ServletConfig config = null;
public void init(ServletConfig config) throws ServletException {
this.config = config;
super.init(config);
}
public void doGet(javax.servlet.http.HttpServletRequest httpRequest, javax.servlet.http.HttpServletResponse httpResponse) throws IOException {
httpResponse.setContentType("text/xml");
PrintWriter out = httpResponse.getWriter();
String siteMap = "";
siteMap = PortalPreferences.getInstance().getSiteMap();
siteMap = siteMap.replaceAll("/faces/testNav","http://sample.com");
siteMap = siteMap.replaceAll("/faces/home","http://sample.com/");
siteMap = siteMap.replaceAll("\\?wcnav.model=%2Foracle%2Fwebcenter%2Fportalapp%2Fnavigations%2Fdefault-navigation-model","");
siteMap = siteMap.replaceAll("</loc>","</loc> \r <changefreq>weekly</changefreq>");
out.println(siteMap);
out.close();
}
}
No comments:
Post a Comment