Example usage for com.google.gwt.xml.client Document createProcessingInstruction

List of usage examples for com.google.gwt.xml.client Document createProcessingInstruction

Introduction

In this page you can find the example usage for com.google.gwt.xml.client Document createProcessingInstruction.

Prototype

ProcessingInstruction createProcessingInstruction(String target, String data);

Source Link

Document

This method creates a new ProcessingInstruction.

Usage

From source file:org.openxdata.designer.client.util.LanguageUtil.java

/**
 * Creates a new language of locale document.
 * //www.j a  v a 2s  .c o m
 * @return the new language document.
 */
public static Document createNewLanguageDoc() {
    com.google.gwt.xml.client.Document doc = XMLParser.createDocument();
    doc.appendChild(doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));
    Element rootNode = doc.createElement("LanguageText");
    rootNode.setAttribute("lang", Context.getLocale().getKey());
    doc.appendChild(rootNode);
    return doc;
}

From source file:org.openxdata.designer.client.view.DesignSurfaceView.java

/**
 * Gets the widgets layout xml./*from w w w .  java  2 s  .  co  m*/
 * 
 * @return the xml.
 */
public String getLayoutXml() {

    if (tabs.getWidgetCount() == 0)
        return null;

    com.google.gwt.xml.client.Document doc = XMLParser.createDocument();
    doc.appendChild(doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));
    Element rootNode = doc.createElement("Form");
    if (formDef != null)
        rootNode.setAttribute(XformConstants.ATTRIBUTE_NAME_ID, formDef.getId() + "");
    doc.appendChild(rootNode);

    this.doc = doc;

    boolean hasWidgets = false;
    AbsolutePanel prevSelPanel = selectedPanel;
    for (int i = 0; i < tabs.getWidgetCount(); i++) {
        Element node = doc.createElement("Page");
        node.setAttribute(WidgetEx.WIDGET_PROPERTY_TEXT,
                DesignWidgetWrapper.getTabDisplayText(tabs.getTabBar().getTabHTML(i)));

        pageWidgets.get(i).buildLabelProperties(node);

        if (pageWidgets.get(i) != null)
            node.setAttribute(WidgetEx.WIDGET_PROPERTY_BINDING, pageWidgets.get(i).getBinding());

        rootNode.appendChild(node);
        AbsolutePanel panel = (AbsolutePanel) tabs.getWidget(i);

        selectedPanel = panel;
        node.setAttribute(WidgetEx.WIDGET_PROPERTY_WIDTH, getWidth());
        node.setAttribute(WidgetEx.WIDGET_PROPERTY_HEIGHT, getHeight());
        node.setAttribute(WidgetEx.WIDGET_PROPERTY_BACKGROUND_COLOR, getBackgroundColor());

        boolean b = buildLayoutXml(node, panel, doc);
        if (b)
            hasWidgets = true;
    }

    selectedPanel = prevSelPanel;

    if (hasWidgets)
        return FormDesignerUtil.formatXml(doc.toString());

    return null;
}

From source file:org.openxdata.designer.client.view.DesignSurfaceView.java

/**
 * Gets the root node of the language or locale translation document for the widgets 
 * layout on the design surface.//from   w ww .ja va  2s.  c om
 * 
 * @return the root node.
 */
public Element getLanguageNode() {
    if (tabs.getWidgetCount() == 0)
        return null;

    com.google.gwt.xml.client.Document doc = XMLParser.createDocument();
    doc.appendChild(doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));
    Element rootNode = doc.createElement("Form");
    if (formDef != null)
        rootNode.setAttribute(XformConstants.ATTRIBUTE_NAME_ID, formDef.getId() + "");
    doc.appendChild(rootNode);

    for (int i = 0; i < tabs.getWidgetCount(); i++) {
        if (pageWidgets.get(i) == null)
            continue; //TODO Need to deal with this case where all widgets are deleted but layout and locale text remains

        String xpath = "Form/Page[@Binding='" + pageWidgets.get(i).getBinding() + "']/Item[@";

        String text = DesignWidgetWrapper.getTabDisplayText(tabs.getTabBar().getTabHTML(i));
        Element node = doc.createElement(XformConstants.NODE_NAME_TEXT);
        node.setAttribute(XformConstants.ATTRIBUTE_NAME_XPATH,
                "Form/Page[@Binding='" + pageWidgets.get(i).getBinding() + "'][@Text]");
        node.setAttribute(XformConstants.ATTRIBUTE_NAME_VALUE, text);
        rootNode.appendChild(node);

        buildLanguageNode((AbsolutePanel) tabs.getWidget(i), doc, rootNode, xpath);
    }

    return rootNode;
}

From source file:org.openxdata.designer.client.xforms.OpenXdataFormBuilder.java

public static String build(FormDef formDef, HashMap<String, String> localeText) {

    Document doc = XMLParser.createDocument();
    doc.appendChild(doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));

    Element openXdataFormNode = doc.createElement("PurcForm");
    doc.appendChild(openXdataFormNode);/*  w  w w .  j  a  v  a 2 s.c  om*/

    Element xformNode = doc.createElement("Xform");
    Element node = (Element) formDef.getDoc().getDocumentElement().cloneNode(true);
    doc.importNode(node, true);
    xformNode.appendChild(node);
    openXdataFormNode.appendChild(xformNode);

    String xml = formDef.getLayoutXml();
    if (xml != null && xml.trim().length() > 0) {
        node = (Element) XmlUtil.getDocument(xml).getDocumentElement().cloneNode(true);
        doc.importNode(node, true);
        Element layoutNode = doc.createElement("Layout");
        layoutNode.appendChild(node);
        openXdataFormNode.appendChild(layoutNode);
    }

    String src = formDef.getJavaScriptSource();
    if (src != null && src.trim().length() > 0) {
        Element javaScriptNode = doc.createElement("JavaScript");
        javaScriptNode.appendChild(doc.createCDATASection(src));
        openXdataFormNode.appendChild(javaScriptNode);
    }

    openXdataFormNode.appendChild(getLanguageNode(doc, localeText));

    return XmlUtil.fromDoc2String(doc);
}

From source file:org.openxdata.designer.client.xforms.OpenXdataFormBuilder.java

public static String getCombinedLanguageText(HashMap<String, String> localeText) {
    Document doc = XMLParser.createDocument();
    doc.appendChild(doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));
    doc.appendChild(getLanguageNode(doc, localeText));

    return XmlUtil.fromDoc2String(doc);
}

From source file:org.openxdata.designer.client.xforms.XhtmlBuilder.java

/**
 * Converts a form definition object to an XHTML document object.
 * //from w w  w . ja v a 2 s  .c  om
 * @param formDef the form definition object.
 * @return the xhtml document object.
 */
public static Document fromFormDef2XhtmlDoc(FormDef formDef) {
    Document prevdoc = formDef.getDoc();

    Document doc = XMLParser.createDocument();
    doc.appendChild(doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));

    Element htmlNode = doc.createElement("h:html");
    //formDef.setXformsNode(htmlNode);

    htmlNode.setAttribute("xmlns:h", "http://www.w3.org/1999/xhtml");
    htmlNode.setAttribute("xmlns:jr", "http://openrosa.org/javarosa");
    htmlNode.setAttribute(
            XformConstants.XML_NAMESPACE /*XformConstants.XML_NAMESPACE_PREFIX+XformConstants.PREFIX_XFORMS*/,
            XformConstants.NAMESPACE_XFORMS);
    htmlNode.setAttribute(XformConstants.XML_NAMESPACE_PREFIX + XformConstants.PREFIX_XML_SCHEMA,
            XformConstants.NAMESPACE_XML_SCHEMA);

    doc.appendChild(htmlNode);

    //add head
    Element headNode = doc.createElement("h:head");
    htmlNode.appendChild(headNode);

    //add title
    Element titleNode = doc.createElement("h:title");
    titleNode.appendChild(doc.createTextNode(formDef.getName()));
    headNode.appendChild(titleNode);

    //add body
    Element bodyNode = doc.createElement("h:body");
    htmlNode.appendChild(bodyNode);

    //add model
    Element modelNode = doc.createElement(XformConstants.NODE_NAME_MODEL);
    headNode.appendChild(modelNode);

    //we do not want to lose anything that the model could have had which we do not build when
    //creating an xform from scratch
    XformBuilder.buildXform(formDef, doc, bodyNode, modelNode);

    XformUtil.copyModel(prevdoc, doc);

    return doc;
}

From source file:org.openxdata.sharedlib.client.model.FormDef.java

public Element getLanguageNode() {
    com.google.gwt.xml.client.Document doc = XMLParser.createDocument();
    doc.appendChild(doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));
    Element rootNode = doc.createElement("xform");
    rootNode.setAttribute(XformConstants.ATTRIBUTE_NAME_ID, id + "");
    doc.appendChild(rootNode);/*from  www  .  j  a v  a2  s . co  m*/

    if (dataNode != null) {
        Element node = doc.createElement(XformConstants.NODE_NAME_TEXT);
        node.setAttribute(XformConstants.ATTRIBUTE_NAME_XPATH, FormUtil.getNodePath(dataNode) + "[@name]");
        node.setAttribute(XformConstants.ATTRIBUTE_NAME_VALUE, name);
        rootNode.appendChild(node);

        if (pages != null) {
            for (int index = 0; index < pages.size(); index++)
                ((PageDef) pages.elementAt(index)).buildLanguageNodes(doc, rootNode);
        }

        if (validationRules != null) {
            for (int index = 0; index < validationRules.size(); index++)
                ((ValidationRule) validationRules.elementAt(index)).buildLanguageNodes(this, rootNode);
        }

        if (dynamicOptions != null) {
            Iterator<Entry<Integer, DynamicOptionDef>> iterator = dynamicOptions.entrySet().iterator();
            while (iterator.hasNext())
                iterator.next().getValue().buildLanguageNodes(this, rootNode);
        }
    }

    return rootNode;
}

From source file:org.openxdata.sharedlib.client.xforms.XformBuilder.java

/**
 * Converts a form definition object to its xforms xml.
 * //from w ww.  j  a  va 2s  .  c  om
 * @param formDef the form definition object.
 * @return the xforms xml.
 */
public static String fromFormDef2Xform(FormDef formDef) {

    //Create a new document.
    Document doc = XMLParser.createDocument();
    doc.appendChild(doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));
    formDef.setDoc(doc);

    //Create the document root node.
    Element xformsNode = doc.createElement(XformConstants.NODE_NAME_XFORMS);
    formDef.setXformsNode(xformsNode);

    //Set the xf and xsd prefix values and then add the root node to the document. 
    xformsNode.setAttribute(
            XformConstants.XML_NAMESPACE /*XformConstants.XML_NAMESPACE_PREFIX+XformConstants.PREFIX_XFORMS*/,
            XformConstants.NAMESPACE_XFORMS);
    xformsNode.setAttribute(XformConstants.XML_NAMESPACE_PREFIX + XformConstants.PREFIX_XML_SCHEMA,
            XformConstants.NAMESPACE_XML_SCHEMA);
    doc.appendChild(xformsNode);

    //Create the xforms model node and add it to the root node.
    Element modelNode = doc.createElement(XformConstants.NODE_NAME_MODEL);
    xformsNode.appendChild(modelNode);

    //Now build the rest of the xforms elements and add them to the document.
    buildXform(formDef, doc, xformsNode, modelNode);

    //Return the string representation of the document to the caller.
    return XmlUtil.fromDoc2String(doc);
}

From source file:org.openxdata.sharedlib.client.xforms.XformUtil.java

/**
 * Gets the instance data node of an xforms document as a new document.
 * //from  w  ww.  ja  va 2 s . c o m
 * @param doc the xforms document.
 * @return the new document having the instance data node as its root node.
 */
public static Document getInstanceDataDoc(Document doc) {
    Element data = getInstanceDataNode(getInstanceNode(doc));
    Document dataDoc = XMLParser.createDocument();
    dataDoc.appendChild(dataDoc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));
    dataDoc.appendChild(data.cloneNode(true));

    Element root = dataDoc.getDocumentElement();
    NamedNodeMap attributes = doc.getDocumentElement().getAttributes();
    for (int index = 0; index < attributes.getLength(); index++) {
        Node attribute = attributes.item(index);
        String name = attribute.getNodeName();
        if (name.startsWith("xmlns:")) {
            try {
                root.setAttribute(name, attribute.getNodeValue());
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    return dataDoc;
}