TextTransfromUtils (gCube Share Updates Portlet 1.7.0-3.7.0 API)
Date: 2015-05-19

org.gcube.portlets.user.shareupdates.server

## Class TextTransfromUtils

- java.lang.Object
- - org.gcube.portlets.user.shareupdates.server.TextTransfromUtils

-     public class TextTransfromUtils
      extends Object

  this class contains utility method for parsing and trasforming users pasted text containing URLs and other utility methods
  Author:
    Massimiliano Assante, ISTI-CNR

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TextTransfromUtils()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected static String` | `convertFileNameAnchorHTML(String url)`
    `protected static String` | `convertHashtagsAnchorHTML(String escapedFeedText, List<String> hashtags)` convert the hashtag in HTML anchor and also Encode the params Base64
    `protected static String` | `convertMentionPeopleAnchorHTML(String escapedFeedText, List<org.gcube.portlets.widgets.pickitem.shared.ItemBean> taggedPeople)` convert the mentioned people in HTML anchor and also Encode the params Base64
    `protected static String` | `escapeHtmlAndTransformUrl(String html)` Escape an html string.
    `protected static String` | `extractURL(String feedText)` utility method that extract an url ina text when you paste a link
    `protected static List<String>` | `getHashTags(String postText)` utility method that extract the hashtags from a text
    `protected static ArrayList<String>` | `getImagesWithCleaner(URL pageURL)` try with HtmlCleaner API to read the images
    `protected static String` | `getImageUrlFromSrcAttribute(URL pageURL, String srcAttr)` There are several ways to refer an image in a HTML, this method use an heuristic to get the actual image url
    `protected static LinkPreview` | `getInfoFromHTML(URLConnection connection, URL pageUrl, String link, String host)` to use when OpenGraph is not available, Tries Metadata first, then Best guess from page content
    `protected static String` | `replaceAmpersand(String toReplace)`
    `protected static String` | `transformUrls(String feedText)` utility method that convert a url ina text in a clickable url by the browser and if the user has just pasted a link, converts the link in: shared a link
    `protected static void` | `trustAllHTTPSConnections()` this method handles the non trusted https connections

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### TextTransfromUtils

          public TextTransfromUtils()

  - ### Method Detail

    - #### convertFileNameAnchorHTML

          protected static String convertFileNameAnchorHTML(String url)

      Parameters:
        `preview` -
      Returns:

    - #### convertMentionPeopleAnchorHTML

          protected static String convertMentionPeopleAnchorHTML(String escapedFeedText,
                                              List<org.gcube.portlets.widgets.pickitem.shared.ItemBean> taggedPeople)

      convert the mentioned people in HTML anchor and also Encode the params Base64
      Parameters:
        `escapedFeedText` -
        `taggedPeople` -
      Returns:

    - #### getHashTags

          protected static List<String> getHashTags(String postText)

      utility method that extract the hashtags from a text
      Parameters:
        `postText` -
      Returns:
        the list of hashtags present in the text

    - #### convertHashtagsAnchorHTML

          protected static String convertHashtagsAnchorHTML(String escapedFeedText,
                                         List<String> hashtags)

      convert the hashtag in HTML anchor and also Encode the params Base64
      Parameters:
        `escapedFeedText` -
        `hashtags` -
      Returns:

    - #### escapeHtmlAndTransformUrl

          protected static String escapeHtmlAndTransformUrl(String html)

      Escape an html string. Escaping data received from the client helps to prevent cross-site script vulnerabilities.
      Parameters:
        `html` - the html string to escape
      Returns:
        the escaped string

    - #### extractURL

          protected static String extractURL(String feedText)

      utility method that extract an url ina text when you paste a link
      Parameters:
        `feedText` -
      Returns:
        the text with the clickable url in it

    - #### getImagesWithCleaner

          protected static ArrayList<String> getImagesWithCleaner(URL pageURL)
                                                           throws IOException

      try with HtmlCleaner API to read the images
      Parameters:
        `pageURL` -
      Returns:
        the title of the page or null if can't read it
      Throws:
        `IOException`

    - #### getImageUrlFromSrcAttribute

          protected static String getImageUrlFromSrcAttribute(URL pageURL,
                                           String srcAttr)

      There are several ways to refer an image in a HTML, this method use an heuristic to get the actual image url
      Parameters:
        `pageURL` - the url
        `srcAttr` - the content of the img src attribute
      Returns:
        the image url ready to be referred outside native environment

    - #### getInfoFromHTML

          protected static LinkPreview getInfoFromHTML(URLConnection connection,
                                    URL pageUrl,
                                    String link,
                                    String host)
                                                throws Exception

      to use when OpenGraph is not available, Tries Metadata first, then Best guess from page content
      Parameters:
        `pageUrl` -
        `link` -
        `host` -
      Returns:
        a LinPreview object instance filled with the extracted information
      Throws:
        `IOException`
        `Exception`

    - #### replaceAmpersand

          protected static String replaceAmpersand(String toReplace)

    - #### transformUrls

          protected static String transformUrls(String feedText)

      utility method that convert a url ina text in a clickable url by the browser and if the user has just pasted a link, converts the link in: shared a link
      Parameters:
        `feedText` -
      Returns:
        the text with the clickable url in it

    - #### trustAllHTTPSConnections

          protected static void trustAllHTTPSConnections()

      this method handles the non trusted https connections

Copyright © 2015. All Rights Reserved.