Example usage for org.w3c.dom Text appendData

List of usage examples for org.w3c.dom Text appendData

Introduction

In this page you can find the example usage for org.w3c.dom Text appendData.

Prototype

public void appendData(String arg) throws DOMException;

Source Link

Document

Append the string to the end of the character data of the node.

Usage

From source file:Main.java

public static void modifyingTextbyCuttingandPasting(Document doc) {
    Element root = doc.getDocumentElement();
    Element place = (Element) root.getFirstChild();
    Text name = (Text) place.getFirstChild().getFirstChild();
    Text directions = (Text) place.getLastChild().getFirstChild();

    //    name.deleteData(offset,count);
    name.deleteData(2, 3);//from w  ww.ja v a 2 s. c  o  m

    //String bridge = directions.substringData(offset,count);
    String bridge = directions.substringData(2, 3);
    name.appendData(bridge);
}

From source file:DOMEdit.java

public static void modifyingTextbyCuttingandPasting(Document doc) {
        Element root = doc.getDocumentElement();
        Element place = (Element) root.getFirstChild();
        Text name = (Text) place.getFirstChild().getFirstChild();
        Text directions = (Text) place.getLastChild().getFirstChild();

        //    name.deleteData(offset,count);
        name.deleteData(2, 3);//from   w w  w  .  j av a  2s .  c o  m

        //String bridge = directions.substringData(offset,count);
        String bridge = directions.substringData(2, 3);
        name.appendData(bridge);
    }

From source file:com.icesoft.faces.component.panelpopup.PanelPopupRenderer.java

public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    validateParameters(facesContext, uiComponent, PanelPopup.class);

    String styleClass = (String) uiComponent.getAttributes().get("styleClass");
    String headerClass = (String) uiComponent.getAttributes().get("headerClass");
    String bodyClass = (String) uiComponent.getAttributes().get("bodyClass");
    Boolean resizable = null; // resizable functionality has not been
    // implemented yet.
    Boolean modal = (Boolean) uiComponent.getAttributes().get("modal");
    if (log.isTraceEnabled()) {
        log.trace("Value of modal is [" + modal + "]");
    }/*from w w w.j av a  2 s .co m*/
    Boolean visible = (Boolean) uiComponent.getAttributes().get("visible");

    String dndType = getDndType(uiComponent);

    DOMContext domContext = DOMContext.attachDOMContext(facesContext, uiComponent);

    // initialize DOMContext
    PanelPopup panelPopup = (PanelPopup) uiComponent;

    String clientId = uiComponent.getClientId(facesContext);

    Element rootDiv = domContext.createRootElement(HTML.DIV_ELEM);
    setRootElementId(facesContext, rootDiv, uiComponent);
    rootDiv.setAttribute(HTML.NAME_ATTR, clientId);
    DOMContext.enableOnElementUpdateNotify(rootDiv, clientId);

    if (uiComponent instanceof PanelTooltip) {
        if (((PanelTooltip) uiComponent).isDynamic() && !((PanelTooltip) uiComponent).isVisible()) {
            rootDiv.setAttribute(HTML.STYLE_ATTR, "display:none;");
            domContext.stepOver();
            return;
        }
    }
    Element table = domContext.createElement(HTML.TABLE_ELEM);
    table.setAttribute(HTML.CELLPADDING_ATTR, "0");
    table.setAttribute(HTML.CELLSPACING_ATTR, "0");
    //         table.setAttribute(HTML.WIDTH_ATTR, "100%");
    rootDiv.appendChild(table);
    /*
            Text iframe = domContext.createTextNode("<!--[if lte IE 6.5]><iframe src=\"" +
        CoreUtils.resolveResourceURL(FacesContext.getCurrentInstance(), "/xmlhttp/blank") +
        "\" class=\"iceIEIFrameFix\" style=\"width:100%;height:100%;\"></iframe><![endif]-->");
            rootDiv.appendChild(iframe);
    */
    // extracted from GroupRenderer encodeBegin
    if (dndType != null) {
        // Drag an drop needs some hidden fields
        Element statusField = createHiddenField(domContext, facesContext, uiComponent, STATUS);
        rootDiv.appendChild(statusField);
        Element targetID = createHiddenField(domContext, facesContext, uiComponent, DROP);
        rootDiv.appendChild(targetID);
        UIComponent form = findForm(uiComponent);
        String formId = form.getClientId(facesContext);
        FormRenderer.addHiddenField(facesContext, ClientIdPool.get(
                formId + UINamingContainer.getSeparatorChar(FacesContext.getCurrentInstance()) + HIDDEN_FIELD));
    }
    // Write Modal Javascript so that on refresh it will still be modal.
    String script = modalJavascript(uiComponent, modal, visible, facesContext, clientId);
    Element scriptWrapper = domContext.createElement(HTML.SPAN_ELEM);
    scriptWrapper.setAttribute(HTML.ID_ATTR, ClientIdPool.get(clientId + "script"));
    Element scriptEle = domContext.createElement(HTML.SCRIPT_ELEM);
    scriptEle.setAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT);
    Text scriptTextNode = domContext.createTextNodeUnescaped(script);
    rootDiv.appendChild(scriptWrapper);
    scriptWrapper.appendChild(scriptEle);
    scriptEle.appendChild(scriptTextNode);

    Element root = (Element) domContext.getRootNode();

    try {
        root.setAttribute(HTML.CLASS_ATTR, styleClass);
    } catch (Exception e) {
        log.error("Error rendering Modal Panel Popup ", e);
    }
    JavascriptContext.fireEffect(uiComponent, facesContext);

    // get tables , our table is the first and only one
    NodeList tables = root.getElementsByTagName(HTML.TABLE_ELEM);
    // assumption we want the first table in tables. there should only be
    // one
    Element t = (Element) tables.item(0);
    // clean out child nodes and build a fresh selectinputdate
    DOMContext.removeChildrenByTagName(t, HTML.TR_ELEM);

    doPassThru(facesContext, uiComponent, root);
    String handleId = null;
    if (panelPopup.getHeader() != null) {
        Element headerTr = domContext.createElement(HTML.TR_ELEM);
        Element headerTd = domContext.createElement(HTML.TD_ELEM);
        headerTd.setAttribute(HTML.CLASS_ATTR, headerClass);
        handleId = ClientIdPool.get(uiComponent.getClientId(facesContext) + "Handle");
        headerTd.setAttribute(HTML.ID_ATTR, handleId);
        //            headerTd.setAttribute(HTML.STYLE_ATTR, "width:100%;");
        headerTr.appendChild(headerTd);
        Element headerTdSpacer = domContext.createElement(HTML.TD_ELEM);
        Element headerDiv = domContext.createElement("div");
        headerDiv.setAttribute(HTML.STYLE_ATTR, "width:1px;");
        headerTdSpacer.setAttribute(HTML.CLASS_ATTR, headerClass);
        headerTdSpacer.appendChild(headerDiv);
        headerTr.appendChild(headerTdSpacer);
        // add header facet to header tr and add to table
        t.appendChild(headerTr);
        // set the cursor parent to the new table row Element
        // to the new table row Element
        domContext.setCursorParent(headerTd);

        UIComponent header = panelPopup.getHeader();
        CustomComponentUtils.renderChild(facesContext, header);
    }

    if (panelPopup.getBody() != null) {

        Element bodyTr = domContext.createElement(HTML.TR_ELEM);
        Element bodyTd = domContext.createElement(HTML.TD_ELEM);

        bodyTd.setAttribute(HTML.CLASS_ATTR, bodyClass);
        bodyTr.setAttribute(HTML.ID_ATTR, ClientIdPool.get(clientId + "-tr"));
        bodyTr.appendChild(bodyTd);
        bodyTd.setAttribute(HTML.COLSPAN_ATTR, "2");
        // add body facet to body tr then add to table
        t.appendChild(bodyTr);
        // set the cursor parent to the new table row Element
        // this will cause the renderChild method to append the child nodes
        // to the new table row Element
        domContext.setCursorParent(bodyTd);

        UIComponent body = panelPopup.getBody();

        CustomComponentUtils.renderChild(facesContext, body);
    }
    // if the popup is resizable render a resize handle
    if (resizable != null && resizable.booleanValue()) {
        Element footerTr = domContext.createElement(HTML.TR_ELEM);
        footerTr.setAttribute(HTML.HEIGHT_ATTR, "15px");
        footerTr.setAttribute(HTML.STYLE_ATTR, "text-align: right; float: right;");
        Element footerTd = domContext.createElement(HTML.TD_ELEM);
        footerTd.setAttribute(HTML.STYLE_CLASS_ATTR, "panelPopupFooter");
        footerTd.setAttribute(HTML.COLSPAN_ATTR, "2");
        Element img = domContext.createElement(HTML.IMG_ELEM);
        img.setAttribute(HTML.SRC_ATTR,
                CoreUtils.resolveResourceURL(facesContext, "/xmlhttp/css/xp/css-images/resize.gif"));
        img.setAttribute(HTML.STYLE_ATTR, "cursor: se-resize");
        footerTd.appendChild(img);
        footerTr.appendChild(footerTd);
        t.appendChild(footerTr);
    }

    panelPopup.applyStyle(facesContext, root);
    domContext.stepOver();

    // Rebroadcast Javascript to survive refresh
    if (dndType != null) {
        scriptTextNode.appendData("; Ice.DnD.adjustPosition('" + uiComponent.getClientId(facesContext) + "');");
        StringBuffer dropCall = new StringBuffer();
        String call = addJavascriptCalls(uiComponent, "DRAG", handleId, facesContext, dropCall);
        scriptTextNode.appendData("; " + call + (" //" + RANDOM.nextLong()));
        if (panelPopup.isClientOnly()) {
            //the "submit" method in the dragdrop_custom.js would check for this
            //element inside the panelPopup and will not fire submit if found
            Element clientOnly = domContext.createElement(HTML.INPUT_ELEM);
            clientOnly.setAttribute(HTML.TYPE_ATTR, "hidden");
            clientOnly.setAttribute(HTML.ID_ATTR, clientId + "clientOnly");
            clientOnly.setAttribute(HTML.AUTOCOMPLETE_ATTR, "off");
            root.appendChild(clientOnly);
        }
    }

    // autoPosition handling
    String autoPositionJS = null;
    boolean positionOnLoadOnly = panelPopup.isPositionOnLoadOnly();
    boolean dragged = panelPopup.isDragged();
    String positions = panelPopup.getAutoPosition();
    if (positions != null && !positions.equalsIgnoreCase("manual")
            && (!positionOnLoadOnly || (positionOnLoadOnly && !dragged))) {
        if (positions.indexOf(',') < 1) {
            if (positions.trim().length() != 0) {
                log.warn("The autoPosition attribute should be used with an "
                        + " x and y value for the position, such as '20,40'");
            }
        } else {
            String x = positions.substring(0, positions.indexOf(','));
            String y = positions.substring(positions.indexOf(',') + 1);
            autoPositionJS = "Ice.autoPosition.start('" + clientId + "'," + x + "," + y + ","
                    + positionOnLoadOnly + ");";
        }

    } else {
        autoPositionJS = "Ice.autoPosition.stop('" + clientId + "');";
    }
    JavascriptContext.addJavascriptCall(facesContext, "; " + autoPositionJS);

    // autoCentre handling
    boolean autoCentre = panelPopup.isAutoCentre();
    String centreJS;
    if (autoCentre && (!positionOnLoadOnly || (positionOnLoadOnly && !dragged))) {
        centreJS = "Ice.autoCentre.start('" + clientId + "'," + positionOnLoadOnly + ");";
    } else {
        centreJS = "Ice.autoCentre.stop('" + clientId + "');";
    }

    JavascriptContext.addJavascriptCall(facesContext, "; " + centreJS);
    JavascriptContext.addJavascriptCall(facesContext, "; Ice.iFrameFix.start('" + clientId + "','"
            + CoreUtils.resolveResourceURL(facesContext, "/xmlhttp/blank") + "');");
}

From source file:org.apache.shindig.gadgets.render.RenderingGadgetRewriter.java

/**
 * Injects message bundles into the gadget output.
 * @throws GadgetException If we are unable to retrieve the message bundle.
 *//*from  w w w  . j  ava2 s. co  m*/
protected void injectMessageBundles(MessageBundle bundle, Node scriptTag) throws GadgetException {
    String msgs = bundle.toJSONString();

    Text text = scriptTag.getOwnerDocument().createTextNode("gadgets.Prefs.setMessages_(");
    text.appendData(msgs);
    text.appendData(");");
    scriptTag.appendChild(text);
}

From source file:org.apache.shindig.gadgets.render.RenderingGadgetRewriter.java

/**
 * Injects default values for user prefs into the gadget output.
 *//* w w w.j ava 2  s.c o  m*/
protected void injectDefaultPrefs(Gadget gadget, Node scriptTag) {
    Collection<UserPref> prefs = gadget.getSpec().getUserPrefs().values();
    Map<String, String> defaultPrefs = Maps.newHashMapWithExpectedSize(prefs.size());
    for (UserPref up : prefs) {
        defaultPrefs.put(up.getName(), up.getDefaultValue());
    }
    Text text = scriptTag.getOwnerDocument().createTextNode("gadgets.Prefs.setDefaultPrefs_(");
    text.appendData(JsonSerializer.serialize(defaultPrefs));
    text.appendData(");");
    scriptTag.appendChild(text);
}

From source file:org.apache.shindig.gadgets.render.RenderingGadgetRewriter.java

/**
 * Injects preloads into the gadget output.
 *
 * If preloading fails for any reason, we just output an empty object.
 *///  w w w.ja  va2s  . c  om
protected void injectPreloads(Gadget gadget, Node scriptTag) {
    List<Object> preload = Lists.newArrayList();
    for (PreloadedData preloaded : gadget.getPreloads()) {
        try {
            preload.addAll(preloaded.toJson());
        } catch (PreloadException pe) {
            // This will be thrown in the event of some unexpected exception. We can move on.
            LOG.log(Level.WARNING, "Unexpected error when preloading", pe);
        }
    }
    Text text = scriptTag.getOwnerDocument().createTextNode("gadgets.io.preloaded_=");
    text.appendData(JsonSerializer.serialize(preload));
    text.appendData(";");
    scriptTag.appendChild(text);
}

From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java

/**
 * __UNDOCUMENTED__//from   w w w  .  j a v  a 2  s.  c  o  m
 *
 * @param xForm      __UNDOCUMENTED__
 * @param annotation __UNDOCUMENTED__
 * @return __UNDOCUMENTED__
 */
protected Element addHintFromDocumentation(Document xForm, XSAnnotation annotation) {
    if (annotation != null) {
        Element hintElement = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "hint");
        this.setXFormsId(hintElement);

        Text hintText = (Text) hintElement.appendChild(xForm.createTextNode(""));

        //write annotation to empty doc
        Document doc = DOMUtil.newDocument(true, false);
        annotation.writeAnnotation(doc, XSAnnotation.W3C_DOM_DOCUMENT);

        //get "annotation" element
        NodeList annots = doc.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "annotation");
        if (annots.getLength() > 0) {
            Element annotEl = (Element) annots.item(0);

            //documentation
            NodeList docos = annotEl.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema",
                    "documentation");
            int nbDocos = docos.getLength();
            for (int j = 0; j < nbDocos; j++) {
                Element doco = (Element) docos.item(j);

                //get text value
                String text = DOMUtil.getTextNodeAsString(doco);
                hintText.appendData(text);

                if (j < nbDocos - 1) {
                    hintText.appendData(" ");
                }
            }
            return hintElement;
        }
        return null;
    }

    return null;
}