Example usage for org.w3c.dom Element removeAttribute

List of usage examples for org.w3c.dom Element removeAttribute

Introduction

In this page you can find the example usage for org.w3c.dom Element removeAttribute.

Prototype

public void removeAttribute(String name) throws DOMException;

Source Link

Document

Removes an attribute by name.

Usage

From source file:name.vysoky.epub.Part.java

private void removeStyleClass(Element element, String styleClass) {
    String classAttributeValue = element.getAttribute("class");
    if (classAttributeValue != null && classAttributeValue.contains(styleClass)) {
        classAttributeValue = removeStyleClass(classAttributeValue, styleClass);
        if (classAttributeValue.isEmpty())
            element.removeAttribute("class");
        else//from  w w w  . j a v a 2 s  . c om
            element.setAttribute("class", classAttributeValue);
        if (element.getTagName().equals("span") && hasNoStyleInformation(element))
            DomUtils.removeElement(element, true);
    }
    // recursive call
    for (Element child : listChildElements(element))
        removeStyleClass(child, styleClass);
}

From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.AbstractXmlElementConverter.java

protected void setAttribute(Element xmlElement, String attributeName, Object value,
        Properties catalinaProperties, boolean required) {
    String oldValue = xmlElement.getAttribute(attributeName);
    String valueToWrite = determineNewValue(oldValue, value, catalinaProperties);
    if (required || (valueToWrite != null && !"".equals(valueToWrite))) {
        xmlElement.setAttribute(attributeName, valueToWrite);
    } else {/*from   w w w. j  a  va 2 s .com*/
        xmlElement.removeAttribute(attributeName);
    }
}

From source file:org.alfresco.web.config.ConfigRuntime.java

/**
 * @param configElem//  www. j a  v  a 2 s .  c  o m
 * @param attrName
 * @param attrValue
 * @return
 */
protected boolean manageAttribute(Element configElem, String attrName, String attrValue) {
    boolean status = false;
    if (attrValue != null && !attrValue.equals("")) {
        if (!configElem.hasAttribute(attrName) || !configElem.getAttribute(attrName).equals(attrValue)) {
            status = true;
        }
        configElem.setAttribute(attrName, attrValue);
    } else {
        if (configElem.hasAttribute(attrName)) {
            configElem.removeAttribute(attrName);
            status = true;
        }
    }
    return status;
}

From source file:com.adaptris.util.XmlUtils.java

/**
 * Method which deletes an attribute from the specified Node, which must be of
 * type org.w3c.dom.Element./* ww w.  jav  a 2 s. c o  m*/
 *
 * @param name the attribute name
 * @param n the node to be modified
 * @throws Exception on error.
 */
public void deleteAttribute(String name, Node n) throws Exception {
    Element e = castOrFail(n, Element.class, "Only Element Nodes have attributes");
    e.removeAttribute(name);
}

From source file:org.dozer.eclipse.plugin.editorpage.DozerModelManager.java

private Binding bindAttr(IDOMDocument document, final IObservableValue parent, final String attrName,
        IObservableValue observedView) {
    IObservableValue observedValue = SSEDOMObservables.observeDetailAttrValue(Realm.getDefault(), parent,
            attrName);/*  w  w  w .  j av a 2 s .c om*/

    //do the binding
    return dataBindingContext.bindValue(observedView, observedValue,
            new UpdateValueStrategy().setConverter(new Converter(String.class, String.class) {

                public Object convert(Object fromObject) {
                    //remove node if value is set to empty
                    if ("".equals(fromObject.toString())) {
                        Element element = (Element) parent.getValue();
                        element.removeAttribute(attrName);
                        return null;
                    }

                    return fromObject;
                }

            }).setBeforeSetValidator(new IValidator() {

                public IStatus validate(Object value) {
                    //dont set value if it is null. Thus no parent node gets created.
                    //The parent node has been deleted in converter
                    return value == null ? Status.CANCEL_STATUS : Status.OK_STATUS;
                }

            }), null);
}

From source file:org.dozer.eclipse.plugin.editorpage.DozerModelManager.java

private Binding bindMethodAttr(IDOMDocument document, final IObservableValue parent, final String attrName,
        ObservableSingleSelectionObject observedView, List<IMethod> existingMethods) {
    IObservableValue observedValue = SSEDOMObservables.observeDetailAttrValue(Realm.getDefault(), parent,
            attrName);/* ww  w  .j  a  v  a 2s  . c  o  m*/

    //do the binding
    return dataBindingContext.bindValue(observedView.getValue(), observedValue,
            new UpdateValueStrategy().setConverter(new Converter(IMethod.class, String.class) {

                public Object convert(Object fromObject) {
                    IMethod method = (IMethod) fromObject;
                    String value = null;

                    if (method != null)
                        value = method.getElementName();

                    //remove node if value is set to empty
                    if ("".equals(value.toString()) || value == null) {
                        Element element = (Element) parent.getValue();
                        element.removeAttribute(attrName);
                        return null;
                    }

                    return value;
                }

            }).setBeforeSetValidator(new IValidator() {

                public IStatus validate(Object value) {
                    //dont set value if it is null. Thus no parent node gets created.
                    //The parent node has just been deleted in converter
                    return value == null ? Status.CANCEL_STATUS : Status.OK_STATUS;
                }

            }), new UpdateValueStrategy()
                    .setConverter(new StringToMethodConverter(existingMethods, observedView.getViewer())));
}

From source file:com.icesoft.faces.component.panelpositioned.PanelPositionedRenderer.java

public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {

    try {// ww  w.j a  va  2s . c o  m
        DOMContext domContext = DOMContext.attachDOMContext(facesContext, uiComponent);
        if (!domContext.isInitialized()) {
            Element root = domContext.createRootElement(HTML.DIV_ELEM);
            domContext.setRootNode(root);
            setRootElementId(facesContext, root, uiComponent);

            String style = ((PanelPositioned) uiComponent).getStyle();
            String styleClass = ((PanelPositioned) uiComponent).getStyleClass();
            if (style != null && style.length() > 0)
                root.setAttribute(HTML.STYLE_ATTR, style);
            else
                root.removeAttribute(HTML.STYLE_ATTR);
            if (styleClass != null && styleClass.length() > 0)
                root.setAttribute(HTML.CLASS_ATTR, styleClass);
            else
                root.removeAttribute(HTML.CLASS_ATTR);
            Element orderField = domContext.createElement(HTML.INPUT_ELEM);
            String orderFieldId = ClientIdPool.get(getHiddenFieldName(facesContext, uiComponent, INPUT_ID));
            orderField.setAttribute(HTML.ID_ATTR, orderFieldId);
            orderField.setAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN);
            orderField.setAttribute(HTML.NAME_ATTR, orderFieldId);
            orderField.setAttribute(HTML.VALUE_ATTR, "");

            if (isChanged(facesContext)) {
                // Force the re rendering of the entire component. This is due to a strange quick with positioned
                // panel. When an element is moved in the same list then it container element moves with it
                // When the update occurs the elements are replaced but because the containers have moved
                // then the result looks the same. (But a refresh shows otherwise)
                Node node = domContext.createTextNodeUnescaped("<!-- " + (new Random().nextInt(1000)) + "-->");
                root.appendChild(node);
            }
            root.appendChild(orderField);

        }

        Element root = (Element) domContext.getRootNode();
        if (!Beans.isDesignTime()) {
            DOMContext.removeChildrenByTagName(root, HTML.DIV_ELEM);
        }
    } catch (Exception e) {
        log.error("Encode Begin", e);
    }
}

From source file:com.enonic.vertical.adminweb.ContentObjectHandlerServlet.java

public void handlerCopy(HttpServletRequest request, HttpServletResponse response, HttpSession session,
        AdminService admin, ExtendedMap formItems, User user, int key)
        throws VerticalAdminException, VerticalEngineException {

    String xmlCO = admin.getContentObject(Integer.parseInt(request.getParameter("key")));
    Document doc = XMLTool.domparse(xmlCO);

    Element nameElem = (Element) XMLTool.selectNode(doc, "/contentobjects/contentobject/name");
    Node[] nameArray = XMLTool.filterNodes(nameElem.getChildNodes(), Node.TEXT_NODE);

    Text name = (Text) nameArray[0];
    AdminConsoleTranslationService languageMap = AdminConsoleTranslationService.getInstance();
    Map translationMap = languageMap.getTranslationMap(user.getSelectedLanguageCode());
    name.setData(name.getData() + " (" + translationMap.get("%txtCopy%") + ")");

    Element coElem = (Element) XMLTool.selectNode(doc, "/contentobjects/contentobject");
    coElem.removeAttribute("key");

    Element docRoot = doc.getDocumentElement();
    doc.replaceChild(coElem, docRoot);/* w  ww.j a v a2  s. c  o m*/

    key = admin.createContentObject(user, XMLTool.documentToString(doc));

    redirectClientToReferer(request, response);
}

From source file:com.enonic.vertical.adminweb.ContentObjectHandlerServlet.java

private void addStyleSheet(Element contentobjectElem, String elemName, ResourceKey styleSheetKey)
        throws VerticalAdminException {

    ResourceFile resource = resourceService.getResourceFile(styleSheetKey);
    if (resource == null) {
        throw new StylesheetNotFoundException(styleSheetKey);
    }//from  ww  w  .  j a v  a2 s. c  o m
    Document styleSheetDoc;
    try {
        styleSheetDoc = resource.getDataAsXml().getAsDOMDocument();
    } catch (XMLException e) {
        throw new InvalidStylesheetException(styleSheetKey, e);
    }

    Element styleSheetRoot = styleSheetDoc.getDocumentElement();
    String attr = styleSheetRoot.getAttribute("xmlns:xsl");
    styleSheetRoot.removeAttribute("xmlns:xsl");
    styleSheetRoot.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsl", attr);
    Document doc = contentobjectElem.getOwnerDocument();
    Element elem = XMLTool.createElement(doc, contentobjectElem, elemName);
    elem.appendChild(doc.importNode(styleSheetRoot, true));
}

From source file:com.icesoft.faces.component.selectinputtext.SelectInputTextRenderer.java

public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    validateParameters(facesContext, uiComponent, null);
    if (log.isTraceEnabled()) {
        log.trace("encodeBegin");
    }/*w ww  .jav a  2 s  . co m*/
    SelectInputText component = (SelectInputText) uiComponent;
    DOMContext domContext = DOMContext.attachDOMContext(facesContext, uiComponent);
    String clientId = uiComponent.getClientId(facesContext);
    String divId = ClientIdPool.get(clientId + AUTOCOMPLETE_DIV);

    if (!domContext.isInitialized()) {
        Element root = domContext.createRootElement(HTML.DIV_ELEM);
        Element input = domContext.createElement(HTML.INPUT_ELEM);
        input.setAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_TEXT);
        setRootElementId(facesContext, input, uiComponent);
        root.appendChild(input);
        input.setAttribute(HTML.NAME_ATTR, clientId);
        input.setAttribute(HTML.CLASS_ATTR, component.getInputTextClass());

        String mousedownScript = (String) uiComponent.getAttributes().get(HTML.ONMOUSEDOWN_ATTR);
        input.setAttribute(HTML.ONMOUSEDOWN_ATTR, combinedPassThru(mousedownScript, "this.focus();"));

        String inputStyle = component.getWidthAsStyle();
        if (inputStyle != null && inputStyle.length() > 0)
            input.setAttribute(HTML.STYLE_ATTR, inputStyle);
        else
            input.removeAttribute(HTML.STYLE_ATTR);
        input.setAttribute("autocomplete", "off");
        Element div = domContext.createElement(HTML.DIV_ELEM);
        String listClass = component.getListClass();

        div.setAttribute(HTML.ID_ATTR, divId);
        if (listClass == null) {
            div.setAttribute(HTML.STYLE_ATTR,
                    "display:none;border:1px solid black;background-color:white;z-index:500;");
        } else {
            div.setAttribute(HTML.CLASS_ATTR, listClass);
        }
        root.appendChild(div);

        Element index = domContext.createElement(HTML.INPUT_ELEM);
        index.setAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN);
        String indexId = ClientIdPool.get(clientId + AUTOCOMPLETE_INDEX);
        index.setAttribute(HTML.NAME_ATTR, indexId);
        root.appendChild(index);

        String rootStyle = component.getStyle();
        if (rootStyle != null && rootStyle.length() > 0)
            root.setAttribute(HTML.STYLE_ATTR, rootStyle);
        else
            root.removeAttribute(HTML.STYLE_ATTR);
        root.setAttribute(HTML.CLASS_ATTR, component.getStyleClass());

        //  Element script = domContext.createElement(HTML.SCRIPT_ELEM);
        //  script.setAttribute(HTML.SCRIPT_LANGUAGE_ATTR,
        //  HTML.SCRIPT_LANGUAGE_JAVASCRIPT);
        //     String scriptCode = "window.onLoad(function(){" + call + "});";
        //   Node node = domContext.createTextNode(scriptCode);
        //  script.appendChild(node);
        //  root.appendChild(script);
        if (log.isDebugEnabled()) {
            log.debug("SelectInputText:encodeBegin():component created with the following id : " + clientId);
        }
        PassThruAttributeRenderer.renderHtmlAttributes(facesContext, uiComponent, input, null,
                passThruAttributes);
        PassThruAttributeRenderer.renderHtmlAttributes(facesContext, uiComponent, input, null,
                new String[] { HTML.TABINDEX_ATTR });
        PassThruAttributeRenderer.renderBooleanAttributes(facesContext, uiComponent, input,
                PassThruAttributeRenderer.EMPTY_STRING_ARRAY);

        Element scriptEle = domContext.createElement(HTML.SCRIPT_ELEM);
        scriptEle.setAttribute(HTML.ID_ATTR, ClientIdPool.get(clientId + "script"));
        scriptEle.setAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT);
        boolean partialSubmit = component.getPartialSubmit();
        if (!component.isDisabled() && !component.isReadonly()) {
            Node node = domContext.createTextNodeUnescaped("new Ice.Autocompleter('" + clientId + "','" + divId
                    + "', " + component.getOptions() + " ,'" + component.getRowClass() + "','"
                    + component.getSelectedRowClass() + "'," + partialSubmit + ");");
            scriptEle.appendChild(node);
        }
        root.appendChild(scriptEle);

        Map domUpdateMap = new HashMap();
        domUpdateMap.put("rows", component.getRows());
        Element span = domContext.createElement(HTML.SPAN_ELEM);
        span.setAttribute("data-hashcode", String.valueOf(domUpdateMap.hashCode()));
        span.setAttribute("style", "display: none;");
        root.appendChild(span);
    }
}