2 Replies Latest reply: Aug 20, 2012 6:29 PM by chris n RSS

Ume assignments display

chris n
Currently Being Moderated

i found below code in portal section of wiki page , when i deployed into portal and ran , i am getting blank page any help is really helpful.

 

--------------------------------------------

 

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

import java.util.Iterator; 

import javax.servlet.http.HttpServletResponse; 

import com.sap.security.api.IGroup;

import com.sap.security.api.IGroupFactory;

import com.sap.security.api.IGroupSearchFilter;

import com.sap.security.api.IRole;

import com.sap.security.api.IRoleFactory;

import com.sap.security.api.ISearchAttribute;

import com.sap.security.api.ISearchResult;

import com.sap.security.api.IUser;

import com.sap.security.api.IUserFactory;

import com.sap.security.api.IUserSearchFilter;

import com.sap.security.api.UMFactory;

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

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

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

import com.sapportals.portal.prt.pom.IEvent;

 

 

public class Assignments extends AbstractPortalComponent

{

 

          public void doOnNodReady(IPortalComponentRequest request, IEvent event) {

                              HttpServletResponse response = request.getServletResponse(true);

                              response.setContentType("text/xml");

                              response.setHeader("Content-disposition", "filename=\"test.xml\"");

                              try {

                              java.io.PrintWriter out = response.getWriter();

                              out.print("<?xml version=\"1.0\"?> ");

                              out.print("<?mso-application progid=\"Excel.Sheet\"?> ");

                              out.print("<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" ");

                              out.print("xmlns:o=\"urn:lschemas-microsoft-com:office:office\" ");

                              out.print("xmlns:x=\"urn:schemas-microsoft-com:office:excel\" ");

                              out.print("xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\" ");

                              out.print("xmlns:html=\"http://www.w3.org/TR/REC-html40\"> ");

 

 

                              out.print("<Worksheet ss:Name=\"UserGroups\"> ");

                              out.print("<Table> ");

                              IUserFactory userFact = UMFactory.getUserFactory();

                              IGroupFactory groupFact = UMFactory.getGroupFactory();

                              IRoleFactory roleFact = UMFactory.getRoleFactory();

                              out.print("<Row> <Cell> <Data ss:Type=\"String\">User</Data> </Cell> <Cell> <Data ss:Type=\"String\">Group</Data> </Cell>");

                              out.print("</Row> ");

 

 

                              IUserSearchFilter userFilt =

                                        userFact.getUserSearchFilter();

 

 

                              userFilt.setSearchAttribute(

                                        "com.sap.security.core.usermanagement",

                                        "uniquename",

                                        "*",

                                        ISearchAttribute.LIKE_OPERATOR,

                                        false);

 

 

                              for (ISearchResult result = userFact.searchUsers(userFilt); result.hasNext(); ) {

                                        IUser thisone = userFact.getUser(result.next().toString());

                                        for (Iterator groups = thisone.getParentGroups(false); groups.hasNext(); ) {

                                                  IGroup group = groupFact.getGroup(groups.next().toString());

                                                  String groupname = group.getDisplayName();

                                                  if (!groupname.equals("Everyone") && !groupname.equals("Authenticated Users"))

                                                            out.print("<Row> <Cell> <Data ss:Type=\"String\">"+thisone.getUniqueName()+"</Data> </Cell> "+

                                                            "<Cell> <Data ss:Type=\"String\">"+groupname+"</Data> </Cell> </Row> ");

                                        }

                              };

                              out.print("</Table> ");

                              out.print("<WorksheetOptions xmlns=\"urn:schemas-microsoft-com:office:excel\"> ");

                              out.print("<Selected/> ");

                              out.print("<ProtectObjects>False</ProtectObjects> ");

                              out.print("<ProtectScenarios>False</ProtectScenarios> ");

                              out.print("</WorksheetOptions> ");

                              out.print("</Worksheet> ");

 

 

                              out.print("<Worksheet ss:Name=\"UserRoles\"> ");

                              out.print("<Table> ");

                              out.print("<Row> <Cell> <Data ss:Type=\"String\">User</Data> </Cell> <Cell> <Data ss:Type=\"String\">Role</Data> </Cell>");

                              out.print("</Row> ");

 

 

                              userFilt =

                                        userFact.getUserSearchFilter();

 

 

                              userFilt.setSearchAttribute(

                                        "com.sap.security.core.usermanagement.init",

                                        "uniquename",

                                        "*",

                                        ISearchAttribute.LIKE_OPERATOR,

                                        false);

 

 

                              for (ISearchResult result = userFact.searchUsers(userFilt); result.hasNext(); ) {

                                        IUser thisone = userFact.getUser(result.next().toString());

                                        for (Iterator roles = thisone.getRoles(true); roles.hasNext(); ) {

                                                  IRole role = roleFact.getRole(roles.next().toString());

                                                  String rolename = role.getDisplayName();

                                                            out.print("<Row> <Cell> <Data ss:Type=\"String\">"+thisone.getUniqueName()+"</Data> </Cell> "+

                                                            "<Cell> <Data ss:Type=\"String\">"+rolename+"</Data> </Cell> </Row> ");

                                        }

                              };

                              out.print("</Table> ");

                              out.print("<WorksheetOptions xmlns=\"urn:schemass-microsoft-com:office:excel\"> ");

                              out.print("<Selected/> ");

                              out.print("<ProtectObjects>False</ProtectObjects> ");

                              out.print("<ProtectScenarios>False</ProtectScenarios> ");

                              out.print("</WorksheetOptions> ");

                              out.print("</Worksheet> ");

 

 

                              out.print("<Worksheet ss:Name=\"GroupRoles\"> ");

                              out.print("<Table> ");

                              out.print("<Row> <Cell> <Data ss:Type=\"String\">Group</Data> </Cell> <Cell> <Data ss:Type=\"String\">Role</Data> </Cell>");

                              out.print("</Row> ");

 

 

                              IGroupSearchFilter groupFilt =

                                        groupFact.getGroupSearchFilter();

 

 

                              groupFilt.setSearchAttribute(

                                        "com.sap.security.core.usermanagement",

                                        "uniquename",

                                        "*",

                                        ISearchAttribute.LIKE_OPERATOR,

                                        false);

 

 

                              for (ISearchResult result = groupFact.searchGroups(groupFilt); result.hasNext(); ) {

                                        IGroup thisone = groupFact.getGroup(result.next().toString());

                                        for (Iterator roles = thisone.getRoles(false); roles.hasNext(); ) {

                                                  IRole role = roleFact.getRole(roles.next().toString());

                                                  String rolename = role.getDisplayName();

                                                            out.print("<Row> <Cell> <Data ss:Type=\"String\">"+thisone.getUniqueName()+"</Data> </Cell> "+

                                                            "<Cell> <Data ss:Type=\"String\">"+rolename+"</Data> </Cell> </Row> ");

                                        }

                              };

                              out.print("</Table> ");

                              out.print("<WorksheetOptions xmlns=\"urn:schemas-microsoft-com:office:excel\"> ");

                              out.print("<Selected/> ");

                              out.print("<ProtectObjects>False</ProtectObjects> ");

                              out.print("<ProtectScenarios>False</ProtectScenarios> ");

                              out.print("</WorksheetOptions> ");

                              out.print("</Worksheet> ");

 

 

 

 

                              out.print("</Workbook>");

                              out.close();

                              } catch (Exception e) {

//                                        out.print("Error getting users - "+e.getLocalizedMessage());

                                        };

                    }

    public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)

    {

 

 

    }

}

 

------------------------------

 

portalapp.xml

 

<?xml version="1.0" encoding="UTF-8"?>

<application>

  <application-config/>

  <components>

    <component name="Assignments">

      <component-config>

        <property name="ClassName" value="Assignments"/>

      </component-config>

      <component-profile/>

    </component>

  </components>

  <services/>

</application>

 

----------------------------------

 

I have added servlet.jar as external jar.

 

Thank you in advance

Actions