protected void injectBaseTag(Gadget gadget, Node headTag) {
GadgetContext context = gadget.getContext();
if (containerConfig.getBool(context.getContainer(), INSERT_BASE_ELEMENT_KEY)) {
Uri base = gadget.getSpec().getUrl();
View view = gadget.getCurrentView();
if (view != null && view.getHref() != null) {
base = view.getHref();
}
Element baseTag = headTag.getOwnerDocument().createElement("base");
baseTag.setAttribute("href", base.toString());
headTag.insertBefore(baseTag, headTag.getFirstChild());
}