Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Introduction


In this weblog i am going to present code to build a nice weather magnet for you portal. The code uses xml feed from weather.com and transforms the feed into a nice display using XSLT.





Required Jars


contentconverterapi.jar,contentconversionapi.jar




Step1:


Get an account from weather.com for your xml feed. Weather.com will send you a partner id and account key. You will see this info to retrieve the xml feed.

[http://www.weather.com/services/xmloap.html | http://www.weather.com/services/xmloap.html]




Step2:


Create a portal project(com.ust.weather) in NWDS or eclipse. Add a Dynpage class called

"Display"



Step3:


Save the following image to your dist->images folder by right clicking on it. Make sure you don't rename the image.

































































!http://image.weather.com/web/common/wxicons/31/0.gif!


!http://image.weather.com/web/common/wxicons/31/1.gif!


!http://image.weather.com/web/common/wxicons/31/2.gif!


!http://image.weather.com/web/common/wxicons/31/3.gif!


!http://image.weather.com/web/common/wxicons/31/5.gif!


!http://image.weather.com/web/common/wxicons/31/5.gif!


!http://image.weather.com/web/common/wxicons/31/6.gif!


!http://image.weather.com/web/common/wxicons/31/7.gif!


!http://image.weather.com/web/common/wxicons/31/8.gif!


!http://image.weather.com/web/common/wxicons/31/9.gif!


!http://image.weather.com/web/common/wxicons/31/10.gif!


!http://image.weather.com/web/common/wxicons/31/11.gif!


!http://image.weather.com/web/common/wxicons/31/12.gif!


!http://image.weather.com/web/common/wxicons/31/13.gif!


!http://image.weather.com/web/common/wxicons/31/14.gif!


!http://image.weather.com/web/common/wxicons/31/15.gif!


!http://image.weather.com/web/common/wxicons/31/16.gif!


!http://image.weather.com/web/common/wxicons/31/17.gif!


!http://image.weather.com/web/common/wxicons/31/18.gif!


!http://image.weather.com/web/common/wxicons/31/19.gif!


!http://image.weather.com/web/common/wxicons/31/20.gif!


!http://image.weather.com/web/common/wxicons/31/21.gif!


!http://image.weather.com/web/common/wxicons/31/22.gif!


!http://image.weather.com/web/common/wxicons/31/23.gif!


!http://image.weather.com/web/common/wxicons/31/24.gif!


!http://image.weather.com/web/common/wxicons/31/25.gif!


!http://image.weather.com/web/common/wxicons/31/26.gif!


!http://image.weather.com/web/common/wxicons/31/27.gif!


!http://image.weather.com/web/common/wxicons/31/28.gif!


!http://image.weather.com/web/common/wxicons/31/29.gif!


!http://image.weather.com/web/common/wxicons/31/30.gif!


!http://image.weather.com/web/common/wxicons/31/31.gif!


!http://image.weather.com/web/common/wxicons/31/32.gif!


!http://image.weather.com/web/common/wxicons/31/33.gif!


!http://image.weather.com/web/common/wxicons/31/34.gif!


!http://image.weather.com/web/common/wxicons/31/35.gif!


!http://image.weather.com/web/common/wxicons/31/36.gif!


!http://image.weather.com/web/common/wxicons/31/37.gif!


!http://image.weather.com/web/common/wxicons/31/38.gif!


!http://image.weather.com/web/common/wxicons/31/39.gif!


!http://image.weather.com/web/common/wxicons/31/40.gif!


!http://image.weather.com/web/common/wxicons/31/41.gif!


!http://image.weather.com/web/common/wxicons/31/42.gif!


!http://image.weather.com/web/common/wxicons/31/43.gif!


!http://image.weather.com/web/common/wxicons/31/44.gif!


!http://image.weather.com/web/common/wxicons/31/45.gif!


!http://image.weather.com/web/common/wxicons/31/46.gif!


!http://image.weather.com/web/common/wxicons/31/47.gif!


!http://image.weather.com/web/common/wxicons/31/na.gif!

!https://weblogs.sdn.sap.com/weblogs/images/11062/transparent_orange_go.gif|height=19|alt=image|width...!

!https://weblogs.sdn.sap.com/weblogs/images/11062/TWClogo_32px.gif|height=32|alt=image|width=43|src=h...!





Step4:


Modify your Display.java to add the following code.

Make sure you change the code to use your partner id and key sent to you by weather.com. This code will not work till you update your information in it.


/* Built By: Prakash Singh

  • Technical Consultant

  • Universal System Technologies, Inc

  • 2500 W. Lake Mary Blvd., Ste 212-A

  • Lake Mary, FL 32746 USA

  • M 407-474-2216

*/

package com.ust.weather;

import java.io.BufferedInputStream;

import java.io.BufferedReader;

import java.io.ByteArrayInputStream;

import java.io.File;

import java.io.IOException;

import java.io.InputStreamReader;

import java.net.MalformedURLException;

import java.net.URL;

import com.sapportals.htmlb.DropdownListBox;

import com.sapportals.htmlb.Form;

import com.sapportals.htmlb.GridLayout;

import com.sapportals.htmlb.GridLayoutCell;

import com.sapportals.htmlb.Link;

import com.sapportals.htmlb.enum.CellHAlign;

import com.sapportals.htmlb.enum.DropdownListBoxDesign;

import com.sapportals.htmlb.event.Event;

import com.sapportals.htmlb.htmlcontainer.NonIsolatedHtmlContainer;

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.IPortalComponentInitContext;

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

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

import com.sapportals.portal.prt.contentconversion.XSLConverter;

import com.sapportals.portal.prt.logger.ILogger;

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

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

/**

  • @author Prakash Singh

*/

public class display extends PageProcessorComponent {

     /* (non-Javadoc)

     

  • @see com.sapportals.portal.htmlb.page.PageProcessorComponent#getPage()

      */

     public DynPage getPage() {

          return new RSSDynPage();

     }

     /* (non-Javadoc)

     

  • @see com.sapportals.portal.prt.component.IPortalComponentInit#init(com.sapportals.portal.prt.component.IPortalComponentInitContext)

      */

     public void init(IPortalComponentInitContext arg0)

          throws PortalComponentException {

          // TODO Auto-generated method stub

          super.init(arg0);

     }

     public class RSSDynPage extends DynPage {

          /* (non-Javadoc)

          

  • @see com.sapportals.htmlb.page.DynPage#doInitialization()

          */

          private String location = "";

          private String center = "";

          private String tendayurl = "";

          public void doInitialization() throws PageException {

               // TODO Auto-generated method stub

               location = "";

          }

          /* (non-Javadoc)

          

  • @see com.sapportals.htmlb.page.DynPage#doProcessAfterInput()

           */

          public void doProcessAfterInput() throws PageException {

               // TODO Auto-generated method stub

          }

          

          public void onSelect(Event vent) throws PageException {

               DropdownListBox centerfld =

                                   (DropdownListBox) getComponentByName("DDLocation");

             location = centerfld.getValueAsDataType().toString();

                    }

          /* (non-Javadoc)

          

  • @see com.sapportals.htmlb.page.DynPage#doProcessBeforeOutput()

           */

          public void doProcessBeforeOutput() throws PageException {

               ILogger logger =

                    PortalRuntime.getLogger(IPortalConstants.IVIEW_LOGGER);

               BufferedReader reader = null;

               try {

                    IPortalComponentRequest request =

                         (IPortalComponentRequest) this.getRequest();

                    URL url = getURL();

                    reader =

                         new BufferedReader(

                              new InputStreamReader(

                                   new BufferedInputStream(url.openStream())));

                    StringBuffer buff = new StringBuffer();

                    for (int i = reader.read(); i != -1; i = reader.read()) {

                         buff.append((char) i);

                    }

                    reader.close();

                    String rssString = buff.toString();

                    //get rss stylesheet

                    File file = getRssStyleSheet(request);

                    XSLConverter converter = new XSLConverter(file, null);

                    String result = converter.convert(rssString, request);

                    NonIsolatedHtmlContainer container =

                         new NonIsolatedHtmlContainer(

                              new ByteArrayInputStream(result.getBytes()));

                    Form form = this.getForm();

                    form.addRawText("

Deploy your component and run it. BAM! you got yourself a nice weather magnet.

27 Comments
Top kudoed authors