Skip to Content

It is sometimes useful to be able to change the contents of the image that appears on the portal logon page to pass on information to the users before they actually logon.

For example, if the general user community has been locked out by an operator while new functionality is added, then an appropriate message can be displayed.

This blog will describe the use of standard Java libraries to create the logon branding image.

This blog does not attempt to describe all the capabilities of changing the portal logon screen – they have been adequately covered in other blogs, for example Karl Unewisse’s recent Portal Customizations Intro – Login Part 1.

The default portal logon page has an image on the right hand side that shows what looks like the corner of a building. (As an aside, I would be curious about the heritage of this particular image…) Depending on the version of SAP NetWeaver that is being used, this image is stored in one of the many(!) subfolders under the Java instance’s home folder.

As we will be changing the contents of this image, we first need to know this location, so spend 5 minutes working out where it is. For SAP NetWeaver Portal it is in C:usrsapXYZJC66j2eeclusterserver0appssap.comirjservlet_jspirj
ootportalappscom.sap.portal.runtime.logonlayout randing-image.jpg, assuming an instance SID of XYZ, and a central instance number of 66. server0 shows that this is the first server node of this instance number..

OK, now for some code. First some header type stuff…

package com.sap.anz;

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics2D;

import java.awt.RenderingHints;

import java.awt.font.FontRenderContext;

import java.awt.font.TextLayout;

import java.awt.geom.Rectangle2D;

import java.awt.image.BufferedImage;

import java.awt.image.RenderedImage;

import java.io.File;

import java.io.IOException;

import java.io.RandomAccessFile;

import java.text.DateFormat;

import java.util.Calendar;

import java.util.Date;

import javax.imageio.ImageIO;

import com.sapportals.htmlb.Button;

import com.sapportals.htmlb.Form;

import com.sapportals.htmlb.GridLayout;

import com.sapportals.htmlb.Group;

import com.sapportals.htmlb.InputField;

import com.sapportals.htmlb.Label;

import com.sapportals.htmlb.TextView;

import com.sapportals.htmlb.enum.ButtonDesign;

import com.sapportals.htmlb.enum.DataType;

import com.sapportals.htmlb.enum.GroupDesign;

import com.sapportals.htmlb.event.Event;

import com.sapportals.htmlb.page.DynPage;

import com.sapportals.htmlb.page.PageException;

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

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

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

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

public class SimpleMessage extends PageProcessorComponent {

  public DynPage getPage() {

    return new SimpleMessageDynPage();

  }

  public static class SimpleMessageDynPage extends DynPage {

          /**

          

  • Initialization code executed once per user.

           */

          String jpegFile = “”;

          String problem = “”;

          String path = “”;

          

          public void doInitialization() {

               IPortalComponentResponse response =

                    (IPortalComponentResponse) this.getResponse();

               IPortalComponentRequest request =

                    (IPortalComponentRequest) this.getRequest();

          }

          /**

          

  • 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

               IPortalComponentRequest request =

                    (IPortalComponentRequest) this.getRequest();

All fairly standard type stuff. Now,
I’m going to assume we need to gather the text to put in the message, so I’ll setup 5 (imaginatively named) fields to use and give them some default values. Then setup the HTMLB structures and let the user enter their values….

We have three buttons for the user to select – one to update the image file, and the other two to allow them to make a copy of the original file (backup) and restore it later (restore). It should look like this at runtime…

!https://weblogs.sdn.sap.com/weblogs/images/3225/setup1.gif|height=225|alt=image|width=510|src=https://weblogs.sdn.sap.com/weblogs/images/3225/setup1.gif|border=0!

After execution with the standard values, the logon screen might look like this:

image

The user may need to refresh their browser cache (F5 for IE) to see the latest image…

Anyway, what happens when we press one of the buttons?

The update button executes the following:

          public void doExecute(Event evt) {

               Calendar rightNow = Calendar.getInstance();

               IPortalComponentRequest request =

                    (IPortalComponentRequest) this.getRequest();

               IPortalComponentResponse response =

                    (IPortalComponentResponse) this.getResponse();

               IPortalComponentProfile profile =

                    request.getComponentContext().getProfile();

               //

               //          properties for message

               //

               path = request.getPublicResourcePath();

               path = path.substring(0,path.indexOf(“
server”)+8);

               jpegFile = path+profile.getProperty(“jpegFile”);

               String line1 =

                    ((InputField) getComponentByName(“line1”))

                         .getValue()

                         .toString();

               String line2 =

                    ((InputField) getComponentByName(“line2”))

                         .getValue()

                         .toString();

               String line3 =

                    ((InputField) getComponentByName(“line3”))

                         .getValue()

                         .toString();

               String line4 =

                    ((InputField) getComponentByName(“line4”))

                         .getValue()

                         .toString();

               String line5 =

                    ((InputField) getComponentByName(“line5”)).getValue().toString();

     

                    if (!jpegFile.equals(“”)) {

                         problem = “About to update…”;

                         RenderedImage rendImage =

                              myCreateImage(

                                   request,

                                   line1,

                                   line2,

                                   line3,

                                   line4,

                                   line5);

                         File file = new File(jpegFile);

                         try {

                         ImageIO.write(rendImage, “jpg”, file);

                         problem =

                              “iView updated and JPEG file ” + jpegFile + ” written”;

                         } catch (Exception e) {

                         problem = “Error with JPEG:”+e.getMessage();

                         }

                    };

          }

          public void doBackup(Event evt) {

               IPortalComponentRequest request =

                    (IPortalComponentRequest) this.getRequest();

               IPortalComponentResponse response =

                    (IPortalComponentResponse) this.getResponse();

               IPortalComponentProfile profile =

                    request.getComponentContext().getProfile();

               path = request.getPublicResourcePath();

               path = path.substring(0,path.indexOf(“
server”)+8);

               jpegFile = path+profile.getProperty(“jpegFile”);

               problem = “Backing up current image to ” + jpegFile + “.backup”;

               problem = copy(jpegFile, jpegFile + “.backup.jpg”,problem);

          };

          public void doRestore(Event evt) {

               IPortalComponentRequest request =

                    (IPortalComponentRequest) this.getRequest();

               IPortalComponentResponse response =

                    (IPortalComponentResponse) this.getResponse();

               IPortalComponentProfile profile =

                    request.getComponentContext().getProfile();

               path = request.getPublicResourcePath();

               path = path.substring(0,path.indexOf(“
server”)+8);

               jpegFile = path+profile.getProperty(“jpegFile”);

               problem = “Restoring ” + jpegFile + “.backup to current image”;

               problem = copy(jpegFile + “.backup.jpg”, jpegFile,problem);

          };

          public String copy(String in_file, String out_file,String OK_mess) {

               try {

                    RandomAccessFile inFile = null;  // declare in outer loop

                    RandomAccessFile outFile = null;

                    int buf;

                    inFile = new RandomAccessFile(new File(in_file), “r”);

                    outFile = new RandomAccessFile(new File(out_file), “rw”);

                    while ((buf = inFile.read()) != -1)

                    {

                      outFile.write(buf);

                    }

                    inFile.close();

                    outFile.close();

                    return OK_mess;

               } catch (IOException e) {

                    return(e.toString());

               }

               

          };

Note

: As building this is basically a cut and paste operation, I won’t be distributing a PAR file.

To report this post you need to login first.

2 Comments

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

  1. Gregor Wolf
    Hi Michael,

    cool function. But could you put some p- or br-Tags into your Weblog so it can be printed better.

    Thanks
    Gregor

    (0) 

Leave a Reply