File host /etc/host seems not working in Mac OSX Lion 10.7

Posted in Uncategorized on October 17th, 2011 by admin – Be the first to comment

Sometimes, you need to override a dns public entry with a custom one.
Of course, you’ll modify the hosts file.
In Mac OS X, like in *nix operating system, it’s located in /etc/hosts and you can edit it using root permissions.
But, in osx lion 10.7, your system will use the network DNS, then the hosts file.
All you need to do, is to install a local DNS server – DNSMasq using MacPort, then add 127.0.0.1 as a DNS server and move it to first in network configuration panel.

As soon as possible I’ll post the steps necessary to get it working.

Create XsltExtension and using in Umbraco 4.5

Posted in .NET, Umbraco 4.5 on July 12th, 2010 by admin – Be the first to comment

This post will explain how to create and use Xslt Extension in Umbraco 4.5.We will add few basic function we always needs in everyday coding.
First of all, we need to create a class library project (you can add this project to your solution or create a new solution). All we need is to add references to umbraco dlls. Generally umbraco, cms, interfaces and businesslogic will cover all our needs.

Now we will add a new class (for example, Library in Library.cs) and add two  methods: QueryString and ToUpper:

public class Library
{
 public String QueryString(String key, String defaultValue)
 {
   return HttpContext.Current.Request.QueryString[key] ?? defaultValue;
 }

 public String ToUpper(String inputString)
 {
   return inputString.ToUpper();
 }
}

Next, we need to put the output assembly in the Umbraco bin folder, then open the file /config/xsltExtension.config and add this line before the </XsltExtensions> closing tag:

<ext
  assembly="My.Umbraco.XsltExtensions"
  type="My.Umbraco.XsltExtensions.Library"
  alias="my" />

Finally, in our xslt files, we have to modify the xsl:stylesheet opening tag:

<xsl:stylesheet 
  version="1.0"  
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:umbraco.library="urn:umbraco.library"
  xmlns:my="urn:my"
  exclude-result-prefixes="msxml umbraco.library my">

and use our methods in this way:


where exampleText is a dataType “textstring” of the current page document type.


Autocomplete in Umbraco 4.5 using jQuery

Posted in .NET, Umbraco 4.5 on July 12th, 2010 by admin – Be the first to comment

I was searching too much, and never found something fast and useful. So I had to implmenet, using jQuery and the new Umbraco 4.5 a frontend feature everyone calls “AutoComplete”.

Here it is my implementation; of course it could be faster and optimized, but this solution works pretty nice with the website i was working on.

First of all, we need jQuery on our website, I’m using the 1.4.2 version today. Next, we need the jQuery UI plugin downloadable from here (remember the dependencies if you choose custom download).

When we could have this (I choosed the custom download) in our head tag:

<script type="text/javascript" src="/scripts/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/scripts/jquery-ui-1.8.2.custom.min.js"></script>

we can go on.

Next step is to create the remote datasource for autocomplete. I suppose we needs to “autocomplete” only one of our document-types called ExampleDoc, ad I also suppose we have ad homepage tree node using ExampleHome as a document-type.

If you don’t use, we should create a node “Services” in our content tree. This node will contains services nodes will be never shown in menus or in website, but we use it for other purposes, like this example.

As a child of Services we create a node called “AutoComplete”. In the template (masterpage) corresponding to the document-type, we will add a Umbraco Macro referencing a new xslt file, we should AutoComplete.xslt.

The output I’m expecting is a json serialized object will be deserialized  by jQuery UI plugin we download before.

So i work in this way:

<xsl:template match="/">
  [
  <xsl:for-each select="$currentPage/ancestor-or-self::ExampleHome/descendant::ExampleDoc[@isDoc and starts-with(my:ToUpper(./@nodeName), my:ToUpper(my:QueryString('term','')))]">

    { "id": "<xsl:value-of select="./@nodeName"/>",
    "label": "<xsl:value-of select="./@nodeName"/>",
    "value": "<xsl:value-of select="./@nodeName"/>" }
    <xsl:if test="position()!=last()">
      ,
    </xsl:if>
  </xsl:for-each>
  ]
</xsl:template>

You can clearly see I use two custom functions (Xslt Extension): ToUpper and QueryString. Here it is a post shows how to create and use these methods in xslt files.

Now, we just need to add this script to our page contains the search text-box:

$(function () {
  $("input#searchText").autocomplete({
    source: "/services/autocomplete.aspx",
    minLength: 2
  });
});

where /services/autocomplete.aspx is the page corresponding to the page contains the macro just created.

Breadcrumbs in Umbraco 4.5

Posted in .NET, Umbraco 4.5 on July 11th, 2010 by admin – Be the first to comment

Working on a new website using the new Umbraco 4.5 (with the new xml schema), I had to write a new Breadcrumb xslt.

So, let’s see how we can handle this feature:

First, I’m assuming the HTML structure I wish at the end:

<div id="breadcrumb">
  <ul>
    <li>
      <a href="/" title="Home">Home</a>
    </li>
    <li>
      <a href="/parent.aspx" title="Parent">Parent</a>
    </li>
    <li>Current Page</li>
  </ul>
</div>

I’m assuming too my root DocumentType (the homepage one) is called “CommonHomePage” and my homepage url is the relative “/”.

Let’s begin with the “HOME” item we should manage in a different way than others:

        <li>
          <xsl:choose>
            <xsl:when test="$currentPage/ancestor-or-self::CommonHomePage/@id = $currentPage/@id">
              <xsl:value-of select="umbraco.library:GetDictionaryItem('Home')" />
            </xsl:when>
            <xsl:otherwise>
              <a href="/" title="{umbraco.library:GetDictionaryItem('Home')}">
                <xsl:value-of select="umbraco.library:GetDictionaryItem('Home')" />
              </a>
            </xsl:otherwise>
          </xsl:choose>
        </li>

With this piece of code, you’ll get Home with or without link based on current location.
Now you should keep the “Home”-code, we will use it later.

Next, I will create a recursive xsl template:

  <xsl:template name="innerNode">
    <xsl:param name="node"/>
        <xsl:for-each select="$node/*[@isDoc]">
          <xsl:if test="./descendant::*/@id = $currentPage/@id or ./@id = $currentPage/@id">
            <li>
              <xsl:choose>
                <xsl:when test="not(./@id = $currentPage/@id)">
                  <a href="{umbraco.library:NiceUrl(@id)}" title="{@nodeName}">
                    <xsl:value-of select="@nodeName" />
                  </a>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="@nodeName" />
                </xsl:otherwise>
              </xsl:choose>
            </li>
          </xsl:if>
          <xsl:call-template name="innerNode">
            <xsl:with-param name="node" select="."/>
          </xsl:call-template>
        </xsl:for-each>
  </xsl:template>

Now we can call this template from the “/” template:

  <xsl:template match="/">
    <div id="breadcrumb">
      <ul>
        <xsl:call-template name="innerNode">
          <xsl:with-param name="node" select="$currentPage/ancestor-or-self::CommonHomePage"/>
        </xsl:call-template>
      </ul>
    </div>
  </xsl:template>

And now it’s time to put the “Home” piece of code, so this is the full code:

><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp " ">
]>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">

  <xsl:output method="xml" omit-xml-declaration="yes" />

  <xsl:param name="currentPage"/>

  <xsl:template match="/">
    <div id="breadcrumb">
      <ul>
        <li>
          <xsl:choose>
            <xsl:when test="$currentPage/ancestor-or-self::CommonHomePage/@id = $currentPage/@id">
              <xsl:value-of select="umbraco.library:GetDictionaryItem('Home')" />
            </xsl:when>
            <xsl:otherwise>
              <a href="/" title="{umbraco.library:GetDictionaryItem('Home')}">
                <xsl:value-of select="umbraco.library:GetDictionaryItem('Home')" />
              </a>
            </xsl:otherwise>
          </xsl:choose>
        </li>
        <xsl:call-template name="innerNode">
          <xsl:with-param name="node" select="$currentPage/ancestor-or-self::CommonHomePage"/>
        </xsl:call-template>
      </ul>
    </div>
  </xsl:template>

  <xsl:template name="innerNode">
    <xsl:param name="node"/>
        <xsl:for-each select="$node/*[@isDoc]">
          <xsl:if test="./descendant::*/@id = $currentPage/@id or ./@id = $currentPage/@id">
            <li>
              <xsl:choose>
                <xsl:when test="not(./@id = $currentPage/@id)">
                  <a href="{umbraco.library:NiceUrl(@id)}" title="{@nodeName}">
                    <xsl:value-of select="@nodeName" />
                  </a>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="@nodeName" />
                </xsl:otherwise>
              </xsl:choose>
            </li>
          </xsl:if>
          <xsl:call-template name="innerNode">
            <xsl:with-param name="node" select="."/>
          </xsl:call-template>
        </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

We have $node/*[isDoc] because the new XML schema.
Each child of $node now have as its nodename its alias. The empty attribute isDoc ensured it is a Document-Node, and not a Property-node.