Skip to Content

Earlier this year I wrote a blog that described a portal component that could be used to find recently modified PCD objects. This would allow a content administrator to find PCD objects that had been changed and report these in reverse date order.

The other day I read an SAP How To Guide that covered transporting portal content. It is available here. This document mentioned that since EP6 SP9 exporting PCD content caused a specially formatted file to be generated which contained details of the export.

package com.sap.anz;

import java.io.File;

import java.io.IOException;

import java.text.DecimalFormat;

import java.text.SimpleDateFormat;

import java.util.Collections;

import java.util.Comparator;

import java.util.Date;

import java.util.Hashtable;

import java.util.Locale;

import java.util.Vector;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.naming.NameClassPair;

import javax.naming.NamingEnumeration;

import javax.naming.NamingException;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

import org.xml.sax.SAXException;

import com.sap.ip.portal.service.ume.IUserManagementEngine;

import com.sap.portal.pcm.iview.IiViews;

import com.sap.security.api.IUser;

import com.sap.security.api.UMException;

import com.sap.security.api.srvUser.IServiceUserFactory;

import com.sapportals.htmlb.Form;

import com.sapportals.htmlb.GridLayout;

import com.sapportals.htmlb.Group;

import com.sapportals.htmlb.MessageBar;

import com.sapportals.htmlb.enum.GroupDesign;

import com.sapportals.htmlb.enum.MessageType;

import com.sapportals.htmlb.enum.TableColumnType;

import com.sapportals.htmlb.page.DynPage;

import com.sapportals.htmlb.page.PageException;

import com.sapportals.htmlb.table.DefaultTableViewModel;

import com.sapportals.htmlb.table.TableView;

import com.sapportals.portal.htmlb.page.PageProcessorComponent;

import com.sapportals.portal.pcd.gl.IAcl;

import com.sapportals.portal.pcd.gl.IAclHandle;

import com.sapportals.portal.pcd.gl.IPcdAttribute;

import com.sapportals.portal.pcd.gl.IPcdContext;

import com.sapportals.portal.pcd.gl.IPcdGlService;

import com.sapportals.portal.pcd.gl.IPcdObjectFactory;

import com.sapportals.portal.prt.component.IPortalComponentContext;

import com.sapportals.portal.prt.component.IPortalComponentProfile;

import com.sapportals.portal.prt.component.IPortalComponentRequest;

import com.sapportals.portal.prt.component.IPortalComponentResponse;

import com.sapportals.portal.prt.runtime.PortalRuntime;

public class PCDPlusTransports extends PageProcessorComponent {

  public DynPage getPage() {

    return new PCDPlusTransportsDynPage();

  }

  public static class PCDPlusTransportsDynPage extends DynPage {

          private final String PCDCONTEXT =

               “com.sapportals.portal.pcd.gl.IPcdContext”;

          private final String PCDIVIEW =

               “com.sapportals.portal.ivs.iviews.IPortalIview”;

          private final String PCDPAGE =

               “com.sapportals.portal.ivs.iviews.IPortalPage”;

          private final String PCDROLE =

               “com.sapportals.portal.pcd.pcm.roles.IRoleDescriptor”;

          private final String PCDWORKSET =

               “com.sapportals.portal.pcd.pcm.roles.IWorksetDescriptor”;

          private final String PCDSYSTEM =

               “com.sapportals.iviewserver.systemlandscape.service.ISystemObject”;

          private final String PCDLAYOUT =

               “com.sapportals.portal.ivs.iviews.ILayout”;

          private final String PCDRULE =

               “com.sapportals.portal.resolving.sl.IRulePcmObject”;

          private final String PCDPACKAGE =

               “com.sapportals.portal.transport.app.IPcmTransportPackage”;

          private final String PCDTHEME =

               “com.sapportals.portal.style.IPortalStyle”;

          private final String PCDDESKTOP =

               “com.sap.portal.productivity.desktop.IDesktop”;

          /**

          

  • Initialization code executed once per user.

          */

          IPortalComponentRequest request;

          IPortalComponentResponse response;

          IPortalComponentContext myContext;

          String path = System.getProperty(“j2ee.path”).toString();

          String divider = System.getProperty(“file.separator”).toString();

          String dirname =

          path + divider + “temp”divider“pcd”divider“transport”divider“reports”divider“Export”;

          IUser mainUser = null;

          Locale userLocale = null;

          SimpleDateFormat sdf = new SimpleDateFormat(“yyyyMMddHHmmss”);

          Vector objects = new Vector();

          Vector sortObjects = new Vector();

          Vector transports = new Vector();

          Integer objectCounter = new Integer(0);

          DecimalFormat z4 = new DecimalFormat(“####”);

          IPortalComponentProfile profile;

          String messageText = “”;

          int tvtSelectedRow = 0;

          public void doInitialization() {

               response = (IPortalComponentResponse) this.getResponse();

               request = (IPortalComponentRequest) this.getRequest();

               profile = request.getComponentContext().getProfile();

               myContext = request.getComponentContext();

               userLocale = request.getUser().getLocale();

               getTransports();

               getPCDobjects();

          }

          

          public void getTransports() {

               File dir = new File(dirname);

               File[] files = dir.listFiles();

               for (int i = 0; i  b

               // 0 if a == b

               // -1 (or any -ve number) if a < b

               public final int compare(Object a, Object b) {

                    return – ((String) a).compareTo((String) b);

               } // end compare

          } // end class DescendingStringComparator

          /**

          

  • Input handling code. In general called the first time with the second page request from the user.

           */

          public void doProcessAfterInput() throws PageException {

          }

          /**

          

  • Create output. Called once per request.

           */

          public void doProcessBeforeOutput() throws PageException {

               Form myForm = this.getForm(); // get the form from DynPage

               Group myGroup = new Group();

               myGroup.setWidth(“700”);

               myGroup.setTitle(“PCD objects and their transports”);

               myGroup.setDesign(GroupDesign.SAPCOLOR);

               myForm.addComponent(myGroup);

               int row = 1;

               TableView tvp = new TableView(“tvp”);

               Vector colName = new Vector();

               /* Define column names */

               colName.addElement(“Modified”);

               colName.addElement(“Type”);

               colName.addElement(“Id”);

               colName.addElement(“User”);

               colName.addElement(“PCD location (pcd:portal_content)”);

               colName.addElement(“Title”);

               colName.addElement(“Latest transport”);

               colName.addElement(“Status”);

//               colName.addElement(“DateTime”);

               Vector data = new Vector();

               for (int i = 0; i < sortObjects.size(); i++) {
// response.write(“
“+sortObjects.elementAt(i).toString());
Integer c =
new Integer(
sortObjects.elementAt(i).toString().substring(14, 18));
Vector thispcdobject = (Vector) objects.elementAt(c.intValue());
data.addElement(thispcdobject);
}
DefaultTableViewModel tvpModel =
new DefaultTableViewModel(data, colName);
myContext.putValue(“tvpModel”, tvpModel);
tvp.setModel(tvpModel);
// tvp.setColumnType(TableColumnType.INPUT, 8);
tvp.setVisibleRowCount(sortObjects.size());
tvp.setFooterVisible(false);
tvp.setHeaderText(“Recently changed PCD objects and their transports”);

GridLayout gl = new GridLayout();
gl.setCellSpacing(4);
int grow = 1;
MessageBar mb = new MessageBar(“mb”);
mb.setMessageText(messageText);
if (!messageText.equals(“”)) {
mb.setMessageType(MessageType.ERROR);
gl.addComponent(grow, 1, mb);
grow++;
}
gl.addComponent(grow, 1, tvp);
myGroup.addComponent(gl);
// myGroup.addComponent(tvp);

// create your GUI here….

}
private void list_context(
// IPortalComponentRequest request,
IPortalComponentResponse response,
Context initialContext,
String browsing_root) {

NamingEnumeration names;

try {
IPcdContext t =
(IPcdContext) initialContext.lookup(browsing_root);
IAclHandle myHandle = t.getAclHandle();
IAcl ownAcl = myHandle.getOwnAcl();

names = initialContext.list(browsing_root);

if ((names != null) && (names.hasMoreElements())) {
NameClassPair nameClass;
while (names.hasMore()) {
nameClass = (NameClassPair) names.next();
String new_root =
browsing_root + “/” + nameClass.getName();
if (nameClass.getClassName().equals(PCDCONTEXT)) {
//FOLDER, so list its contents

list_context(response, initialContext, new_root);
} else {
boolean found = false;

// ignore some SAP supplied objects
//
if (!(new_root.indexOf(“com.sap.ip.collab”) > 0
|| new_root.indexOf(“com.sap.portal.”) > 0
|| new_root.indexOf(“com.sap.netweaver.”) > 0
|| new_root.indexOf(“/com.sap.pct/”) > 0
|| new_root.indexOf(“com.sap.pct.”) > 0)) {
if (nameClass
.getClassName()
.equals(PCDIVIEW)) {
//IVIEW
found =
showDetails(
initialContext,
new_root,
“IVU “,
response);
}
if (nameClass.getClassName().equals(PCDPAGE)) {
//PAGE
found =
showDetails(
initialContext,
new_root,
“PAGE”,
response);
}
if (nameClass
.getClassName()
.equals(PCDWORKSET)) {
//WORKSET
found =
showDetails(
initialContext,
new_root,
“WKST”,
response);
}
if (nameClass.getClassName().equals(PCDROLE)) {
//ROLE
found =
showDetails(
initialContext,
new_root,
“ROLE”,
response);
}
if (nameClass.getClassName().equals(PCDRULE)) {
//RULE
found =
showDetails(
initialContext,
new_root,
“RULE”,
response);
}
if (nameClass
.getClassName()
.equals(PCDLAYOUT)) {
//LAYOUT
found =
showDetails(
initialContext,
new_root,
“LAYO”,
response);
}
if (nameClass
.getClassName()
.equals(PCDTHEME)) {
//THEME
found =
showDetails(
initialContext,
new_root,
“THEM”,
response);
}
if (nameClass
.getClassName()
.equals(PCDPACKAGE)) {
//PACKAGE
found =
showDetails(
initialContext,
new_root,
“TPKG”,
response);
}
if (nameClass
.getClassName()
.equals(PCDSYSTEM)) {
//SYSTEM
found =
showDetails(
initialContext,
new_root,
“SYST”,
response);
}
if (nameClass
.getClassName()
.equals(PCDDESKTOP)) {
//DESKTOP
found =
showDetails(
initialContext,
new_root,
“DSKT”,
response);
}
}
}
}
}
} catch (Exception e) {
response.write(e.toString());

}
}
public boolean showDetails(
Context initialContext,
String object,
String type,
IPortalComponentResponse response) {
Hashtable env = new Hashtable();

try {
String title = “”;
String lastChangedBy = “”;
String firstChangedBy = “”;
Date lastChangedOn = new Date();
Date firstChangedOn = new Date();
IPcdContext targetobject =
(IPcdContext) initialContext.lookup(object);
Object obj = null;

obj =
targetobject.getAttributes(“”).get(
“com.sap.portal.pcm.Title”);
if (obj == null) {
title = “Null title”;
if (type.equals(“THEM”))
title =
(String) targetobject
.getAttributes(“”)
.get(“com.sapportals.portal.style.name”)
.get()
.toString();
// else
// response.write(“
“+type+
// targetobject.getAttributes(“”).toString());
} else {

if (obj instanceof IPcdAttribute) {
IPcdAttribute att = (IPcdAttribute) obj;
// title=att.get(request.getLocale());
title = att.get(userLocale);
} else
title = “No title”;
};

lastChangedBy =
targetobject
.getAttributes(“”)
.get(“com.sap.portal.pcd.gl.LastChangedBy”)
.get()
.toString();
firstChangedBy =
targetobject
.getAttributes(“”)
.get(“com.sap.portal.pcd.gl.CreatedBy”)
.get()
.toString();
firstChangedOn =
(Date) (targetobject
.getAttributes(“”)
.get(“com.sap.portal.pcd.gl.CreatedAt”)
.get());
lastChangedOn =
(Date) (targetobject
.getAttributes(“”)
.get(“com.sap.portal.pcd.gl.LastChangedAt”)
.get());
int lastSlash = object.lastIndexOf(“/”);
Vector thisObject = new Vector();

// add entries, unless…
// they have been changed by SAP or SAP*
// they were created before 01/01/2005

if (!lastChangedBy.equals(“SAP”)
&& !lastChangedBy.equals(“SAP*”)
&& sdf.format(lastChangedOn).compareTo(“20050101000000”) > 0) {

                         thisObject.add(lastChangedOn); // date

                         thisObject.add(type); // type

                         thisObject.add(

                              object.substring(lastSlash + 1, object.length()));

                         // name

                         thisObject.add(lastChangedBy); // owner

                         String path = object.substring(0, lastSlash + 1).replaceFirst(“portal_content”,””);

                         if (path.length()<50) {

                              thisObject.add(path);

                         } else {

                              thisObject.add(path.substring(0,20)“…”path.substring(path.length()-30));

                              }                         // location

                         thisObject.add(title);

                         String thisTransport = “No transport found”;

                         String thisStatus = “”;

                         for (int i=0;i<transports.size();i++) {

                              Vector testline = (Vector) transports.elementAt(i);

                              String thisDate = testline.elementAt(0).toString().substring(0,18);

                              thisDate = thisDate.substring(0,4)+

                                   thisDate.substring(5,7)+

                                   thisDate.substring(8,10)+

                                   thisDate.substring(10,12)+

                                   thisDate.substring(13,15)+

                                   thisDate.substring(16,18);

                              String thisObj = testline.elementAt(0).toString().substring(18);

                              if (thisObj.equals(object.substring(14))) {

                                   int p = testline.elementAt(1).toString().lastIndexOf(divider);

                                   thisTransport = testline.elementAt(1).toString().substring(p+1);

                                   thisStatus = “Latest version exported”;

                                   if (thisDate.compareTo(sdf.format(lastChangedOn))<0) {

                                        thisStatus = “Newer version in PCD”;

                                   }

                              }

                         };                         

                         thisObject.addElement(thisTransport);

                         thisObject.addElement(thisStatus);

//                         thisObject.addElement(thisStatus);

                         objects.add(thisObject);

                         z4.setMinimumIntegerDigits(4);

                         z4.setMaximumFractionDigits(0);

                         sortObjects.add(

                              sdf.format(lastChangedOn)

                                   + z4.format(objectCounter.longValue()));

                         objectCounter = new Integer(objectCounter.intValue() + 1);

                    }

                    return true;

               } catch (Exception e) {

                    response.write(“naming error ” + e.getMessage());

                    return false;

               }

          }

          public InitialContext getEnvironment(IPortalComponentRequest request) {

               InitialContext initialContext = null;

               try {

                    IUser principalObj = null;

                    // set the security principal

                    principalObj = this.getServiceUser(“pcd_service”);

                    Hashtable env =new Hashtable();

                    env.put(

                         Context.INITIAL_CONTEXT_FACTORY,

                         “com.sapportals.portal.pcd.gl.PcdInitialContextFactory”);

                    if (principalObj != null) {

                         env.put(Context.SECURITY_PRINCIPAL, principalObj);

                    }

                    env.put(

                         “com.sap.portal.jndi.requested_aspect”,

                         “com.sap.portal.pcd.gl.PersistencyAspect”);

                    env.put(“java.naming.factory.object”, “__IPcdContext__”);

                    initialContext = new InitialContext(env);

               } catch (NamingException e) {

                    response.write(

                         “Failed to initialize environment ” + e.toString());

               }

               return initialContext;

          }

          public IUser getServiceUser(String username) {

               IPortalComponentResponse response =

                    (IPortalComponentResponse) this.getResponse();

               IUser serviceUser = null;

               IUserManagementEngine ume =

                    (IUserManagementEngine) PortalRuntime

                         .getRuntimeResources()

                         .getService(

                         IUserManagementEngine.KEY);

               IServiceUserFactory sufactory = ume.getServiceUserFactory();

               try {

                    serviceUser = sufactory.getServiceUser(username);

               } catch (UMException e) {

                    response.write(e.getMessage());

               }

               return serviceUser;

          }

     }

}

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply