Class LinkShare

java.lang.Object
org.cyberneko.html.filters.DefaultFilter
org.exoplatform.social.service.rest.LinkShare
All Implemented Interfaces:
org.apache.xerces.xni.parser.XMLComponent, org.apache.xerces.xni.parser.XMLDocumentFilter, org.apache.xerces.xni.parser.XMLDocumentSource, org.apache.xerces.xni.XMLDocumentHandler, org.cyberneko.html.HTMLComponent

public class LinkShare extends org.cyberneko.html.filters.DefaultFilter
LinkShare - gets preview information of a link including: - link - title - description - images - media (from popular sites: youtube, vimeo, flickr...) - low priority (NOT IMPLEMENTED YET) This should be implemented from the client side to display preview and media player.
In order to provide this preview, always looks for the title of the page, a summary of the main content, and an image. Looks for preview information by the following priority:
1.
 
 <meta name="title" content="page_title" />
 <meta name="description" content="page_description" />
 <link rel="image_src" href="image_source" />
 
 

2. If title not found, then find in <title> tag. If description not found, then find first

tag. If no description, then return "" If img_src not found, then find all images in page with max, min specified width + height
3. To specify medium, use tag:

 <meta name="medium" content="medium_type" />
 
In which: medium_type can be "audio", "image", "video", "news", "blog" and "mult".
Created by The eXo Platform SEA TODO: hoatle improvement: + scans description with MIN_CHARACTER + handles exception + parser more faster with and without scanning image tag, stop right when things got.
Since:
Oct 8, 2009
Author:
hoatle
See Also:
  • "http://activitystrea.ms/"
  • "http://www.facebook.com/share_partners.php"
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     

    Fields inherited from class org.cyberneko.html.filters.DefaultFilter

    fDocumentHandler, fDocumentSource
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    characters(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs)
    filter method is called back when scanning meets the end of text in a tag
    void
    emptyElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs)
    this filter method is called back when scanning meets empty element tag Getting the image will use the following : 1- Meta tag with property og:image 2- Otherwise, link tag with image_src as Rel value 3- Otherwise the first image to get from the page
    void
    endElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.Augmentations augs)
    filter method is called back when scanning meets end element tag
    gets description
    gets images list
    static LinkShare
    Gets LinkShare instance with specified link.
    static LinkShare
    getInstance(String link, String lang)
    Gets LinkShare instance with link and lang specified.
    gets provided link
    gets mediaAlbum if provided in:
    gets mediaArtist if provided in:
    gets mediaHeight if provided in:
    org.exoplatform.commons.embedder.ExoMedia
    get mediaObject
    gets mediaSrc
    gets mediaTitle if provided in:
    gets mediaType if provided in:
    gets mediaWidth if provided in:
    gets mediumType
    gets title
    void
    setDescription(String description)
    Set new value for description.
    void
    Set new value for title.
    void
    startElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attrs, org.apache.xerces.xni.Augmentations augs)
    filter method is called back when scanning meets start element tag

    Methods inherited from class org.cyberneko.html.filters.DefaultFilter

    comment, doctypeDecl, endCDATA, endDocument, endGeneralEntity, endPrefixMapping, getDocumentHandler, getDocumentSource, getFeatureDefault, getPropertyDefault, getRecognizedFeatures, getRecognizedProperties, ignorableWhitespace, merge, processingInstruction, reset, setDocumentHandler, setDocumentSource, setFeature, setProperty, startCDATA, startDocument, startDocument, startGeneralEntity, startPrefixMapping, textDecl, xmlDecl

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • getLink

      public String getLink()
      gets provided link
      Returns:
      provided link
    • getTitle

      public String getTitle()
      gets title
      Returns:
      title
    • setTitle

      public void setTitle(String title)
      Set new value for title.
      Parameters:
      title -
    • getDescription

      public String getDescription()
      gets description
      Returns:
      description
    • setDescription

      public void setDescription(String description)
      Set new value for description.
      Parameters:
      description -
    • getImages

      public List<String> getImages()
      gets images list
      Returns:
      images
    • getMediumType

      public String getMediumType()
      gets mediumType
      Returns:
      mediumType
    • getMediaSrc

      public String getMediaSrc()
      gets mediaSrc
      Returns:
      mediaSrc
    • getMediaType

      public String getMediaType()
      gets mediaType if provided in:
        <meta name="audio_type" content="Content-Type header field" />
       
      or:
        <meta name="video_type" content="Content-Type header field" />
       
      Returns:
      mediaType
    • getMediaTitle

      public String getMediaTitle()
      gets mediaTitle if provided in:
        <meta name="audio_title" content="audio_title_name" />
       
      Returns:
      mediaTitle
    • getMediaArtist

      public String getMediaArtist()
      gets mediaArtist if provided in:
        <meta name="audio_artist" content="audio_artist_name" />
       
      Returns:
      mediaArtist
    • getMediaAlbum

      public String getMediaAlbum()
      gets mediaAlbum if provided in:
        <meta name="audio_album" content="audio_album_name" />
       
      Returns:
      mediaAlbum
    • getMediaHeight

      public String getMediaHeight()
      gets mediaHeight if provided in:
        <meta name="video_height" content="video_height_value" />
       
      Returns:
      mediaHeight;
    • getMediaWidth

      public String getMediaWidth()
      gets mediaWidth if provided in:
        <meta name="video_width" content="video_width_value" />
       
      Returns:
      mediaWidth
    • getMediaObject

      public org.exoplatform.commons.embedder.ExoMedia getMediaObject()
      get mediaObject
      Returns:
    • getInstance

      public static LinkShare getInstance(String link) throws Exception
      Gets LinkShare instance with specified link. The default lang = "en"
      Parameters:
      link -
      Returns:
      LinkShare instance
      Throws:
      Exception
    • getInstance

      public static LinkShare getInstance(String link, String lang) throws Exception
      Gets LinkShare instance with link and lang specified.
      Parameters:
      link -
      lang -
      Returns:
      LinkShare instance
      Throws:
      Exception
    • startElement

      public void startElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attrs, org.apache.xerces.xni.Augmentations augs)
      filter method is called back when scanning meets start element tag
      Specified by:
      startElement in interface org.apache.xerces.xni.XMLDocumentHandler
      Overrides:
      startElement in class org.cyberneko.html.filters.DefaultFilter
    • endElement

      public void endElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.Augmentations augs)
      filter method is called back when scanning meets end element tag
      Specified by:
      endElement in interface org.apache.xerces.xni.XMLDocumentHandler
      Overrides:
      endElement in class org.cyberneko.html.filters.DefaultFilter
    • emptyElement

      public void emptyElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs)
      this filter method is called back when scanning meets empty element tag Getting the image will use the following : 1- Meta tag with property og:image 2- Otherwise, link tag with image_src as Rel value 3- Otherwise the first image to get from the page
      Specified by:
      emptyElement in interface org.apache.xerces.xni.XMLDocumentHandler
      Overrides:
      emptyElement in class org.cyberneko.html.filters.DefaultFilter
    • characters

      public void characters(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs)
      filter method is called back when scanning meets the end of text in a tag
      Specified by:
      characters in interface org.apache.xerces.xni.XMLDocumentHandler
      Overrides:
      characters in class org.cyberneko.html.filters.DefaultFilter