<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dev @ Work &#187; SEO</title>
	<atom:link href="http://www.devatwork.nl/tag/seo/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devatwork.nl</link>
	<description>A day in the life of a developer</description>
	<lastBuildDate>Tue, 18 Oct 2011 16:32:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>SEO Friendly URLs for Liferay Portlets</title>
		<link>http://www.devatwork.nl/2010/04/seo-friendly-urls-for-liferay-portlets/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=seo-friendly-urls-for-liferay-portlets</link>
		<comments>http://www.devatwork.nl/2010/04/seo-friendly-urls-for-liferay-portlets/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 10:40:31 +0000</pubDate>
		<dc:creator>Bert Willems</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Liferay]]></category>
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/?p=679</guid>
		<description><![CDATA[In my previous article I showed you how you can optimize SEO from within a portlet. Today we will take it one step further: I will show you how you can optimize portlet URLs. By default the URLs generate by Liferay are quite messy; it contains the portlet ID, the state and several other options. [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-656" title="Liferay" src="http://www.devatwork.nl/wp-content/uploads/2010/01/liferay-logo-block.jpg" alt="" width="99" height="96" />In my <a title="SEO optimize a Liferay portlet – Title, Description, Keywords" href="http://www.devatwork.nl/2010/03/seo-optimize-a-liferay-portlet-title-description-keywords/">previous article</a> I showed you how you can optimize SEO from within a portlet. Today we will take it one step further: I will show you how you can optimize portlet URLs. By default the URLs generate by Liferay are quite messy; it contains the portlet ID, the state and several other options. This doesn&#8217;t really look nice for Google.</p>
<p>However, Liferay has a nice method of controlling the URL the portal generates for a portlet, the &#8216;<em>FriendlyURLMapper</em>&#8216;. You can implement this interface, registerd it in the liferay-portlet.xml and you will have nice URLs. In the following example I will show how to implement it and what each individual method does.</p>
<p><span id="more-679"></span>I assume you have installed Liferay and the plugin SDK and that you know how to develop Liferay portlets.</p>
<p>The first step is to create a new class which will implement the &#8216;<em>FriendlyURLMapper</em>&#8216; interface. To make things easies we will derive that class from &#8216;<em>BaseFriendlyURLMapper</em>&#8216;. You have to implement several methods yourself but don&#8217;t worry I will show you how.</p>
<h3>The getMapping method</h3>
<p>The &#8216;<em>getMapping</em>&#8216; method must return an identifier for the mapping. The mapping identifier is used by Liferay to map URLs to instances of the &#8216;<em>FriendlyURLMapper</em>&#8216;. For example Liferay will resolve the following URL &#8216;/seoPortlet/123/view&#8217; to a &#8216;<em>FriendlyURLMapper</em>&#8216; instance with mapping &#8216;<em>seoPortlet</em>&#8216;. You can choose whatever mapping you want, just make sure your custom URLs always start with the mapping identifier.</p>
<p>To implement the &#8216;<em>getMapping</em>&#8216; method just return an unique identifier for the URL mapper.</p>
<pre class="brush: java; title: ; notranslate">public String getMapping() {
    return &quot;seoPortlet&quot;;
}</pre>
<h3>The buildPath method</h3>
<p>The &#8216;<em>buildPath</em>&#8216; method builds the actual URL. Here you implement the URL generation logic. You have access to the &#8216;<em>LiferayPortletURL</em>&#8216; object for which the URL is generated. You can extract the portletId, parameters, window state, etc. from it. The method should return a string containing the friendly URL for that particular portletURL, when the method returns <em>null</em> the default portletURL is used.</p>
<p>For each parameter (p_p_id for example) you move from the query string to the URL, you need to call &#8216;<em>portletURL.addParameterIncludedInPath(&#8220;p_p_id&#8221;)</em>&#8216;. This will tell Liferay to not include the parameter in the query string. Parameters who are not marked as &#8216;included in path&#8217; will be added to the query string automatically by Liferay.</p>
<p>Here is an example which maps URLs with a parameter named event to a friendly URL.</p>
<pre class="brush: java; title: ; notranslate">public String buildPath(final LiferayPortletURL portletURL) {
    String friendlyURLPath = null;

    // get the value
    final String portletId = portletURL.getPortletId();
    final String eventName = GetterUtil.getString(portletURL.getParameter(&quot;event&quot;));

    if (Validator.isNotNull(portletId) &amp;&amp; Validator.isNotNull(eventName)) {
        friendlyURLPath = StringPool.FORWARD_SLASH + &quot;seoPortlet&quot;+ StringPool.FORWARD_SLASH + portletId + StringPool.FORWARD_SLASH + eventName;
        portletURL.addParameterIncludedInPath(&quot;event&quot;);
    }

    // add other pararmeters
    if (Validator.isNotNull(friendlyURLPath)) {
        portletURL.addParameterIncludedInPath(&quot;p_p_id&quot;);
    }

    return friendlyURLPath;
}</pre>
<p>Notice that we are including the mapping prefix &#8216;seoPortlet&#8217; and that we are excluding the &#8216;p_p_id&#8217; and &#8216;event&#8217;  parameters from the URL.</p>
<h3>The getPortletId method</h3>
<p>This method is used by the &#8216;<em>BaseFriendlyURLMapper</em>&#8216; super class to retrieve the portlet id. This will be used by <em>&#8216;populateParams</em>&#8216; method.</p>
<p>To implement the &#8216;<em>getPortletId</em>&#8216; method just return the value of a backing field with the name portletId. See example:</p>
<pre class="brush: java; title: ; notranslate">private String portletId;
public String getPortletId() {
    return portletId;
}</pre>
<h3>The populateParams method</h3>
<p>This method will be called by Liferay each time a request is made with the mapping identifier in the URL. This method is responsible for mapping the parameters we removed from the query string and added to the path back to parameters: reversing the work we did in the &#8216;buildPath&#8217; method.</p>
<p>Here is an example implementation.</p>
<pre class="brush: java; title: ; notranslate">public void populateParams(final String friendlyURLPath, final Map&lt;String, String[]&gt; params) {
    // get the values
    final String[] parts = StringUtil.split(friendlyURLPath, StringPool.SLASH);
    portletId = parts[2];
    final String event = parts[3];
    final String namespace = getNamespace();

    params.put(&quot;p_p_id&quot;, new String[]{portletId});
    params.put(&quot;p_p_state&quot;, new String[]{WindowState.NORMAL.toString()});
    params.put(namespace + &quot;event&quot;, new String[]{event});
}</pre>
<p>The method takes apart the &#8216;<em>friendlyURLPath</em>&#8216; and assembles parameters from it&#8217;s parts. Notice that in order to avoid parameter clashes between portlets the event parameter is prefixed with the portlet namespace, generated by the &#8216;<em>BaseFriendlyURLMapper</em>&#8221;s &#8216;<em>getNamespace</em>&#8216; method. The &#8216;<em>getNamespace</em>&#8216; method consumes the portletId using the &#8216;<em>getPortletId</em>&#8216; method.</p>
<h3>liferay-portlet.xml</h3>
<p>Now that the mapper is finished we need to tell Liferay to start using it. Add the friendly-url-mapper-class declaration to the portlet declaration and set its content to point to the class you just wrote:</p>
<pre class="brush: xml; title: ; notranslate">&lt;friendly-url-mapper-class&gt;com.sample.FriendlyURLMapper&lt;/friendly-url-mapper-class&gt;</pre>
<p>That is it, know you can assemble your own FriendlyURLMapper now. I hope this article was useful to you. Please let me know if you have any questions or comments.</p>

	Tags: <a href="http://www.devatwork.nl/tag/liferay/" title="Liferay" rel="tag">Liferay</a>, <a href="http://www.devatwork.nl/tag/seo/" title="SEO" rel="tag">SEO</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2010/04/seo-friendly-urls-for-liferay-portlets/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>SEO optimize a Liferay portlet &#8211; Title, Description, Keywords</title>
		<link>http://www.devatwork.nl/2010/03/seo-optimize-a-liferay-portlet-title-description-keywords/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=seo-optimize-a-liferay-portlet-title-description-keywords</link>
		<comments>http://www.devatwork.nl/2010/03/seo-optimize-a-liferay-portlet-title-description-keywords/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 13:28:52 +0000</pubDate>
		<dc:creator>Bert Willems</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Liferay]]></category>
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/?p=678</guid>
		<description><![CDATA[In this post I will show you how you can SEO optimize your Liferay portlets. When you are building a portal which is (partially) available to the general public you want the search engines to rank your portal as high as possible in order to draw as much traffic to your portal as possible. Because [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-656" title="Liferay" src="http://www.devatwork.nl/wp-content/uploads/2010/01/liferay-logo-block.jpg" alt="" width="99" height="96" />In this post I will show you how you can SEO optimize your Liferay portlets. When you are building a portal which is (partially) available to the general public you want the search engines to rank your portal as high as possible in order to draw as much traffic to your portal as possible. Because of the nature of a portal (a &#8216;empty&#8217; canvas filled with several unrelated portlets) it&#8217;s pages aren&#8217;t ideal for search engines because it hasn&#8217;t got a SEO description and keywords (or even a SEO friendly title).</p>
<p>In this post I will show you how you can in use build in features of Liferay to optimize SEO, First we will discus what you can do on a portal level and then I will show you how you can optimize SEO directly from a portlet itself.<br />
<span id="more-678"></span></p>
<h3>Liferay Page Search Engine Optimization</h3>
<p>In this section I will discuss the features Liferay provides to optimize SEO on a page level. First of all log in as (community) administrator on your portal. Navigate to the page you want to optimize. Click on &#8216;manage pages&#8217; in the dock. You will now see the following screen:</p>
<p><a href="http://www.devatwork.nl/wp-content/uploads/2010/03/edit-pages-seo.png" rel="lightbox[678]"><img class="alignnone size-medium wp-image-702" title="edit-pages-seo" src="http://www.devatwork.nl/wp-content/uploads/2010/03/edit-pages-seo-172x300.png" alt="" width="172" height="300" /></a></p>
<p>You can use HTML title to specify the title of the page, you can use this field to change the title of the page in the HTML to something much more elaborate, the title of the for example menu item will not change.</p>
<p>When you expand the &#8216;Meta Tags&#8217; tab you can specify (localized!) values for description and keywords.</p>
<p>Although this level of optimization is sufficient for static content, it wont react to the individual portlets displayed on the page: If you have a detail portlet for example you might want to extract keywords from it. In the next section I will show you how to achieve that.</p>
<h3>Liferay Portlet Search Engine Optimization</h3>
<p>In this section I will show you how you can optimize page SEO from inside a portlet, this is done using a Liferay specific API.  You can use the API from the <em>com.liferay.portal.util.PortalUtil</em> class. There are a lot of methods in this class but you only need a few of them to perform SEO optimization. Please take a look at the following documented code:</p>
<pre class="brush: java; title: ; notranslate">// Adds a title to the page
PortalUtil.addPageTitle(&quot;title&quot;, PortalUtil.getHttpServletRequest(renderRequest));
// Adds a subtitle to the page
PortalUtil.addPageSubtitle(&quot;subtitle&quot;, PortalUtil.getHttpServletRequest(renderRequest));
// Adds a description to the page
PortalUtil.addPageDescription(&quot;description&quot;, PortalUtil.getHttpServletRequest(renderRequest));
// adds a keyword to the page
PortalUtil.addPageKeywords(&quot;keywords&quot;, PortalUtil.getHttpServletRequest(renderRequest));
//Replaces the title of the page with this
PortalUtil.setPageTitle(&quot;title&quot;, PortalUtil.getHttpServletRequest(renderRequest));
// Replaces the subtitle of the page with this
PortalUtil.setPageSubtitle(&quot;subtitle&quot;, PortalUtil.getHttpServletRequest(renderRequest));
// Replaces the description of the page with this
PortalUtil.setPageDescription(&quot;description&quot;, PortalUtil.getHttpServletRequest(renderRequest));
// Replaces the keyword of the page with this
PortalUtil.setPageKeywords(&quot;keyword&quot;, PortalUtil.getHttpServletRequest(renderRequest));</pre>
<p>I recommend that you make use of the addPage* function because you don&#8217;t know what other portlets will be on the page.</p>
<p>That is it for now. You can find a tutorial on <a title="SEO Friendly URLs for Liferay Portlets" href="http://www.devatwork.nl/2010/04/seo-friendly-urls-for-liferay-portlets/">how to create portlet SEO friendly URLs here</a>.</p>

	Tags: <a href="http://www.devatwork.nl/tag/liferay/" title="Liferay" rel="tag">Liferay</a>, <a href="http://www.devatwork.nl/tag/seo/" title="SEO" rel="tag">SEO</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2010/03/seo-optimize-a-liferay-portlet-title-description-keywords/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

