Package org.itsnat.feashow.features.core.misc.remtmpl

Source Code of org.itsnat.feashow.features.core.misc.remtmpl.RemoteTemplateResultDocument

/*
* This file is not part of the ItsNat framework.
*
* Original source code use and closed source derivatives are authorized
* to third parties with no restriction or fee.
* The original source code is owned by the author.
*
* This program is distributed AS IS in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* (C) Innowhere Software a service of Jose Maria Arranz Santamaria, Spanish citizen.
*/

package org.itsnat.feashow.features.core.misc.remtmpl;

import java.io.Serializable;
import org.itsnat.core.ItsNatDocument;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.css.ElementCSSInlineStyle;
import org.w3c.dom.html.HTMLAnchorElement;
import org.w3c.dom.html.HTMLImageElement;
import org.w3c.dom.html.HTMLInputElement;

/**
*
* @author jmarranz
*/
public class RemoteTemplateResultDocument implements Serializable
{
    protected ItsNatDocument itsNatDoc;
   
    public RemoteTemplateResultDocument(ItsNatDocument itsNatDoc)
    {
        this.itsNatDoc = itsNatDoc;
        load();
    }

    public void load()
    {
        Document doc = itsNatDoc.getDocument();
      
        HTMLInputElement inputSearch = null;
        NodeList list = doc.getElementsByTagName("input");
        int len = list.getLength();
        for(int i = 0; i < len; i++)
        {
            HTMLInputElement input = (HTMLInputElement)list.item(i);
            String type = input.getType();
            if ("text".equals(type)) { inputSearch = input; break; }
        }

        Element div = doc.createElement("div");
        div.setAttribute("style","font-size:25px;");
        div.appendChild(doc.createTextNode("End of demo. Yes I know, is a clone far of perfect :)"));
        inputSearch.getParentNode().insertBefore(div, inputSearch);

        list = doc.getElementsByTagName("a");
        len = list.getLength();
        for(int i = 0; i < len; i++)
        {
            HTMLAnchorElement elem = (HTMLAnchorElement)list.item(i);
            String href = elem.getHref();
            if (!href.startsWith("http:"))
                elem.setHref("http://www.google.com" + href);
        }

        list = doc.getElementsByTagName("img");
        len = list.getLength();
        for(int i = 0; i < len; i++)
        {
            HTMLImageElement elem = (HTMLImageElement)list.item(i);
            String src = elem.getSrc();
            if (!src.startsWith("http:"))
                elem.setSrc("http://www.google.com" + src);
        }
    }
}
TOP

Related Classes of org.itsnat.feashow.features.core.misc.remtmpl.RemoteTemplateResultDocument

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.