• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Surfacing External Data Through Magnolia

Surfacing External Data Through Magnolia



A technical presentation focusing on how to bring data from other systems into a Magnolia CMS and present it.

A technical presentation focusing on how to bring data from other systems into a Magnolia CMS and present it.

Most current version at http://blitl.us/zBW5



Total Views
Views on SlideShare
Embed Views



10 Embeds 166

http://www.magnolia-cms.com 92
http://localhost 30
http://localhost:8080 12
http://new-author.magnolia-cms.com 8
http://test-author.magnolia-cms.com 7
http://www.slideshare.net 7
http://magnolia-cms.com 5
http://website-test.magnolia-cms.com 2
http://author.magnolia-cms.com 2
http://test-mgnl1 1



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment
  • Introduce selves Discuss needs for getting external data: Other systems (HR for directory, feeds for news, Twitter for twitterstuff, order system for sales data) Going to discuss Three Approaches: Standard JSP/Servlet Data Module RSS Aggregator
  • We give our users something very simple…
  • … and give them a lot in return. Nicely formatted, auto-updates, microformats Explain the basic mechanics.
  • Code for custom control to display department list The XML-RPC client library expects any parameters to be stored into a Vector object.
  • Actually display the information
  • Tell what the data module is, its raison d'etre. "DMS for structured data"
  • Jan working on Advanced Data Module Example -- ready to go yet? Provide an aside on the scheduler module and how lovely it is.
  • 1. Define new data type for Special events root path: /events   Mention Silk project as source for icons 2. Show default dialog definition and dialog that results. Add field for start-date. Show updated dialog. Enter conference data. Enter birthday. Show data in JCR browser.
  • All ImportTarget does is provide a container for any options you want to specify. It has no logic! ImportHandler *must* be subclassed so that it actually does something.
  • Discuss what each of the options do   cron format: this is the Java version (6 fields), not the Unix-standard version (5 fields). Warning: lockDuringImport -- can leave your database bollixed up and needing a export/import. ImportTarget: name, targetPath SimpleImportTarget: adds FileURL, ZipFileURL
  • Simply a data structure. This is the *entire* code.   If you need to specify options that aren't already there, subclass this and add your own private fields and accessors for them.
  • This is mandatory for any import job Use the "parent" parameter, rather than target.targetPath(), because we may be importing into a temporary location to be moved on completion. uuids is an empty set to start with.
  • Demo: SQL version: select * from event XPATH version: //element(*, event)
  • Be sure to use the name you defined for your data type when using the getChildren() call.
  • In order to bootstrap data, you must load the data module before you load your own module. Declare this in your pom.xml file.
  • Tell about our RSS implementation and why the RSS module is better.
  • Talk about ROME project a bit Mention that the module can also be used to generate RSS feeds, though that's a bit beyond the scope of this presentation.
  • Go to Data -> RSS Aggregators Create a new aggregator http://feeds.feedburner.com/mcmains/ruminations http://twitter.com/statuses/user_timeline/1809041.rss   http://api.flickr.com/services/feeds/photos_public.gne?id=51035705089@N01&lang=en-us&format=rss_200   Use description = ^[^@]*$ to exclude Twitter replies --- Go to RSS Config, trigger fetch Show Data in JCR Browser --- Go to demo-features -> Aggregation Paragraphs -> latest-news Add a paragraph of each type to show how they work

Surfacing External Data Through Magnolia Surfacing External Data Through Magnolia Presentation Transcript

  • Surfacing External Data Through Magnolia Sean McMains & Jeff Snider September 10, 2009
  • 3 Approaches: JSP/Servlet Data Module RSS Module
  • JSP/Servlet Approach or "Teaching an  Old Dog New Tricks" Photo Credit: Stephen Poff
  • Department Directory
  • Department Directory XML-RPC Methods: getDepartmentList() getResults()
  • Implementing a Custom Control
    •     <jsp:scriptlet>         DialogControlImpl control = 
    •             (DialogControlImpl)pageContext.getRequest().getAttribute(&quot;dialogObject&quot;);  
    •         XmlRpcClientLite client =             new XmlRpcClientLite(&quot;http://apps.its.txstate.edu/people/RPC.mpl&quot;);         String method = &quot;getDepartmentList&quot;;         Vector params = new Vector();         Vector result = (Vector)client.execute( method, params );         ListIterator i = result.listIterator();
    •         Select selectControl = new Select( control.getName(), control.getWebsiteNode() );         selectControl.setCssClass( CssConstants.CSSCLASS_SELECT );
    •         while (i.hasNext() )         {             String department = (String)i.next();             SelectOption option = new SelectOption( department, department );             if ( department.equals( control.getValue() ) ) option.setSelected( true );             selectControl.setOptions( option );         }        out.println( selectControl.getHtml() );     </jsp:scriptlet>
  • Presenting the Directory Info
    • XmlRpcClientLite client = 
    •   new XmlRpcClientLite(&quot;http://apps.its.txstate.edu/people/RPC.mpl&quot;);
    • String department =
    •   Resource.getLocalContentNode(request).getNodeData(&quot;department&quot;).getString();
    • String filter = 
    •   Resource.getLocalContentNode(request).getNodeData(&quot;filter&quot;).getString(); 
    • String method = &quot;getResults&quot;;
    • Vector params = new Vector();
    • String searchTerm = &quot;department=&quot;&quot; + department + &quot;&quot;&quot;;
    • params.addElement(searchTerm);
    • Vector result = (Vector)client.execute( method, params );
    • ListIterator i = result.listIterator();
    • while ( i.hasNext() ) {
    •   Hashtable person = (Hashtable)i.next();
    •   ...
    •   String firstName = (String)person.get(&quot;firstname&quot;);
    •   String lastName = (String)person.get(&quot;lastname&quot;);   html.append( &quot;<div class=&quot;txst-departmentdirectory-name fn n&quot;>
    •     <span class=&quot;given-name&quot;>&quot; + firstName + &quot;</span> <span class=&quot;family-name&quot;>&quot; +
    •     lastName + &quot;</span>&nbsp;</div>&quot; );
    •   ...
    • }                                     
  • JSP/Servlet Approach
    • Pros:
      • Quick & easy
      • No additional modules needed, aside from whatever you use to actually fetch the data
      • Uses familiar techniques
    • Cons:
      • Page caching issues
      • Performance
      • At mercy of connection to data source
      • You have to write it all yourself!
  • The Data Module or &quot;How I Learned to Stop Worrying and Love the JCR&quot; Photo Credit: Kjunstorm
  • The Data Module
    • Info:
      • Data Module Docs
      • Footers Example
      • Advanced Data Module Example (?)
    • Requirements:
      • Magnolia 4.x
      • Scheduler Module
      • A Bit of Patience
  • Creating a New Data Type Demonstration
  • Import Handlers
      • Built on scheduler module
      • Provide an automated means to suck in new data
      • At /modules/data/config/importers
  • Using Import Handlers
  • Configuring an Import Handler
  • ImportTarget Code public class ImportTarget {     protected String name;     protected String targetPath;     public void setName(String name) {         this.name = name;     }     public void setTargetPath(String targetPath) {         this.targetPath = targetPath;     }     public ImportTarget() {     }     public String getTargetPath() {         return targetPath;     }     public String getName() {         return name;     } }
  • ImportHandler Sample
    • public class DateTimeImportHandler extends ImportHandler {     ...     protected Set doImport(ImportTarget target, Content parent, Set uuids) throws ImportException {
    •             ...             String date = dateFormat.format( new Date() );             String name = &quot;ImportedSampleData&quot; + parent.getChildren(&quot;example&quot;).size();
    •             // create new data node.             // FYI: if the name matches existing node and &quot;deleteExisting&quot; is             // set to true, old copy of the node will be automatically deleted.             Content child = parent.createContent( name, &quot;example&quot; );
    •             // set properties for newly created node             NodeDataUtil.getOrCreate( child, &quot;name&quot;).setValue(name);             NodeDataUtil.getOrCreate(child, &quot;comment&quot;).setValue(&quot;Example of data import.
    •               Generated on &quot; + date);             NodeDataUtil.getOrCreate(child, &quot;data&quot;).setValue(date);
    •             parent.save();
    •             uuids.add(child.getUUID());
    •             ...         return uuids;     } }
  • JCR Query
      • XPath or SQL-style
      • Powerful selection capabilities
      • Can be complicated
    • Additional Info:
      •   JSR-170 Spec
  • Using the Node Object
    •             <jsp:scriptlet>
    •                 final String BR = &quot;&lt;br/&gt;&quot;;                                 HierarchyManager dataHierarchyManager = 
    •                      MgnlContext.getHierarchyManager( &quot;data&quot; );                 Content eventsNode = dataHierarchyManager.getContent( &quot;/event&quot; );                 Iterator eventsNodeIterator = eventsNode.getChildren( &quot;event&quot; ).iterator();                                 while ( eventsNodeIterator.hasNext() ) {                     Content event = (Content)eventsNodeIterator.next();                     out.write( event.getNodeData( &quot;name&quot; ).getString() + BR );                     out.write( event.getNodeData( &quot;date&quot; ).getString() + BR + BR );                 }                             </jsp:scriptlet>
  • Caveat: Bootstrapping Data
    • Add to your project's pom.xml:
    • <dependencies>     <dependency>       <name>data</name>       <version>1.2.1/*</version>     </dependency> </dependencies>
  • Data Module
    • Pros:
      • Data is cached in JCR
      • Resilient to temporary disconnect from data
      • Can enter data manually through AdminCentral or import automatically
    • Cons:
      • You still have to write it all yourself
      • Requires learning another framework
  • Bringing in RSS Content or &quot;All the news that fits, we print!&quot; Photo Credit: tantrum_dan
  • The RSS Module
    • Info:
      • Official Documentation
      • Jan's Weblog Entry
    • Requires:
      • Magnolia 4.x
      • Scheduler Module
      • Data Module
      • Built on ROME Project
  • Sightseeing in the RSS Module Add new feeds Configure RSS Module
  • Setting up RSS Feeds Demonstration
  • RSS Module
    • Pros:
      • Easy set up
      • Includes several useful paragraphs
      • Can use it without writing any additional code
    • Cons:
      • Can only use content that's published in RSS format
  • Questions?
    • Photo Credit: coldtaxi
  • Photo Credit: damaradeaella