net.sf.mgaip
Class Replacer

java.lang.Object
  extended by net.sf.mgaip.Replacer

public final class Replacer
extends Object

Class that replaces the already existent reports.

Control Version

Since:
1.0
Version:
1.0 20110529
Author:
Jose Francisco "Pachito" Saray, Andres Gomez Casanova (AngocA)

Field Summary
private static int HORIZONTAL_AD
          Internal id for horizontal ad.
private static int LOGO_AD
          Internal id for logo ad.
private  AdInserterMojo report
          Mojo that calls the replacer.
private static int UNIQUE_AD
          Internal id for unique ad.
private static int VERTICAL_AD
          Internal id for vertical ad.
 
Constructor Summary
Replacer(AdInserterMojo caller)
          Instantiates the mojo.
 
Method Summary
private  boolean changeHTMLTag(org.jdom.Element single, String content)
          Replaces an HTML tag with the given type of ad.
private  String getAdContent(int type)
          Returns the Google ad according to the requested type.
private  org.jdom.Element getCommon()
           
private  boolean getCustomPoweredBy(org.jdom.Element single)
          Replaces the customPoweredBy tag with the given code.
private  boolean getFacebookILike(org.jdom.Element single)
          Returns the I like Facebook script.
private  boolean getGooglePlusOne(org.jdom.Element single)
          Adds the google plus one script in the page.
private  boolean htmlReplacement(org.jdom.Element elem)
          Searches the tags to modify the HTML file and call the respective method to insert an ad.
protected  void replace(String directory, String filename)
          Open the file, parses the HTML and the searches the defined tags to replace with other content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HORIZONTAL_AD

private static final int HORIZONTAL_AD
Internal id for horizontal ad.

See Also:
Constant Field Values

LOGO_AD

private static final int LOGO_AD
Internal id for logo ad.

See Also:
Constant Field Values

UNIQUE_AD

private static final int UNIQUE_AD
Internal id for unique ad.

See Also:
Constant Field Values

VERTICAL_AD

private static final int VERTICAL_AD
Internal id for vertical ad.

See Also:
Constant Field Values

report

private AdInserterMojo report
Mojo that calls the replacer.

Constructor Detail

Replacer

Replacer(AdInserterMojo caller)
Instantiates the mojo.

Parameters:
caller - Mojo containing all parameters.
Method Detail

changeHTMLTag

private boolean changeHTMLTag(org.jdom.Element single,
                              String content)
Replaces an HTML tag with the given type of ad.

Parameters:
single - XML component that contains the location of the tag to replace.
content - Content to insert.
Returns:
true because the HTML has been modified and it has to be rewritten.

getAdContent

private String getAdContent(int type)
Returns the Google ad according to the requested type.

Parameters:
type - Type of ad.
Returns:
Script to show this ad in html.

getCommon

private org.jdom.Element getCommon()
Returns:
Returns the common part of Google Ad.

getCustomPoweredBy

private boolean getCustomPoweredBy(org.jdom.Element single)
Replaces the customPoweredBy tag with the given code.

TODO this should call an external javascript file that will contain the code and stuff to show here.

Parameters:
single - Element where the custom code has to be inserted.
Returns:
true to indicate that the file has been modified..

getFacebookILike

private boolean getFacebookILike(org.jdom.Element single)
Returns the I like Facebook script.

<iframe src= "http://www.facebook.com/plugins/like.php? href=https%3A%2F%2Fwww.facebook.com%2Fpages%2FZemucan%2F138284808329 &send=false&layout=box_count&width=150&show_faces=false &action=like&colorscheme=light&font&height=90" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:150px; height:90px;" allowTransparency="true"></iframe>

The example is for Zemucan, but it is defined in the variable facebookLink. There are two types of links:

However the link has to be transformed from

https://www.facebook.com/pages/Zemucan/138284808329

to

https%3A%2F%2Fwww.facebook.com%2Fpages%2FZemucan%2F138284808329

Parameters:
single - Element where the code has to be inserted.
Returns:
true to indicate that the file has been modified.

getGooglePlusOne

private boolean getGooglePlusOne(org.jdom.Element single)
Adds the google plus one script in the page.

Parameters:
Element - where the code has to be inserted.
Returns:
true to indicate that the file has been modified.

htmlReplacement

private boolean htmlReplacement(org.jdom.Element elem)
                         throws org.jdom.JDOMException
Searches the tags to modify the HTML file and call the respective method to insert an ad.

Vertical (xpath: html/body/div id="leftColumn"/div id="navcolumn" title="googleAds"):

<a href="" title="googleAds" class="poweredBy">
<logo name="googleAds" img="googleAds"/>
</a>

Horizontal (xpath: html/body/div id="bodyColumn"/div id="contextBox"/div class="section"):

<img src="googleAds" alt="googleAds" />

Unique (xpath: html/body/div id="bodyColumn"/div id="contextBox"/div class="section"/p):

<a href="#googleAds">googleAds</a>

Logo (xpath: html/body/div id="banner"/span id="bannerLeft" | id="bannerRight"):

<img src="googleAds" alt="googleAds" />

And then put the publicity:

<script type="text/javascript"><!--
google_ad_client = "XXXXX";
google_ad_slot = "YYYYY";
google_ad_width = 120;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

Where XXXXX the google user id, and YYYYY is the ad identifier.

Also, it replaces the powered by for facebook (xpath: html/body/div id="leftColumn"/div id="navcolumn" title="facebookILike").

<a href="" title="facebookILike" class="poweredBy">
<logo name="facebookILike" img="facebookILike"/>
</a>

And a custom code as powered by (xpath: html/body/div id="leftColumn"/div id="navcolumn" title="customPoweredBy").

<a href="" title="customPoweredBy" class="poweredBy">
<logo name="customPoweredBy" img="customPoweredBy"/>
</a>

Parameters:
elem - Root element.
Returns:
true if the HTML has been modified and it has to be rewritten, false otherwise.
Throws:
org.jdom.JDOMException - If there is a problem

replace

protected void replace(String directory,
                       String filename)
Open the file, parses the HTML and the searches the defined tags to replace with other content.

Parameters:
directory - Directory of the file.
filename - Name of the file to modify.


AngocA 2011 Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.