You Are Here:

Community: Wiki

This page was last modified on 3 August 2009, at 09:42.

Example Xml Filter

From Forum Nokia Wiki

This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. The article is believed to be still valid for the original topic scope.
Image:FNWID.gif

This script uses HTTP service access XML service, and filters content using XML filter.

WidSets Example

xml_filter.he

class
{
  const int    CMD_CANCEL = 1;
  const int    CMD_BACK   = 2;
  
  MenuItem     BACK   = new MenuItem(CMD_BACK, "Back");
  MenuItem     CANCEL = new MenuItem(CMD_CANCEL, "Cancel");

  //randomly selected feed ("REST" api)
  String URL = "http://krumelur.jaiku.com/presence/xml";
  
  Flow m_flow;
  Prompt m_prompt;
  
  
  void startWidget()
  {
    setMinimizedView(createMinimizedView("viewMini", getStyle("default")));
  }


  Shell openWidget()
  {
    Flow flow = new Flow(getStyle("shell"));
    
    flow.setPreferredSize(-100, -100);
    requestData();
    
    return new Shell(m_flow = flow);
  }
  
  
  void addText(String name, String value)
  {
    Label label = new Label(getStyle("name"), name);
    label.setFlags(VISIBLE|LINEFEED);
    label.setPreferredWidth(-100);
    m_flow.add(label);

    Text text = new Text(getStyle("value"), value);
    text.setFlags(VISIBLE|LINEFEED);
    text.setPreferredWidth(-100);
    m_flow.add(text);
  }
  

  void addPicture(String url)
  {
    Picture pict = getPicture(url);
    pict.setStyle(getStyle("name"));
    m_flow.add(pict);
  }
  

  MenuItem getSoftKey(Shell shell, Component focused, int key)
  {
    if (key == SOFTKEY_BACK) {
      return BACK;
    }
    return null;
  }


  void actionPerformed(Shell shell, Component source, int action)
  {
    if (action == CMD_BACK) {
      popShell(shell);
    
    } else if (action == CMD_CANCEL) {
      closePrompt();
      //there's no actually a way to cancel on going
      //call() but atleast release the UI
    }
  }
  

  void requestData()
  {
    Value arg = [
      "url" => URL
    ];
    call(null, "httpService", "get", arg, ok, nok);

    m_prompt = new Prompt(null, "Loading...", null, CANCEL);
    //prompt.setProgress(current, 10);
    m_prompt.push();

    void ok(Object state, Value ret)
    {
      closePrompt();
      foreach (Value item : ret) {
        String key = item[0];
        String value = item[1];
        if ("avatar".equals(key)) {
          addPicture(value);
        } else {
          addText(key, value);
        }
      }
    }
  
    void nok(Object state, String error)
    {
      closePrompt();
      addText("Request failed", error);
    }
  }
  
  
  void closePrompt()
  {
    if (m_prompt != null) {
      m_prompt.pop();
      m_prompt = null;
    }
  }
  
}

widget.xml

<?xml version="1.0" encoding="utf-8"?>
 
<widget spec_version="2.0">
  <info>
    <name>XML Filter</name>
    <version>1.3</version>
    <author>test</author>
    <clientversion>0.98</clientversion>
    <shortdescription>XML Filter example</shortdescription>
    <longdescription>XML Filter example demonstrationg content pulling from Jaiku</longdescription>
    <tags>helium example</tags>
  </info>
   
  <services>
    <service type="http" id="httpService">
      <filter id="digg"/>
    </service>
  </services>

  <filters>
    <filter id="digg">
      <list>
        <item name="nick">
          <xpath>/presence/user/@nick</xpath>
        </item>

        <item name="line">
          <xpath>/presence/line/text()</xpath>
        </item>

        <item name="location">
          <choice>
            <xpath>/presence/location/neighbourhood/text()</xpath>
            <xpath>/presence/location/city/text()</xpath>
            <xpath>/presence/location/country/text()</xpath>
          </choice>
        </item>

        <item name="avatar">
          <xpath>/presence/user/@avatar</xpath>
        </item>
      </list>
    </filter>
  </filters>
  
  <parameters>
    <parameter type="string" name="widgetname" description="Name of widget" editable="no" visible="false">XML Filter</parameter>
  </parameters>
  
  <resources>
    <code src="xml_filter.he"/>
    <stylesheet>
      shell {
        background: solid white;
        color: black;
      }
      
      name {
        color: black;
        font: medium bold;
        margin: 2sp 2sp 2sp 2sp;
      }

      value {
        color: black;
        font: medium plain;
        margin: 2sp 2sp 2sp 20sp;
      }
      
      minText {
        background: solid white;
        color: black;
        align: vcenter hcenter;
      }
    </stylesheet>
  </resources>
    
  <layout minimizedheight="2em">
    <view id="viewMini">
      <label class="minText">${widgetname}</label>
    </view>
	</layout>
 
</widget>

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fWebfeedE5fserviceX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxWebfeedE20serviceE20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d02X qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ