Menu

command line example & mypackage.MyXmlLibrary

Help
Cal
2006-11-09
2012-09-04
  • Cal

    Cal - 2006-11-09

    I'm intrigued by the potential usage of mypackage.MyXmlLibrary
    in the example given on the Usage page. Can anyone point me to
    (or offer?) any guidance on the usage?

    cheers, Cal

     
    • Vladimir Nikic

      Vladimir Nikic - 2006-11-09

      That is the way to extend expressing power of Web-Harvest.
      mypackage.MyXmlLibrary is just example name for some user-defined class.

      The line:

      scraper.addVariableToContext("myXmlLib", new MyXmlLibrary());
      

      adds new variable - instance of class MyXmlLibrary to the web-harvest's context.

      After that you may use it in your configuration, for example:

      <loop item="currItem">
          <list><var name="someList"/></list>
          <body><template>${myXmlLib.doWhateverYouWant(currItem)}</template></body>
      </loop>
      

      This example applies custom logic on each element of the list.

       
    • Cal

      Cal - 2006-11-09

      very cool, thank you!

       
    • Cal

      Cal - 2006-11-17

      Cool maybe, but I'm struggling with it. A straight object passes back and forth just fine, but trying to use anything with a method fails -
      Exception in thread "main" org.webharvest.exception.TemplaterException:
      Error evaluating expression: myXmlLib.append( groupurl )
      at org.webharvest.runtime.templaters.BaseTemplater.execute(Unknown Source)
      ...
      Caused by: ognl.MethodFailedException: Method "append" failed for object
      MyXmlLibrary@140c281 [java.lang.NoSuchMethodException:
      append(org.webharvest.runtime.variables.NodeVariable)]

      That's with a very simple class -
      public class MyXmlLibrary {
      public void append( NodeVariable x ) {
      // do whatever you want
      }
      }

      Any suggestions are most welcome.

      cheers, Cal

       
    • Luca

      Luca - 2006-11-26

      Hi Cal,

      try this:
      scraper.getContext().put("celi",new XXXX());

      It worked for me.
      Bests,
      Luca

       
      • Cal

        Cal - 2006-11-26

        Putting the variable into the scraper context is fine, but in terms of "It worked for me", how do you go when you try to use a XXXX.method in your config? That's where I was having trouble.

         

Log in to post a comment.