private void InjectBaseTag(Gadget gadget, Node headTag)
 {
     GadgetContext context = gadget.getContext();
     if ("true".Equals(containerConfig.Get(context.getContainer(), INSERT_BASE_ELEMENT_KEY))) 
     {
         Uri baseUrl = gadget.getSpec().getUrl();
         View view = gadget.getCurrentView();
         if (view != null && view.getHref() != null) 
         {
             baseUrl = view.getHref();
         }
         Element baseTag = headTag.getOwnerDocument().createElement("base");
         baseTag.setAttribute("href", baseUrl.ToString());
         headTag.insertBefore(baseTag, headTag.getFirstChild());
     }
 }