List of usage examples for org.w3c.dom Element setAttribute
public void setAttribute(String name, String value) throws DOMException;
From source file:org.joy.config.Configuration.java
private void writeTemplate(Element elem, TemplateElement t) { Element e = elem.getOwnerDocument().createElement("template"); e.setAttribute("name", t.getTemplateName()); e.setAttribute("engine", t.getEngine()); e.setAttribute("selected", String.valueOf(t.isSelected())); setTextChild(e, "templateFile", t.getTemplateFile()); setTextChild(e, "targetPath", t.getTargetPath()); setTextChild(e, "targetFileName", t.getTargetFileName()); setTextChild(e, "encoding", t.getEncoding()); elem.appendChild(e);// www . j a v a2 s . c o m }
From source file:net.phoenix.thrift.xml.ArgsBeanDefinitionParser.java
@Override protected void preParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { Element parent = (Element) element.getParentNode(); String name = parent.getAttribute("name") + BEAN_NAME_SUFFIX; if (StringUtils.isEmpty(element.getAttribute("id"))) { element.setAttribute("id", name); }//from w w w . ja v a2 s . com if (StringUtils.isEmpty(element.getAttribute("name"))) { element.setAttribute("name", name); } builder.addConstructorArgValue(this.buildSocket(element)); }
From source file:org.getwheat.harvest.library.dom.DomHelper.java
/** * Adds an {@link Element} to the parent if the value is not null. * <p />//from www. ja v a2 s . c om * A type attribute is also added to the {@link Element}. * * @param document * @param parent * @param tag * @param value */ public void addElement(final Document document, final Element parent, final XmlTag tag, final Integer value) { if (value != null) { final Element element = addElement(document, parent, tag, value.toString()); element.setAttribute(VALUE_TYPE, VALUE_INTEGER); } }
From source file:org.getwheat.harvest.library.dom.DomHelper.java
/** * Adds an {@link Element} to the parent if the value is not null. * <p />//from w ww. ja v a2 s .c o m * A type attribute is also added to the {@link Element}. * * @param document * @param parent * @param tag * @param value */ public void addElement(final Document document, final Element parent, final XmlTag tag, final BigDecimal value) { if (value != null) { final Element element = addElement(document, parent, tag, value.toString()); element.setAttribute(VALUE_TYPE, VALUE_DECIMAL); } }
From source file:org.getwheat.harvest.library.dom.DomHelper.java
/** * Adds an {@link Element} to the parent. * <p />/* w w w .ja v a2 s .co m*/ * A type attribute is also added to the {@link Element}. * * @param document * @param parent * @param tag * @param value */ public void addElement(final Document document, final Element parent, final XmlTag tag, final boolean value) { final Element element = addElement(document, parent, tag, Boolean.toString(value)); element.setAttribute(VALUE_TYPE, VALUE_BOOLEAN); }
From source file:com.icesoft.faces.component.selectinputtext.SelectInputTextRenderer.java
public void populateList(FacesContext facesContext, SelectInputText component) throws IOException { if (log.isTraceEnabled()) { log.trace("populateList"); }// ww w .j ava2s .co m component.populateItemList(); Iterator matches = component.getItemList(); int rows = component.getRows(); if (rows == 0) rows = Integer.MAX_VALUE; int rowCounter = 0; if (component.getSelectFacet() != null) { if (log.isDebugEnabled()) { log.debug( "SelectInputText:populateList(): \"selectInputText\" facet found, generate generic html for list"); } UIComponent facet = component.getSelectFacet(); DOMContext domContext = DOMContext.getDOMContext(facesContext, component); Element listDiv = domContext.createElement(HTML.DIV_ELEM); Map requestMap = facesContext.getExternalContext().getRequestMap(); //set index to 0, so child components can get client id from autoComplete component component.setIndex(0); while (matches.hasNext() && rowCounter++ < rows) { Element div = domContext.createElement(HTML.DIV_ELEM); SelectItem item = (SelectItem) matches.next(); requestMap.put(component.getListVar(), item.getValue()); listDiv.appendChild(div); // When HTML is display we still need a selected value. Hidding the value in a hidden span // accomplishes this. Element spanToDisplay = domContext.createElement(HTML.SPAN_ELEM); spanToDisplay.setAttribute(HTML.CLASS_ATTR, "informal"); div.appendChild(spanToDisplay); domContext.setCursorParent(spanToDisplay); encodeParentAndChildren(facesContext, facet); Element spanToSelect = domContext.createElement(HTML.SPAN_ELEM); spanToSelect.setAttribute(HTML.STYLE_ATTR, "visibility:hidden;display:none;"); String itemLabel = item.getLabel(); if (itemLabel == null) { itemLabel = converterGetAsString(facesContext, component, item.getValue()); } Text label = domContext.createTextNode((itemLabel)); spanToSelect.appendChild(label); div.appendChild(spanToSelect); component.resetId(facet); } component.setIndex(-1); String nodeValue = DOMUtils.nodeToString(listDiv).replaceAll("\n", ""); String call = "Ice.Scriptaculous.Autocompleter.Finder.find('" + component.getClientId(facesContext) + "').updateNOW('" + escapeSingleQuote(nodeValue) + "');"; JavascriptContext.addJavascriptCall(facesContext, call); } else { if (log.isDebugEnabled()) { log.debug("SelectInputText:populateList(): \"selectItem(s)\" found, generate plain-text for list"); } if (matches.hasNext()) { StringBuffer sb = new StringBuffer("<div>"); SelectItem item = null; while (matches.hasNext() && rowCounter++ < rows) { item = (SelectItem) matches.next(); String itemLabel = item.getLabel(); if (itemLabel == null) { itemLabel = converterGetAsString(facesContext, component, item.getValue()); } sb.append("<div>").append(DOMUtils.escapeAnsi(itemLabel)).append("</div>"); } sb.append("</div>"); String call = "Ice.Scriptaculous.Autocompleter.Finder.find('" + component.getClientId(facesContext) + "').updateNOW('" + escapeSingleQuote(sb.toString()) + "');"; JavascriptContext.addJavascriptCall(facesContext, call); } } }
From source file:chat.viska.xmpp.plugins.webrtc.WebRtcPlugin.java
@Nonnull public Completable sendIceCandidates(@Nonnull final Jid recipient, @Nonnull final String id, @Nonnull final Collection<IceCandidate> candidates) { final Document iq = Stanza.getIqTemplate(Stanza.IqType.SET, UUID.randomUUID().toString(), getSession().getNegotiatedJid(), recipient); final Element webrtc = (Element) iq.getDocumentElement().appendChild(iq.createElementNS(XMLNS, "webrtc")); webrtc.setAttribute("id", id); for (IceCandidate candidate : candidates) { final Element candidateElement = (Element) webrtc.appendChild(iq.createElement("ice-candidate")); candidateElement.setAttribute("sdpMLineIndex", Integer.toString(candidate.sdpMLineIndex)); if (StringUtils.isNotBlank(candidate.sdpMid)) { candidateElement.setAttribute("sdpMid", candidate.sdpMid); }/*from w w w. j av a 2 s .c om*/ if (StringUtils.isNotBlank(candidate.sdp)) { final Element sdpElement = (Element) candidateElement.appendChild(iq.createElement("sdp")); for (String line : candidate.sdp.split(REGEX_LINE_BREAK)) { final Node node = sdpElement.appendChild(iq.createElement("line")); node.setTextContent(line); } } } return this.context.sendIq(new XmlWrapperStanza(iq)).getResponse().toSingle().toCompletable(); }
From source file:eu.europa.esig.dss.xades.signature.XAdESBuilder.java
/** * This method creates the ds:DigestMethod DOM object * * @param parentDom/*w ww.j a va 2 s . c o m*/ * @param digestAlgorithm digest algorithm xml identifier */ protected void incorporateDigestMethod(final Element parentDom, final DigestAlgorithm digestAlgorithm) { // <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> final Element digestMethodDom = documentDom.createElementNS(XMLNS, DS_DIGEST_METHOD); final String digestAlgorithmXmlId = digestAlgorithm.getXmlId(); digestMethodDom.setAttribute(ALGORITHM, digestAlgorithmXmlId); parentDom.appendChild(digestMethodDom); }
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"); }/*from ww w . j av a 2s . c o 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); } }
From source file:edu.umd.cfar.lamp.viper.examples.textline.AttributeWrapperTextline.java
/** * Creates an XML element from the given object o * /*from w w w . ja va2 s .c om*/ * @return the XML serialization of o (a TextlineModel object) */ public Element getXMLFormat(Document root, Object o, Node container) { String qualifier = ViperData.ViPER_DATA_QUALIFIER; String uri = ViperData.ViPER_DATA_URI; Element el = root.createElementNS(uri, qualifier + "textline"); TextlineModel tm = (TextlineModel) o; el.setAttribute(AT_X, String.valueOf(tm.getX())); el.setAttribute(AT_Y, String.valueOf(tm.getY())); el.setAttribute(AT_W, String.valueOf(tm.getWidth())); el.setAttribute(AT_H, String.valueOf(tm.getHeight())); el.setAttribute(AT_R, String.valueOf(tm.getRotation())); el.setAttribute(AT_OCC, String.valueOf(tm.getOcclusionsAsStr())); el.setAttribute(AT_OFF, String.valueOf(tm.getWordOffsetsAsStr())); el.setAttribute(AT_TXT, String.valueOf(tm.getText(null))); return el; }